aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/word_literals_test.py
blob: cfac811b36b48d8170ff8a295c3c7e756753339c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 [['build/bin/zy'], ['build/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 [['build/bin/zy'], ['build/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])