]> Nishi Git Mirror - gwion.git/commitdiff
:art: Fix dyn_switch
authorfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 19 Feb 2019 10:21:56 +0000 (11:21 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 19 Feb 2019 10:22:39 +0000 (11:22 +0100)
examples/dyn_switch.gw [new file with mode: 0644]
examples/template_dyn.gw [new file with mode: 0644]
src/emit/emit.c
src/lib/instr.c

diff --git a/examples/dyn_switch.gw b/examples/dyn_switch.gw
new file mode 100644 (file)
index 0000000..8051367
--- /dev/null
@@ -0,0 +1,11 @@
+3 => 
+const int i;
+2 => const int y;
+switch(i) {
+  case 1: <<<1>>>;break;
+  case 3: <<<3>>>;break;
+  case y: <<<2>>>;break;
+  default:
+    <<<"0">>>;
+}
+<<<y>>>;
diff --git a/examples/template_dyn.gw b/examples/template_dyn.gw
new file mode 100644 (file)
index 0000000..ebfa251
--- /dev/null
@@ -0,0 +1,52 @@
+fun void test(C cc) { <<< cc.test(2) >>>; }
+
+fun void test(C cc, int i) { <<<1>>>; <<<cc.test(i, i)>>>; }
+
+
+class C {
+  template<~A~>
+  fun int test(A a) { <<<" A ", a>>>; }
+  template<~A~>
+  fun int test(A a, int i) { <<<" ", a >>>; }
+  template<~A~>
+  fun int test(A a, int i, int j) { <<<a>>>; }
+}
+class D extends C {
+  template<~A~>
+  fun int test(A a, int i) { <<<this, " extent ", a, __func__>>>; }
+}
+class E extends D {
+  template<~A~>
+  fun int test(A a, int i) { <<<this, " Extent ", a, __func__>>>; }
+}
+
+
+<<<C c>>>;
+<<<D d>>>;
+<<<E e>>>;
+
+test(c);
+test(d);
+test(e);
+test(c,1);
+test(d,2);
+test(e,3);
+<<<test>>>;
+
+
+c.test(1);
+c.test(123,1);
+c.test(1, 2, 3);
+
+d.test(2);
+d.test(123,3);
+d.test(2, 2, 3);
+
+e.test(3);
+e.test(123,3);
+e.test(3, 2, 3);
+
+fun void _test() {<<<"test">>>; }
+fun void test() { _test(); }
+test();
+
index 7c1860730cb80ce460c9aef22a0b3f114d6d23fe..298d338215020c4c2b0588a0f1f1930715c9e5c5 100644 (file)
@@ -1128,7 +1128,6 @@ ANN static m_bool emit_switch_instr(const Emitter emit, Instr *instr) {
     while((e = switch_expget(emit->env)))
       CHECK_BB(emit_exp(emit, e, 0))
     *instr = emit_add_instr(emit, SwitchIni);
-    (*instr)->m_val = (m_uint)switch_vec(emit->env);
   } else {
     const Instr instr = emit_add_instr(emit, RegPushImm);
     instr->m_val = (m_uint)switch_map(emit->env);
@@ -1139,7 +1138,7 @@ ANN static m_bool emit_switch_instr(const Emitter emit, Instr *instr) {
 ANN static void emit_switch_map(const Instr instr, const Map map) {
   const Map m = new_map();
   for(m_uint i = map_size(map) + 1; --i;)
-    map_set(m, VKEY(map, i), VVAL(map, i -1));
+    map_set(m, VKEY(map, i-1), VVAL(map, i -1));
   instr->m_val2 = (m_uint)m;
 }
 
@@ -1155,6 +1154,7 @@ ANN static m_bool emit_stmt_switch(const Emitter emit, const Stmt_Switch stmt) {
   instr->m_val = switch_idx(emit->env) ?: emit_code_size(emit);
   if(push) {
     emit_switch_map(push, (Map)instr->m_val2);
+    (push)->m_val = (m_uint)switch_vec(emit->env);
   }
   switch_end(emit->env);
   pop_vector(&emit->code->stack_break, emit_code_size(emit));
index c2f18f2d12e347554e334201ddee8777c42108a7..da88ca359d199ec9dcb5b2f7163fe77e6ec10049 100644 (file)
@@ -36,7 +36,7 @@ INSTR(SwitchIni) {
   const Vector v = (Vector)instr->m_val;
   const m_uint size = vector_size(v);
   const Map m = (Map)instr->m_val2;
-  POP_REG(shred, SZ_INT * (size - 1));
+  POP_REG(shred, SZ_INT * (size-1));
   for(m_uint i = 0; i < size; ++i)
     map_set(m, *(vtype*)REG((i-1) * SZ_INT), vector_at(v, i));
   *(Map*)REG(-SZ_INT) = m;