diff --git a/hscript/Bytes.hx b/hscript/Bytes.hx index 7cffd3f..30ccf4c 100644 --- a/hscript/Bytes.hx +++ b/hscript/Bytes.hx @@ -30,7 +30,7 @@ class Bytes { var bin : haxe.io.Bytes; var bout : haxe.io.BytesBuffer; var pin : Int; - var hstrings : Hash; + var hstrings : #if haxe3 Map #else Hash #end; var strings : Array; var nstrings : Int; @@ -38,7 +38,7 @@ class Bytes { this.bin = bin; pin = 0; bout = new haxe.io.BytesBuffer(); - hstrings = new Hash(); + hstrings = #if haxe3 new Map() #else new Hash() #end; strings = [null]; nstrings = 1; } @@ -47,7 +47,7 @@ class Bytes { var vid = hstrings.get(v); if( vid == null ) { if( nstrings == 256 ) { - hstrings = new Hash(); + hstrings = #if haxe3 new Map() #else new Hash() #end; nstrings = 1; } hstrings.set(v,nstrings); diff --git a/hscript/Interp.hx b/hscript/Interp.hx index d73d8cc..063fe3b 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -33,15 +33,27 @@ private enum Stop { class Interp { + #if haxe3 + public var variables : Map; + var locals : Map; + var binops : Map Expr -> Dynamic >; + #else public var variables : Hash; var locals : Hash<{ r : Dynamic }>; - var binops : Hash Expr -> Dynamic>; + var binops : Hash< Expr -> Expr -> Dynamic >; + #end + var declared : Array<{ n : String, old : { r : Dynamic } }>; public function new() { + #if haxe3 + locals = new Map(); + variables = new Map(); + #else locals = new Hash(); - declared = new Array(); variables = new Hash(); + #end + declared = new Array(); variables.set("null",null); variables.set("true",true); variables.set("false",false); @@ -51,7 +63,11 @@ class Interp { function initOps() { var me = this; + #if haxe3 + binops = new Map(); + #else binops = new Hash(); + #end binops.set("+",function(e1,e2) return me.expr(e1) + me.expr(e2)); binops.set("-",function(e1,e2) return me.expr(e1) - me.expr(e2)); binops.set("*",function(e1,e2) return me.expr(e1) * me.expr(e2)); @@ -170,7 +186,11 @@ class Interp { } public function execute( expr : Expr ) : Dynamic { + #if haxe3 + locals = new Map(); + #else locals = new Hash(); + #end return exprReturn(expr); } @@ -187,8 +207,12 @@ class Interp { return null; } - function duplicate( h : Hash ) { + function duplicate( h : #if haxe3 Map < String, T > #else Hash #end ) { + #if haxe3 + var h2 = new Map(); + #else var h2 = new Hash(); + #end for( k in h.keys() ) h2.set(k,h.get(k)); return h2; diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 15a6483..9067a74 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -49,10 +49,16 @@ class Parser { public var line : Int; public var opChars : String; public var identChars : String; + #if haxe3 + public var opPriority : Map; + public var opRightAssoc : Map; + public var unops : Map; // true if allow postfix + #else public var opPriority : Hash; public var opRightAssoc : Hash; public var unops : Hash; // true if allow postfix - + #end + /** activate JSON compatiblity **/ @@ -81,8 +87,13 @@ class Parser { static inline var readPos = 0; static inline var tokenMin = 0; static inline var tokenMax = 0; + #if haxe3 + var tokens : haxe.ds.GenericStack; + #else var tokens : haxe.FastList; #end + + #end public function new() { @@ -101,14 +112,20 @@ class Parser { ["||"], ["=","+=","-=","*=","/=","%=","<<=",">>=",">>>=","|=","&=","^="], ]; + #if haxe3 + opPriority = new Map(); + opRightAssoc = new Map(); + unops = new Map(); + #else opPriority = new Hash(); opRightAssoc = new Hash(); + unops = new Hash(); + #end for( i in 0...priorities.length ) for( x in priorities[i] ) { opPriority.set(x, i); if( i == 9 ) opRightAssoc.set(x, true); } - unops = new Hash(); for( x in ["!", "++", "--", "-", "~"] ) unops.set(x, x == "++" || x == "--"); } @@ -136,8 +153,10 @@ class Parser { tokenMin = oldTokenMin = 0; tokenMax = oldTokenMax = 0; tokens = new List(); + #elseif haxe3 + tokens = new haxe.ds.GenericStack(); #else - tokens = new haxe.FastList(); + tokens = new FastList(); #end char = -1; input = s; @@ -294,7 +313,7 @@ class Parser { switch( tk ) { case TBrClose: return parseExprNext(mk(EObject([]),p1)); - case TId(id): + case TId(_): var tk2 = token(); push(tk2); push(tk); @@ -660,7 +679,7 @@ class Parser { } var t2 = parseType(); switch( t2 ) { - case CTFun(args, ret): + case CTFun(args, _): args.unshift(t); return t2; default: