codegen: add emitting of unary exprs
This commit is contained in:
parent
3d47c0cca8
commit
c7920246a5
3 changed files with 11 additions and 2 deletions
|
@ -37,7 +37,7 @@ fn func_refer_param(b: i32) i32 {
|
|||
|
||||
fn multwo(num: i32, double_flag: bool) i32 {
|
||||
if (!double_flag) {
|
||||
var value = false;
|
||||
var value = 32;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
|
@ -214,9 +214,9 @@ pub const TypeSolver = struct {
|
|||
};
|
||||
},
|
||||
|
||||
// for now, unary operators only have .Not
|
||||
.Unary => |unary| {
|
||||
var right_type = try self.resolveExprType(ctx, unary.right);
|
||||
|
||||
return switch (unary.op) {
|
||||
.Negate => right_type,
|
||||
.Not => right_type,
|
||||
|
|
|
@ -132,6 +132,15 @@ pub const Codegen = struct {
|
|||
};
|
||||
},
|
||||
|
||||
.Unary => |unary| {
|
||||
var right = try self.emitExpr(builder, unary.right);
|
||||
|
||||
return switch (unary.op) {
|
||||
.Negate => llvm.LLVMBuildNeg(builder, right, c"neg_tmp"),
|
||||
.Not => llvm.LLVMBuildNot(builder, right, c"neg_tmp"),
|
||||
};
|
||||
},
|
||||
|
||||
.Binary => |binary| {
|
||||
var left = try self.emitExpr(builder, binary.left);
|
||||
var right = try self.emitExpr(builder, binary.right);
|
||||
|
|
Loading…
Reference in a new issue