Cleanup + loopRun

- added loopRun to define custom loops (https://github.com/HaxeFoundation/hscript/commit/20c8bc3f3c72a4dedabf9a647940b9c4f43eedf8)
This commit is contained in:
Jaime Humberto Macias Bustamante
2025-07-26 15:34:35 -07:00
parent 0b1fbf66dc
commit cacb0cdbd6
3 changed files with 30 additions and 78 deletions
-45
View File
@@ -146,52 +146,7 @@ class CustomClassHandler implements IHScriptCustomConstructor implements IHScrip
return name;
}
}
/*
class CustomTemplateClass implements IHScriptCustomClassBehaviour {
public var __interp:Interp;
public var __allowSetGet:Bool = true;
public var __custom__variables:Map<String, Dynamic>;
public var __real_fields:Array<String>;
public var __class__fields:Array<String>;
public function hset(name:String, val:Dynamic):Dynamic {
if(__allowSetGet && __custom__variables.exists("set_" + name))
return __callSetter(name, val);
if (__custom__variables.exists(name)) {
__custom__variables.set(name, val);
return val;
}
if(__real_fields.contains(name)) {
UnsafeReflect.setProperty(this, name, val);
return UnsafeReflect.field(this, name);
}
__custom__variables.set(name, val);
return val;
}
public function hget(name:String):Dynamic {
if(__allowSetGet && __custom__variables.exists("get_" + name))
return __callGetter(name);
if (__custom__variables.exists(name))
return __custom__variables.get(name);
return UnsafeReflect.getProperty(this, name);
}
public function __callGetter(name:String):Dynamic {
__allowSetGet = false;
var v = __custom__variables.get("get_" + name)();
__allowSetGet = true;
return v;
}
public function __callSetter(name:String, val:Dynamic):Dynamic {
__allowSetGet = false;
var v = __custom__variables.get("set_" + name)(val);
__allowSetGet = true;
return v;
}
}
*/
/**
* This is for backwards compatibility with old hscript-improved, since some scripts use it
+22 -33
View File
@@ -1289,17 +1289,8 @@ class Interp {
function doWhileLoop(econd:Expr, e:Expr):Void {
var old = declared.length;
do {
try {
expr(e);
} catch (err:Stop) {
switch (err) {
case SContinue:
case SBreak:
break;
case SReturn:
throw err;
}
}
if (!loopRun(() -> expr(e)))
break;
} while (expr(econd) == true);
restore(old);
}
@@ -1307,17 +1298,8 @@ class Interp {
function whileLoop(econd:Expr, e:Expr):Void {
var old = declared.length;
while (expr(econd) == true) {
try {
expr(e);
} catch (err:Stop) {
switch (err) {
case SContinue:
case SBreak:
break;
case SReturn:
throw err;
}
}
if (!loopRun(() -> expr(e)))
break;
}
restore(old);
}
@@ -1378,21 +1360,28 @@ class Interp {
if(isKeyValue)
locals.set(ithv, {r: next.key, depth: depth});
locals.set(n, {r: isKeyValue ? next.value : next, depth: depth});
try {
expr(e);
} catch (err:Stop) {
switch (err) {
case SContinue:
case SBreak:
break;
case SReturn:
throw err;
}
}
if (!loopRun(() -> expr(e)))
break;
}
restore(old);
}
inline function loopRun(f:Void -> Void) {
var cont = true;
try {
f();
} catch (err:Stop) {
switch (err) {
case SContinue:
case SBreak:
cont = false;
case SReturn:
throw err;
}
}
return cont;
}
inline function isMap(o:Dynamic):Bool {
return (o is IMap);
}
+8
View File
@@ -35,6 +35,14 @@ class Property {
var isVar:Bool;
var interp:Interp;
public function new(r:Dynamic, getter:FieldPropertyAccess, setter:FieldPropertyAccess, isVar:Bool, interp:Interp) {
this.r = r;
this.getter = getter;
this.setter = setter;
this.isVar = isVar;
this.interp = interp;
}
var __allowReadAccess:Bool = false;
var __allowWriteAccess:Bool = false;
var __allowSetGet:Null<Bool> = null;