aboutsummaryrefslogtreecommitdiff
path: root/test/cases/bytecode.bqn
blob: 72fdb8cb1b6270766d1fc56404ea0753ebf5f85a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Tests of bytecode operations.
# These use no primitives, so that compiled code can be run directly in
# a correct VM even if it has no runtime.
# Compile with a command such as $ src/cjs.bqn "a←2⋄b←3⋄a"

# Tests are meant to be run in order; comments indicate new instructions
# introduced by each.

5  % 5                     #  0 PUSH,  7 RETN
3  % 43                   #  6 POPS
5  % a5                   # 33 VARM, 48 SETN
4  % a5a4               # 49 SETU
2  % a2b3a             # 32 VARO
1  % a1A 4               # 16 FN1C
2  % a23 A 4             # 17 FN2C
6  % {𝕩}6                  #  1 DFND
3  % A{𝕨}3 A 4           #    dyadic block function
7  % ab72a             # 11 ARRO, 12 ARRM
2  % 0{𝕨𝕏1}2               # 19 FN2O (doesn't test call type)
5  % {({𝕨}𝕨)𝕏𝕩}5           # 18 FN1O not called
8  % {𝕩{ab𝕨}𝕨,𝕩}8        # 19 FN2O not called
4  % 4{𝔽}                  # 26 MD1C
6  % 4{𝔽𝕩}6               #    deferred modifier
1  % 3{𝔾}{𝕩} 1             # 27 MD2C
2  % (2{𝔽}{𝕩})3            # 20 TR2D
3  % 3({ab𝕩a}{𝕨𝕩})4    #    dyadic 2-train
4  % 4({𝕨𝕩}{𝕩}{𝕨})5       # 21 TR3D
2  % ab(2{𝕨𝕩}{𝕩})5a    #    monadic, data in left branch
2  % ({a2𝕩}{𝕩a}{a3𝕩})a4 # ordering
8  % a3a{𝕩}8a          # 50 SETM
5  % a4a{𝕨5}6          #    returns new value
1  % a3a{𝕩1}a         # 51 SETC
4  % ab21ab{𝕩𝕨}4a  #    lists

# Call type tests; can also replace {a←𝕩⋄{a↩𝕩}𝕨⋄a} with {𝕩;𝕨}
7  %      {𝕨{a𝕩{a𝕩}𝕨a}𝕩}7  # 19 FN2O call type
3  %     3{𝕨{a𝕩{a𝕩}𝕨a}𝕩}7  # 19 FN2O call type
7  % {𝕏0} {𝕨{a𝕩{a𝕩}𝕨a}𝕏}7  # 23 TR3O call type
3  % {𝕏0}3{𝕨{a𝕩{a𝕩}𝕨a}𝕏}7  # 23 TR3O call type

# Further tests for lexical scoping
1  % a1{a2}a
2  % a1{a2}a
6  % fg{a2{a𝕩}{𝕩a}}F 6G 0
5  % L{𝕩{𝕏𝕗}}{𝕏𝕤}L L L 5
3  % _l{𝕩{𝕏𝕗} 𝔽}{𝕏𝕤} {𝕩}_l 3 _l 5
1  % 1{𝕨}{𝔽{𝕩𝔽𝕨}𝔾𝔽}{𝕩}0    # 0≠1 via Church booleans
2  % 0(0{𝕩}){{ab𝕩t𝕤{𝕤T{𝕤{ab𝕩a}}}{B𝕗}0(T b){ab𝕩𝔽b}}𝕗} 0(1(2(3(4{𝕩}))))