From ca701335b44ff46bca7de67735999d649aaf508b Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Mon, 22 Oct 2012 11:01:06 +0000 Subject: [PATCH] haxe3 support --- Test.hx | 5 +++++ haxelib.xml | 4 ++-- hscript.hxml | 3 ++- hscript/Bytes.hx | 8 ++++++-- hscript/Expr.hx | 2 ++ hscript/Interp.hx | 4 +++- hscript/Parser.hx | 22 +++++++++++++++++++++- 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Test.hx b/Test.hx index 65e6804..bd22311 100644 --- a/Test.hx +++ b/Test.hx @@ -16,10 +16,15 @@ class Test { static function main() { test("0",0); test("0xFF", 255); + #if haxe3 + test("n(0xBFFFFFFF)",0xBFFFFFFF); + test("n(0x7FFFFFFF)", 0x7FFFFFFF); + #else #if !neko test("n(0xBFFFFFFF)",0xBFFFFFFF,{ n : haxe.Int32.toNativeInt }); test("n(0x7FFFFFFF)", 0x7FFFFFFF, { n : haxe.Int32.toNativeInt } ); #end + #end test("-123",-123); test("- 123",-123); test("1.546",1.546); diff --git a/haxelib.xml b/haxelib.xml index 97e7cc2..42c354f 100644 --- a/haxelib.xml +++ b/haxelib.xml @@ -1,6 +1,6 @@ - haXe Script is a scripting engine for a subset of the haXe language - minor fixes + Haxe Script is a scripting engine for a subset of the haXe language + minor fixes \ No newline at end of file diff --git a/hscript.hxml b/hscript.hxml index 8b9870c..1106017 100644 --- a/hscript.hxml +++ b/hscript.hxml @@ -1,4 +1,5 @@ --swf9 hscript.swf +-swf hscript.swf -swf-header 800:600:30:FFFFFF --flash-strict +-swf-version 9 -main Test diff --git a/hscript/Bytes.hx b/hscript/Bytes.hx index 3973ef8..7cffd3f 100644 --- a/hscript/Bytes.hx +++ b/hscript/Bytes.hx @@ -87,13 +87,15 @@ class Bytes { bout.addByte((v >> 16) & 0xFF); bout.addByte(v >>> 24); } + #if !haxe3 case CInt32(v): bout.addByte(4); var mid = haxe.Int32.toInt(haxe.Int32.and(v,haxe.Int32.ofInt(0xFFFFFF))); bout.addByte(mid & 0xFF); bout.addByte((mid >> 8) & 0xFF); bout.addByte(mid >> 16); - bout.addByte(haxe.Int32.toInt(haxe.Int32.ushr(v,24))); + bout.addByte(haxe.Int32.toInt(haxe.Int32.ushr(v, 24))); + #end case CFloat(f): bout.addByte(2); doEncodeString(Std.string(f)); @@ -115,11 +117,13 @@ class Bytes { CFloat( Std.parseFloat(doDecodeString()) ); case 3: CString( doDecodeString() ); + #if !haxe3 case 4: var i = bin.get(pin) | (bin.get(pin+1) << 8) | (bin.get(pin+2) << 16); var j = bin.get(pin+3); pin += 4; - CInt32(haxe.Int32.or(haxe.Int32.ofInt(i),haxe.Int32.shl(haxe.Int32.ofInt(j),24))); + CInt32(haxe.Int32.or(haxe.Int32.ofInt(i), haxe.Int32.shl(haxe.Int32.ofInt(j), 24))); + #end default: throw "Invalid code "+bin.get(pin-1); } diff --git a/hscript/Expr.hx b/hscript/Expr.hx index ebb74a1..c100c03 100644 --- a/hscript/Expr.hx +++ b/hscript/Expr.hx @@ -28,7 +28,9 @@ enum Const { CInt( v : Int ); CFloat( f : Float ); CString( s : String ); + #if !haxe3 CInt32( v : haxe.Int32 ); + #end } #if hscriptPos diff --git a/hscript/Interp.hx b/hscript/Interp.hx index 45e5815..3d2f88b 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -206,9 +206,11 @@ class Interp { case EConst(c): switch( c ) { case CInt(v): return v; - case CInt32(v): return v; case CFloat(f): return f; case CString(s): return s; + #if !haxe3 + case CInt32(v): return v; + #end } case EIdent(id): var l = locals.get(id); diff --git a/hscript/Parser.hx b/hscript/Parser.hx index eba421f..15a6483 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -839,6 +839,23 @@ class Parser { if( n > 0 || exp > 0 ) invalidChar(char); // read hexa + #if haxe3 + var n = 0; + while( true ) { + char = readChar(); + switch( char ) { + case 48,49,50,51,52,53,54,55,56,57: // 0-9 + n = (n << 4) + char - 48; + case 65,66,67,68,69,70: // A-F + n = (n << 4) + (char - 55); + case 97,98,99,100,101,102: // a-f + n = (n << 4) + (char - 87); + default: + this.char = char; + return TConst(CInt(n)); + } + } + #else var n = haxe.Int32.ofInt(0); while( true ) { char = readChar(); @@ -858,6 +875,7 @@ class Parser { return TConst(v); } } + #end default: this.char = char; var i = Std.int(n); @@ -975,9 +993,11 @@ class Parser { function constString( c ) { return switch(c) { case CInt(v): Std.string(v); - case CInt32(v): Std.string(v); case CFloat(f): Std.string(f); case CString(s): s; // TODO : escape + quote + #if !haxe3 + case CInt32(v): Std.string(v); + #end } }