Skip to content

Commit

Permalink
fix: fiber.isMain() was wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Jul 3, 2024
1 parent 0b0be57 commit 5caca2f
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/builtin/fiber.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn cancel(ctx: *NativeCtx) c_int {
pub fn isMain(ctx: *NativeCtx) c_int {
const self = ObjFiber.cast(ctx.vm.peek(0).obj()).?;

ctx.vm.push(Value.fromBoolean(ctx.vm.main_fiber == self.fiber));
ctx.vm.push(Value.fromBoolean(self.fiber.parent_fiber == null));

return 1;
}
1 change: 0 additions & 1 deletion src/lib/buzz_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ pub const ObjPattern = opaque {

pub const ObjFiber = opaque {
pub extern fn bz_getFiberProperty(vm: *VM, property_idx: usize) Value;
pub extern fn bz_isMainFiber(self: *ObjFiber, vm: *VM) Value;
};

pub const ObjForeignContainer = opaque {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/std.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ export extern fun currentFiber() > fib<any, any?>;
|| Print message and exit program
extern fun buzzPanic(str message) > void;

export buzzPanic as panic;
export buzzPanic as panic;
2 changes: 0 additions & 2 deletions src/vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ pub const VM = struct {
gc: *GarbageCollector,
current_fiber: *Fiber,
current_ast: Ast,
main_fiber: *Fiber,
globals: std.ArrayList(Value),
globals_count: usize = 0,
import_registry: *ImportRegistry,
Expand All @@ -462,7 +461,6 @@ pub const VM = struct {
.globals = std.ArrayList(Value).init(gc.allocator),
.current_ast = undefined,
.current_fiber = undefined,
.main_fiber = undefined,
.flavor = flavor,
.reporter = Reporter{
.allocator = gc.allocator,
Expand Down
2 changes: 2 additions & 0 deletions tests/038-fibers.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ test "fiber" {
std.assert(sum == 45, message: "Sum is good");

std.assert(resolve &count(10) == "Counting is done!", message: "Resolve without any resume");

std.assert(std.currentFiber().isMain(), message: "We recognize main fiber");
}

| returns str, yields int
Expand Down

0 comments on commit 5caca2f

Please sign in to comment.