Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix multi return and initial implementation of multi assign

  • Loading branch information...
commit 53b8b9d65835f519fe1600ae11a1a32c5a1ef752 1 parent 1fbb314
@NotFound authored
Showing with 50 additions and 2 deletions.
  1. +1 −0  Makefile
  2. +29 −0 t/base/05mreturn.t
  3. +20 −2 winxedxx.winxed
View
1  Makefile
@@ -115,6 +115,7 @@ TESTS = t/base/00test.t \
t/base/02bitwiseops.t \
t/base/02varcast.t \
t/base/03pmc.t t/base/03class.t \
+ t/base/05mreturn.t \
t/base/06localfunctions.t \
t/base/10closure.t \
t/base/features.t
View
29 t/base/05mreturn.t
@@ -0,0 +1,29 @@
+#! winxed
+
+// winxedxx base tests
+// multi assign and multi return
+
+using extern Test.More plan, is, ok;
+
+function main()
+{
+ plan(2);
+
+ int i, j;
+ :(i, j) = ret2();
+ is(i, 42, "first value of 2");
+ is(j, 24, "second value of 2");
+
+}
+
+function ret1()
+{
+ return 7;
+}
+
+function ret2()
+{
+ return 42, 24;
+}
+
+// End
View
22 winxedxx.winxed
@@ -109,6 +109,7 @@ class IntArrayStatement;
class FloatArrayStatement;
class StringArrayStatement;
class ConstStatement;
+class MultiAssignStatement;
class ReturnStatement;
class LabelStatement;
class BreakStatement;
@@ -1586,6 +1587,20 @@ function emitStatement(var out, :VarStatement st)
}
}
+function emitStatement(var out, :MultiAssignStatement st)
+{
+ out.print("{\n WxxObjectPtr __m_1 = ");
+ emit_expr(out, st.expr);
+ out.print(";\n");
+ var params = st.params.params;
+ int i = 0;
+ for (var param in params) {
+ var data = param.getvar();
+ out.print(" ", param.name, " = __m_1.get_pmc_keyed(", i++, ");\n");
+ }
+ out.print("}\n");
+}
+
function emitStatement(var out, :LabelStatement labelst)
{
out.print(labelst.name);
@@ -1785,12 +1800,15 @@ function emitStatement(var out, :ReturnStatement returnst)
emit_expr(out, expr);
break;
default:
- out.print(Type_PMCArray, "()");
+ out.print(Type_PMC, "(&((new ", Type_PMCArray, "())->");
for (int i = 0; i < nargs; ++i) {
- out.print(".push(");
+ if (i)
+ out.print(".");
+ out.print("push(");
emit_expr(out, values.getfreearg(i));
out.print(")");
}
+ out.print("))");
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.