Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tiny optimisation for better runtime speed #68

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions flash/.gitignore

This file was deleted.

94 changes: 0 additions & 94 deletions flash/Install.hx

This file was deleted.

54 changes: 0 additions & 54 deletions flash/Run.hx

This file was deleted.

2 changes: 0 additions & 2 deletions flash/install.hxml

This file was deleted.

2 changes: 0 additions & 2 deletions flash/run.hxml

This file was deleted.

35 changes: 29 additions & 6 deletions hscript/Interp.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,29 @@ private enum Stop {
SReturn( v : Dynamic );
}

@:structInit
private class Declared {
public var n : String;
public var old : Hashed;
public function new(n,old){
this.n = n;
this.old = old;
}
}

@:structInit
private class Hashed {
public var r : Dynamic;
public function new(r){
this.r = r;
}
}

class Interp {

#if haxe3
public var variables : Map<String,Dynamic>;
var locals : Map<String,{ r : Dynamic }>;
var locals : Map<String, Hashed>;
var binops : Map<String, Expr -> Expr -> Dynamic >;
#else
public var variables : Hash<Dynamic>;
Expand All @@ -43,7 +61,7 @@ class Interp {

var depth : Int;
var inTry : Bool;
var declared : Array<{ n : String, old : { r : Dynamic } }>;
var declared : Array<Declared>;

#if hscriptPos
var curExpr : Expr;
Expand Down Expand Up @@ -80,9 +98,13 @@ class Interp {
#else
binops = new Hash();
#end

/**
* BEWARE ON CPP TARGET INLINE VARIABLES ARE CULLED AND HAVE NO COUNTERPARTS
*/
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));
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));
binops.set("&",function(e1,e2) return me.expr(e1) & me.expr(e2));
Expand Down Expand Up @@ -111,7 +133,8 @@ class Interp {
assignOp("^=",function(v1,v2) return v1 ^ v2);
assignOp("<<=",function(v1,v2) return v1 << v2);
assignOp(">>=",function(v1,v2) return v1 >> v2);
assignOp(">>>=",function(v1,v2) return v1 >>> v2);
assignOp(">>>=", function(v1, v2) return v1 >>> v2);

}

function assign( e1 : Expr, e2 : Expr ) : Dynamic {
Expand Down Expand Up @@ -384,7 +407,7 @@ class Interp {
case EReturn(e):
throw SReturn((e == null)?null:expr(e));
case EFunction(params,fexpr,name,_):
var capturedLocals = duplicate(locals);
var capturedLocals : Map<String,Hashed> = duplicate(locals);
var me = this;
var hasOpt = false, minParams = 0;
for( p in params )
Expand Down Expand Up @@ -446,7 +469,7 @@ class Interp {
} else {
// function-in-function is a local function
declared.push( { n : name, old : locals.get(name) } );
var ref = { r : f };
var ref : Hashed = { r : f };
locals.set(name, ref);
capturedLocals.set(name, ref); // allow self-recursion
}
Expand Down