Compare commits

...

9 commits

Author SHA1 Message Date
5771877457 fix llvm_table shenanigans 2020-07-23 18:07:21 -03:00
2357de5a04 llvm10 time 2020-07-23 18:07:13 -03:00
5713df2a8b more fixes 2020-07-23 17:17:06 -03:00
b0ddffd5fe hashmap changes, part 2 2020-07-23 17:06:43 -03:00
0265eddb2e hashmap changes 2020-07-23 16:56:37 -03:00
56be677c7a at() -> items[] 2020-07-23 16:46:46 -03:00
e0f0ae7f24 toSlice -> items 2020-07-23 16:42:59 -03:00
03561ebe6a zig fmt pass 2020-07-23 16:42:49 -03:00
3a55f8dbcc Update README install/use instructions 2020-04-02 15:17:14 -03:00
8 changed files with 96 additions and 94 deletions

View file

@ -9,13 +9,12 @@ this time it'll work i promise it wont be like vig plrease
```
git clone https://gitdab.com/luna/rayoko
cd rayoko
zig build install --prefix ~/.local/
zig build
```
# use
```
rayoko examples/hello.ry # outputs to outpath.o
gcc outpath.o examples/hello.c -o hello
./hello
./zig-cache/bin/rayoko examples/hello.ry
./a.out # gives 123 as exit code which i think is epic
```

View file

