diff --git a/src/Ast.zig b/src/Ast.zig index d59e156c..22405996 100644 --- a/src/Ast.zig +++ b/src/Ast.zig @@ -231,11 +231,11 @@ pub fn usesFiber(self: Self, node: Node.Index, seen: *std.AutoHashMap(Node.Index return switch (self.nodes.items(.tag)[node]) { .As => try self.usesFiber(components.As.left, seen), .AsyncCall, - .Resolve, .Resume, - .Yield, + .Resolve, => true, - .Binary => try self.usesFiber(components.Binary.left, seen) or try self.usesFiber(components.Binary.right, seen), + .Binary => try self.usesFiber(components.Binary.left, seen) or + try self.usesFiber(components.Binary.right, seen), .Block => blk: { for (components.Block) |stmt| { if (try self.usesFiber(stmt, seen)) { @@ -264,7 +264,10 @@ pub fn usesFiber(self: Self, node: Node.Index, seen: *std.AutoHashMap(Node.Index break :blk false; }, .Call => call: { - if (try self.usesFiber(components.Call.callee, seen) or (components.Call.catch_default != null and try self.usesFiber(components.Call.catch_default.?, seen))) { + if (try self.usesFiber(components.Call.callee, seen) or + (components.Call.catch_default != null and + try self.usesFiber(components.Call.catch_default.?, seen))) + { break :call true; } @@ -319,10 +322,15 @@ pub fn usesFiber(self: Self, node: Node.Index, seen: *std.AutoHashMap(Node.Index break :for_loop false; }, .ForceUnwrap => try self.usesFiber(components.ForceUnwrap.unwrapped, seen), - .ForEach => try self.usesFiber(components.ForEach.iterable, seen) or try self.usesFiber(components.ForEach.key, seen) or try self.usesFiber(components.ForEach.value, seen) or try self.usesFiber(components.ForEach.body, seen), + .ForEach => try self.usesFiber(components.ForEach.iterable, seen) or + try self.usesFiber(components.ForEach.key, seen) or + try self.usesFiber(components.ForEach.value, seen) or + try self.usesFiber(components.ForEach.body, seen), .Function => components.Function.body != null and try self.usesFiber(components.Function.body.?, seen), .Grouping => try self.usesFiber(components.Grouping, seen), - .If => try self.usesFiber(components.If.condition, seen) or try self.usesFiber(components.If.body, seen) or (components.If.else_branch != null and try self.usesFiber(components.If.else_branch.?, seen)), + .If => try self.usesFiber(components.If.condition, seen) or + try self.usesFiber(components.If.body, seen) or (components.If.else_branch != null and + try self.usesFiber(components.If.else_branch.?, seen)), .Is => try self.usesFiber(components.Is.left, seen), .List => list: { for (components.List.items) |item| { @@ -335,14 +343,17 @@ pub fn usesFiber(self: Self, node: Node.Index, seen: *std.AutoHashMap(Node.Index }, .Map => map: { for (components.Map.entries) |entry| { - if (try self.usesFiber(entry.key, seen) or try self.usesFiber(entry.value, seen)) { + if (try self.usesFiber(entry.key, seen) or + try self.usesFiber(entry.value, seen)) + { break :map true; } } break :map false; }, - .NamedVariable => components.NamedVariable.value != null and try self.usesFiber(components.NamedVariable.value.?, seen), + .NamedVariable => components.NamedVariable.value != null and + try self.usesFiber(components.NamedVariable.value.?, seen), .ObjectInit => obj_init: { for (components.ObjectInit.properties) |property| { if (try self.usesFiber(property.value, seen)) { @@ -353,12 +364,17 @@ pub fn usesFiber(self: Self, node: Node.Index, seen: *std.AutoHashMap(Node.Index break :obj_init false; }, .Out => try self.usesFiber(components.Out, seen), - .Range => try self.usesFiber(components.Range.low, seen) or try self.usesFiber(components.Range.high, seen), + .Range => try self.usesFiber(components.Range.low, seen) or + try self.usesFiber(components.Range.high, seen), .Return => components.Return.value != null and try self.usesFiber(components.Return.value.?, seen), - .Subscript => try self.usesFiber(components.Subscript.subscripted, seen) or try self.usesFiber(components.Subscript.index, seen) or (components.Subscript.value != null and try self.usesFiber(components.Subscript.value.?, seen)), + .Subscript => try self.usesFiber(components.Subscript.subscripted, seen) or + try self.usesFiber(components.Subscript.index, seen) or + (components.Subscript.value != null and try self.usesFiber(components.Subscript.value.?, seen)), .Throw => try self.usesFiber(components.Throw.expression, seen), .Try => @"try": { - if (try self.usesFiber(components.Try.body, seen) or (components.Try.unconditional_clause != null and try self.usesFiber(components.Try.unconditional_clause.?, seen))) { + if (try self.usesFiber(components.Try.body, seen) or + (components.Try.unconditional_clause != null and try self.usesFiber(components.Try.unconditional_clause.?, seen))) + { break :@"try" true; } @@ -375,6 +391,7 @@ pub fn usesFiber(self: Self, node: Node.Index, seen: *std.AutoHashMap(Node.Index .Unwrap => try self.usesFiber(components.Unwrap.unwrapped, seen), .VarDeclaration => components.VarDeclaration.value != null and try self.usesFiber(components.VarDeclaration.value.?, seen), .While => try self.usesFiber(components.While.condition, seen) or try self.usesFiber(components.While.body, seen), + .Yield => false, // Yield is an issue only if the function is called within a fiber, and we already forbid async call from being jit compiled else => false, }; } diff --git a/src/Jit.zig b/src/Jit.zig index aaeb9c2f..94f8dbe4 100644 --- a/src/Jit.zig +++ b/src/Jit.zig @@ -509,10 +509,10 @@ fn generateNode(self: *Self, node: Ast.Node.Index) Error!?m.MIR_op_t { .ForEach => try self.generateForEach(node), .TypeExpression => try self.generateTypeExpression(node), .TypeOfExpression => try self.generateTypeOfExpression(node), + .Yield => try self.generateNode(components[node].Yield), .AsyncCall, .Resume, .Resolve, - .Yield, => return Error.CantCompile, else => { diff --git a/src/obj.zig b/src/obj.zig index 34763753..2fb1250f 100644 --- a/src/obj.zig +++ b/src/obj.zig @@ -434,7 +434,8 @@ pub const Obj = struct { .List => ObjList.cast(self).?.type_def.eql(type_def), .Map => ObjMap.cast(self).?.type_def.eql(type_def), .Fiber => ObjFiber.cast(self).?.type_def.eql(type_def), - .UserData, .Native => unreachable, // TODO + .UserData => type_def.def_type == .UserData, + .Native => unreachable, // TODO }; }