From 3f98441918b8e80cf1e5d51ffa18535079bed206 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Tue, 3 Sep 2024 13:42:25 +0200 Subject: [PATCH] Fixed bugs and ram improvements --- hscript/Async.hx | 14 ++-- hscript/Bytes.hx | 14 ++-- hscript/Expr.hx | 18 ++++- hscript/Interp.hx | 30 +++---- hscript/Macro.hx | 2 +- hscript/Parser.hx | 125 +++++++++++++++-------------- hscript/Printer.hx | 16 ++-- hscript/Tools.hx | 6 +- hscript/macros/ClassExtendMacro.hx | 2 +- hscript/utils/UnsafeReflect.hx | 4 +- 10 files changed, 122 insertions(+), 109 deletions(-) diff --git a/hscript/Async.hx b/hscript/Async.hx index c0b9584..6f220e5 100644 --- a/hscript/Async.hx +++ b/hscript/Async.hx @@ -153,11 +153,11 @@ class Async { } inline function fun(arg:String, e, ?name) { - return mk(EFunction([{ name : arg, t : null }], e, name), e); + return mk(EFunction([{ name : arg, t : null, opt: false, value: null }], e, name), e); } inline function funs(arg:Array, e, ?name) { - return mk(EFunction([for( a in arg ) { name : a, t : null }], e, name), e); + return mk(EFunction([for( a in arg ) { name : a, t : null, opt: false, value: null }], e, name), e); } inline function block(arr:Array, e) { @@ -260,7 +260,7 @@ class Async { defineVar(name, Defined); for( a in args ) defineVar(a.name, Defined); - args.unshift( { name : "_onEnd", t : null } ); + args.unshift( { name : "_onEnd", t : null, opt: false, value: null } ); var frest = ident("_onEnd",e); var oldFun = currentFun; currentFun = name; @@ -417,10 +417,10 @@ class Async { if( currentLoop == null ) throw "Continue outside loop"; return block([retNull(currentLoop, e), mk(EReturn(),e)], e); case ESwitch(v, cases, def): - var cases = [for( c in cases ) { values : c.values, expr : toCps(c.expr, rest, exit) } ]; - return toCps(v, mk(EFunction([ { name : "_c", t : null } ], mk(ESwitch(ident("_c",v), cases, def == null ? retNull(rest) : toCps(def, rest, exit)),e)),e), exit ); + var cases:Array = [for( c in cases ) { values : c.values, expr : toCps(c.expr, rest, exit) } ]; + return toCps(v, mk(EFunction([ { name : "_c", t : null, opt: false, value: null } ], mk(ESwitch(ident("_c",v), cases, def == null ? retNull(rest) : toCps(def, rest, exit)),e)),e), exit ); case EThrow(v): - return toCps(v, mk(EFunction([ { name : "_v", t : null } ], mk(EThrow(v),v)), v), exit); + return toCps(v, mk(EFunction([ { name : "_v", t : null, opt: false, value: null } ], mk(EThrow(v),v)), v), exit); case EMeta(name,_,e) if( name.charCodeAt(0) == ":".code ): // ignore custom ":" metadata return toCps(e, rest, exit); //case EDoWhile(_), ETry(_), ECall(_): @@ -436,7 +436,7 @@ class AsyncInterp extends Interp { public function setContext( api : Dynamic ) { - var funs = new Array(); + var funs = []; for( v in variables.keys() ) if( Reflect.isFunction(variables.get(v)) ) funs.push({ v : v, obj : null }); diff --git a/hscript/Bytes.hx b/hscript/Bytes.hx index 4b7ece8..3b7817f 100644 --- a/hscript/Bytes.hx +++ b/hscript/Bytes.hx @@ -278,7 +278,7 @@ class Bytes { case 3: EParent(doDecode()); case 4: - var a = new Array(); + var a = []; for( i in 0...bin.get(pin++) ) a.push(doDecode()); EBlock(a); @@ -295,7 +295,7 @@ class Bytes { EUnop(op,prefix,doDecode()); case 8: var e = doDecode(); - var params = new Array(); + var params = []; for( i in 0...bin.get(pin++) ) params.push(doDecode()); ECall(e,params); @@ -317,7 +317,7 @@ class Bytes { case 14: var params = new Array(); for( i in 0...bin.get(pin++) ) - params.push({ name : doDecodeString() }); + params.push({ name : doDecodeString(), opt: false, value: null, t: null }); var e = doDecode(); var name = doDecodeString(); EFunction(params,e,(name == "") ? null: name); @@ -327,13 +327,13 @@ class Bytes { var e = doDecode(); EArray(e,doDecode()); case 17: - var el = new Array(); + var el = []; for( i in 0...bin.get(pin++) ) el.push(doDecode()); EArrayDecl(el); case 18: var cl = doDecodeString(); - var el = new Array(); + var el = []; for( i in 0...bin.get(pin++) ) el.push(doDecode()); ENew(cl,el); @@ -344,7 +344,7 @@ class Bytes { var v = doDecodeString(); ETry(e,v,null,doDecode()); case 21: - var fl = new Array(); + var fl = []; for( i in 0...bin.get(pin++) ) { var name = doDecodeString(); var e = doDecode(); @@ -358,7 +358,7 @@ class Bytes { ETernary(cond, e1, e2); case 23: var e = doDecode(); - var cases = []; + var cases:Array = []; while( true ) { var v = doDecode(); if( v == null ) break; diff --git a/hscript/Expr.hx b/hscript/Expr.hx index f050259..e3e7c00 100644 --- a/hscript/Expr.hx +++ b/hscript/Expr.hx @@ -92,9 +92,21 @@ final class SwitchCase { public var expr : Expr; } -typedef Argument = { name : String, ?t : CType, ?opt : Bool, ?value : Expr }; +@:structInit +final class Argument { + public var name : String; + public var t : CType; + public var opt : Bool; + public var value : Expr; +} -typedef Metadata = Array<{ name : String, params : Array }>; +@:structInit +final class MetadataEntry { + public var name : String; + public var params : Array; +} + +typedef Metadata = Array; enum CType { CTPath( path : Array, ?params : Array ); @@ -190,7 +202,7 @@ enum FieldKind { typedef FunctionDecl = { var args : Array; - var expr : Expr; + var body : Expr; var ret : Null; } diff --git a/hscript/Interp.hx b/hscript/Interp.hx index 71225e2..425a376 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -146,12 +146,12 @@ class Interp { #else locals = new Hash(); #end - declared = new Array(); + declared = []; resetVariables(); initOps(); } - private function resetVariables() { + private function resetVariables():Void { #if haxe3 customClasses = new Map(); variables = new Map(); @@ -184,7 +184,7 @@ class Interp { return cast {fileName: "hscript", lineNumber: 0}; } - function initOps() { + function initOps():Void { var me = this; #if haxe3 binops = new Map(); @@ -236,7 +236,7 @@ class Interp { assignOp("??" + "=", function(v1, v2) return v1 == null ? v2 : v1); } - function checkIsType(e1,e2): Bool { + function checkIsType(e1:Expr,e2:Expr): Bool { var expr1:Dynamic = expr(e1); return switch(Tools.expr(e2)) @@ -255,7 +255,7 @@ class Interp { return allowStaticVariables && staticVariables.exists(name) || allowPublicVariables && publicVariables.exists(name) || variables.exists(name); } - public function setVar(name:String, v:Dynamic) { + public function setVar(name:String, v:Dynamic):Void { if (allowStaticVariables && staticVariables.exists(name)) staticVariables.set(name, v); else if (allowPublicVariables && publicVariables.exists(name)) @@ -331,12 +331,12 @@ class Interp { return v; } - function assignOp(op, fop:Dynamic->Dynamic->Dynamic) { + function assignOp(op:String, fop:Dynamic->Dynamic->Dynamic):Void { var me = this; binops.set(op, function(e1, e2) return me.evalAssignOp(op, fop, e1, e2)); } - function evalAssignOp(op, fop, e1, e2):Dynamic { + function evalAssignOp(op:String, fop:Dynamic->Dynamic->Dynamic, e1:Expr, e2:Expr):Dynamic { var v; switch (Tools.expr(e1)) { case EIdent(id): @@ -473,7 +473,7 @@ class Interp { #else locals = new Hash(); #end - declared = new Array(); + declared = []; return exprReturn(expr); } @@ -519,7 +519,7 @@ class Interp { return h2; } - function restore(old:Int) { + function restore(old:Int):Void { while (declared.length > old) { var d = declared.pop(); locals.set(d.n, d.old); @@ -537,7 +537,7 @@ class Interp { return null; } - inline function rethrow(e:Dynamic) { + inline function rethrow(e:Dynamic):Void { #if hl hl.Api.rethrow(e); #else @@ -924,7 +924,7 @@ class Interp { } return map; } else { - var a = new Array(); + var a = []; for (e in arr) { a.push(expr(e)); } @@ -939,7 +939,7 @@ class Interp { return arr[index]; } case ENew(cl, params): - var a = new Array(); + var a = []; for (e in params) a.push(expr(e)); return cnew(cl, a); @@ -1007,7 +1007,7 @@ class Interp { return null; } - function doWhileLoop(econd, e) { + function doWhileLoop(econd:Expr, e:Expr):Void { var old = declared.length; do { try { @@ -1025,7 +1025,7 @@ class Interp { restore(old); } - function whileLoop(econd, e) { + function whileLoop(econd:Expr, e:Expr):Void { var old = declared.length; while (expr(econd) == true) { try { @@ -1065,7 +1065,7 @@ class Interp { return v; } - function forLoop(n, it, e, ?ithv) { + function forLoop(n:String, it:Expr, e:Expr, ?ithv:String):Void { var isKeyValue = ithv != null; var old = declared.length; if(isKeyValue) diff --git a/hscript/Macro.hx b/hscript/Macro.hx index 527c9b2..fe9e9bd 100644 --- a/hscript/Macro.hx +++ b/hscript/Macro.hx @@ -110,7 +110,7 @@ class Macro { #end function map < T, R > ( a : Array, f : T -> R ) : Array { - var b = new Array(); + var b = []; for( x in a ) b.push(f(x)); return b; diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 522b583..379a40a 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -20,6 +20,7 @@ * DEALINGS IN THE SOFTWARE. */ package hscript; +import haxe.rtti.Meta; import hscript.Expr; enum Token { @@ -146,7 +147,7 @@ class Parser { opPriority.set(x, x == "++" || x == "--" ? -1 : -2); } - public inline function error( err, pmin, pmax ) { + public inline function error( err:#if hscriptPos ErrorDef #else Error #end, pmin:Int, pmax:Int ) { if( !resumeErrors ) #if hscriptPos throw new Error(err, pmin, pmax, origin, line); @@ -155,11 +156,11 @@ class Parser { #end } - public function invalidChar(c) { + public function invalidChar(c:Int) { error(EInvalidChar(c), readPos-1, readPos-1); } - function initParser( origin ) { + function initParser( origin:String ) { // line=1 - don't reset line : it might be set manualy preprocStack = []; #if hscriptPos @@ -174,8 +175,8 @@ class Parser { tokens = new haxe.FastList(); #end char = -1; - ops = new Array(); - idents = new Array(); + ops = []; + idents = []; uid = 0; for( i in 0...opChars.length ) ops[opChars.charCodeAt(i)] = true; @@ -183,12 +184,12 @@ class Parser { idents[identChars.charCodeAt(i)] = true; } - public function parseString( s : String, ?origin : String = "hscript" ) { + public function parseString( s : String, ?origin : String = "hscript" ):Expr { initParser(origin); if(s == "") s = "0;"; // fixing crash with empty file input = s; readPos = 0; - var a = new Array(); + var a = []; while( true ) { var tk = token(); if( tk == TEof ) break; @@ -198,12 +199,12 @@ class Parser { return if( a.length == 1 ) a[0] else mk(EBlock(a),0); } - function unexpected( tk ) : Dynamic { + function unexpected( tk:Token ) : Any { error(EUnexpected(tokenString(tk)),tokenMin,tokenMax); return null; } - inline function push(tk) { + inline function push(tk: Token):Void { #if hscriptPos tokens.push( { t : tk, min : tokenMin, max : tokenMax } ); tokenMin = oldTokenMin; @@ -213,17 +214,17 @@ class Parser { #end } - inline function ensure(tk) { + inline function ensure(tk:Token):Void { var t = token(); if( t != tk ) unexpected(t); } - inline function ensureToken(tk) { + inline function ensureToken(tk:Token):Void { var t = token(); if( !Type.enumEq(t,tk) ) unexpected(t); } - function maybe(tk) { + function maybe(tk:Token):Bool { var t = token(); if( Type.enumEq(t, tk) ) return true; @@ -231,7 +232,7 @@ class Parser { return false; } - function getIdent() { + function getIdent():String { var tk = token(); switch( tk ) { case TId(id): return id; @@ -241,7 +242,7 @@ class Parser { } } - inline function expr(e:Expr) { + inline function expr(e:Expr):#if hscriptPos ExprDef #else Expr #end { #if hscriptPos return e.e; #else @@ -249,7 +250,7 @@ class Parser { #end } - inline function pmin(e:Expr) { + inline function pmin(e:Expr):Int { #if hscriptPos return e == null ? 0 : e.pmin; #else @@ -257,7 +258,7 @@ class Parser { #end } - inline function pmax(e:Expr) { + inline function pmax(e:Expr):Int { #if hscriptPos return e == null ? 0 : e.pmax; #else @@ -265,7 +266,7 @@ class Parser { #end } - inline function mk(e,?pmin,?pmax) : Expr { + inline function mk(e:#if hscriptPos ExprDef #else Expr #end,?pmin:Int,?pmax:Int) : Expr { #if hscriptPos if( e == null ) return null; if( pmin == null ) pmin = tokenMin; @@ -276,7 +277,7 @@ class Parser { #end } - function isBlock(e) { + function isBlock(e:Expr):Bool { if( e == null ) return false; return switch( expr(e) ) { case EBlock(_), EObject(_), ESwitch(_): true; @@ -296,7 +297,7 @@ class Parser { } } - function parseFullExpr( exprs : Array ) { + function parseFullExpr( exprs : Array ):Void { var e = parseExpr(); exprs.push(e); @@ -316,9 +317,9 @@ class Parser { } } - function parseObject(p1) { + function parseObject(p1:Int):Expr { // parse object - var fl = new Array(); + var fl = []; while( true ) { var tk = token(); var id = null; @@ -351,7 +352,7 @@ class Parser { return parseExprNext(mk(EObject(fl),p1)); } - function parseExpr() { + function parseExpr():Expr { var oldPos = readPos; var tk = token(); @@ -390,14 +391,14 @@ class Parser { return parseExprNext(mk(ECheckType(e,t),p1,tokenMax)); case TComma: switch( expr(e) ) { - case EIdent(v): return parseLambda([{ name : v, t : t }], pmin(e)); + case EIdent(v): return parseLambda([{ name : v, t : t, opt: false, value: null }], pmin(e)); default: } default: } case TComma: switch( expr(e) ) { - case EIdent(v): return parseLambda([{name:v}], pmin(e)); + case EIdent(v): return parseLambda([{name: v, opt: false, value: null, t: null}], pmin(e)); default: } default: @@ -437,7 +438,7 @@ class Parser { default: push(tk); } - var a = new Array(); + var a = []; while( true ) { parseFullExpr(a); tk = token(); @@ -468,7 +469,7 @@ class Parser { return makeUnop(op,parseExpr()); return unexpected(tk); case TBkOpen: - var a = new Array(); + var a = []; tk = token(); while( tk != TBkClose && (!resumeErrors || tk != TEof) ) { push(tk); @@ -501,11 +502,11 @@ class Parser { } } - function parseLambda( args : Array, pmin ) { + function parseLambda( args : Array, pmin: Int ): Expr { while( true ) { var id = getIdent(); var t = maybe(TDoubleDot) ? parseType() : null; - args.push({ name : id, t : t }); + args.push({ name : id, t : t, opt: false, value: null }); var tk = token(); switch( tk ) { case TComma: @@ -521,13 +522,13 @@ class Parser { return mk(EFunction(args, mk(EReturn(eret),pmin)), pmin); } - function parseMetaArgs() { + function parseMetaArgs():Array { var tk = token(); if( tk != TPOpen ) { push(tk); return null; } - var args = []; + var args:Array = []; tk = token(); if( tk != TPClose ) { push(tk); @@ -545,7 +546,7 @@ class Parser { return args; } - function mapCompr( tmp : String, e : Expr ) { + function mapCompr( tmp : String, e : Expr ):Expr { if( e == null ) return null; var edef = switch( expr(e) ) { case EFor(v, it, e2, ithv): @@ -566,7 +567,7 @@ class Parser { return mk(edef, pmin(e), pmax(e)); } - function makeUnop( op, e ) { + function makeUnop( op:String, e:Expr ):Expr { if( e == null && resumeErrors ) return null; return switch( expr(e) ) { @@ -576,7 +577,7 @@ class Parser { } } - function makeBinop( op, e1, e ) { + function makeBinop( op:String, e1:Expr, e:Expr ):Expr { if( e == null && resumeErrors ) return mk(EBinop(op,e1,e),pmin(e1),pmax(e1)); return switch( expr(e) ) { @@ -602,7 +603,7 @@ class Parser { var nextIsFinal:Bool = false; var nextIsInline:Bool = false; var nextType:CType = null; - function parseStructure(id, ?oldPos:Int) { + function parseStructure(id:String, ?oldPos:Int):Expr { #if hscriptPos var p1 = tokenMin; #end @@ -1047,7 +1048,7 @@ class Parser { var e = if( tk == TSemicolon ) null else parseExpr(); mk(EReturn(e),p1,if( e == null ) tokenMax else pmax(e)); case "new": - var a = new Array(); + var a = []; a.push(getIdent()); while( true ) { var tk = token(); @@ -1160,7 +1161,7 @@ class Parser { } } - function parseExprNext( e1 : Expr ) { + function parseExprNext( e1 : Expr ):Expr { var tk = token(); switch( tk ) { case TOp(op): @@ -1170,10 +1171,10 @@ class Parser { switch( expr(e1) ) { case EIdent(i), EParent(expr(_) => EIdent(i)): var eret = parseExpr(); - return mk(EFunction([{ name : i }], mk(EReturn(eret),pmin(eret))), pmin(e1)); + return mk(EFunction([{ name : i, opt: false, value: null, t: null }], mk(EReturn(eret),pmin(eret))), pmin(e1)); case ECheckType(expr(_) => EIdent(i), t): var eret = parseExpr(); - return mk(EFunction([{ name : i, t : t }], mk(EReturn(eret),pmin(eret))), pmin(e1)); + return mk(EFunction([{ name : i, t : t, opt: false, value: null }], mk(EReturn(eret),pmin(eret))), pmin(e1)); default: } unexpected(tk); @@ -1212,8 +1213,8 @@ class Parser { } } - function parseFunctionArgs() { - var args = new Array(); + function parseFunctionArgs():Array { + var args:Array = []; var tk = token(); if( tk != TPClose ) { var done = false; @@ -1231,7 +1232,7 @@ class Parser { unexpected(tk); break; } - var arg : Argument = { name : name }; + var arg : Argument = { name : name, opt: false, value: null, t: null }; args.push(arg); if( opt ) arg.opt = true; if( allowTypes ) { @@ -1256,7 +1257,7 @@ class Parser { return args; } - function parseFunctionDecl() { + function parseFunctionDecl():FunctionDecl { ensure(TPOpen); var args = parseFunctionArgs(); var ret = null; @@ -1270,7 +1271,7 @@ class Parser { return { args : args, ret : ret, body : parseExpr() }; } - function parsePath() { + function parsePath():Array { var path = [getIdent()]; while( true ) { var t = token(); @@ -1371,7 +1372,7 @@ class Parser { } case TBrOpen: var fields = []; - var meta = null; + var meta:Array = null; while( true ) { t = token(); switch( t ) { @@ -1413,7 +1414,7 @@ class Parser { } } - function parseTypeNext( t : CType ) { + function parseTypeNext( t : CType ): CType { var tk = token(); switch( tk ) { case TOp(op): @@ -1435,8 +1436,8 @@ class Parser { } } - function parseExprList( etk ) { - var args = new Array(); + function parseExprList( etk:Token ): Array { + var args:Array = []; var tk = token(); if( tk == etk ) return args; @@ -1457,13 +1458,13 @@ class Parser { // ------------------------ module ------------------------------- - public function parseModule( content : String, ?origin : String = "hscript" ) { + public function parseModule( content : String, ?origin : String = "hscript" ):Array { initParser(origin); input = content; readPos = 0; allowTypes = true; allowMetadata = true; - var decls = []; + var decls:Array = []; while( true ) { var tk = token(); if( tk == TEof ) break; @@ -1474,7 +1475,7 @@ class Parser { } function parseMetadata() : Metadata { - var meta = []; + var meta:Array = []; while( true ) { var tk = token(); switch( tk ) { @@ -1488,7 +1489,7 @@ class Parser { return meta; } - function parseParams() { + function parseParams():{} { if( maybe(TOp("<")) ) error(EInvalidOp("Unsupported class type parameters"), readPos, readPos); return {}; @@ -1614,7 +1615,7 @@ class Parser { access : access, kind : KFunction({ args : inf.args, - expr : inf.body, + body : inf.body, ret : inf.ret, }), }; @@ -1661,11 +1662,11 @@ class Parser { // ------------------------ lexing ------------------------------- - inline function readChar() { + inline function readChar():Int { return StringTools.fastCodeAt(input, readPos++); } - function readString( until ) { + function readString( until:Int ):String { var c = 0; var b = new StringBuf(); var esc = false; @@ -1725,7 +1726,7 @@ class Parser { return b.toString(); } - function token() { + function token():Token { //function token(?infos : Null) { //function ttrace(v:Dynamic, ?infos : Null) { // Sys.print(infos.fileName+":"+infos.lineNumber+": " + Std.string(v)); @@ -1750,7 +1751,7 @@ class Parser { return t; } - function _token() { + function _token():Token { #else if( !tokens.isEmpty() ) return tokens.pop(); @@ -2034,7 +2035,7 @@ class Parser { var preprocStack : Array<{ r : Bool }>; - function parsePreproCond() { + function parsePreproCond():Expr { var tk = token(); return switch( tk ) { case TPOpen: @@ -2064,7 +2065,7 @@ class Parser { } } - function evalPreproCond( e : Expr ) { + function evalPreproCond( e : Expr ): Bool { switch( expr(e) ) { case EIdent(id): return preprocValue(id) != null; @@ -2123,7 +2124,7 @@ class Parser { } } - function skipTokens() { + function skipTokens():Void { var spos = preprocStack.length - 1; var obj = preprocStack[spos]; var pos = readPos; @@ -2139,7 +2140,7 @@ class Parser { } } - function tokenComment( op : String, char : Int ) { + function tokenComment( op : String, char : Int ):Token { var c = op.charCodeAt(1); var s = input; if( c == '/'.code ) { // comment @@ -2181,7 +2182,7 @@ class Parser { return TOp(op); } - function constString( c ) { + function constString( c:Const ):String { return switch(c) { case CInt(v): Std.string(v); case CFloat(f): Std.string(f); @@ -2192,7 +2193,7 @@ class Parser { } } - function tokenString( t ) { + function tokenString( t:Token ):String { return switch( t ) { case TEof: ""; case TConst(c): constString(c); diff --git a/hscript/Printer.hx b/hscript/Printer.hx index 9e1f883..8e464c2 100644 --- a/hscript/Printer.hx +++ b/hscript/Printer.hx @@ -30,23 +30,23 @@ class Printer { public function new() { } - public function exprToString( e : Expr ) { + public function exprToString( e : Expr ):String { buf = new StringBuf(); tabs = ""; expr(e); return buf.toString(); } - public function typeToString( t : CType ) { + public function typeToString( t : CType ):String { buf = new StringBuf(); tabs = ""; type(t); return buf.toString(); } - inline function add(s:T) buf.add(s); + inline function add(s:T):Void buf.add(s); - function type( t : CType ) { + function type( t : CType ):Void { switch( t ) { case CTOpt(t): add('?'); @@ -101,14 +101,14 @@ class Printer { } } - function addType( t : CType ) { + function addType( t : CType ):Void { if( t != null ) { add(" : "); type(t); } } - function expr( e : Expr ) { + function expr( e : Expr ):Void { if( e == null ) { add("??NULL??"); return; @@ -347,11 +347,11 @@ class Printer { } } - public static function toString( e : Expr ) { + public static function toString( e : Expr ):String { return new Printer().exprToString(e); } - public static function errorToString( e : Expr.Error ) { + public static function errorToString( e : Expr.Error ):String { var message = switch( #if hscriptPos e.e #else e #end ) { case EInvalidChar(c): "Invalid character: '"+(StringTools.isEof(c) ? "EOF (End Of File)" : String.fromCharCode(c))+"' ("+c+")"; case EUnexpected(s): "Unexpected token: \""+s+"\""; diff --git a/hscript/Tools.hx b/hscript/Tools.hx index 2cab09f..492f66b 100644 --- a/hscript/Tools.hx +++ b/hscript/Tools.hx @@ -24,7 +24,7 @@ import hscript.Expr; class Tools { - public static function iter( e : Expr, f : Expr -> Void ) { + public static function iter( e : Expr, f : Expr -> Void ):Void { switch( expr(e) ) { case EConst(_), EIdent(_): case EImport(c): f(e); @@ -63,7 +63,7 @@ class Tools { } } - public static function map( e : Expr, f : Expr -> Expr ) { + public static function map( e : Expr, f : Expr -> Expr ):Expr { var edef = switch( expr(e) ) { case EConst(_), EIdent(_), EBreak, EContinue: expr(e); case EVar(n, t, e, isPublic, isStatic, isPrivate): EVar(n, t, if( e != null ) f(e) else null, isPublic, isStatic, isPrivate); @@ -103,7 +103,7 @@ class Tools { #end } - public static inline function mk( e : ExprDef, p : Expr ) { + public static inline function mk( e : ExprDef, p : Expr ):Expr { #if hscriptPos return { e : e, pmin : p.pmin, pmax : p.pmax, origin : p.origin, line : p.line }; #else diff --git a/hscript/macros/ClassExtendMacro.hx b/hscript/macros/ClassExtendMacro.hx index f7c03f8..9c7ec92 100644 --- a/hscript/macros/ClassExtendMacro.hx +++ b/hscript/macros/ClassExtendMacro.hx @@ -214,7 +214,7 @@ class ClassExtendMacro { } if (f.name.startsWith(FUNC_PREFIX)) continue; - if (f.access.contains(ADynamic) || f.access.contains(AStatic) || f.access.contains(AExtern) || f.access.contains(AInline)) + if (f.access.contains(ADynamic) || f.access.contains(AStatic) || f.access.contains(AExtern) || f.access.contains(AInline) || f.access.contains(AFinal)) continue; if(f.name == "hget" || f.name == "hset") continue; // sorry, no overwriting the hget and hset in custom classes, yet diff --git a/hscript/utils/UnsafeReflect.hx b/hscript/utils/UnsafeReflect.hx index 267b6c3..430763c 100644 --- a/hscript/utils/UnsafeReflect.hx +++ b/hscript/utils/UnsafeReflect.hx @@ -52,7 +52,7 @@ class UnsafeReflect { o.__SetField(field, value, untyped __cpp__("::hx::paccAlways")); } #else - Reflect.setProperty(o, field); + Reflect.setProperty(o, field, value); #end } @@ -64,7 +64,7 @@ class UnsafeReflect { return untyped func.__Run(args); } #else - return Reflect.callMethod(o, func, args); + return Reflect.callMethod(o, Reflect.field(o, field), args); #end }