diff --git a/src/Ast.zig b/src/Ast.zig index d59e156c..403796ff 100644 --- a/src/Ast.zig +++ b/src/Ast.zig @@ -157,8 +157,8 @@ pub const Node = struct { As: IsAs, AsyncCall: Node.Index, Binary: Binary, - Block: []Node.Index, - BlockExpression: []Node.Index, + Block: []const Node.Index, + BlockExpression: []const Node.Index, Boolean: bool, Break: ?Node.Index, Call: Call, @@ -202,7 +202,7 @@ pub const Node = struct { Return: Return, // The type should be taken from the type_def field and not the token SimpleType: void, - String: []Node.Index, + String: []const Node.Index, StringLiteral: *obj.ObjString, Subscript: Subscript, Throw: Throw, @@ -380,7 +380,7 @@ pub fn usesFiber(self: Self, node: Node.Index, seen: *std.AutoHashMap(Node.Index } pub const AnonymousObjectType = struct { - fields: []Field, + fields: []const Field, pub const Field = struct { name: TokenIndex, @@ -399,7 +399,7 @@ pub const Call = struct { callee: Node.Index, // We need this because in a dot.call, callee is dot and its type will be == to call return type callee_type_def: *obj.ObjTypeDef, - arguments: []Argument, + arguments: []const Argument, catch_default: ?Node.Index, tail_call: bool = false, @@ -436,7 +436,7 @@ pub const Enum = struct { name: TokenIndex, case_type: ?Node.Index, slot: Slot, - cases: []Case, + cases: []const Case, pub const Case = struct { name: TokenIndex, @@ -457,9 +457,9 @@ pub const FiberType = struct { }; pub const For = struct { - init_declarations: []Node.Index, + init_declarations: []const Node.Index, condition: Node.Index, - post_loop: []Node.Index, + post_loop: []const Node.Index, body: Node.Index, label: ?TokenIndex, }; @@ -506,8 +506,8 @@ pub const Function = struct { pub const Entry = struct { main_slot: ?usize = null, main_location: ?TokenIndex = null, - test_slots: []usize, - test_locations: []TokenIndex, + test_slots: []const usize, + test_locations: []const TokenIndex, exported_count: usize = 0, }; }; @@ -516,9 +516,9 @@ pub const FunctionType = struct { name: ?TokenIndex, return_type: ?Node.Index, yield_type: ?Node.Index, - error_types: []Node.Index, - arguments: []Argument, - generic_types: []TokenIndex, + error_types: []const Node.Index, + arguments: []const Argument, + generic_types: []const TokenIndex, lambda: bool, pub const Argument = struct { @@ -536,7 +536,7 @@ pub const FunDeclaration = struct { }; pub const GenericResolveType = struct { - resolved_types: []Node.Index, + resolved_types: []const Node.Index, }; pub const If = struct { @@ -549,7 +549,7 @@ pub const If = struct { }; pub const Import = struct { - imported_symbols: []TokenIndex, + imported_symbols: []const TokenIndex, prefix: ?TokenIndex, path: TokenIndex, import: ?Parser.ScriptImport, @@ -562,7 +562,7 @@ pub const IsAs = struct { pub const List = struct { explicit_item_type: ?TokenIndex, - items: []Node.Index, + items: []const Node.Index, }; pub const ListType = struct { @@ -573,7 +573,7 @@ pub const Map = struct { explicit_key_type: ?Node.Index, explicit_value_type: ?Node.Index, - entries: []Entry, + entries: []const Entry, pub const Entry = struct { key: Node.Index, @@ -605,10 +605,10 @@ pub const NamedVariable = struct { pub const ObjectDeclaration = struct { name: TokenIndex, slot: Slot, - protocols: []Node.Index, - generics: []TokenIndex, + protocols: []const Node.Index, + generics: []const TokenIndex, // List of either Function (methods) or VarDeclaration (properties) - members: []Member, + members: []const Member, pub const Member = struct { name: TokenIndex, @@ -620,7 +620,7 @@ pub const ObjectDeclaration = struct { pub const ObjectInit = struct { object: ?Node.Index, // Should be a NamedVariableNode or GenericResolve - properties: []Property, + properties: []const Property, pub const Property = struct { name: TokenIndex, @@ -631,7 +631,7 @@ pub const ObjectInit = struct { pub const ProtocolDeclaration = struct { name: TokenIndex, slot: Slot, - methods: []Method, + methods: []const Method, pub const Method = struct { docblock: ?TokenIndex, @@ -665,7 +665,7 @@ pub const Throw = struct { pub const Try = struct { body: Node.Index, - clauses: []Clause, + clauses: []const Clause, unconditional_clause: ?Node.Index, pub const Clause = struct { diff --git a/src/Codegen.zig b/src/Codegen.zig index 8b34843d..ff85cbcb 100644 --- a/src/Codegen.zig +++ b/src/Codegen.zig @@ -290,7 +290,7 @@ pub fn emitConstant(self: *Self, location: Ast.TokenIndex, value: Value) !void { } pub fn makeConstant(self: *Self, value: Value) !u24 { - const constant: u24 = try self.current.?.function.?.chunk.addConstant(null, value); + const constant = try self.current.?.function.?.chunk.addConstant(null, value); if (constant > Chunk.max_constants) { self.reportError("Too many constants in one chunk."); return 0; diff --git a/src/Parser.zig b/src/Parser.zig index cd6c5ad8..3157332b 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -848,7 +848,7 @@ pub fn parse(self: *Self, source: []const u8, file_name: []const u8) !?Ast { }) |decl| { var statements = std.ArrayList(Ast.Node.Index).fromOwnedSlice( self.gc.allocator, - self.ast.nodes.items(.components)[body_node].Block, + @constCast(self.ast.nodes.items(.components)[body_node].Block), ); defer statements.shrinkAndFree(statements.items.len); @@ -869,7 +869,7 @@ pub fn parse(self: *Self, source: []const u8, file_name: []const u8) !?Ast { }) |decl| { var statements = std.ArrayList(Ast.Node.Index).fromOwnedSlice( self.gc.allocator, - self.ast.nodes.items(.components)[body_node].Block, + @constCast(self.ast.nodes.items(.components)[body_node].Block), ); defer statements.shrinkAndFree(statements.items.len); @@ -4270,6 +4270,15 @@ fn dot(self: *Self, can_assign: bool, callee: Ast.Node.Index) Error!Ast.Node.Ind const property_field = obj_def.fields.get(member_name); var property_type = if (property_field) |field| field.type_def else null; + if (property_field != null and !property_field.?.static) { + self.reportErrorFmt( + .undefined, + "Static property `{s}` is not defined", + .{ + self.ast.tokens.items(.lexeme)[member_name_token], + }, + ); + } else // Not found, create a placeholder, this is a root placeholder not linked to anything // TODO: test with something else than a name if (property_type == null and self.current_object != null and std.mem.eql( diff --git a/src/Reporter.zig b/src/Reporter.zig index d252115c..fbe62c7f 100644 --- a/src/Reporter.zig +++ b/src/Reporter.zig @@ -12,7 +12,7 @@ const io = @import("io.zig"); const Self = @This(); -// Do not reorder whitout updating documentation, values are explicit so they can be retrieved easily +// Do not reorder without updating documentation, values are explicit so they can be retrieved easily pub const Error = enum(u8) { already_conforming_protocol = 0, arguments_count = 1, diff --git a/src/vm.zig b/src/vm.zig index 87ce5fa5..12dd408c 100644 --- a/src/vm.zig +++ b/src/vm.zig @@ -2073,9 +2073,14 @@ pub const VM = struct { return false; } - inline fn repurposeFrame(self: *Self, closure: *ObjClosure, arg_count: u8, catch_value: ?Value) Error!void { + fn repurposeFrame(self: *Self, closure: *ObjClosure, arg_count: u8, catch_value: ?Value) Error!void { // Is or will be JIT compiled, call and stop there - if (!is_wasm and self.current_fiber.parent_fiber == null and try self.compileAndCall(closure, arg_count, catch_value)) { + if (!is_wasm and self.current_fiber.parent_fiber == null and + try self.compileAndCall( + closure, + arg_count, + catch_value, + )) { return; } @@ -2719,8 +2724,6 @@ pub const VM = struct { fn OP_GET_ENUM_CASE(self: *Self, _: *CallFrame, _: u32, _: OpCode, arg: u24) void { const enum_ = self.peek(0).obj().access(ObjEnum, .Enum, self.gc).?; - _ = self.pop(); - var enum_case: *ObjEnumInstance = self.gc.allocateObject( ObjEnumInstance, ObjEnumInstance{ @@ -2732,6 +2735,7 @@ pub const VM = struct { unreachable; }; + _ = self.pop(); self.push(Value.fromObj(enum_case.toObj())); const next_full_instruction: u32 = self.readInstruction();