Skip to content
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
6 changes: 3 additions & 3 deletions polymod/format/ScriptParseFormat.hx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ScriptParseFormat implements BaseParseFormat
}
catch (e:Error)
{
Polymod.error(ASSET_MERGE_FAILED, 'Script merge error: ${e#if hscriptPos .toString() #end}');
Polymod.error(ASSET_MERGE_FAILED, 'Script merge error: ${e.toString()}');
return [];
}

Expand Down Expand Up @@ -160,7 +160,7 @@ class ScriptParseFormat implements BaseParseFormat
continue;
}

var insertIndex:Int = switch (meta.params[0]#if hscriptPos .e #end)
var insertIndex:Int = switch (meta.params[0].e)
{
case EConst(c):
switch (c)
Expand All @@ -177,7 +177,7 @@ class ScriptParseFormat implements BaseParseFormat
switch (baseClass.fields[baseFieldIndex].kind)
{
case KFunction(f2):
var funcExpr = #if hscriptPos f2.expr.e; #else f2.expr; #end
var funcExpr = f2.expr.e;

// If the function isn't in a block, turn it into a block.
switch (funcExpr)
Expand Down
40 changes: 17 additions & 23 deletions polymod/hscript/_internal/Async.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,31 @@ class Async
public var asyncIdents:Map<String, Bool>;

static var nullExpr:Expr =
#if hscriptPos
{
e: null,
pmin: 0,
pmax: 0,
origin: "<null>",
line: 0
}
#else
null
#end;
{
e: null,
pmin: 0,
pmax: 0,
origin: "<null>",
line: 0
}

static var nullId = mk(EIdent("null"), nullExpr);

inline static function expr(e:Expr)
{
return #if hscriptPos e.e #else e #end;
return e.e;
}

inline static function mk(e, inf:Expr):Expr
{
return #if hscriptPos
{
e: e,
pmin: inf.pmin,
pmax: inf.pmax,
origin: inf.origin,
line: inf.line
}
#else
e
#end;
return
{
e: e,
pmin: inf.pmin,
pmax: inf.pmax,
origin: inf.origin,
line: inf.line
}
}

/**
Expand Down
36 changes: 18 additions & 18 deletions polymod/hscript/_internal/Bytes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,9 @@ class Bytes

function doEncode(e:Expr)
{
#if hscriptPos
doEncodeString(e.origin);
doEncodeInt(e.line);
var e = e.e;
#end
bout.addByte(exprIndex(e));
switch (e)
{
Expand Down Expand Up @@ -296,24 +294,26 @@ class Bytes

function doDecode():Expr
{
#if hscriptPos
if (bin.get(pin) == 255)
{
pin++;
return null;
if (bin.get(pin) == 255)
{
pin++;
return null;
}

var origin = doDecodeString();
var line = doDecodeInt();

return {
e: _doDecode(),
pmin: 0,
pmax: 0,
origin: origin,
line: line
}
}
var origin = doDecodeString();
var line = doDecodeInt();
return {
e: _doDecode(),
pmin: 0,
pmax: 0,
origin: origin,
line: line
};
} function _doDecode():ExprDef

function _doDecode():ExprDef
{
#end
return switch (bin.get(pin++))
{
case 0:
Expand Down
12 changes: 2 additions & 10 deletions polymod/hscript/_internal/Checker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -509,17 +509,13 @@ class Checker

inline function edef(e:Expr)
{
#if hscriptPos
return e.e;
#else
return e;
#end
}

inline function error(msg:String, curExpr:Expr)
{
var e = ECustom(msg);
#if hscriptPos var e = new Error(e, curExpr.pmin, curExpr.pmax, curExpr.origin, curExpr.line); #end
var e = new Error(e, curExpr.pmin, curExpr.pmax, curExpr.origin, curExpr.line);
if (!isCompletion) throw e;
}

Expand Down Expand Up @@ -1043,17 +1039,13 @@ class Checker

function mk(e, p):Expr
{
#if hscriptPos
return {
e: e,
pmin: p.pmin,
pmax: p.pmax,
origin: p.origin,
line: p.line
};
#else
return e;
#end
}
}

function isString(t:TType)
Expand Down
10 changes: 0 additions & 10 deletions polymod/hscript/_internal/Expr.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ enum Const
CString(s:String, ?interpolated:Bool);
}

#if hscriptPos
typedef Expr =
{
var e:ExprDef;
Expand All @@ -40,11 +39,6 @@ typedef Expr =
}

enum ExprDef
#else
typedef ExprDef = Expr;

enum Expr
#end
{
EConst(c:Const);
EIdent(v:String);
Expand Down Expand Up @@ -99,7 +93,6 @@ enum CType
CTExpr(e:Expr); // for type parameters only
}

#if hscriptPos
/**
* Stores information about an error.
*/
Expand Down Expand Up @@ -147,9 +140,6 @@ class Error
}

enum ErrorDef
#else
enum Error
#end
{
EInvalidChar(c:Int);
EUnexpected(s:String);
Expand Down
16 changes: 2 additions & 14 deletions polymod/hscript/_internal/Interp.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class Interp
var declared:Array<{n:String, old:{r:Dynamic, ?isfinal:Bool}}>;
var returnValue:Dynamic;

#if hscriptPos
var curExpr:Expr;
#end

public function new()
{
Expand Down Expand Up @@ -75,9 +73,7 @@ class Interp

public function posInfos():PosInfos
{
#if hscriptPos
if (curExpr != null) return cast {fileName: curExpr.origin, lineNumber: curExpr.line};
#end
return cast {fileName: "hscript", lineNumber: 0};
}

Expand Down Expand Up @@ -209,10 +205,8 @@ class Interp

function increment(e:Expr, prefix:Bool, delta:Int):Dynamic
{
#if hscriptPos
curExpr = e;
var e = e.e;
#end
switch (e)
{
case EIdent(id):
Expand Down Expand Up @@ -323,9 +317,9 @@ class Interp
}
}

inline function error(e:#if hscriptPos ErrorDef #else Error #end, rethrow = false):Dynamic
inline function error(e:ErrorDef, rethrow = false):Dynamic
{
#if hscriptPos var e = new Error(e, curExpr?.pmin ?? 0, curExpr?.pmax ?? 0, curExpr?.origin ?? 'unknown', curExpr?.line ?? 0); #end
var e = new Error(e, curExpr?.pmin ?? 0, curExpr?.pmax ?? 0, curExpr?.origin ?? 'unknown', curExpr?.line ?? 0);
if (rethrow) this.rethrow(e)
else
throw e;
Expand All @@ -350,10 +344,8 @@ class Interp

public function expr(e:Expr):Dynamic
{
#if hscriptPos
curExpr = e;
var e = e.e;
#end
switch (e)
{
case EConst(c):
Expand Down Expand Up @@ -435,9 +427,7 @@ class Interp
Tools.getKeyIterator(it, function(vk, vv, it) {
if (vk == null)
{
#if hscriptPos
curExpr = it;
#end
error(ECustom("Invalid for expression"));
return;
}
Expand Down Expand Up @@ -549,9 +539,7 @@ class Interp
keys.push(expr(eKey));
values.push(expr(eValue));
default:
#if hscriptPos
curExpr = e;
#end
error(ECustom("Invalid map key=>value expression"));
}
}
Expand Down
10 changes: 0 additions & 10 deletions polymod/hscript/_internal/JsInterp.hx
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,9 @@ class JsInterp extends Interp

function addPos(estr:String)
{
#if hscriptPos
var expr = curExpr;
var p = '{pmin:,pmax:,origin:"",line:}';
return '($$i._p(${expr.pmin},${expr.pmax},"${expr.origin}",${expr.line}),$estr)';
#else
return estr;
#end
}

function isContext(v:String)
Expand Down Expand Up @@ -145,10 +141,8 @@ class JsInterp extends Interp

function exprJS(expr:Expr):String
{
#if hscriptPos
curExpr = expr;
var expr = expr.e;
#end
switch (expr)
{
case EConst(c):
Expand Down Expand Up @@ -346,9 +340,7 @@ class JsInterp extends Interp
keys.push(exprValue(eKey));
values.push(exprValue(eValue));
default:
#if hscriptPos
curExpr = e;
#end
error(ECustom("Invalid map key=>value expression"));
}
}
Expand Down Expand Up @@ -427,7 +419,6 @@ class JsInterp extends Interp
return Std.isOfType(v1, v2);
}

#if hscriptPos
function _p(pmin, pmax, origin, line)
{
curExpr =
Expand All @@ -439,5 +430,4 @@ class JsInterp extends Interp
line: line
};
}
#end
}
10 changes: 4 additions & 6 deletions polymod/hscript/_internal/Macro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
package polymod.hscript._internal;

import polymod.hscript._internal.Expr.Error;
#if hscriptPos
import polymod.hscript._internal.Expr.ErrorDef;
#end
import haxe.macro.Expr;

class Macro
Expand Down Expand Up @@ -185,7 +183,7 @@ class Macro
public function convert(e:hscript.Expr):Expr
{
return {
expr: switch (#if hscriptPos e.e #else e #end)
expr: switch (e.e)
{
case EConst(c):
EConst( switch (c)
Expand Down Expand Up @@ -223,7 +221,7 @@ class Macro
case EDoWhile(c, e):
EWhile(convert(c), convert(e), false);
case EFor(v, it, efor):
var p = #if (!macro && hscriptPos)
var p = #if !macro
{file: p.file, min: e.pmin, max: e.pmax} #else p #end;
EFor({expr: EBinop(OpIn, {expr: EConst(CIdent(v)), pos: p}, convert(it)), pos: p}, convert(efor));
case EForGen(it, efor):
Expand Down Expand Up @@ -282,13 +280,13 @@ class Macro
{values: [for (v in c.values) convert(v)], expr: convert(c.expr)}
], edef == null ? null : convert(edef));
case EMeta(m, params, esub):
var mpos = #if (!macro && hscriptPos)
var mpos = #if !macro
{file: p.file, min: e.pmin, max: e.pmax} #else p #end;
EMeta({name: m, params: params == null ? [] : [for (p in params) convert(p)], pos: mpos}, convert(esub));
case ECheckType(e, t):
ECheckType(convert(e), convertType(t));
},
pos: #if (!macro && hscriptPos)
pos: #if !macro
{file: p.file, min: e.pmin, max: e.pmax} #else p #end
}
}
Expand Down
Loading