Permalink
Browse files

fix volatile lexicals

  • Loading branch information...
1 parent ad1eaf3 commit 1fbb314dfb742bbddeb46edbc347373fdea767c9 @NotFound committed Jun 21, 2012
Showing with 40 additions and 22 deletions.
  1. +11 −1 t/base/10closure.t
  2. +29 −21 winxedxx.winxed
View
@@ -12,11 +12,21 @@ function getfun()
return f;
}
+function getfuni()
+{
+ int n = 43;
+ var f = function () { return n; };
+ return f;
+}
+
function main[main](var args)
{
var fun = getfun();
int i = fun();
- is(i, 42, "calling a closure");
+ is(i, 42, "closure with a lexical var");
+ fun = getfuni();
+ i = fun();
+ is(i, 43, "closure with a lexical int");
done_testing();
}
View
@@ -709,6 +709,12 @@ function emitExpr(var out, :IdentifierExpr expr)
out.print(name);
}
+function emitExpr(var out, :LexicalVolatileExpr expr)
+{
+ string name = expr.start.getidentifier();
+ out.print(name);
+}
+
function emitExpr(var out, :NullExpr expr)
{
out.print("winxedxxnull");
@@ -1471,23 +1477,27 @@ function emit_nativetypestatement(out, st, string type, string nullinit)
string name = st.name;
var init = st.init;
- out.print(generatedType(type), " ", name, " = ");
- if (init == null) {
- out.print(nullinit);
- }
- else {
- switch (type) {
- case REGint:
- emit_intexpr(out, init);
- break;
- case REGfloat:
- emit_numexpr(out, init);
- break;
- case REGstring:
- emit_stringexpr(out, init);
- break;
- }
+ int flags = 0;
+ string lexname = null;
+ var local = st.owner.getvar(name);
+ if (local != null) {
+ flags = local.getflags();
+ lexname = local.getlex();
}
+ int is_lex = (flags & VAR_is_lexical) || lexname != null;
+ // If lexical, declare a reference to the data struct
+ // Else, declare plain var
+ out.print(generatedType(type), " ");
+ if (is_lex)
+ out.print("&", name, " = ", DATA, "->", name);
+ else
+ out.print(name);
+
+ out.print(" = ");
+ if (init == null)
+ out.print(nullinit);
+ else
+ emit_typedexpr(out, init, type);
}
function emit_nativearraystatement(out, st, string arraytype)
@@ -1566,11 +1576,9 @@ function emitStatement(var out, :VarStatement st)
// Else, declare plain var
out.print(Type_PMC, " ");
if (is_lex)
- out.print("&");
- out.print(st.name);
- if (is_lex) {
- out.print(" = ", DATA, "->", st.name);
- }
+ out.print("&", name, " = ", DATA, "->", name);
+ else
+ out.print(name);
if (init != null) {
out.print(" = ");

0 comments on commit 1fbb314

Please sign in to comment.