Skip to content

Commit 6642d3f

Browse files
Merge remote-tracking branch 'haxe/master' into funkin-dev
2 parents ca7c9a4 + d676059 commit 6642d3f

File tree

5 files changed

+82
-14
lines changed

5 files changed

+82
-14
lines changed

TestHScript.hx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class TestHScript extends TestCase {
4949
assertScript("- 123",-123);
5050
assertScript("1.546",1.546);
5151
assertScript(".545",.545);
52+
assertScript("1e5",100000);
53+
assertScript("1.2e2",120);
54+
assertScript("100e-2",1);
55+
assertScript("1.2e-1",0.12);
5256
assertScript("'bla'","bla");
5357
assertScript("null",null);
5458
assertScript("true",true);
@@ -120,6 +124,12 @@ class TestHScript extends TestCase {
120124
assertScript("var f:(x:Int)->(Int, Int)->Int = (x:Int) -> (y:Int, z:Int) -> x + y + z; f(3)(1, 2)", 6, null, true);
121125
assertScript("var a = 10; var b = 5; a - -b", 15);
122126
assertScript("var a = 10; var b = 5; a - b / 2", 7.5);
127+
assertScript("var a; a", null);
128+
assertScript("var a = 1, b = 5; a + b;", 6);
129+
assertScript("var a, b = 5; if (a == null) a = 2; a + b;", 7);
130+
assertScript("var a:Int; a", null, null, true);
131+
assertScript("var a:Int = 1, b:Int = 5; a + b;", 6, null, true);
132+
assertScript("var a:Int, b:Int = 5; if (a == null) a = 2; a + b;", 7, null, true);
123133
assertScript("false && xxx", false);
124134
assertScript("true || xxx", true);
125135
assertScript("[for( x in arr ) switch( x ) { case 1: 55; case 3: 66; default: 0; }].join(':')",'55:0:66',{ arr : [1,2,3] });
@@ -245,4 +255,4 @@ class TestHScript extends TestCase {
245255
#end
246256
}
247257

248-
}
258+
}

haxelib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"url": "https://github.com/HaxeFoundation/hscript",
44
"license": "MIT",
55
"description": "Haxe Script is a scripting engine for a subset of the Haxe language",
6-
"version": "2.5.1",
7-
"releasenote": "Haxe 4.2 compat and bug fixes",
6+
"version": "2.6.0",
7+
"releasenote": "More Haxe 4/5 features",
88
"contributors": ["ncannasse","HaxeFoundation"]
99
}

