ast: change AstBinOp to use *AstNode instead of AstNode

using raw AstNode causes compile-errors due to recursion.
This commit is contained in:
Luna 2019-06-04 23:53:55 -03:00
parent c32b802765
commit b040f47956
2 changed files with 15 additions and 6 deletions

View file

@ -18,8 +18,8 @@ pub const AstBinOp = struct {
optype: BinOpType, optype: BinOpType,
// TODO expression // TODO expression
left: AstNumber, left: *AstNode,
right: AstNumber, right: *AstNode,
}; };
pub const NumberType = enum { pub const NumberType = enum {
@ -50,9 +50,9 @@ pub fn printNode(stdout: var, node: AstNode) anyerror!void {
} }
try stdout.write(" "); try stdout.write(" ");
try printNode(stdout, AstNode{ .Number = bin_op.left }); try printNode(stdout, bin_op.left.*);
try stdout.write(" "); try stdout.write(" ");
try printNode(stdout, AstNode{ .Number = bin_op.right }); try printNode(stdout, bin_op.right.*);
try stdout.print(")"); try stdout.print(")");
}, },
.Number => |ast_num| { .Number => |ast_num| {

View file

@ -46,12 +46,21 @@ pub const Runner = struct {
.Program = &[]ast.AstNode{ast.AstNode{ .Program = &[]ast.AstNode{ast.AstNode{
.BinOp = ast.AstBinOp{ .BinOp = ast.AstBinOp{
.optype = ast.BinOpType.Equality, .optype = ast.BinOpType.Equality,
.left = ast.AstNumber{ .Integer32 = 30 }, .left = &ast.AstNode{
.right = ast.AstNumber{ .Integer32 = 30 }, .Number = ast.AstNumber{
.Integer32 = 30,
},
},
.right = &ast.AstNode{
.Number = ast.AstNumber{
.Integer32 = 30,
},
},
}, },
}}, }},
}); });
try self.stdout.print("\n"); try self.stdout.print("\n");
return Result.Ok; return Result.Ok;
} }
}; };