From 22d6404799438506740946f22f2b0d2a07603d89 Mon Sep 17 00:00:00 2001 From: Jaime Humberto Macias Bustamante Date: Thu, 15 May 2025 01:17:11 -0700 Subject: [PATCH] getter/setter for variables --- hscript/Interp.hx | 7 +++++-- hscript/Parser.hx | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hscript/Interp.hx b/hscript/Interp.hx index 270de08..6629bcc 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -65,6 +65,9 @@ enum abstract ScriptObjectType(UInt8) { class DeclaredVar { public var r:Dynamic; public var depth:Int; + // TODO: getter/setter for variables + public var getter:FieldPropertyAccess = null; + public var setter:FieldPropertyAccess = null; } @:structInit @@ -878,7 +881,7 @@ class Interp { }; customClassFields.push(fd); - case EVar(n, t, e, isPublic, isStatic, isPrivate, isFinal, isInline, getter, setter): + case EVar(n, t, e, isPublic, isStatic, _, isFinal, _, getter, setter): var varAcc:Array = []; if (isPublic) varAcc.push(APublic); if (isStatic) varAcc.push(AStatic); @@ -1020,7 +1023,7 @@ class Interp { } case EIdent(id): return resolve(id); - case EVar(n, _, e, isPublic, isStatic): + case EVar(n, _, e, isPublic, isStatic, _, isFinal, _, getter, setter): declared.push({n: n, old: locals.get(n), depth: depth}); locals.set(n, {r: (e == null) ? null : expr(e), depth: depth}); if (depth == 0) { diff --git a/hscript/Parser.hx b/hscript/Parser.hx index e647560..e1f618b 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -902,7 +902,7 @@ class Parser { error(ECustom("Property requires type-hint or initialization"), p1, tokenMax); nextType = null; - mk(EVar(ident, t, e, nextIsPublic, nextIsStatic, nextIsPrivate, id == "final", nextIsInline), p1, (e == null) ? tokenMax : pmax(e)); + mk(EVar(ident, t, e, nextIsPublic, nextIsStatic, nextIsPrivate, id == "final", nextIsInline, get, set), p1, (e == null) ? tokenMax : pmax(e)); case "while": var econd = parseExpr(); var e = parseExpr();