hscript/Checker.hx

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ class Checker {
327327
var currentFunType : TType;
328328
var isCompletion : Bool;
329329
var allowDefine : Bool;
330+
var hasReturn : Bool;
330331
public var allowAsync : Bool;
331332
public var allowReturn : Null<TType>;
332333
public var allowGlobalsDefine : Bool;
@@ -337,10 +338,10 @@ class Checker {
337338
this.types = types;
338339
}
339340

340-
public function setGlobals( cl : CClass ) {
341+
public function setGlobals( cl : CClass, allowPrivate = false ) {
341342
while( true ) {
342343
for( f in cl.fields )
343-
if( f.isPublic )
344+
if( f.isPublic || allowPrivate )
344345
setGlobal(f.name, f.params.length == 0 ? f.t : TLazy(function() return apply(f.t,f.params,[for( i in 0...f.params.length) makeMono()])));
345346
if( cl.superClass == null )
346347
break;
@@ -367,6 +368,10 @@ class Checker {
367368
return globals;
368369
}
369370

371+
public dynamic function onTopDownEnum( en : CEnum, field : String ) {
372+
return false;
373+
}
374+
370375
function typeArgs( args : Array<Argument>, pos : Expr ) {
371376
return [for( i in 0...args.length ) {
372377
var a = args[i];
@@ -709,7 +714,7 @@ class Checker {
709714
default: throw "assert";
710715
}
711716
}
712-
if( !typeEq(f1.t,f2.t) )
717+
if( !typeEq(apply(f1.t,cl1.params,pl1),f2.t) )
713718
return false;
714719
}
715720
return true;
@@ -815,6 +820,9 @@ class Checker {
815820
case TAnon(fl):
816821
for( f in fl )
817822
fields.push({ name : f.name, t : f.t });
823+
case TFun(args, ret):
824+
if( isCompletion )
825+
fields.push({ name : "bind", t : TFun(args,TVoid) });
818826
default:
819827
}
820828
return fields;
@@ -956,7 +964,19 @@ class Checker {
956964
case "trace":
957965
return TDynamic;
958966
default:
959-
if( isCompletion) return TDynamic;
967+
switch( withType ) {
968+
case WithType(et = TEnum(e, args)):
969+
for( c in e.constructors )
970+
if( c.name == v ) {
971+
if( onTopDownEnum(e,v) ) {
972+
var ct = c.args == null ? et : TFun(c.args, et);
973+
return apply(ct, e.params, args);
974+
}
975+
break;
976+
}
977+
default:
978+
}
979+
if( isCompletion ) return TDynamic;
960980
error("Unknown identifier "+v, expr);
961981
}
962982
case EBlock(el):
@@ -977,7 +997,29 @@ class Checker {
977997
case EParent(e):
978998
return typeExpr(e,withType);
979999
case ECall(e, params):
980-
var ft = typeExpr(e, Value);
1000+
switch( edef(e) ) {
1001+
case EField(val, "bind"):
1002+
var ft = typeExpr(val, Value);
1003+
switch( ft ) {
1004+
case TFun(args,ret):
1005+
var remainArgs = args.copy();
1006+
for( p in params ) {
1007+
var a = remainArgs.shift();
1008+
if( a == null ) {
1009+
error("Too many arguments", p);
1010+
return TFun([], ret);
1011+
}
1012+
typeExprWith(p, a.t);
1013+
}
1014+
return TFun(remainArgs, ret);
1015+
default:
1016+
}
1017+
default:
1018+
}
1019+
var ft = typeExpr(e, switch( [edef(e),withType] ) {
1020+
case [EIdent(_),WithType(TEnum(_))]: withType;
1021+
default: Value;
1022+
});
9811023
switch( follow(ft) ) {
9821024
case TFun(args, ret):
9831025
for( i in 0...params.length ) {
@@ -1047,6 +1089,7 @@ class Checker {
10471089
return TVoid;
10481090
case EReturn(v):
10491091
var et = v == null ? TVoid : typeExpr(v, allowReturn == null ? Value : WithType(allowReturn));
1092+
hasReturn = true;
10501093
if( allowReturn == null )
10511094
error("Return not allowed here", expr);
10521095
else
@@ -1089,8 +1132,10 @@ class Checker {
10891132
var locals = saveLocals();
10901133
var oldRet = allowReturn;
10911134
var oldGDef = allowDefine;
1135+
var oldHasRet = hasReturn;
10921136
allowReturn = tret;
10931137
allowDefine = false;
1138+
hasReturn = false;
10941139
var withArgs = null;
10951140
if( name != null && !withType.match(WithType(follow(_) => TFun(_))) ) {
10961141
var ev = events.get(name);
@@ -1115,8 +1160,11 @@ class Checker {
11151160
if( withArgs != null && targs.length < withArgs.length )
11161161
error("Missing "+(withArgs.length - targs.length)+" arguments ("+[for( i in targs.length...withArgs.length ) typeStr(withArgs[i].t)].join(",")+")", expr);
11171162
typeExpr(body,NoValue);
1163+
if( !hasReturn && !tryUnify(tret, TVoid) )
1164+
error("Missing return "+typeStr(tret), expr);
11181165
allowDefine = oldGDef;
11191166
allowReturn = oldRet;
1167+
hasReturn = oldHasRet;
11201168
this.locals = locals;
11211169
if( ft == null ) {
11221170
ft = TFun(targs, tret);
@@ -1284,7 +1332,8 @@ class Checker {
12841332
case TAbstract(a, args):
12851333
// special case : we allow unconditional access
12861334
// to an abstract iterator() underlying value (eg: ArrayProxy)
1287-
ft = getField(apply(a.t,a.params,args),"iterator",it);
1335+
var at = apply(a.t,a.params,args);
1336+
return getIteratorType(it, at);
12881337
default:
12891338
}
12901339
if( ft != null )

hscript/JsInterp.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class JsInterp extends Interp {
8080
#if hscriptPos
8181
var expr = curExpr;
8282
var p = '{pmin:,pmax:,origin:"",line:}';
83-
return '($$i._p(${expr.pmin},${expr.pmax},${expr.origin},${expr.line}),$estr)';
83+
return '($$i._p(${expr.pmin},${expr.pmax},"${expr.origin}",${expr.line}),$estr)';
8484
#else
8585
return estr;
8686
#end

hscript/Parser.hx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,17 @@ class Parser {
601601
tk = token();
602602
}
603603
var e = null;
604-
if( Type.enumEq(tk,TOp("=")) )
605-
e = parseExpr();
606-
else
607-
push(tk);
604+
605+
switch (tk)
606+
{
607+
case TOp("="): e = parseExpr();
608+
case TOp(_): unexpected(tk);
609+
case TComma | TSemicolon: push(tk);
610+
// Above case should be enough but semicolon is not mandatory after }
611+
case _ if (t != null): push(tk);
612+
default: unexpected(tk);
613+
}
614+
608615
mk(EVar(ident,t,e),p1,(e == null) ? tokenMax : pmax(e));
609616
case "while":
610617
var econd = parseExpr();
@@ -1393,6 +1400,8 @@ class Parser {
13931400
}
13941401
if( pow == null )
13951402
invalidChar(char);
1403+
if( exp == 0 )
1404+
exp = 10;
13961405
return TConst(CFloat((Math.pow(10, pow) / exp) * n * 10));
13971406
case ".".code:
13981407
if( exp > 0 ) {

0 commit comments

Comments
 (0)