🐐 Numbers as strings when needed

This commit is contained in:
2026-04-01 13:35:25 +02:00
parent 77a4f8ae2b
commit d029ae1782
2 changed files with 11 additions and 3 deletions

View File

@@ -418,9 +418,14 @@ class BinOp(Node):
return vtable, ValNul() return vtable, ValNul()
return vtable, ValInt((lv or 0) + (rv or 0)) return vtable, ValInt((lv or 0) + (rv or 0))
case "SYMBOL_COLON": case "SYMBOL_COLON":
lv = lv if lv is not None else "" magnvm = "MAGNVM" in vtable["#modules"]
rv = rv if rv is not None else "" svbnvlla = "SVBNVLLA" in vtable["#modules"]
return vtable, ValStr(lv + rv) def _coerce(v):
if v is None: return ""
if isinstance(v, bool): return "VERITAS" if v else "FALSITAS"
if isinstance(v, int): return int_to_num(v, magnvm, svbnvlla)
return v
return vtable, ValStr(_coerce(lv) + _coerce(rv))
case "SYMBOL_MINUS": case "SYMBOL_MINUS":
return vtable, ValInt((lv or 0) - (rv or 0)) return vtable, ValInt((lv or 0) - (rv or 0))
case "SYMBOL_TIMES": case "SYMBOL_TIMES":

View File

@@ -611,6 +611,9 @@ string_concat_tests = [
('NVLLVS : "hello"', Program([], [ExpressionStatement(BinOp(Nullus(), String("hello"), "SYMBOL_COLON"))]), ValStr("hello")), ('NVLLVS : "hello"', Program([], [ExpressionStatement(BinOp(Nullus(), String("hello"), "SYMBOL_COLON"))]), ValStr("hello")),
('"hello" : NVLLVS', Program([], [ExpressionStatement(BinOp(String("hello"), Nullus(), "SYMBOL_COLON"))]), ValStr("hello")), ('"hello" : NVLLVS', Program([], [ExpressionStatement(BinOp(String("hello"), Nullus(), "SYMBOL_COLON"))]), ValStr("hello")),
('NVLLVS : NVLLVS', Program([], [ExpressionStatement(BinOp(Nullus(), Nullus(), "SYMBOL_COLON"))]), ValStr("")), ('NVLLVS : NVLLVS', Program([], [ExpressionStatement(BinOp(Nullus(), Nullus(), "SYMBOL_COLON"))]), ValStr("")),
# integers coerce to Roman numerals in string context
('"value: " : V', Program([], [ExpressionStatement(BinOp(String("value: "), Numeral("V"), "SYMBOL_COLON"))]), ValStr("value: V")),
('X : " items"', Program([], [ExpressionStatement(BinOp(Numeral("X"), String(" items"), "SYMBOL_COLON"))]), ValStr("X items")),
] ]
class TestStringConcat(unittest.TestCase): class TestStringConcat(unittest.TestCase):