@ -7,7 +7,7 @@ pub fn build(b: *Builder) void {
exe.install();
exe.linkSystemLibrary("c");
exe.linkSystemLibrary("LLVM-9");
exe.linkSystemLibrary("LLVM-10");
exe.linkSystemLibrary("stdc++");
const run_cmd = exe.run();

View file

@ -25,7 +25,7 @@ pub const Analyzer = struct {
};
}
fn setErrContext(self: *@This(), comptime fmt: ?[]const u8, args: var) void {
fn setErrContext(self: *@This(), comptime fmt: ?[]const u8, args: anytype) void {
if (fmt == null) {
self.err_ctx = null;
return;
@ -42,7 +42,7 @@ pub const Analyzer = struct {
self.err_tok = tok;
}
fn doError(self: *@This(), comptime fmt: []const u8, args: var) void {
fn doError(self: *@This(), comptime fmt: []const u8, args: anytype) void {
self.hadError = true;
std.debug.warn("analysis error", .{});
@ -80,14 +80,14 @@ pub const Analyzer = struct {
return null;
}
return switch (sym.?.value.*) {
return switch (sym.?.*) {
.Struct => SymbolUnderlyingType{ .Struct = val },
.Enum => SymbolUnderlyingType{ .Enum = val },
else => blk: {
self.doError("expected struct or enum for '{}', got {}", .{
val,
@tagName(@as(comp.SymbolType, sym.?.value.*)),
@tagName(@as(comp.SymbolType, sym.?.*)),
});
break :blk null;
},
@ -257,8 +257,8 @@ pub const Analyzer = struct {
var symbol = try ctx.fetchGlobalSymbol(func_name, .Function);
var func_sym = symbol.Function;
for (call.arguments.toSlice()) |arg_expr, idx| {
var param_type = func_sym.parameter_list.at(idx);
for (call.arguments.items) |arg_expr, idx| {
var param_type = func_sym.parameter_list.items[idx];
var arg_type = try self.resolveExprType(ctx, &arg_expr);
self.expectSymUnTypeEqual(arg_type, param_type) catch {
@ -314,7 +314,7 @@ pub const Analyzer = struct {
.Enum => |enum_identifier| {
// fetch an enum off symbol table, then we use the
// identifier map to ensure get.name exists in the enum
var map = ctx.symbol_table.get(enum_identifier).?.value.Enum;
var map = ctx.symbol_table.get(enum_identifier).?.Enum;
const name = get.name.lexeme;
var kv = map.get(name);
@ -355,8 +355,8 @@ pub const Analyzer = struct {
}
var value_type = try self.resolveExprType(ctx, assign.value);
try self.expectSymUnTypeEqual(var_type.?.value, value_type);
return var_type.?.value;
try self.expectSymUnTypeEqual(var_type.?, value_type);
return var_type.?;
},
.Set => @panic("TODO analysis of Set exprs"),
@ -411,7 +411,7 @@ pub const Analyzer = struct {
try ctx.bumpScope("if_then");
for (ifstmt.then_branch.toSlice()) |then_stmt| {
for (ifstmt.then_branch.items) |then_stmt| {
try self.stmtPass(ctx, then_stmt);
}
@ -421,7 +421,7 @@ pub const Analyzer = struct {
try ctx.bumpScope("if_else");
defer ctx.dumpScope();
for (else_branch.toSlice()) |else_stmt| {
for (else_branch.items) |else_stmt| {
try self.stmtPass(ctx, else_stmt);
}
}
@ -437,7 +437,7 @@ pub const Analyzer = struct {
try ctx.bumpScope("loop");
for (loop.then_branch.toSlice()) |then_stmt| {
for (loop.then_branch.items) |then_stmt| {
try self.stmtPass(ctx, then_stmt);
}
@ -476,7 +476,7 @@ pub const Analyzer = struct {
});
var parameters = comp.TypeList.init(self.allocator);
for (decl.params.toSlice()) |param| {
for (decl.params.items) |param| {
var param_type = self.resolveGlobalType(ctx, param.typ.lexeme);
if (param_type == null) continue;
try parameters.append(param_type.?);
@ -490,14 +490,14 @@ pub const Analyzer = struct {
// we intentionally insert the function so that:
// - we can do return statement validation
// - we have parameter types fully analyzed
if (ret_type != null and parameters.len == decl.params.len) {
if (ret_type != null and parameters.items.len == decl.params.items.len) {
try ctx.insertFn(decl, ret_type.?, parameters, scope);
} else {
if (ret_type != null)
self.doError("Return type was not fully resolved", .{});
if (parameters.len != decl.params.len)
self.doError("Fully analyzed {} parameters, wanted {}", .{ parameters.len, decl.params.len });
if (parameters.items.len != decl.params.items.len)
self.doError("Fully analyzed {} parameters, wanted {}", .{ parameters.items.len, decl.params.items.len });
return CompileError.TypeError;
}
@ -507,7 +507,7 @@ pub const Analyzer = struct {
std.debug.assert(ctx.current_scope == null);
ctx.setScope(scope);
for (decl.body.toSlice()) |stmt| {
for (decl.body.items) |stmt| {
try self.stmtPass(ctx, stmt);
}
@ -522,7 +522,7 @@ pub const Analyzer = struct {
var types = comp.TypeList.init(self.allocator);
for (struc.fields.toSlice()) |field| {
for (struc.fields.items) |field| {
self.setErrToken(field.name);
var field_type = self.resolveGlobalType(ctx, field.typ.lexeme);
if (field_type == null) continue;
@ -534,7 +534,7 @@ pub const Analyzer = struct {
// we don't return type errors from the main loop so we can
// keep going and find more type errors
if (types.len == struc.fields.len)
if (types.items.len == struc.fields.items.len)
try ctx.insertStruct(struc, types);
},
@ -547,7 +547,7 @@ pub const Analyzer = struct {
},
.ConstDecl => |constlist| {
for (constlist.toSlice()) |constdecl| {
for (constlist.items) |constdecl| {
self.setErrToken(constdecl.name);
self.setErrContext("const {}", .{constdecl.name.lexeme});
@ -566,7 +566,7 @@ pub const Analyzer = struct {
pub fn pass(self: *@This(), root: *ast.Node) !comp.CompilationContext {
var ctx = comp.CompilationContext.init(self.allocator);
var slice = root.Root.toSlice();
var slice = root.Root.items;
for (slice) |_, idx| {
try self.nodePass(&ctx, &slice[idx]);
}

View file

@ -14,15 +14,15 @@ fn printIdent(ident: usize) void {
}
}
fn print(ident: usize, comptime fmt: []const u8, args: var) void {
fn print(ident: usize, comptime fmt: []const u8, args: anytype) void {
printIdent(ident);
std.debug.warn(fmt, args);
}
fn printBlock(ident: usize, block: var, endNewline: bool) void {
fn printBlock(ident: usize, block: anytype, endNewline: bool) void {
std.debug.warn("(\n", .{});
for (block.toSlice()) |stmt| {
for (block.items) |stmt| {
printIdent(ident);
printStmt(ident, &stmt);
std.debug.warn("\n", .{});
@ -53,7 +53,7 @@ pub fn printNode(node: *const Node, ident: usize) void {
warn("(fn {} {} (", .{ name, ret_type });
}
for (decl.params.toSlice()) |param| {
for (decl.params.items) |param| {
warn(" ({} {})", .{ param.name.lexeme, param.typ.lexeme });
}
warn(") ", .{});
@ -65,7 +65,7 @@ pub fn printNode(node: *const Node, ident: usize) void {
.ConstDecl => |consts| {
print(ident, "(const (\n", .{});
for (consts.toSlice()) |const_decl| {
for (consts.items) |const_decl| {
print(ident + 1, "({} ", .{
const_decl.name.lexeme,
});
@ -80,7 +80,7 @@ pub fn printNode(node: *const Node, ident: usize) void {
.Enum => |decl| {
print(ident, "(enum {} (\n", .{decl.name.lexeme});
for (decl.fields.toSlice()) |field| {
for (decl.fields.items) |field| {
print(ident + 1, "{}\n", .{
field.lexeme,
});
@ -90,14 +90,14 @@ pub fn printNode(node: *const Node, ident: usize) void {
},
.Root => {
for (node.Root.toSlice()) |child| {
for (node.Root.items) |child| {
printNode(&child, ident + 1);
}
},
.Struct => |struc| {
print(ident, "(struct {} (\n", .{struc.name.lexeme});
for (struc.fields.toSlice()) |field| {
for (struc.fields.items) |field| {
print(ident + 1, "({} {})\n", .{ field.name.lexeme, field.typ.lexeme });
}
print(ident, "))\n", .{});
@ -156,7 +156,7 @@ fn binOpToStr(op: BinaryOperator) ?[]const u8 {
return null;
}
fn printBinOp(inner: var) void {
fn printBinOp(inner: anytype) void {
std.debug.warn("({}", .{binOpToStr(inner.op)});
printTwoExprs(inner.left, inner.right);
std.debug.warn(")", .{});
@ -203,7 +203,7 @@ pub fn printExpr(expr: *const Expr) void {
.Float => |val| std.debug.warn("{}", .{val}),
.String => |val| std.debug.warn("'{}'", .{val}),
.Array => |exprs| {
parenthetize("array", exprs.toSlice());
parenthetize("array", exprs.items);
},
else => |typ| std.debug.warn("UnknownLiteral-{}", .{typ}),
}
@ -222,7 +222,7 @@ pub fn printExpr(expr: *const Expr) void {
std.debug.warn("(", .{});
printExpr(call.callee);
for (call.arguments.toSlice()) |arg| {
for (call.arguments.items) |arg| {
std.debug.warn(" ", .{});
printExpr(&arg);
}
@ -233,7 +233,7 @@ pub fn printExpr(expr: *const Expr) void {
.Struct => |val| {
std.debug.warn("({} (", .{val.name.lexeme});
for (val.inits.toSlice()) |init| {
for (val.inits.items) |init| {
std.debug.warn(" ({} ", .{init.field.lexeme});
printExpr(init.expr);
std.debug.warn(")", .{});
@ -345,12 +345,11 @@ fn prettyType(typ: SymbolUnderlyingType) []const u8 {
pub fn printScope(scope: *Scope, ident: usize) void {
print(ident, "scope '{}' at addr {}\n", .{ scope.id, @ptrToInt(scope) });
var it = scope.env.iterator();
while (it.next()) |kv| {
print(ident + 1, "sym: {}, typ: {}\n", .{ kv.key, prettyType(kv.value) });
for (scope.env.items()) |entry| {
print(ident + 1, "sym: {}, typ: {}\n", .{ entry.key, prettyType(entry.value) });
}
for (scope.children.toSlice()) |child| {
for (scope.children.items) |child| {
printScope(child, ident + 1);
}
}
@ -366,11 +365,11 @@ pub fn printContext(ctx: CompilationContext) void {
prettyType(fn_sym.return_type),
});
for (fn_sym.decl.params.toSlice()) |param| {
var param_kv = fn_sym.parameters.get(param.name.lexeme).?;
for (fn_sym.decl.params.items) |param| {
var actual_param = fn_sym.parameters.get(param.name.lexeme).?;
std.debug.warn("\tparameter {} typ {}\n", .{
param_kv.key,
prettyType(param_kv.value.typ),
param.name.lexeme,
prettyType(actual_param.typ),
});
}

View file

@ -46,7 +46,7 @@ pub const Codegen = struct {
},
.Struct, .Enum => |lex| blk: {
var sym_data = self.ctx.symbol_table.get(lex).?.value;
var sym_data = self.ctx.symbol_table.get(lex).?;
break :blk switch (sym_data.*) {
.Struct => unreachable,
.Enum => llvm.LLVMInt32Type(),
@ -64,8 +64,8 @@ pub const Codegen = struct {
};
}
fn emitForVariableType(self: *@This(), vari: var, get: var, kv: var) !llvm.LLVMValueRef {
var sym = kv.value;
fn emitForVariableType(self: *@This(), vari: anytype, get: anytype, kv: anytype) !llvm.LLVMValueRef {
var sym = kv;
switch (sym.*) {
.Enum => |map| {
@ -76,7 +76,7 @@ pub const Codegen = struct {
get.name.lexeme,
});
}
return llvm.LLVMConstInt(llvm.LLVMInt32Type(), val.?.value, 1);
return llvm.LLVMConstInt(llvm.LLVMInt32Type(), val.?, 1);
},
.Struct => @panic("TODO handle struct"),
@ -89,7 +89,7 @@ pub const Codegen = struct {
fn emitExpr(
self: *Codegen,
builder: var,
builder: anytype,
expr: *const ast.Expr,
) anyerror!llvm.LLVMValueRef {
return switch (expr.*) {
@ -176,25 +176,27 @@ pub const Codegen = struct {
.Call => |call| {
const name = call.callee.*.Variable.lexeme;
var llvm_func = self.llvm_table.get(name);
if (llvm_func == null) {
var llvm_func_entry = self.llvm_table.getEntry(name);
if (llvm_func_entry == null) {
std.debug.warn("Function '{}' not found\n", .{name});
return CompileError.EmitError;
}
const llvm_func = llvm_func_entry.?.value;
var args = LLVMValueList.init(self.allocator);
errdefer args.deinit();
for (call.arguments.toSlice()) |arg_expr| {
for (call.arguments.items) |arg_expr| {
var arg_val = try self.emitExpr(builder, &arg_expr);
try args.append(arg_val);
}
var args_slice = args.toSlice();
var args_slice = args.items;
return llvm.LLVMBuildCall(
builder,
llvm_func.?.value,
llvm_func,
args_slice.ptr,
@intCast(c_uint, args_slice.len),
"call",
@ -203,10 +205,10 @@ pub const Codegen = struct {
.Assign => |assign| {
const name = assign.name.lexeme;
var meta = self.ctx.current_scope.?.meta_map.get(name).?.value;
var meta = self.ctx.current_scope.?.meta_map.get(name).?;
var assign_expr = try self.emitExpr(builder, assign.value);
var llvm_alloca: llvm.LLVMValueRef = switch (meta.using) {
.Function => meta.from_function.?.parameters.get(name).?.value.llvm_alloca.?,
.Function => meta.from_function.?.parameters.get(name).?.llvm_alloca.?,
.Scope => meta.llvm_alloca.?,
};
@ -224,7 +226,7 @@ pub const Codegen = struct {
// we have metadata, which means we can check if the variable
// is coming from the scope or from the function
var metadata = kv_opt.?.value;
var metadata = kv_opt.?;
std.debug.warn("!! LOAD FROM VAR META {}\n", .{@ptrToInt(metadata)});
var buf = try self.allocator.alloc(u8, 512);
@ -237,13 +239,13 @@ pub const Codegen = struct {
return switch (metadata.using) {
.Function => blk: {
var param = metadata.from_function.?.parameters.get(vari.lexeme).?.value;
var param = metadata.from_function.?.parameters.get(vari.lexeme).?;
break :blk llvm.LLVMBuildLoad(builder, param.llvm_alloca.?, load_cstr.ptr);
},
.Scope => blk: {
var llvm_alloca = metadata.llvm_alloca.?;
//var var_typ = metadata.from_scope.?.env.get(vari.lexeme).?.value;
//var var_typ = metadata.from_scope.?.env.get(vari.lexeme).?;
break :blk llvm.LLVMBuildLoad(builder, llvm_alloca, load_cstr.ptr);
},
};
@ -260,7 +262,7 @@ pub const Codegen = struct {
};
}
fn emitStmt(self: *Codegen, builder: var, stmt: *ast.Stmt) anyerror!void {
fn emitStmt(self: *Codegen, builder: anytype, stmt: *ast.Stmt) anyerror!void {
std.debug.warn("cgen: emitting stmt {}\n", .{@as(ast.StmtType, stmt.*)});
switch (stmt.*) {
@ -294,7 +296,7 @@ pub const Codegen = struct {
self.ctx.setScope(self.ctx.current_scope.?.nextChild());
var then_branch = ifstmt.then_branch.toSlice();
var then_branch = ifstmt.then_branch.items;
for (then_branch) |_, idx| {
// keep emitting until branch has ret
var then_stmt = &then_branch[idx];
@ -326,7 +328,7 @@ pub const Codegen = struct {
if (ifstmt.else_branch) |else_block| {
self.ctx.setScope(self.ctx.current_scope.?.nextChild());
var else_slice = else_block.toSlice();
var else_slice = else_block.items;
for (else_slice) |_, idx| {
// keep emitting until branch has ret
var else_stmt = &else_slice[idx];
@ -361,7 +363,7 @@ pub const Codegen = struct {
// analyze pass and the current scope contains the variable's
// type(hopefully), so we resolve it
const name = vardecl.name.lexeme;
var var_metadata = self.ctx.current_scope.?.meta_map.get(name).?.value;
var var_metadata = self.ctx.current_scope.?.meta_map.get(name).?;
var name_cstr = try std.cstr.addNullByte(self.allocator, name);
errdefer self.allocator.free(name_cstr);
@ -392,7 +394,7 @@ pub const Codegen = struct {
}
fn getFnSymbol(self: *@This(), name: []const u8) *comp.FunctionSymbol {
var fn_sym_search = self.ctx.symbol_table.get(name).?.value;
var fn_sym_search = self.ctx.symbol_table.get(name).?;
std.debug.assert(@as(comp.SymbolType, fn_sym_search.*) == .Function);
return &fn_sym_search.Function;
}
@ -418,21 +420,22 @@ pub const Codegen = struct {
var param_types = llvm.LLVMTypeList.init(self.allocator);
errdefer param_types.deinit();
for (decl.params.toSlice()) |param| {
for (decl.params.items) |param| {
try param_types.append(try self.typeToLLVM(fn_sym.parameters.get(
param.name.lexeme,
).?.value.typ));
).?.typ));
}
var llvm_ret_type = llvm.LLVMFunctionType(
try self.typeToLLVM(fn_sym.return_type),
param_types.toSlice().ptr,
@intCast(c_uint, param_types.len),
param_types.items.ptr,
@intCast(c_uint, param_types.items.len),
0,
);
var func = llvm.LLVMAddFunction(mod, name_cstr.ptr, llvm_ret_type);
_ = try self.llvm_table.put(name, func);
std.debug.warn("inserting function '{}' to llvm table\n", .{name});
try self.llvm_table.put(name, func);
var buf = try self.allocator.alloc(u8, 512);
var entry_lbl = try std.fmt.bufPrint(buf, "fn_{}_entry", .{name});
@ -444,9 +447,9 @@ pub const Codegen = struct {
// to have the ability to mutate parameters, we must allocate them on
// the stack
var params_slice = decl.params.toSlice();
var params_slice = decl.params.items;
for (params_slice) |param_node, idx| {
var param = fn_sym.parameters.get(param_node.name.lexeme).?.value;
var param = fn_sym.parameters.get(param_node.name.lexeme).?;
const param_name_cstr = try std.cstr.addNullByte(self.allocator, param_node.name.lexeme);
errdefer self.allocator.free(param_name_cstr);
@ -467,7 +470,7 @@ pub const Codegen = struct {
// TODO check if stmt is return and if we already
// returned before
var body_slice = decl.body.toSlice();
var body_slice = decl.body.items;
for (body_slice) |_, idx| {
try self.emitStmt(builder, &body_slice[idx]);
}
@ -480,10 +483,10 @@ pub const Codegen = struct {
.Enum => {},
.ConstDecl => |constdecls| {
for (constdecls.toSlice()) |constdecl| {
for (constdecls.items) |constdecl| {
const name = constdecl.name.lexeme;
var const_type = self.ctx.symbol_table.get(name).?.value;
var const_type = self.ctx.symbol_table.get(name).?;
var const_llvm_type = try self.typeToLLVM(const_type.Const);
const const_name = try std.cstr.addNullByte(self.allocator, name);
@ -515,7 +518,7 @@ pub const Codegen = struct {
var mod = llvm.LLVMModuleCreateWithName("awoo").?;
defer llvm.LLVMDisposeModule(mod);
var root_slice = root.Root.toSlice();
var root_slice = root.Root.items;
for (root_slice) |_, idx| {
try self.genNode(mod, &root_slice[idx]);
}

View file

@ -70,13 +70,14 @@ pub const Scope = struct {
}
pub fn nextChild(self: *@This()) *Scope {
var child = self.children.at(self.cur_child_idx);
var child = self.children.items[self.cur_child_idx];
self.cur_child_idx += 1;
return child;
}
pub fn deinit(self: *const @This()) void {
self.env.deinit();
// XXX: fix this someday
// self.env.deinit();
}
};
@ -271,8 +272,8 @@ pub const CompilationContext = struct {
pub fn insertStruct(self: *@This(), struc: ast.Struct, field_types: TypeList) !void {
var type_map = UnderlyingTypeMap.init(self.allocator);
for (struc.fields.toSlice()) |field, idx| {
_ = try type_map.put(field.name.lexeme, field_types.at(idx));
for (struc.fields.items) |field, idx| {
_ = try type_map.put(field.name.lexeme, field_types.items[idx]);
}
var symbol = try self.allocator.create(SymbolData);
@ -289,13 +290,13 @@ pub const CompilationContext = struct {
) !void {
var param_map = ParameterMap.init(self.allocator);
for (decl.params.toSlice()) |param, idx| {
for (decl.params.items) |param, idx| {
var param_sym = try self.allocator.create(Parameter);
param_sym.* = Parameter{
.name = param.name.lexeme,
.idx = idx,
.typ = param_types.at(idx),
.typ = param_types.items[idx],
};
_ = try param_map.put(param.name.lexeme, param_sym);
}
@ -318,7 +319,7 @@ pub const CompilationContext = struct {
_ = try self.symbol_table.put(lex, symbol);
var kv = self.symbol_table.get(lex);
self.cur_function = &kv.?.value.Function;
self.cur_function = &kv.?.Function;
}
pub fn insertEnum(self: *@This(), enu: ast.Enum) !void {
@ -326,7 +327,7 @@ pub const CompilationContext = struct {
errdefer ident_map.deinit();
// TODO change this when enums get support for custom values
for (enu.fields.toSlice()) |token, idx| {
for (enu.fields.items) |token, idx| {
_ = try ident_map.put(token.lexeme, @intCast(u32, idx));
}
@ -352,7 +353,7 @@ pub const CompilationContext = struct {
return CompilationError.TypeError;
}
var value = sym_kv.?.value;
var value = sym_kv.?;
var sym_typ = @as(SymbolType, value.*);
if (sym_typ != typ) {
@ -378,7 +379,7 @@ pub const CompilationContext = struct {
return try VariableMetadata.withScope(
self.allocator,
scope,
kv.value,
kv,
);
} else {
return null;
@ -408,7 +409,7 @@ pub const CompilationContext = struct {
return try VariableMetadata.withParam(
self.allocator,
cur_function,
kv.value.typ,
kv.typ,
);
} else {
return null;

View file

@ -12,7 +12,7 @@ pub fn reportN(line: usize, message: []const u8) void {
report(line, "", message);
}
pub fn reportFmt(line: usize, ctx_opt: ?[]const u8, comptime fmt: []const u8, args: var) void {
pub fn reportFmt(line: usize, ctx_opt: ?[]const u8, comptime fmt: []const u8, args: anytype) void {
if (ctx_opt) |ctx| {
std.debug.warn("[line {}] Error on {}", .{ line, ctx });
} else {

View file

@ -94,7 +94,7 @@ pub const Parser = struct {
self.tokens.deinit();
}
fn setErrContext(self: *Parser, comptime fmt: ?[]const u8, args: var) void {
fn setErrContext(self: *Parser, comptime fmt: ?[]const u8, args: anytype) void {
if (fmt == null) {
self.err_ctx = null;
return;
@ -104,7 +104,7 @@ pub const Parser = struct {
self.err_ctx = std.fmt.bufPrint(buf, fmt.?, args) catch unreachable;
}
fn doError(self: *Parser, comptime fmt: []const u8, args: var) ParseError {
fn doError(self: *Parser, comptime fmt: []const u8, args: anytype) ParseError {
self.hadError = true;
std.debug.warn("parser error at line {}", .{self.scanner.line});
@ -138,11 +138,11 @@ pub const Parser = struct {
}
fn peek(self: *Parser) Token {
return self.tokens.at(self.tokens.len - 1);
return self.tokens.items[self.tokens.items.len - 1];
}
fn previous(self: *Parser) Token {
return self.tokens.at(self.tokens.len - 2);
return self.tokens.items[self.tokens.items.len - 2];
}
fn tokenError(self: *Parser, token: Token, msg: []const u8) ParseError {
@ -215,7 +215,7 @@ pub const Parser = struct {
}
/// check() against multiple tokens
fn compareAnyOf(self: *@This(), ttypes: []TokenType) bool {
fn compareAnyOf(self: *@This(), ttypes: []const TokenType) bool {
for (ttypes) |typ| {
if (self.check(typ)) return true;
}