match statements
This commit is contained in:
+15
-1
@@ -253,7 +253,7 @@ valid_value :: proc(
|
||||
}
|
||||
switch instructions[value_id].op {
|
||||
case .Param, .Const, .String, .Aggregate, .None, .Optional_Some,
|
||||
.Load_Global, .Function_Address, .Address_Of, .Load, .Slice, .Length, .Slice_Ptr,
|
||||
.Load_Global, .Function_Address, .Address_Of, .Load, .Union_Tag, .Slice, .Length, .Slice_Ptr,
|
||||
.Extract, .Select, .Unwrap,
|
||||
.Optional_Is_Some, .Optional_Value, .Orelse,
|
||||
.Widen, .C_Coerce, .C_Vararg_Promote, .Retype, .Weaken_Pointer, .Weaken_Slice, .Decay_Array_Pointer,
|
||||
@@ -979,6 +979,20 @@ emit_instruction_stream :: proc(
|
||||
llvm_type(instruction.type, &emitter.module.types),
|
||||
instruction.a,
|
||||
)
|
||||
case .Union_Tag:
|
||||
// `instruction.a` is the address of a tagged union; the discriminant lives at
|
||||
// offset 0, so load the tag enum (`instruction.type`) straight from it.
|
||||
if !valid_instruction(instructions, instruction.a) {
|
||||
emit_recovery_value(emitter, instruction_index, instruction, "invalid union tag base")
|
||||
continue
|
||||
}
|
||||
fmt.sbprintf(
|
||||
&emitter.builder,
|
||||
" %%v%d = load %s, ptr %%v%d\n",
|
||||
instruction_index,
|
||||
llvm_type(instruction.type, &emitter.module.types),
|
||||
instruction.a,
|
||||
)
|
||||
case .Store:
|
||||
if !valid_address(instructions, instruction.a, instruction.type, &emitter.module.types) ||
|
||||
!valid_value(instructions, instruction.b, instruction.type, &emitter.module.types) {
|
||||
|
||||
Reference in New Issue
Block a user