selfhost: port switch — N_SWITCH parser + cgen + scratch slot
This commit is contained in:
@@ -345,6 +345,21 @@ probe_ww_compile(const char *bin)
|
||||
" dec(&c); dec(&c); dec(&c);\n"
|
||||
" return c.x;\n"
|
||||
"};", 2 },
|
||||
/* switch with multi-expr cases + default. Lowers to a chain
|
||||
* of CMPQ + JE; the scrutinee lands in a fresh 8B local slot
|
||||
* (".sw_N") so case bodies can spill SP without losing it.
|
||||
* classify(2)=10, classify(7)=70, classify(99)=0, sum 80. */
|
||||
{ "fn classify(x: i32) i32 = {\n"
|
||||
" switch (x) {\n"
|
||||
" case 1, 2, 3: return 10;\n"
|
||||
" case 7: return 70;\n"
|
||||
" case: return 0;\n"
|
||||
" };\n"
|
||||
" return -1;\n"
|
||||
"};\n"
|
||||
"fn main() i32 = {\n"
|
||||
" return classify(2) + classify(7) + classify(99);\n"
|
||||
"};", 80 },
|
||||
/* Chained N_DOT: o.ptr_to_inner.val (read field through a
|
||||
* pointer-to-struct field). Pre-fix the cgen fell through
|
||||
* silently and returned the inner pointer instead of the
|
||||
|
||||
Reference in New Issue
Block a user