-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.dk
69 lines (53 loc) · 1.47 KB
/
deck.dk
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! implement some kind of loop function which checks the top of stack value
#! before jumping to address
#! @loop pushes here to deque @until jumps back to value on deque while tos is 0
#! 3 3 3 +v io_intlnk
#! dbg
#! 10 sys_mmap
#! dup 69 swp mset
#! dup 8 + 420 swp mset
#! dup mget
#! swp dup 8 + mget swp
#! 10 sys_unmap
1 2 3 4 5
10 create
dbg
#! # io_intln
#! msetv
#! delete
sys_ok
@msetv >| #! ( ... ptr cont -> )
&mset++ times
ret
@mset++ >| tuck mset ptr++ ret #! ( x addr cont -> addr )
@create >| #! ( size -> ptr )
#! Allocate some memory and store the size before
#! the allocated chunk so we can use later when
#! freeing the memory. This absolves the user
#! from having to store the size.
++ cell * dup sys_mmap tuck mset ptr++
ret
@delete >| #! ( ptr -> )
#! Free some memory that was previously allocated
#! with `create`. We pull out the size of the block
#! first and then pass both the size and pointer to
#! the unmap call.
dup mget ptr-- sys_unmap
ret
#! @vrotl
#! @vrotl >|
#! retrieve the leftmost element and store it on the deq.
#! next we loop and set every left element equal to its right element's value.
#! lastly we pop the value we stored earlier from the deque.
#! ret
#! @fact2 >| dup 1 = &.end if dup -- fact2 * @.end ret
#! @fact >| 1 swp iota v* ret
#! @kdbg >| &kint map ret
#! here
#! 0 swp 0 # io_hexln swp .
#! 0 here swp
#! dup &io_intln ++
#! dup 10 <=
#! 2 get f ? .
#! @f
#! 0 0 @loop ++ dup dup &io_hexln 5 < loop sys_exit ? .