added trace()
fixed iterators for flash 6-8
This commit is contained in:
@@ -36,6 +36,8 @@ class Test {
|
||||
test("3 * (2 + 5)",21);
|
||||
test("3 * 2 // + 5 \n + 6",12);
|
||||
test("3 /* 2\n */ + 5",8);
|
||||
test("[55,66,77][1]",66);
|
||||
test("var a = [55]; a[0] *= 2; a[0]",110);
|
||||
test("x",55,{ x : 55 });
|
||||
test("var y = 33; y",33);
|
||||
test("{ 1; 2; 3; }",3);
|
||||
@@ -52,6 +54,7 @@ class Test {
|
||||
test("if( true ) 1 else 2",1);
|
||||
test("if( false ) 1 else 2",2);
|
||||
test("var t = 0; for( x in [1,2,3] ) t += x; t",6);
|
||||
test("var a = new Array(); for( x in 0...5 ) a[x] = x; a.join('-')","0-1-2-3-4");
|
||||
test("(function(a,b) return a + b)(4,5)",9);
|
||||
test("var y = 0; var add = function(a) y += a; add(5); add(3); y", 8);
|
||||
test("var a = [1,[2,[3,[4,null]]]]; var t = 0; while( a != null ) { t += a[0]; a = a[1]; }; t",10);
|
||||
@@ -59,6 +62,7 @@ class Test {
|
||||
test("var t = 0; for( x in new IntIter(1,10) ) t +=x; t",45,{ IntIter : IntIter });
|
||||
test("var x = 1; try { var x = 66; throw 789; } catch( e : Dynamic ) e + x",790);
|
||||
test("var x = 1; var f = function(x) throw x; try f(55) catch( e : Dynamic ) e + x",56);
|
||||
trace("Done");
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
# Neko
|
||||
-swf9 hscript9.swf
|
||||
# HScript
|
||||
-swf9 hscript.swf
|
||||
-main Test
|
||||
-debug
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<haxe selected="0">
|
||||
<output name="Neko" mode="swf9" out="hscript9.swf" class="Test" lib="" cmd="" main="True" debug="True"></output>
|
||||
<output name="HScript" mode="swf9" out="hscript.swf" class="Test" lib="" cmd="" main="True" debug="True"></output>
|
||||
<files path="/">
|
||||
<file path="hscript\Expr.hx" />
|
||||
<file path="hscript\Interp.hx" />
|
||||
|
||||
+11
-2
@@ -45,6 +45,7 @@ class Interp {
|
||||
variables.set("null",null);
|
||||
variables.set("true",true);
|
||||
variables.set("false",false);
|
||||
variables.set("trace",function(e) haxe.Log.trace(Std.string(e),cast { fileName : "hscript", lineNumber : 0 }));
|
||||
initOps();
|
||||
}
|
||||
|
||||
@@ -213,7 +214,7 @@ class Interp {
|
||||
if( l != null )
|
||||
return l.r;
|
||||
var v = variables.get(id);
|
||||
if( v == null && !variables.exists(v) )
|
||||
if( v == null && !variables.exists(id) )
|
||||
throw Error.EUnknownVariable(id);
|
||||
return v;
|
||||
case EVar(n,e):
|
||||
@@ -283,12 +284,16 @@ class Interp {
|
||||
me.locals = me.duplicate(capturedLocals);
|
||||
for( i in 0...params.length )
|
||||
me.locals.set(params[i],{ r : args[i] });
|
||||
var r;
|
||||
var r = null;
|
||||
try {
|
||||
r = me.exprReturn(fexpr);
|
||||
} catch( e : Dynamic ) {
|
||||
me.locals = old;
|
||||
#if neko
|
||||
neko.Lib.rethrow(e);
|
||||
#else
|
||||
throw e;
|
||||
#end
|
||||
}
|
||||
me.locals = old;
|
||||
return r;
|
||||
@@ -350,7 +355,11 @@ class Interp {
|
||||
}
|
||||
|
||||
function makeIterator( v : Dynamic ) : Iterator<Dynamic> {
|
||||
#if (flash && !flash9)
|
||||
if( v.iterator != null ) v = v.iterator();
|
||||
#else
|
||||
try v = v.iterator() catch( e : Dynamic ) {};
|
||||
#end
|
||||
if( v.hasNext == null || v.next == null ) throw Error.EInvalidIterator(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user