🐐 Compiler fixes

This commit is contained in:
2026-04-24 17:14:08 +02:00
parent 6d4a456010
commit 37050e3e3b
5 changed files with 82 additions and 8 deletions

View File

@@ -1747,6 +1747,51 @@ class TestMAGNVM(unittest.TestCase):
run_test(self, source, nodes, value, output)
# --- SVBNVLLA module (display of negatives) ---
svbnvlla_display_tests = [
# DIC prints a negative numeral
("CVM SVBNVLLA\nDIC(- III)",
Program([ModuleCall("SVBNVLLA")], [ExpressionStatement(BuiltIn("DIC", [UnaryMinus(Numeral("III"))]))]),
ValStr("-III"), "-III\n"),
# Concat operator & with a negative numeral
('CVM SVBNVLLA\nDIC("x: " & - V)',
Program([ModuleCall("SVBNVLLA")], [ExpressionStatement(BuiltIn("DIC", [BinOp(String("x: "), UnaryMinus(Numeral("V")), "SYMBOL_AMPERSAND")]))]),
ValStr("x: -V"), "x: -V\n"),
# String interpolation of a negative numeral
('CVM SVBNVLLA\nDIC("val: {- X}")',
Program([ModuleCall("SVBNVLLA")], [ExpressionStatement(BuiltIn("DIC", [InterpolatedString([String("val: "), UnaryMinus(Numeral("X"))])]))]),
ValStr("val: -X"), "val: -X\n"),
# DIC of LITTERA(negative numeral)
("CVM SVBNVLLA\nDIC(LITTERA(- III))",
Program([ModuleCall("SVBNVLLA")], [ExpressionStatement(BuiltIn("DIC", [BuiltIn("LITTERA", [UnaryMinus(Numeral("III"))])]))]),
ValStr("-III"), "-III\n"),
# Combined with MAGNVM: negative of a number > 3999
("CVM MAGNVM\nCVM SVBNVLLA\nDIC(- (M + M + M + M))",
Program([ModuleCall("MAGNVM"), ModuleCall("SVBNVLLA")], [ExpressionStatement(BuiltIn("DIC", [UnaryMinus(BinOp(BinOp(BinOp(Numeral("M"), Numeral("M"), "SYMBOL_PLUS"), Numeral("M"), "SYMBOL_PLUS"), Numeral("M"), "SYMBOL_PLUS"))]))]),
ValStr("-MV_"), "-MV_\n"),
# Negative fraction via int / -int
("CVM FRACTIO\nCVM SVBNVLLA\nDIC(V / - II)",
Program([ModuleCall("FRACTIO"), ModuleCall("SVBNVLLA")], [ExpressionStatement(BuiltIn("DIC", [BinOp(Numeral("V"), UnaryMinus(Numeral("II")), "SYMBOL_DIVIDE")]))]),
ValStr("-IIS"), "-IIS\n"),
# Negative pure fraction (no integer part)
("CVM FRACTIO\nCVM SVBNVLLA\nDIC(I / - II)",
Program([ModuleCall("FRACTIO"), ModuleCall("SVBNVLLA")], [ExpressionStatement(BuiltIn("DIC", [BinOp(Numeral("I"), UnaryMinus(Numeral("II")), "SYMBOL_DIVIDE")]))]),
ValStr("-S"), "-S\n"),
("CVM FRACTIO\nCVM SVBNVLLA\nDIC(- S)",
Program([ModuleCall("FRACTIO"), ModuleCall("SVBNVLLA")], [ExpressionStatement(BuiltIn("DIC", [UnaryMinus(Fractio("S"))]))]),
ValStr("-S"), "-S\n"),
("CVM FRACTIO\nCVM SVBNVLLA\nDIC(- IIS)",
Program([ModuleCall("FRACTIO"), ModuleCall("SVBNVLLA")], [ExpressionStatement(BuiltIn("DIC", [UnaryMinus(Fractio("IIS"))]))]),
ValStr("-IIS"), "-IIS\n"),
]
class TestSVBNVLLADisplay(unittest.TestCase):
@parameterized.expand(svbnvlla_display_tests)
def test_svbnvlla_display(self, source, nodes, value, output=""):
run_test(self, source, nodes, value, output)
# --- ET and AVT (boolean and/or) ---
et_avt_tests = [