Skip to content

Commit

Permalink
AST refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed May 14, 2024
1 parent b20dc83 commit d272ae8
Show file tree
Hide file tree
Showing 32 changed files with 4,239 additions and 4,822 deletions.
14 changes: 11 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var vmEngine: config.Engine = undefined;
var testFilter: ?[]const u8 = undefined;
var testBackend: config.TestBackend = undefined;
var trace: bool = undefined;
var link_test: bool = undefined;
var optFFI: ?bool = undefined;
var optStatic: ?bool = undefined;
var optJIT: ?bool = undefined;
Expand Down Expand Up @@ -41,6 +42,7 @@ pub fn build(b: *std.Build) !void {
trace = b.option(bool, "trace", "Enable tracing features.") orelse (optimize == .Debug);
optJIT = b.option(bool, "jit", "Build with JIT.");
optRT = b.option(config.Runtime, "rt", "Runtime.");
link_test = b.option(bool, "link-test", "Build test by linking lib. Disable for better stack traces.") orelse true;

tcc = tcc_lib.createModule(b);
mimalloc = mimalloc_lib.createModule(b);
Expand Down Expand Up @@ -303,7 +305,11 @@ pub const Options = struct {
cli: bool,
jit: bool,
rt: config.Runtime,

/// Link with the lib when building test root.
/// Disable to see better Zig stack traces.
link_test: bool,

export_vmz: bool,

fn applyOverrides(self: *Options) void {
Expand Down Expand Up @@ -347,7 +353,7 @@ fn getDefaultOptions() Options {
.cli = !target.cpu.arch.isWasm(),
.jit = false,
.rt = .vm,
.link_test = false,
.link_test = link_test,
.export_vmz = true,
};
}
Expand Down Expand Up @@ -424,8 +430,10 @@ fn addBehaviorTest(b: *std.Build, opts: Options) !*std.Build.Step.Compile {
const all = try createAllModule(b, build_options, stdx, opts);
step.root_module.addImport("all", all);

const lib = try buildLib(b, opts);
step.linkLibrary(lib);
if (opts.link_test) {
const lib = try buildLib(b, opts);
step.linkLibrary(lib);
}
return step;
}

Expand Down
4 changes: 2 additions & 2 deletions docs/gen-docs.cy
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,11 @@ type ModulePair:
func genFuncDecl(decl Map) String:
var docLine = decl.get('docs') ?else ''
var params = []
for decl['header']['params'] -> param:
for decl['params'] -> param:
var typeSpec = if (param['typeSpec'] != '') param['typeSpec'] else 'any'
params.append("$(param['name']) $(typeSpec)")
var paramsStr = params.join(', ')
return "> `func $(decl['header']['name'])($(paramsStr)) $(decl['header']['ret'])`\n>\n>$(docLine)\n\n"
return "> `func $(decl['name'])($(paramsStr)) $(decl['ret'])`\n>\n>$(docLine)\n\n"

func genDocsModules():
var modules = [
Expand Down
14 changes: 13 additions & 1 deletion src/all.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
/// Used for behavior test.

pub const cy = @import("cyber.zig");
pub const cli = @import("cli.zig");
pub const cli = @import("cli.zig");

const build_options = @import("build_options");
const std = @import("std");

comptime {
if (!build_options.link_test) {
const lib = @import("lib.zig");
for (std.meta.declarations(lib)) |decl| {
_ = &@field(lib, decl.name);
}
}
}
Loading

0 comments on commit d272ae8

Please sign in to comment.