aboutsummaryrefslogtreecommitdiff
path: root/stdlib.rip
blob: 7d209b7d37ebd772afa85336d0ffa2802a955088 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
0I[prints string; destructive]
F<strprint>[
	<strrev>
	28p
	SDW[
		D3RD3rM o D3rq
	D]
	PP
]

0I[gets last character of string; destructive]
F<strlast>[
	28pM
]

0I[drops last character of string; destructive]
F<strinit>[
	28pq
]

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

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

0I[concatenates two strings]
F<strcat>[
	<strrev> 28p S
	DW[
		S D 3r S D 3R M 4R 28pma 3r S D 3r q
	D]
	PP
]

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

0I[compares two strings; 0 = equal, >0, <0 = second string is greater, less than first; destructive]
F<strcmp>[
	0 3r
	<dup2>mW[
		D28pM 3R D28pM S 4r S s
		DI[
			4rPPP00
			0  0I[to counter the P after the if]
		]
		P
		28pqS28pqS
	<dup2>m]
	PP
]


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

0I[hauls variable by name in argument to top of stack (result: name value);
   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
]


0I[takes socket and string; sends string to socket]
F<strsend>[
	<strrev>
	DW[D28pM3RSwS28pqD]P
]


0I[A B -> A B A B]
F<dup2>[
	SD3RD3r
]