Skip to content

Commit

Permalink
Manual GC for cycle detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed Sep 19, 2023
1 parent 4f0b2a8 commit 888198e
Show file tree
Hide file tree
Showing 19 changed files with 1,004 additions and 487 deletions.
8 changes: 8 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ pub const Options = struct {
target: std.zig.CrossTarget,
optimize: std.builtin.OptimizeMode,
useMimalloc: bool,
gc: bool,
};

// deps: struct {
Expand All @@ -296,6 +297,7 @@ fn getDefaultOptions(target: std.zig.CrossTarget, optimize: std.builtin.Optimize
.trace = trace,
.target = target,
.optimize = optimize,
.gc = true,

// Use mimalloc for fast builds.
.useMimalloc = optimize == .ReleaseFast and !target.getCpuArch().isWasm(),
Expand Down Expand Up @@ -328,6 +330,7 @@ fn createBuildOptions(b: *std.build.Builder, opts: Options) !*std.build.Step.Opt
build_options.addOption(bool, "trace", opts.trace);
build_options.addOption(bool, "trackGlobalRC", opts.trackGlobalRc);
build_options.addOption(bool, "is32Bit", is32Bit(opts.target));
build_options.addOption(bool, "gc", opts.gc);
build_options.addOption([]const u8, "full_version", b.fmt("Cyber {s} build-{s}-{s}", .{Version, buildTag, commitTag}));
return build_options;
}
Expand Down Expand Up @@ -440,6 +443,11 @@ pub fn buildCVM(alloc: std.mem.Allocator, step: *std.build.CompileStep, opts: Op
} else {
try cflags.append("-DIS_32BIT=0");
}
if (opts.gc) {
try cflags.append("-DHAS_GC=1");
} else {
try cflags.append("-DHAS_GC=0");
}

// Disable traps for arithmetic/bitshift overflows.
// Note that changing this alone doesn't clear the build cache.
Expand Down
1 change: 1 addition & 0 deletions docs/hugo/content/docs/toc/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ print contents
| `panic(e symbol) noreturn` | Stop execution in the current fiber and starts unwinding the call stack. See [Unexpected Errors]({{<relref "/docs/toc/errors#unexpected-errors">}}). |
| `parseCyber(src any) map` | Parses Cyber source string into structured map object. Currently, only metadata about static declarations is made available but this will be extended to include an AST. |
| `parseCyon(src any) any` | Parses a CYON string into a value. |
| `performGC() map` | Runs the garbage collector once to detect reference cycles and abandoned objects. Returns the statistics of the run in a map value. |
| `pointer(val any) pointer` | Converts a `int` to a `pointer` value, or casts to a `pointer`. This is usually used with FFI. |
| `print(s string) none` | Prints a value as a string to stdout. The new line is also printed. |
| `prints(s string) none` | Prints a value as a string to stdout. |
Expand Down
Loading

0 comments on commit 888198e

Please sign in to comment.