aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/word_literals_test.py
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /tests/drivers/word_literals_test.py
a
Diffstat (limited to 'tests/drivers/word_literals_test.py')
-rw-r--r--tests/drivers/word_literals_test.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/drivers/word_literals_test.py b/tests/drivers/word_literals_test.py
new file mode 100644
index 0000000..a2d230d
--- /dev/null
+++ b/tests/drivers/word_literals_test.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+# every 64-bit word is representable, even outside a single literal's 63-bit range.
+import subprocess
+
+values = [0, 1, (1 << 62) - 1, 1 << 62, (1 << 63) - 1, -(1 << 62), -(1 << 62) - 1, -(1 << 63), -1]
+source = 'fn main() {\n' + ''.join(f'put_n({value}); put_c(10);\n' for value in values) + 'return 0; }\n'
+expected = ''.join(str(value) + '\n' for value in values)
+for command in [['bin/zy'], ['bin/zym'], ['node', 'src/js/tinyvm.js']]:
+ result = subprocess.run(command, input=source, text=True, capture_output=True, timeout=20)
+ assert result.returncode == 0 and result.stdout == expected, (command, result.stdout, result.stderr)
+ print('ok full-width positive and negative word literals: ' + command[0])
+source = '''immediate fn add_word_operator() { next(); add_binop("**", 11, "4611686018427387904 | +"); return 0; }
+add_word_operator
+fn main() { put_n(0 ** 0); put_c(10); return 0; }
+'''
+for command in [['bin/zy'], ['bin/zym'], ['node', 'src/js/tinyvm.js']]:
+ result = subprocess.run(command, input=source, text=True, capture_output=True, timeout=20)
+ assert result.returncode == 0 and result.stdout == '4611686018427387904\n', (command, result.stdout, result.stderr)
+ print('ok full-width word in a stored operator sequence: ' + command[0])