basic conditional compilation
This commit is contained in:
parent
a1d3994395
commit
07c5b66758
@ -1269,36 +1269,18 @@ pub const Builder = struct {
|
|||||||
const If = struct{
|
const If = struct{
|
||||||
condition: Condition,
|
condition: Condition,
|
||||||
const Condition = union(enum){
|
const Condition = union(enum){
|
||||||
true: Value.Index,
|
true,
|
||||||
false,
|
false,
|
||||||
runtime: Value.Index,
|
runtime,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
fn resolveIf(builder: *Builder, unit: *Unit, context: *const Context, node_index: Node.Index) !If {
|
fn resolveIf(builder: *Builder, unit: *Unit, context: *const Context, node_index: Node.Index) !If {
|
||||||
const if_node = unit.getNode(node_index);
|
_ = builder; // autofix
|
||||||
assert(if_node.id == .@"if");
|
_ = unit; // autofix
|
||||||
|
_ = context; // autofix
|
||||||
|
_ = node_index; // autofix
|
||||||
|
|
||||||
const condition = try builder.resolveValueAllocate(unit, context, Type.Expect{
|
|
||||||
.type = .bool,
|
|
||||||
}, if_node.left);
|
|
||||||
assert(condition != .null);
|
|
||||||
|
|
||||||
if (unit.evaluateBooleanAtComptime(condition)) |comptime_condition| {
|
|
||||||
if (comptime_condition == true) {
|
|
||||||
@panic("TODO: if comptime true");
|
|
||||||
// return If{
|
|
||||||
// .condition = .true,
|
|
||||||
// };
|
|
||||||
} else {
|
|
||||||
return If{
|
|
||||||
.condition = .false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try builder.insertDebugCheckPoint(unit, context, if_node.token);
|
|
||||||
unreachable;
|
|
||||||
}
|
|
||||||
|
|
||||||
unreachable;
|
unreachable;
|
||||||
}
|
}
|
||||||
@ -1915,17 +1897,32 @@ pub const Builder = struct {
|
|||||||
assert(node.left != .null);
|
assert(node.left != .null);
|
||||||
assert(node.right != .null);
|
assert(node.right != .null);
|
||||||
|
|
||||||
const if_result = try builder.resolveIf(unit, context, node.left);
|
const if_node = unit.getNode(node.left);
|
||||||
switch (if_result.condition) {
|
assert(if_node.id == .@"if");
|
||||||
.false => {
|
const condition = try builder.resolveValueAllocate(unit, context, Type.Expect{
|
||||||
|
.type = .bool,
|
||||||
|
}, if_node.left);
|
||||||
|
assert(condition != .null);
|
||||||
|
|
||||||
|
if (unit.evaluateBooleanAtComptime(condition)) |comptime_condition| {
|
||||||
|
if (comptime_condition == true) {
|
||||||
|
value.* = .{
|
||||||
|
.unresolved = if_node.right,
|
||||||
|
};
|
||||||
|
try builder.resolveValue(unit, context, Type.Expect{
|
||||||
|
.type = .void,
|
||||||
|
}, value_index);
|
||||||
|
} else {
|
||||||
value.* = .{
|
value.* = .{
|
||||||
.unresolved = node.right,
|
.unresolved = node.right,
|
||||||
};
|
};
|
||||||
try builder.resolveValue(unit, context, Type.Expect{
|
try builder.resolveValue(unit, context, Type.Expect{
|
||||||
.type = .void,
|
.type = .void,
|
||||||
}, value_index);
|
}, value_index);
|
||||||
},
|
}
|
||||||
else => |t| @panic(@tagName(t)),
|
} else {
|
||||||
|
try builder.insertDebugCheckPoint(unit, context, if_node.token);
|
||||||
|
unreachable;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.field_access => {
|
.field_access => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user