aboutsummaryrefslogtreecommitdiff
path: root/stdlib.rip
blob: af428c32903fdb8dd0a475192acbbf1a9a0c131a (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
0I[prints string; destructive]
F<strprint>[
	<strrev>
	97aDm
	SDW[
		D3RD3rM o D3rq
	D]
	PP
]

0I[takes string char; returns string+char]
F<strpush>[
	S97aDmma
]

0I[reverses string in place]
F<strrev>[
	0S
	DW[
		D 97aDm D 3r M 3r q 3r S 97aDm m a S
	D]
	P
]

0I[concatenates two strings]
F<strcat>[
	<strrev> 97aDm S
	DW[
		S D 3r S D 3R M 4R 97aDmma 3r S D 3r q
	D]
	PP
]

0I[takes list of characters and a length, builds a string]
F<mkstr>[
	0S
	DW[
		D2aR 3R 97aDm m a S d
	D]
	P
]


0I[initialises variable store at beginning of stack (no args) (CALL ONLY ONCE)]
F<varinit>[
	0lr 0lr 0lr  0I[guard]
]

0I[INTERNAL FUNCTION
   hauls variable by name in argument to top of stack; pushes 0 0 if non-existent]
F<varhaulup>[
	00  0I[guard]
	lRlR
	SD3rW[
		0I['s't'a'r't' 'w'h'i'l'e 9i 93a<mkstr><strprint>]
		SD3r
		6R  0I[get target varname up]
		D5r
		EDI[P
			0I['e'q'u'a'l'! 9i 7<mkstr><strprint>]
			D3r
			4RD5rW[
				4r4rlrlr
			4RD5r]
			3RP3RP
			0  0I[to stop while loop]
			1  0I[to prevent taking of the else branch]
		]
		nI[
			0I['u'n'e'q'u'a'l'! 9i 9<mkstr><strprint>]
			lRlR  0I[get next one]
			SD3r  0I[get name up; if zero, then while loop should stop: end of var list]
		]
	]
	0I['d'o'n'e' 'w'i't'h' 'w'h'i'l'e 9i  79a<mkstr><strprint>]
	SD3rnI[
		0I['i's' 'z'e'r'o 9i 8<mkstr><strprint>]
		lrlr3RP
		SD3rW[
			lrlr
		SD3r]
	]
	0I['d'o'n'e' 'w'i't'h' 'v'a'r'h'a'u'l'u'p 9i 99aii<mkstr><strprint>]
]

0I[pushes whether specified variable exists in store]
F<varexists>[
	<varhaulup>
	Pnn
]

0I[deletes variable given by argument from store]
F<vardel>[
	00  0I[guard]
	lRlR
	SD3rW[
		0I['s't'a'r't' 'w'h'i'l'e 9i 93a<mkstr><strprint>]
		SD3r
		6R  0I[get target varname up]
		D5r
		EDI[P
			0I['e'q'u'a'l'! 9i 7<mkstr><strprint>]
			PPP
			SD3rW[
				lrlr
			SD3r]
			PP
			1  0I[did find the thing]
			0  0I[to stop while loop]
			1  0I[to prevent taking of the else branch]
		]
		nI[
			0I['u'n'e'q'u'a'l'! 9i 9<mkstr><strprint>]
			lRlR  0I[get next one]
			SD3r  0I[get name up; if zero, then while loop should stop: end of var list]
		]
	]
	0I['d'o'n'e' 'w'i't'h' 'w'h'i'l'e 9i  79a<mkstr><strprint>]
	nI[
		0I['i's' 'z'e'r'o 9i 8<mkstr><strprint>]
		0lrlr3RP
		SD3rW[
			lrlr
		SD3r]
		PP
	]
	0I['d'o'n'e' 'w'i't'h' 'v'a'r'd'e'l 9i 89a<mkstr><strprint>]
]

0I[takes variable name (string) and value to store]
F<varstore>[
	0I['s't'o'r'i'n'g'  8<mkstr><strprint>
	   O
	   ' 'i'n'  4<mkstr><strprint>
	   <strprint>
	   9io
	  ]
	
	SD<vardel>
	Slrlr
]

0I[takes variable name (string) and pushes its value]
F<varget>[
	<varhaulup>
	SP
]