Remove haxe2 support
This commit is contained in:
@@ -26,13 +26,8 @@ class TestHScript extends TestCase {
|
||||
assertScript("0",0);
|
||||
assertScript("0xFF", 255);
|
||||
#if !(php || python)
|
||||
#if haxe3
|
||||
assertScript("0xBFFFFFFF", 0xBFFFFFFF);
|
||||
assertScript("0x7FFFFFFF", 0x7FFFFFFF);
|
||||
#elseif !neko
|
||||
assertScript("n(0xBFFFFFFF)", 0xBFFFFFFF, { n : haxe.Int32.toNativeInt });
|
||||
assertScript("n(0x7FFFFFFF)", 0x7FFFFFFF, { n : haxe.Int32.toNativeInt } );
|
||||
#end
|
||||
#end
|
||||
assertScript("-123",-123);
|
||||
assertScript("- 123",-123);
|
||||
@@ -81,11 +76,7 @@ class TestHScript extends TestCase {
|
||||
assertScript("var a = [1,[2,[3,[4,null]]]]; var t = 0; while( a != null ) { t += a[0]; a = a[1]; }; t",10);
|
||||
assertScript("var a = false; do { a = true; } while (!a); a;",true);
|
||||
assertScript("var t = 0; for( x in 1...10 ) t += x; t", 45);
|
||||
#if haxe3
|
||||
assertScript("var t = 0; for( x in new IntIterator(1,10) ) t +=x; t", 45);
|
||||
#else
|
||||
assertScript("var t = 0; for( x in new IntIter(1,10) ) t +=x; t", 45);
|
||||
#end
|
||||
assertScript("var x = 1; try { var x = 66; throw 789; } catch( e : Dynamic ) e + x",790);
|
||||
assertScript("var x = 1; var f = function(x) throw x; try f(55) catch( e : Dynamic ) e + x",56);
|
||||
assertScript("var i=2; if( true ) --i; i",1);
|
||||
|
||||
+4
-20
@@ -27,7 +27,7 @@ class Bytes {
|
||||
var bin : haxe.io.Bytes;
|
||||
var bout : haxe.io.BytesBuffer;
|
||||
var pin : Int;
|
||||
var hstrings : #if haxe3 Map<String,Int> #else Hash<Int> #end;
|
||||
var hstrings : Map<String,Int>;
|
||||
var strings : Array<String>;
|
||||
var nstrings : Int;
|
||||
|
||||
@@ -35,7 +35,7 @@ class Bytes {
|
||||
this.bin = bin;
|
||||
pin = 0;
|
||||
bout = new haxe.io.BytesBuffer();
|
||||
hstrings = #if haxe3 new Map() #else new Hash() #end;
|
||||
hstrings = new Map();
|
||||
strings = [null];
|
||||
nstrings = 1;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class Bytes {
|
||||
var vid = hstrings.get(v);
|
||||
if( vid == null ) {
|
||||
if( nstrings == 256 ) {
|
||||
hstrings = #if haxe3 new Map() #else new Hash() #end;
|
||||
hstrings = new Map();
|
||||
nstrings = 1;
|
||||
}
|
||||
hstrings.set(v,nstrings);
|
||||
@@ -85,15 +85,6 @@ class Bytes {
|
||||
bout.addByte(1);
|
||||
doEncodeInt(v);
|
||||
}
|
||||
#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)));
|
||||
#end
|
||||
case CFloat(f):
|
||||
bout.addByte(2);
|
||||
doEncodeString(Std.string(f));
|
||||
@@ -120,13 +111,6 @@ 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)));
|
||||
#end
|
||||
default:
|
||||
throw "Invalid code "+bin.get(pin-1);
|
||||
}
|
||||
@@ -344,7 +328,7 @@ class Bytes {
|
||||
var v = doDecodeString();
|
||||
ETry(e,v,null,doDecode());
|
||||
case 21:
|
||||
var fl = [];
|
||||
var fl:Array<ObjectField> = [];
|
||||
for( i in 0...bin.get(pin++) ) {
|
||||
var name = doDecodeString();
|
||||
var e = doDecode();
|
||||
|
||||
@@ -35,9 +35,6 @@ enum Const {
|
||||
CInt( v : Int );
|
||||
CFloat( f : Float );
|
||||
CString( s : String );
|
||||
#if !haxe3
|
||||
CInt32( v : haxe.Int32 );
|
||||
#end
|
||||
}
|
||||
|
||||
#if hscriptPos
|
||||
|
||||
+4
-57
@@ -103,7 +103,7 @@ class Interp {
|
||||
}
|
||||
public var errorHandler:Error->Void;
|
||||
public var importFailedCallback:Array<String>->Bool;
|
||||
#if haxe3
|
||||
|
||||
public var customClasses:Map<String, Dynamic>;
|
||||
public var variables:Map<String, Dynamic>;
|
||||
public var publicVariables:Map<String, Dynamic>;
|
||||
@@ -111,15 +111,6 @@ class Interp {
|
||||
|
||||
public var locals:Map<String, DeclaredVar>;
|
||||
var binops:Map<String, Expr->Expr->Dynamic>;
|
||||
#else
|
||||
public var customClasses:Hash<Dynamic>;
|
||||
public var variables:Hash<Dynamic>;
|
||||
public var publicVariables:Hash<Dynamic>;
|
||||
public var staticVariables:Hash<Dynamic>;
|
||||
|
||||
public var locals:Hash<DeclaredVar>;
|
||||
var binops:Hash<Expr->Expr->Dynamic>;
|
||||
#end
|
||||
|
||||
var depth:Int = 0;
|
||||
var inTry:Bool;
|
||||
@@ -143,29 +134,17 @@ class Interp {
|
||||
#end
|
||||
|
||||
public function new() {
|
||||
#if haxe3
|
||||
locals = new Map();
|
||||
#else
|
||||
locals = new Hash();
|
||||
#end
|
||||
declared = [];
|
||||
resetVariables();
|
||||
initOps();
|
||||
}
|
||||
|
||||
private function resetVariables():Void {
|
||||
#if haxe3
|
||||
customClasses = new Map<String, Dynamic>();
|
||||
variables = new Map<String, Dynamic>();
|
||||
publicVariables = new Map<String, Dynamic>();
|
||||
staticVariables = new Map<String, Dynamic>();
|
||||
#else
|
||||
customClasses = new Hash();
|
||||
variables = new Hash();
|
||||
publicVariables = new Hash();
|
||||
staticVariables = new Hash();
|
||||
#end
|
||||
|
||||
variables.set("null", null);
|
||||
variables.set("true", true);
|
||||
variables.set("false", false);
|
||||
@@ -188,11 +167,7 @@ class Interp {
|
||||
|
||||
function initOps():Void {
|
||||
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));
|
||||
@@ -218,12 +193,7 @@ class Interp {
|
||||
var expr1:Dynamic = me.expr(e1);
|
||||
return expr1 == null ? me.expr(e2) : expr1;
|
||||
});
|
||||
binops.set("...", function(e1, e2) return new
|
||||
#if (haxe_211 || haxe3)
|
||||
IntIterator
|
||||
#else
|
||||
IntIter
|
||||
#end(me.expr(e1), me.expr(e2)));
|
||||
binops.set("...", function(e1, e2) return new IntIterator(me.expr(e1), me.expr(e2)));
|
||||
assignOp("+=", function(v1:Dynamic, v2:Dynamic) return v1 + v2);
|
||||
assignOp("-=", function(v1:Float, v2:Float) return v1 - v2);
|
||||
assignOp("*=", function(v1:Float, v2:Float) return v1 * v2);
|
||||
@@ -477,11 +447,7 @@ class Interp {
|
||||
|
||||
public function execute(expr:Expr):Dynamic {
|
||||
depth = 0;
|
||||
#if haxe3
|
||||
locals = new Map();
|
||||
#else
|
||||
locals = new Hash();
|
||||
#end
|
||||
declared = [];
|
||||
return exprReturn(expr);
|
||||
}
|
||||
@@ -517,8 +483,7 @@ class Interp {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function duplicate<T>(h:#if haxe3 Map<String, T> #else Hash<T> #end) {
|
||||
#if haxe3
|
||||
public function duplicate<T>(h:Map<String, T>) {
|
||||
var h2 = new Map();
|
||||
var keys = h.keys();
|
||||
var _hasNext = keys.hasNext;
|
||||
@@ -528,12 +493,6 @@ class Interp {
|
||||
h2.set(k, h.get(k));
|
||||
}
|
||||
return h2;
|
||||
#else
|
||||
var h2 = new Hash();
|
||||
for (k in h.keys())
|
||||
h2.set(k, h.get(k));
|
||||
return h2;
|
||||
#end
|
||||
}
|
||||
|
||||
function restore(old:Int):Void {
|
||||
@@ -706,9 +665,6 @@ class Interp {
|
||||
case CInt(v): return v;
|
||||
case CFloat(f): return f;
|
||||
case CString(s): return s;
|
||||
#if !haxe3
|
||||
case CInt32(v): return v;
|
||||
#end
|
||||
}
|
||||
case EIdent(id):
|
||||
return resolve(id);
|
||||
@@ -756,11 +712,7 @@ class Interp {
|
||||
case "--":
|
||||
return increment(e, prefix, -1);
|
||||
case "~":
|
||||
#if (neko && !haxe3)
|
||||
return haxe.Int32.complement(expr(e));
|
||||
#else
|
||||
return ~expr(e);
|
||||
#end
|
||||
default:
|
||||
error(EInvalidOp(op));
|
||||
}
|
||||
@@ -799,7 +751,7 @@ class Interp {
|
||||
case EFunction(params, fexpr, name, _, isPublic, isStatic, isOverride, isPrivate, isFinal, isInline):
|
||||
var __capturedLocals = duplicate(locals);
|
||||
var capturedLocals:Map<String, DeclaredVar> = [];
|
||||
#if haxe3
|
||||
|
||||
var keys = __capturedLocals.keys();
|
||||
var _hasNext = keys.hasNext;
|
||||
var _next = keys.next;
|
||||
@@ -809,11 +761,6 @@ class Interp {
|
||||
if (e != null && e.depth > 0)
|
||||
capturedLocals.set(k, e);
|
||||
}
|
||||
#else
|
||||
for(k=>e in __capturedLocals)
|
||||
if (e != null && e.depth > 0)
|
||||
capturedLocals.set(k, e);
|
||||
#end
|
||||
|
||||
var me = this;
|
||||
var hasOpt = false, minParams = 0;
|
||||
|
||||
+3
-37
@@ -29,23 +29,13 @@ import haxe.macro.Expr;
|
||||
class Macro {
|
||||
|
||||
var p : Position;
|
||||
#if haxe3
|
||||
var binops : Map<String,Binop>;
|
||||
var unops : Map<String,Unop>;
|
||||
#else
|
||||
var binops : Hash<Binop>;
|
||||
var unops : Hash<Unop>;
|
||||
#end
|
||||
|
||||
public function new(pos) {
|
||||
p = pos;
|
||||
#if haxe3
|
||||
binops = new Map();
|
||||
unops = new Map();
|
||||
#else
|
||||
binops = new Hash();
|
||||
unops = new Hash();
|
||||
#end
|
||||
for( c in Type.getEnumConstructs(Binop) ) {
|
||||
if( c == "OpAssignOp" ) continue;
|
||||
var op = Type.createEnum(Binop, c);
|
||||
@@ -73,9 +63,7 @@ class Macro {
|
||||
case OpMod: assign = true; "%";
|
||||
case OpAssignOp(_): "";
|
||||
case OpInterval: "...";
|
||||
#if haxe3
|
||||
case OpArrow: "=>";
|
||||
#end
|
||||
#if (haxe_ver >= 4)
|
||||
case OpIn: "in";
|
||||
#end
|
||||
@@ -102,13 +90,6 @@ class Macro {
|
||||
}
|
||||
}
|
||||
|
||||
#if !haxe3
|
||||
function isType(v:String) {
|
||||
var c0 = v.charCodeAt(0);
|
||||
return c0 >= 'A'.code && c0 <= 'Z'.code;
|
||||
}
|
||||
#end
|
||||
|
||||
function map < T, R > ( a : Array<T>, f : T -> R ) : Array<R> {
|
||||
var b = [];
|
||||
for( x in a )
|
||||
@@ -156,17 +137,9 @@ class Macro {
|
||||
case CInt(v): CInt(Std.string(v));
|
||||
case CFloat(f): CFloat(Std.string(f));
|
||||
case CString(s): CString(s);
|
||||
#if !haxe3
|
||||
case CInt32(v): CInt(Std.string(v));
|
||||
#end
|
||||
});
|
||||
case EIdent(v):
|
||||
#if !haxe3
|
||||
if( isType(v) )
|
||||
EConst(CType(v));
|
||||
else
|
||||
#end
|
||||
EConst(CIdent(v));
|
||||
EConst(CIdent(v));
|
||||
case EVar(n, t, e):
|
||||
EVars([ { name : n, expr : if( e == null ) null else convert(e), type : if( t == null ) null else convertType(t) } ]);
|
||||
case EParent(e):
|
||||
@@ -174,12 +147,7 @@ class Macro {
|
||||
case EBlock(el):
|
||||
EBlock(map(el,convert));
|
||||
case EField(e, f):
|
||||
#if !haxe3
|
||||
if( isType(f) )
|
||||
EType(convert(e), f);
|
||||
else
|
||||
#end
|
||||
EField(convert(e), f);
|
||||
EField(convert(e), f);
|
||||
case EBinop(op, e1, e2):
|
||||
var b = binops.get(op);
|
||||
if( b == null ) throw EInvalidOp(op);
|
||||
@@ -200,11 +168,9 @@ class Macro {
|
||||
#if (haxe_ver >= 4)
|
||||
var p = #if hscriptPos { file : p.file, min : e.pmin, max : e.pmax } #else p #end;
|
||||
EFor({ expr : EBinop(OpIn,{ expr : EConst(CIdent(v)), pos : p },convert(it)), pos : p }, convert(efor));
|
||||
#elseif (haxe_211 || haxe3)
|
||||
#else
|
||||
var p = #if hscriptPos { file : p.file, min : e.pmin, max : e.pmax } #else p #end;
|
||||
EFor({ expr : EIn({ expr : EConst(CIdent(v)), pos : p },convert(it)), pos : p }, convert(efor));
|
||||
#else
|
||||
EFor(v, convert(it), convert(efor));
|
||||
#end
|
||||
case EBreak:
|
||||
EBreak;
|
||||
|
||||
+1
-62
@@ -58,13 +58,8 @@ 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>;
|
||||
#else
|
||||
public var opPriority : Hash<Int>;
|
||||
public var opRightAssoc : Hash<Bool>;
|
||||
#end
|
||||
|
||||
/**
|
||||
allows to check for #if / #else in code
|
||||
@@ -113,11 +108,7 @@ class Parser {
|
||||
static inline var p1 = 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
|
||||
|
||||
@@ -139,13 +130,8 @@ class Parser {
|
||||
["->", "??"],
|
||||
["is"]
|
||||
];
|
||||
#if haxe3
|
||||
opPriority = new Map();
|
||||
opRightAssoc = new Map();
|
||||
#else
|
||||
opPriority = new Hash();
|
||||
opRightAssoc = new Hash();
|
||||
#end
|
||||
for( i in 0...priorities.length )
|
||||
for( x in priorities[i] ) {
|
||||
opPriority.set(x, i);
|
||||
@@ -177,10 +163,8 @@ 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 haxe.ds.GenericStack<Token>();
|
||||
#end
|
||||
char = -1;
|
||||
ops = [];
|
||||
@@ -1829,7 +1813,6 @@ class Parser {
|
||||
if( n > 0 || exp > 0 )
|
||||
invalidChar(char);
|
||||
// read hexa
|
||||
#if haxe3
|
||||
var n = 0;
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
@@ -1846,33 +1829,10 @@ class Parser {
|
||||
return TConst(CInt(n));
|
||||
}
|
||||
}
|
||||
#else
|
||||
var n = haxe.Int32.ofInt(0);
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
switch( char ) {
|
||||
case 48,49,50,51,52,53,54,55,56,57: // 0-9
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 48));
|
||||
case 65,66,67,68,69,70: // A-F
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 55));
|
||||
case 97,98,99,100,101,102: // a-f
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 87));
|
||||
case '_'.code:
|
||||
default:
|
||||
this.char = char;
|
||||
// we allow to parse hexadecimal Int32 in Neko, but when the value will be
|
||||
// evaluated by Interpreter, a failure will occur if no Int32 operation is
|
||||
// performed
|
||||
var v = try CInt(haxe.Int32.toInt(n)) catch( e : Dynamic ) CInt32(n);
|
||||
return TConst(v);
|
||||
}
|
||||
}
|
||||
#end
|
||||
case "b".code: // Custom thing, not supported in haxe
|
||||
if( n > 0 || exp > 0 )
|
||||
invalidChar(char);
|
||||
// read binary
|
||||
#if haxe3
|
||||
var n = 0;
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
@@ -1885,24 +1845,6 @@ class Parser {
|
||||
return TConst(CInt(n));
|
||||
}
|
||||
}
|
||||
#else
|
||||
var n = haxe.Int32.ofInt(0);
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
switch( char ) {
|
||||
case 48,49: // 0-1
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,1), cast (char - 48));
|
||||
case '_'.code:
|
||||
default:
|
||||
this.char = char;
|
||||
// we allow to parse binary Int32 in Neko, but when the value will be
|
||||
// evaluated by Interpreter, a failure will occur if no Int32 operation is
|
||||
// performed
|
||||
var v = try CInt(haxe.Int32.toInt(n)) catch( e : Dynamic ) CInt32(n);
|
||||
return TConst(v);
|
||||
}
|
||||
}
|
||||
#end
|
||||
default:
|
||||
this.char = char;
|
||||
var i = Std.int(n);
|
||||
@@ -2195,9 +2137,6 @@ class Parser {
|
||||
case CInt(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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user