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

Haxe Language Support #110

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/hscript.swf
/release.zip

bk/**
26 changes: 13 additions & 13 deletions hscript/Async.hx
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ class Async {
function lookupFunctions( el : Array<Expr> ) {
for( e in el )
switch( expr(e) ) {
case EFunction(_, _, name, _) if( name != null ): defineVar(name, Defined);
case EMeta("sync",_,expr(_) => EFunction(_,_,name,_)) if( name != null ): defineVar(name, ForceSync);
case EFunction(Tools.getFunctionName(_) => name, _) if( name != null ): defineVar(name, Defined);
case EMeta("sync",_,expr(_) => EFunction(Tools.getFunctionName(_) => name, _)) if( name != null ): defineVar(name, ForceSync);
default:
}
}

function buildSync( e : Expr, exit : Expr ) : Expr {
switch( expr(e) ) {
case EFunction(_,_,name,_):
case EFunction(Tools.getFunctionName(_) => name,_):
if( name != null )
return toCps(e, null, null);
return e;
Expand All @@ -116,8 +116,8 @@ class Async {
return e;
case EMeta("async", _, e):
return toCps(e, ignore(), ignore());
case EMeta("sync", args, ef = expr(_) => EFunction(fargs, body, name, ret)):
return mk(EMeta("sync",args,mk(EFunction(fargs, buildSync(body,null), name, ret),ef)),e);
case EMeta("sync", args, ef = expr(_) => EFunction(Tools.getFunctionName(_) => name, {args: fargs, expr: body, ret: ret })):
return mk(EMeta("sync",args,mk(EFunction(Tools.getFunctionType(name), {args: fargs, expr: buildSync(body,null), ret: ret}),ef)),e);
case EBreak if( currentBreak != null ):
return currentBreak(e);
case EContinue if( currentLoop != null ):
Expand Down Expand Up @@ -152,11 +152,11 @@ class Async {
}

inline function fun(arg:String, e, ?name) {
return mk(EFunction([{ name : arg, t : null }], e, name), e);
return mk(EFunction(FNamed(name, false), {args: [{ name : arg, t : null }], expr: e}), e);
}

inline function funs(arg:Array<String>, e, ?name) {
return mk(EFunction([for( a in arg ) { name : a, t : null }], e, name), e);
return mk(EFunction(FNamed(name, false), {expr: e, args: [for( a in arg ) { name : a, t : null }]} ), e);
}

inline function block(arr:Array<Expr>, e) {
Expand All @@ -179,7 +179,7 @@ class Async {

function retNull(e:Expr,?pos) : Expr {
switch( expr(e) ) {
case EFunction([{name:"_"}], e, _, _): return e;
case EFunction(FNamed('_', false), {expr: e}): return e;
default:
}
return call(e, [nullId], pos == null ? e : pos);
Expand Down Expand Up @@ -213,7 +213,7 @@ class Async {
switch( expr(e) ) {
case ECall(_):
syncFlag = false;
case EFunction(_,_,name,_) if( name != null ):
case EFunction(Tools.getFunctionName(_) => name, _) if( name != null ):
syncFlag = false;
case EMeta("sync" | "async", _, _):
// isolated from the sync part
Expand Down Expand Up @@ -247,7 +247,7 @@ class Async {
}
restoreVars(vold);
return retNull(rest);
case EFunction(args, body, name, t):
case EFunction(Tools.getFunctionName(_) => name, {args: args, expr: body, ret: t}):
var vold = saveVars();
if( name != null )
defineVar(name, Defined);
Expand All @@ -258,7 +258,7 @@ class Async {
var oldFun = currentFun;
currentFun = name;
var body = toCps(body, frest, frest);
var f = mk(EFunction(args, body, name, t),e);
var f = mk(EFunction(FNamed(name, false), {args: args, expr: body, ret: t}),e);
restoreVars(vold);
return rest == null ? f : call(rest, [f],e);
case EParent(e):
Expand Down Expand Up @@ -411,9 +411,9 @@ class Async {
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 );
return toCps(v, mk(EFunction (FAnonymous, {expr: mk(ESwitch(ident("_c",v), cases, def == null ? retNull(rest) : toCps(def, rest, exit)),e), args: [ { name : "_c", t : null } ]} ) ,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(FAnonymous, {args: [ { name : "_v", t : null } ], expr: 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(_):
Expand Down
4 changes: 2 additions & 2 deletions hscript/Bytes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Bytes {
doEncode(it);
doEncode(e);
case EBreak, EContinue:
case EFunction(params,e,name,_):
case EFunction(Tools.getFunctionName(_) => name, {args: params,expr: e}):
bout.addByte(params.length);
for( p in params )
doEncodeString(p.name);
Expand Down Expand Up @@ -316,7 +316,7 @@ class Bytes {
params.push({ name : doDecodeString() });
var e = doDecode();
var name = doDecodeString();
EFunction(params,e,(name == "") ? null: name);
EFunction(Tools.getFunctionType(name), {args:params,expr:e});
case 15:
EReturn(doDecode());
case 16:
Expand Down
Loading