haxe 3.0 compat

This commit is contained in:
Nicolas Cannasse
2013-02-24 17:03:22 +00:00
parent 39173b8a90
commit 00f4dcbb57
3 changed files with 54 additions and 11 deletions
+3 -3
View File
@@ -30,7 +30,7 @@ class Bytes {
var bin : haxe.io.Bytes;
var bout : haxe.io.BytesBuffer;
var pin : Int;
var hstrings : Hash<Int>;
var hstrings : #if haxe3 Map<String,Int> #else Hash<Int> #end;
var strings : Array<String>;
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);
+27 -3
View File
@@ -33,15 +33,27 @@ private enum Stop {
class Interp {
#if haxe3
public var variables : Map<String,Dynamic>;
var locals : Map<String,{ r : Dynamic }>;
var binops : Map<String, Expr -> Expr -> Dynamic >;
#else
public var variables : Hash<Dynamic>;
var locals : Hash<{ r : Dynamic }>;
var binops : Hash<Expr -> 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<String,Dynamic>();
#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<T>( h : Hash<T> ) {
function duplicate<T>( h : #if haxe3 Map < String, T > #else Hash<T> #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;
+24 -5
View File
@@ -49,10 +49,16 @@ class Parser {
public var line : Int;
public var opChars : String;
public var identChars : String;
#if haxe3
public var opPriority : Map<String,Int>;
public var opRightAssoc : Map<String,Bool>;
public var unops : Map<String,Bool>; // true if allow postfix
#else
public var opPriority : Hash<Int>;
public var opRightAssoc : Hash<Bool>;
public var unops : Hash<Bool>; // 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<Token>;
#else
var tokens : haxe.FastList<Token>;
#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<Token>();
#else
tokens = new haxe.FastList<Token>();
tokens = new FastList<Token>();
#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: