Optimizations
This commit is contained in:
+12
-5
@@ -75,7 +75,7 @@ enum Expr {
|
||||
ENew( cl : String, params : Array<Expr> );
|
||||
EThrow( e : Expr );
|
||||
ETry( e : Expr, v : String, t : Null<CType>, ecatch : Expr );
|
||||
EObject( fl : Array<{ name : String, e : Expr }> );
|
||||
EObject( fl : Array<ObjectField> );
|
||||
ETernary( cond : Expr, e1 : Expr, e2 : Expr );
|
||||
ESwitch( e : Expr, cases : Array<SwitchCase>, ?defaultExpr : Expr );
|
||||
EDoWhile( cond : Expr, e : Expr);
|
||||
@@ -86,6 +86,12 @@ enum Expr {
|
||||
EClass( name:String, fields:Array<Expr>, ?extend:String, interfaces:Array<String>, ?isFinal:Bool, ?isPrivate:Bool );
|
||||
}
|
||||
|
||||
@:structInit
|
||||
final class ObjectField {
|
||||
public var name : String;
|
||||
public var e : Expr;
|
||||
}
|
||||
|
||||
@:structInit
|
||||
final class SwitchCase {
|
||||
public var values : Array<Expr>;
|
||||
@@ -200,10 +206,11 @@ enum FieldKind {
|
||||
KVar( v : VarDecl );
|
||||
}
|
||||
|
||||
typedef FunctionDecl = {
|
||||
var args : Array<Argument>;
|
||||
var body : Expr;
|
||||
var ret : Null<CType>;
|
||||
@:structInit
|
||||
final class FunctionDecl {
|
||||
public var args : Array<Argument>;
|
||||
public var body : Expr;
|
||||
public var ret : Null<CType>;
|
||||
}
|
||||
|
||||
typedef VarDecl = {
|
||||
|
||||
+26
-4
@@ -74,8 +74,9 @@ class Interp {
|
||||
__instanceFields = Type.getInstanceFields(c);
|
||||
if(v is IHScriptCustomClassBehaviour) {
|
||||
var v = cast(v, IHScriptCustomClassBehaviour);
|
||||
if(v.__class__fields != null)
|
||||
__instanceFields = __instanceFields.concat(v.__class__fields);
|
||||
var classFields = v.__class__fields;
|
||||
if(classFields != null)
|
||||
__instanceFields = __instanceFields.concat(classFields);
|
||||
_scriptObjectType = SCustomClass;
|
||||
} else if(v is IHScriptCustomBehaviour) {
|
||||
_scriptObjectType = SBehaviourClass;
|
||||
@@ -274,6 +275,7 @@ class Interp {
|
||||
|
||||
if (_scriptObjectType == SObject && instanceHasField) {
|
||||
UnsafeReflect.setField(scriptObject, id, v);
|
||||
return v;
|
||||
} else if (_scriptObjectType == SCustomClass && instanceHasField) {
|
||||
var obj = cast(scriptObject, IHScriptCustomClassBehaviour);
|
||||
if(isBypassAccessor) {
|
||||
@@ -511,12 +513,20 @@ class Interp {
|
||||
public function duplicate<T>(h:#if haxe3 Map<String, T> #else Hash<T> #end) {
|
||||
#if haxe3
|
||||
var h2 = new Map();
|
||||
var keys = h.keys();
|
||||
var _hasNext = keys.hasNext;
|
||||
var _next = keys.next;
|
||||
while (_hasNext()) {
|
||||
var k = _next();
|
||||
h2.set(k, h.get(k));
|
||||
}
|
||||
return h2;
|
||||
#else
|
||||
var h2 = new Hash();
|
||||
#end
|
||||
for (k in h.keys())
|
||||
h2.set(k, h.get(k));
|
||||
return h2;
|
||||
#end
|
||||
}
|
||||
|
||||
function restore(old:Int):Void {
|
||||
@@ -775,12 +785,24 @@ class Interp {
|
||||
case EReturn(e):
|
||||
returnValue = e == null ? null : expr(e);
|
||||
throw SReturn;
|
||||
case EFunction(params, fexpr, name, _, isPublic, isStatic, isOverride):
|
||||
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;
|
||||
while (_hasNext()) {
|
||||
var k = _next();
|
||||
var e = __capturedLocals.get(k);
|
||||
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;
|
||||
|
||||
+16
-9
@@ -44,6 +44,13 @@ enum Token {
|
||||
TPrepro( s : String );
|
||||
}
|
||||
|
||||
@:structInit
|
||||
final class TokenInfo {
|
||||
public var min : Int;
|
||||
public var max : Int;
|
||||
public var t : Token;
|
||||
}
|
||||
|
||||
class Parser {
|
||||
|
||||
// config / variables
|
||||
@@ -100,7 +107,7 @@ class Parser {
|
||||
var tokenMax : Int;
|
||||
var oldTokenMin : Int;
|
||||
var oldTokenMax : Int;
|
||||
var tokens : List<{ min : Int, max : Int, t : Token }>;
|
||||
var tokens : List<TokenInfo>;
|
||||
#else
|
||||
static inline var p1 = 0;
|
||||
static inline var tokenMin = 0;
|
||||
@@ -319,7 +326,7 @@ class Parser {
|
||||
|
||||
function parseObject(p1:Int):Expr {
|
||||
// parse object
|
||||
var fl = [];
|
||||
var fl:Array<ObjectField> = [];
|
||||
while( true ) {
|
||||
var tk = token();
|
||||
var id = null;
|
||||
@@ -2033,7 +2040,7 @@ class Parser {
|
||||
return preprocesorValues.get(id);
|
||||
}
|
||||
|
||||
var preprocStack : Array<{ r : Bool }>;
|
||||
var preprocStack : Array<Bool>;
|
||||
|
||||
function parsePreproCond():Expr {
|
||||
var tk = token();
|
||||
@@ -2096,20 +2103,20 @@ class Parser {
|
||||
case "if":
|
||||
var e = parsePreproCond();
|
||||
if( evalPreproCond(e) ) {
|
||||
preprocStack.push({ r : true });
|
||||
preprocStack.push(true);
|
||||
return token();
|
||||
}
|
||||
preprocStack.push({ r : false });
|
||||
preprocStack.push(false);
|
||||
skipTokens();
|
||||
return token();
|
||||
case "else", "elseif" if( preprocStack.length > 0 ):
|
||||
if( preprocStack[preprocStack.length - 1].r ) {
|
||||
preprocStack[preprocStack.length - 1].r = false;
|
||||
if( preprocStack[preprocStack.length - 1] ) {
|
||||
preprocStack[preprocStack.length - 1] = false;
|
||||
skipTokens();
|
||||
return token();
|
||||
} else if( id == "else" ) {
|
||||
preprocStack.pop();
|
||||
preprocStack.push({ r : true });
|
||||
preprocStack.push(true);
|
||||
return token();
|
||||
} else {
|
||||
// elseif
|
||||
@@ -2216,4 +2223,4 @@ class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user