ast: change AstBinOp to use *AstNode instead of AstNode
using raw AstNode causes compile-errors due to recursion.
This commit is contained in:
parent
c32b802765
commit
b040f47956
2 changed files with 15 additions and 6 deletions
|
@ -18,8 +18,8 @@ pub const AstBinOp = struct {
|
|||
optype: BinOpType,
|
||||
|
||||
// TODO expression
|
||||
left: AstNumber,
|
||||
right: AstNumber,
|
||||
left: *AstNode,
|
||||
right: *AstNode,
|
||||
};
|
||||
|
||||
pub const NumberType = enum {
|
||||
|
@ -50,9 +50,9 @@ pub fn printNode(stdout: var, node: AstNode) anyerror!void {
|
|||
}
|
||||
|
||||
try stdout.write(" ");
|
||||
try printNode(stdout, AstNode{ .Number = bin_op.left });
|
||||
try printNode(stdout, bin_op.left.*);
|
||||
try stdout.write(" ");
|
||||
try printNode(stdout, AstNode{ .Number = bin_op.right });
|
||||
try printNode(stdout, bin_op.right.*);
|
||||
try stdout.print(")");
|
||||
},
|
||||
.Number => |ast_num| {
|
||||
|
|
|
@ -46,12 +46,21 @@ pub const Runner = struct {
|
|||
.Program = &[]ast.AstNode{ast.AstNode{
|
||||
.BinOp = ast.AstBinOp{
|
||||
.optype = ast.BinOpType.Equality,
|
||||
.left = ast.AstNumber{ .Integer32 = 30 },
|
||||
.right = ast.AstNumber{ .Integer32 = 30 },
|
||||
.left = &ast.AstNode{
|
||||
.Number = ast.AstNumber{
|
||||
.Integer32 = 30,
|
||||
},
|
||||
},
|
||||
.right = &ast.AstNode{
|
||||
.Number = ast.AstNumber{
|
||||
.Integer32 = 30,
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
});
|
||||
try self.stdout.print("\n");
|
||||
|
||||
return Result.Ok;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue