Skip to content

Commit b00a83b

Browse files
TEST std-list.mx
1 parent f86bea3 commit b00a83b

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

tests/std-list.mx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
%include "memory"
2+
%include "heap"
3+
%include "control"
4+
%include "procedures"
5+
%include "io"
6+
%include "list"
7+
%include "debug"
8+
%include "array"
9+
10+
%proc{ print_lists, ; uses main's local segment
11+
outc 'A'
12+
%seg:push_addr(%local, 0)
13+
%print_spaced( %call(list_print) )
14+
outc 'B'
15+
%seg:push_addr(%local, 1)
16+
%print_spaced( %call(list_print) )
17+
outc 'C'
18+
%seg:push(%local, 2)
19+
%print_endl( %call(list_print) )
20+
}
21+
22+
%macro callListMethodWithArgs(methodName, listIdx, pushArguemts) {
23+
%if_else { ; lives list in main:locals?
24+
ld %listIdx
25+
lle 1
26+
,
27+
%seg:push_addr(%local, %listIdx),
28+
%seg:push(%local, %listIdx)
29+
}
30+
%pushArguemts
31+
%call(%methodName)
32+
}
33+
%macro callListMethod(methodName, listIdx) { ; no arguments
34+
%callListMethodWithArgs(%methodName, %listIdx, ld 0)
35+
}
36+
%macro printResult(desc, delim) {
37+
outc %desc
38+
outc ':'
39+
%stack:pop()
40+
outum
41+
outc %delim
42+
}
43+
%macro populateFirstArray() { ; initialize array at local:0
44+
%callListMethodWithArgs(list_insert_after, 0, %stack:push(5))
45+
%callListMethodWithArgs(list_insert_after, 0, %stack:push(6))
46+
%callListMethodWithArgs(list_insert_back, 0, %stack:push(7))
47+
}
48+
49+
%void_func{ main, 0, 6, ; 2 * sizeof(list) + sizeof(ptr) + sizeof(array)
50+
%seg:local(0, %list:init()) ; first 2 lists live in locals
51+
%seg:local(1, %list:init()) ; NOTE: testing of different schemes
52+
%seg:local(2, %list:construct_here()) ; third lives in heap (here is ptr to that struct)
53+
%seg:local(3, %array:init())
54+
55+
%populateFirstArray()
56+
57+
; A.insert_after(list[1], 2)
58+
%callListMethodWithArgs(list_index, 0, %stack:push(1))
59+
%printResult('I', '\n')
60+
%seg:push_seg(%this)
61+
%stack:push(2)
62+
%call(list_insert_after)
63+
64+
%call(print_lists)
65+
66+
%print_spaced( outc 'A' )
67+
%callListMethod(list_first, 0)
68+
%printResult('F', ' ')
69+
%callListMethod(list_last, 0)
70+
%printResult('L', '\n')
71+
72+
; size(A, B, C)
73+
%print_spaced( outc 'S' )
74+
%callListMethod(list_size, 0)
75+
%printResult('A', ' ')
76+
%callListMethod(list_size, 1)
77+
%printResult('B', ' ')
78+
%callListMethod(list_size, 2)
79+
%printResult('C', '\n')
80+
}
81+
82+
%call(main)

tests/std-list.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:returncode 0
2+
3+
:stdout 50
4+
I:5
5+
A[6, 5, 2, 7] B[] C[]
6+
A F:6 L:7
7+
S A:4 B:0 C:0
8+
9+

0 commit comments

Comments
 (0)