refactor: precompute compiler enum mappings

This commit is contained in:
2026-10-30 10:10:43 +01:00
parent d7e637dc3b
commit 30a98db379
13 changed files with 452 additions and 279 deletions
+18 -13
View File
@@ -1,5 +1,6 @@
import "@std/mem"
import "@std/arraylist"
import "@std/enummap"
import "@source/ast"
#! owns output bytes and retains its allocator; release with deinit.
@@ -161,19 +162,23 @@ append_text proc(renderer @mut Renderer, text []u8) void ! mem.AllocError {
for (text) |byte| try arraylist.append(&renderer.bytes, byte)
}
@hide:file
assignment_operator_texts :: $enummap.init_filled(
ast.BinaryOperator, []u8, "", {
add = "+",
subtract = "-",
multiply = "*",
divide = "/",
bit_and = "&",
bit_or = "|",
bit_xor = "xor",
shift_left = "<<",
shift_right = ">>",
shift_left_saturating = "<<|",
},
)
@hide:file
assignment_operator_text proc(operator ast.BinaryOperator) []u8 {
return match operator {
.add: "+"
.subtract: "-"
.multiply: "*"
.divide: "/"
.bit_and: "&"
.bit_or: "|"
.bit_xor: "xor"
.shift_left: "<<"
.shift_right: ">>"
.shift_left_saturating: "<<|"
else: unreachable
}
return enummap.get(&assignment_operator_texts, operator)?
}