forked from mit-plv/koika
-
Notifications
You must be signed in to change notification settings - Fork 2
/
arrays.lv
49 lines (41 loc) · 1.27 KB
/
arrays.lv
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
49
;;; Unit tests for array functions
(enum test
::x 1'b1)
(module arrays
(register r 16'b0)
(rule init
(let ((arr0 (init (array bool) true false true true))
(arr arr0))
(displn arr)
(setq arr (asubst 0 arr false))
(displn arr)
(setq arr (asubst 1 arr true))
(displn arr)
(displn (= arr0 (asubst 1 (asubst 0 arr true) false)))))
(rule init_chars
(let ((str (init (array char) 8'107 8'195 8'180 8'105 8'107 8'97)))
(displn str)
(print str)
(print (init string "\n"))
(let ((packed (pack str)))
(print (init string "packed: "))
(displn packed)
(let ((unpacked (unpack (array char 6) packed)))
(print (init string "unpacked: "))
(displn unpacked)))))
(rule init_str
(let ((str (init string "kôika")))
(displn str)
(print str)
(print (init string "\n"))
(displn (aref 0 str))))
(rule array_of_strings
(displn
(init (array (array char 8))
(init string "abcdefgh")
(init (array char) 8'97 8'98 8'99 8'100 8'101 8'102 8'103 8'104))))
(rule array_of_enums
(displn
(init (array 'test)
::x ::x ::x)))
(scheduler s (sequence init init_chars init_str array_of_strings array_of_enums)))