diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen.zig | 11 | ||||
| -rw-r--r-- | src/main.zig | 3 | ||||
| -rw-r--r-- | src/parser.zig | 5 | ||||
| -rw-r--r-- | src/symtable.zig | 2 | ||||
| -rw-r--r-- | src/tokenize.zig | 39 |
5 files changed, 46 insertions, 14 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 9fb09cb..49a07fe 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -104,7 +104,7 @@ pub const Generator = struct { const ptr = try self.genAlloc(toLLVMtype(nodeVar.expr.typ orelse try nodeVar.expr.inferType(self.allocator, table), table, nodeVar.expr), nodeVar.ident.ident); const value = try self.genExpr(nodeVar.expr); _ = core.LLVMBuildStore(self.builder, value, ptr); - std.debug.print("\t\t\tGenerated Value {s}\n", .{nodeVar.ident.ident}); + // std.debug.print("\t\t\tGenerated Value {s}\n", .{nodeVar.ident.ident}); try self.references.put(symbol.id, ptr); } @@ -215,7 +215,7 @@ pub const Generator = struct { } fn genStmt(self: *Generator, stmt: parse.NodeStmt) !void { - std.debug.print("======\n\tStmt: {any}\n======\n", .{stmt.kind}); + // std.debug.print("======\n\tStmt: {any}\n======\n", .{stmt.kind}); try switch (stmt.kind) { .exit => |expr| self.genExit(expr), .function => self.genFunc(stmt), @@ -223,11 +223,10 @@ pub const Generator = struct { .defVar => self.genVar(stmt), .assignVar => self.genAssign(stmt), .ifstmt => self.genIf(stmt), + .block => |blk| self.genBlock(blk), .expr => |expression| { _ = try self.genExpr(expression); }, - - else => {}, }; } @@ -259,11 +258,11 @@ pub const Generator = struct { "", ); }, - .intLit => |int| core.LLVMConstInt(core.LLVMInt32TypeInContext(self.context), @intCast(int.intLit), 1), + .intLit => |int| core.LLVMConstInt(core.LLVMInt32Type(), @intCast(int.intLit), 1), .binaryOp => |exp| blk: { const lhs = try self.genExpr(exp.lhs.*); const rhs = try self.genExpr(exp.rhs.*); - std.debug.print("\n\n\tLHS: {any}\n\tRHS: {any}\n\tOP: {any}\n\n", .{ lhs, rhs, exp.op }); + // std.debug.print("\n\n\tLHS: {any}\n\tRHS: {any}\n\tOP: {any}\n\n", .{ exp.lhs.*.kind, exp.rhs.*.kind, exp.op }); break :blk switch (exp.op) { .plus => core.LLVMBuildAdd(self.builder, lhs, rhs, "add"), diff --git a/src/main.zig b/src/main.zig index b51b170..be9a2d8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -13,7 +13,7 @@ pub fn main() !void { var allocator = arena.allocator(); if (std.os.argv.len < 2) { std.debug.print( - \\info: Usage: calico [input file] + \\info: Usage: calico [input file] [output name (defaults to "out")] \\ , .{}); return; @@ -47,6 +47,7 @@ pub fn main() !void { var tokenizer = tok.Tokenizer.init(allocator, all); defer tokenizer.deinit(); const tokens = try tokenizer.tokenize(); + // for (tokens) |tokn| std.debug.print("{s} ", .{tokn.toString()}); // Parse // var arena = std.heap.ArenaAllocator.init(allocator); diff --git a/src/parser.zig b/src/parser.zig index 66d02a2..b1581bb 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -234,8 +234,7 @@ pub const Parser = struct { }; break :blk ExprKind{ .stringLit = (try self.tokens.consume(.stringLit)).? }; }, - else => |expr| break :blk errorblk: { - std.debug.print("Invalid Expression: {any}\n", .{expr}); + else => break :blk errorblk: { break :errorblk ParsingError.InvalidExpression; }, }; @@ -656,7 +655,7 @@ test "Parser" { }, .symtable = symbTable, .typ = TypeIdent{ .list = false, .ident = "i32" }, - .isConst = true, + .isConst = false, }, }, }, diff --git a/src/symtable.zig b/src/symtable.zig index 3017670..fdbc536 100644 --- a/src/symtable.zig +++ b/src/symtable.zig @@ -204,7 +204,7 @@ pub const Populator = struct { try value.expr.inferType(self.allocator, table), false, ); - std.debug.print("Value: {s}\nSymbol: {any}\n", .{ value.ident.ident, symbol }); + // std.debug.print("Value: {s}\nSymbol: {any}\n", .{ value.ident.ident, symbol }); if (!try table.insert(value.ident.ident, symbol)) return error.FailedToInsert; }, .block => { diff --git a/src/tokenize.zig b/src/tokenize.zig index 2c536db..038a4d3 100644 --- a/src/tokenize.zig +++ b/src/tokenize.zig @@ -94,9 +94,9 @@ pub const Token = union(TokenType) { ':' => .colon, '[' => .openBracket, ']' => .closeBracket, - else => { - // std.debug.print("{c}: ", .{char}); - return TokenizeError.UnknownToken; + else => errblk: { + std.debug.print("{c}: ", .{char}); + break :errblk TokenizeError.UnknownToken; }, }; } @@ -111,6 +111,39 @@ pub const Token = union(TokenType) { if (eql(u8, str, "import")) return .import; return Token{ .ident = str }; } + + pub fn toString(self: Token) []const u8 { + return switch (self) { + .ident => "IDENT", + .stringLit => "STRINGlIT", + .intLit => "INTlIT", + .charLit => "CHARlIT", + .ifstmt => "IFSTMT", + .constant => "CONSTANT", + .variable => "VARIABLE", + .exit => "EXIT", + .fun => "FUN", + .import => "IMPORT", + .plus => "PLUS", + .minus => "MINUS", + .star => "STAR", + .slash => "SLASH", + .semiCol => "SEMIcOL", + .equal => "EQUAL", + .eqleql => "EQLEQL", + .lessthan => "LESSTHAN", + .greaterthan => "GREATERTHAN", + .openBrace => "OPENbRACE", + .closeBrace => "CLOSEbRACE", + .openParen => "OPENpAREN", + .closeParen => "CLOSEpAREN", + .openBracket => "OPENbRACKET", + .closeBracket => "CLOSEbRACKET", + .arrow => "ARROW", + .colon => "COLON", + .comma => "COMMA", + }; + } }; pub fn checkType(tok: Token, comptime typ: TokenType) bool { |
