Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garbage collector reimplementation #25

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
582 changes: 296 additions & 286 deletions src/Gc.zig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/List.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn get(list: *const List, ctx: Vm.Context, index: *const Value, res: *?*Valu
if (r.start < 0 or r.end > list.inner.items.len)
return ctx.throw("index out of bounds");

res.* = try ctx.vm.gc.alloc(.list);
res.* = try ctx.vm.gc.alloc();
res.*.?.* = .{ .list = .{} };
const res_list = &res.*.?.*.list;
try res_list.inner.ensureUnusedCapacity(ctx.vm.gc.gpa, r.count());
Expand All @@ -50,7 +50,7 @@ pub fn get(list: *const List, ctx: Vm.Context, index: *const Value, res: *?*Valu
},
.str => |s| {
if (res.* == null) {
res.* = try ctx.vm.gc.alloc(.int);
res.* = try ctx.vm.gc.alloc();
}

if (mem.eql(u8, s.data, "len")) {
Expand Down
12 changes: 6 additions & 6 deletions src/String.zig
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn get(str: *const String, ctx: Vm.Context, index: *const Value, res: *?*Val
.range => return ctx.frame.fatal(ctx.vm, "TODO str get with ranges"),
.str => |*s| {
if (res.* == null) {
res.* = try ctx.vm.gc.alloc(.int);
res.* = try ctx.vm.gc.alloc();
}

if (mem.eql(u8, s.data, "len")) {
Expand Down Expand Up @@ -190,14 +190,14 @@ pub const methods = struct {
return ctx.throw("unused arguments");
}

const ret = try ctx.vm.gc.alloc(.str);
const ret = try ctx.vm.gc.alloc();
ret.* = Value{ .str = b.finish() };
return ret;
}

pub fn join(str: Value.This([]const u8), ctx: Vm.Context, strs: Value.Variadic([]const u8)) !*Value {
if (strs.t.len == 0) {
const ret = try ctx.vm.gc.alloc(.str);
const ret = try ctx.vm.gc.alloc();
ret.* = Value.string("");
return ret;
}
Expand All @@ -215,7 +215,7 @@ pub const methods = struct {
b.inner.appendSliceAssumeCapacity(arg);
}

const ret = try ctx.vm.gc.alloc(.str);
const ret = try ctx.vm.gc.alloc();
ret.* = Value{ .str = b.finish() };
return ret;
}
Expand All @@ -240,7 +240,7 @@ pub fn as(str: *String, ctx: Vm.Context, type_id: Type) Value.NativeError!*Value
return ctx.throw("cannot cast string to bool");
}

const new_val = try ctx.vm.gc.alloc(type_id);
const new_val = try ctx.vm.gc.alloc();
new_val.* = switch (type_id) {
.int => .{
.int = std.fmt.parseInt(i64, str.data, 0) catch |err|
Expand All @@ -262,7 +262,7 @@ pub fn as(str: *String, ctx: Vm.Context, type_id: Type) Value.NativeError!*Value
}

pub fn from(val: *Value, vm: *Vm) Vm.Error!*Value {
const str = try vm.gc.alloc(.str);
const str = try vm.gc.alloc();

if (val == Value.Null) {
str.* = Value.string("null");
Expand Down
Loading