From 149d12abcc130b1b092ba6347ae2372063f40445 Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Tue, 23 Sep 2008 16:49:25 +0000 Subject: [PATCH] added trace() fixed iterators for flash 6-8 --- Test.hx | 4 ++++ hscript.hxml | 4 ++-- hscript.hxp | 2 +- hscript/Interp.hx | 13 +++++++++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Test.hx b/Test.hx index 5f6371b..a993828 100644 --- a/Test.hx +++ b/Test.hx @@ -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"); } } \ No newline at end of file diff --git a/hscript.hxml b/hscript.hxml index 1736481..33bc917 100644 --- a/hscript.hxml +++ b/hscript.hxml @@ -1,5 +1,5 @@ -# Neko --swf9 hscript9.swf +# HScript +-swf9 hscript.swf -main Test -debug diff --git a/hscript.hxp b/hscript.hxp index fddc68f..92a81f9 100644 --- a/hscript.hxp +++ b/hscript.hxp @@ -1,5 +1,5 @@  - + diff --git a/hscript/Interp.hx b/hscript/Interp.hx index 86b8698..f593a8e 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -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 { + #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; }