Rev 7745 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7745 | Rev 7844 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | /* |
|
- | 2 | STDCALL function |
|
- | 3 | Author: PaulCodeman |
|
- | 4 | */ |
|
Line 1... | Line 5... | ||
1 | /* Lisp functions */ |
5 | |
2 | - | ||
3 | :dword std_sleep(dword count, args) |
- | |
4 | { |
- | |
5 | dword ret = 0; |
- | |
6 | dword arg = 0; |
- | |
7 | dword val = 0; |
- | |
8 | WHILE(count) |
- | |
9 | { |
6 | void initFunctionLisp() |
10 | arg = DSDWORD[args]; |
7 | { |
- | 8 | set_procedure("TEST", #lisp_test); |
|
11 | REPEAT1: |
9 | set_procedure("SLEEP", #lisp_sleep); |
- | 10 | set_procedure("PRINT", #lisp_print); |
|
- | 11 | set_procedure("INPUT", #lisp_input); |
|
- | 12 | set_procedure("STDCALL", #lisp_stdcall); |
|
- | 13 | set_procedure("SETQ", #lisp_setq); |
|
12 | IF (DSDWORD[arg+4] == TSym) |
14 | set_procedure("DEFVAR", #lisp_setq); |
13 | { |
- | |
14 | arg = std_get(1, args); |
15 | set_procedure("+", #lisp_add); |
15 | goto REPEAT1; |
16 | set_procedure("-", #lisp_sub); |
16 | } |
17 | set_procedure("=", #lisp_cmp); |
- | 18 | } |
|
17 | IF (DSDWORD[arg+4] == TInt) |
19 | |
18 | { |
20 | dword lisp_test(dword args) |
19 | EAX = 5; |
21 | { |
20 | EBX = DSDWORD[arg]; |
22 | malloc(sizeStruct); |
21 | $int 0x40 |
- | |
22 | } |
- | |
23 | args+=4; |
23 | DSDWORD[EAX] = TString; |
24 | count--; |
24 | DSDWORD[EAX+4] = "ZZZ"; |
25 | } |
- | |
26 | RETURN ret; |
- | |
27 | } |
25 | return EAX; |
Line 28... | Line 26... | ||
28 | 26 | } |
|
29 | :dword std_set(dword count, args) |
27 | |
- | 28 | dword lisp_setq(dword args) |
|
30 | { |
29 | { |
31 | dword name = 0; |
30 | dword i = 0; |
- | 31 | dword name = 0; |
|
- | 32 | dword data = 0; |
|
- | 33 | while(1) |
|
- | 34 | { |
|
- | 35 | i++; |
|
32 | dword value = 0; |
36 | data = indexArray(args, i); |
- | 37 | data = DSDWORD[data]; |
|
- | 38 | IF (!data) break; |
|
33 | WHILE(count > 0) |
39 | |
34 | { |
40 | if (i&1) |
35 | name = DSDWORD[args]; |
- | |
- | 41 | { |
|
36 | IF (DSDWORD[name+4] == TSym) name = DSDWORD[name]; |
42 | name = DSDWORD[data+4]; |
37 | ELSE |
43 | } |
38 | { |
44 | else |
39 | con_printf stdcall ("Error variable!"); |
- | |
40 | ExitProcess(); |
45 | { |
41 | } |
- | |
42 | args += 4; |
- | |
43 | value = DSDWORD[args]; |
- | |
44 | args += 4; |
- | |
45 | variables.set(name, value); |
- | |
46 | count -= 2; |
46 | set_variable(name, data); |
- | 47 | } |
|
47 | } |
48 | } |
Line 48... | Line 49... | ||
48 | } |
49 | return 0; |
49 | 50 | } |
|
50 | :dword std_get(dword count, args) |
51 | |
51 | { |
52 | dword lisp_print(dword args) |
52 | dword name = 0; |
53 | { |
53 | IF(!count) RETURN 0; |
- | |
54 | name = DSDWORD[args]; |
54 | dword i = 0; |
- | 55 | consoleInit(); |
|
55 | IF (DSDWORD[name+4] != TSym) |
56 | while(1) |
56 | { |
57 | { |
- | 58 | i++; |
|
57 | con_printf stdcall ("Error variable!"); |
59 | indexArray(args, i); |
58 | ExitProcess(); |
60 | IF (!DSDWORD[EAX]) break; |
- | 61 | con_printf stdcall (string(DSDWORD[EAX])); |
|
59 | } |
62 | } |
Line 60... | Line 63... | ||
60 | RETURN variables.get(DSDWORD[name]); |
63 | con_printf stdcall ("\r\n"); |
61 | } |
64 | return 0; |
62 | 65 | } |
|
63 | :dword std_str(dword count, args) |
- | |
64 | { |
- | |
65 | dword tmp = 0; |
- | |
66 | IF(!count) RETURN ""; |
- | |
67 | tmp = malloc(15); |
- | |
68 | itoa_(tmp,DSDWORD[args]); |
- | |
69 | RETURN tmp; |
- | |
70 | } |
- | |
71 | - | ||
72 | /* Math functions */ |
66 | |
73 | :dword std_add(dword count, args) |
67 | dword lisp_stdcall(dword args) |
74 | { |
68 | { |
- | 69 | dword i = 0; |
|
- | 70 | dword buffer = 0; |
|
75 | dword ret = 0; |
71 | while(1) |
76 | WHILE(count) |
72 | { |
77 | { |
73 | i++; |
78 | ret += DSDWORD[args]; |
74 | indexArray(args, i); |
- | 75 | buffer = DSDWORD[EAX]; |
|
- | 76 | IF (!buffer) break; |
|
- | 77 | $push DSDWORD[buffer+4]; |
|
- | 78 | } |
|
79 | args+=4; |
79 | IF (i == 2) $pop eax |
80 | count--; |
80 | IF (i == 3) $pop ebx |
Line 81... | Line 81... | ||
81 | } |
81 | IF (i == 4) $pop ecx |
82 | RETURN ret; |
82 | $int 0x40 |
- | 83 | return EAX; |
|
- | 84 | } |
|
- | 85 | ||
83 | } |
86 | dword lisp_input(dword args) |
- | 87 | { |
|
- | 88 | dword buffer = 0; |
|
- | 89 | consoleInit(); |
|
84 | 90 | buffer = malloc(100); |
|
85 | :dword std_exit(dword count, args) |
91 | con_gets stdcall(buffer, 100); |
Line 86... | Line 92... | ||
86 | { |
92 | malloc(sizeStruct); |
87 | IF(initConsole) con_exit stdcall (1); |
93 | DSDWORD[EAX] = TString; |
- | 94 | DSDWORD[EAX+4] = buffer; |
|
88 | ExitProcess(); |
95 | return EAX; |
- | 96 | } |
|
89 | } |
97 | |
90 | 98 | dword lisp_inc(dword args) |
|
- | 99 | { |
|
91 | :dword std_sub(dword count, args) |
100 | dword i = 0; |
92 | { |
101 | dword sum = 0; |
93 | dword ret = 0; |
102 | dword buffer = 0; |
94 | IF(count) |
103 | while(1) |
95 | { |
- | |
96 | ret = DSDWORD[args]; |
- | |
97 | count--; |
- | |
98 | args+=4; |
- | |
99 | } |
104 | { |
100 | WHILE(count) |
- | |
101 | { |
- | |
102 | ret -= DSDWORD[args]; |
105 | i++; |
Line 103... | Line 106... | ||
103 | args += 4; |
106 | buffer = indexArray(args, i); |
104 | count--; |
- | |
105 | } |
- | |
106 | RETURN ret; |
- | |
107 | } |
- | |
108 | - | ||
109 | :dword std_type(dword count, args) |
- | |
110 | { |
- | |
111 | dword ret = 0; |
- | |
112 | dword arg = 0; |
107 | IF (!DSDWORD[buffer]) break; |
113 | dword val = 0; |
108 | buffer = DSDWORD[buffer]; |
114 | ret = malloc(TLen); |
109 | } |
115 | DSDWORD[ret] = "nil"; |
110 | return 0; |
- | 111 | } |
|
116 | DSDWORD[ret+4] = TStr; |
112 | |
117 | WHILE(count) |
- | |
118 | { |
- | |
119 | arg = DSDWORD[args]; |
113 | dword lisp_add(dword args) |
120 | REPEAT1: |
114 | { |
121 | IF (DSDWORD[arg+4] == TSym) |
- | |
122 | { |
- | |
123 | arg = std_get(1, args); |
115 | dword i = 0; |
124 | goto REPEAT1; |
- | |
125 | } |
- | |
126 | switch (DSDWORD[arg+4]) |
116 | dword sum = 0; |
127 | { |
- | |
128 | case TStr: |
- | |
129 | DSDWORD[ret] = "string"; |
- | |
130 | break; |
- | |
131 | case TInt: |
- | |
132 | DSDWORD[ret] = "integer"; |
- | |
133 | break; |
- | |
Line 134... | Line -... | ||
134 | } |
- | |
135 | args+=4; |
- | |
136 | count--; |
- | |
137 | } |
- | |
138 | RETURN ret; |
- | |
139 | } |
- | |
140 | - | ||
141 | /* Console functions */ |
- | |
142 | :dword std_print(dword count, args) |
- | |
143 | { |
- | |
144 | dword ret = 0; |
- | |
145 | dword arg = 0; |
- | |
146 | dword val = 0; |
- | |
147 | consoleInit(); |
- | |
148 | IF (!count) con_printf stdcall ("nil"); |
- | |
149 | WHILE(count) |
- | |
150 | { |
117 | dword buffer = 0; |
151 | arg = DSDWORD[args]; |
- | |
152 | REPEAT1: |
- | |
153 | IF (DSDWORD[arg+4] == TInt) val = itoa(DSDWORD[arg]); |
- | |
154 | ELSE IF (DSDWORD[arg+4] == TStr) val = DSDWORD[arg]; |
- | |
155 | ELSE IF (DSDWORD[arg+4] == TSym) |
- | |
156 | { |
- | |
157 | arg = std_get(1, args); |
118 | while(1) |
- | 119 | { |
|
- | 120 | i++; |
|
- | 121 | buffer = indexArray(args, i); |
|
158 | goto REPEAT1; |
122 | IF (!DSDWORD[buffer]) break; |
159 | } |
123 | buffer = DSDWORD[buffer]; |
Line 160... | Line 124... | ||
160 | IF(!arg) con_printf stdcall ("nil"); |
124 | |
161 | ELSE con_printf stdcall (val); |
125 | sum += number(buffer); |
162 | args+=4; |
- | |
163 | count--; |
126 | } |
164 | } |
127 | malloc(sizeStruct); |
165 | RETURN ret; |
- | |
166 | } |
- | |
167 | - | ||
168 | :dword std_len(dword count, args) |
128 | DSDWORD[EAX] = TNumber; |
169 | { |
129 | DSDWORD[EAX+4] = sum; |
170 | dword ret = 0; |
- | |
171 | dword arg = 0; |
- | |
172 | dword val = 0; |
- | |
173 | ret = malloc(TLen); |
- | |
174 | DSDWORD[ret] = 0; |
130 | return EAX; |
175 | DSDWORD[ret+4] = TInt; |
131 | } |
176 | WHILE(count) |
- | |
177 | { |
- | |
178 | arg = DSDWORD[args]; |
132 | |
179 | REPEAT1: |
133 | dword lisp_sub(dword args) |
180 | IF (DSDWORD[arg+4] == TStr) val = DSDWORD[arg]; |
- | |
181 | ELSE IF (DSDWORD[arg+4] == TSym) |
- | |
182 | { |
134 | { |
- | 135 | dword i = 0; |
|
- | 136 | dword sum = 0; |
|
- | 137 | while(1) |
|
183 | arg = std_get(1, args); |
138 | { |
184 | goto REPEAT1; |
139 | i++; |
Line 185... | Line 140... | ||
185 | } |
140 | indexArray(args, i); |
186 | ELSE return ret; |
- | |
187 | DSDWORD[ret] += DSDWORD[arg+8]; |
- | |
188 | args+=4; |
- | |
189 | count--; |
- | |
190 | } |
- | |
191 | RETURN ret; |
- | |
192 | } |
- | |
193 | - | ||
194 | :dword std_cmp(dword count, args) |
- | |
195 | { |
- | |
196 | dword ret = 0; |
- | |
197 | dword arg = 0; |
- | |
198 | dword val = 0; |
- | |
199 | dword tmp = 0; |
141 | IF (!DSDWORD[EAX]) break; |
200 | dword x = 0; |
142 | sum -= number(DSDWORD[EAX]); |
201 | dword y = 0; |
143 | } |
202 | byte start = 0; |
144 | malloc(sizeStruct); |
- | 145 | DSDWORD[EAX] = TNumber; |
|
- | 146 | DSDWORD[EAX+4] = sum; |
|
203 | ret = malloc(TLen); |
147 | return EAX; |
- | 148 | } |
|
204 | DSDWORD[ret] = 0; |
149 | |
205 | DSDWORD[ret+4] = TInt; |
150 | dword lisp_cmp(dword args) |
206 | IF (!count) return ret; |
151 | { |
207 | while(count) |
152 | dword i = 0; |
208 | { |
153 | dword first = 0; |
209 | arg = DSDWORD[args]; |
154 | dword buffer = 0; |
210 | REPEAT2: |
- | |
211 | IF (DSDWORD[arg+4] == TSym) |
- | |
212 | { |
- | |
213 | arg = std_get(1, args); |
- | |
214 | goto REPEAT2; |
155 | |
215 | } |
- | |
216 | IF (!start) |
156 | while(1) |
217 | { |
157 | { |
218 | start = 1; |
158 | i++; |
219 | tmp = arg; |
- | |
220 | args+=4; |
- | |
221 | count--; |
159 | buffer = indexArray(args, i); |
222 | continue; |
160 | buffer = DSDWORD[buffer]; |
223 | } |
161 | IF (!buffer) break; |
224 | IF (DSDWORD[tmp+4] != DSDWORD[arg+4]) return ret; |
162 | if (i == 1) |
225 | IF (DSDWORD[tmp+4] == TInt) |
163 | { |
226 | { |
164 | first = buffer; |
227 | IF (DSDWORD[tmp] != DSDWORD[arg]) return ret; |
- | |
228 | } |
- | |
229 | ELSE IF (DSDWORD[tmp+4] == TStr) |
165 | } |
230 | { |
- | |
231 | /*IF (!DSDWORD[tmp+8]) DSDWORD[tmp+8] = crc32(DSDWORD[tmp]); |
- | |
232 | IF (!DSDWORD[arg+8]) DSDWORD[arg+8] = crc32(DSDWORD[arg]); |
- | |
233 | IF (DSDWORD[tmp+8] != DSDWORD[arg+8]) return ret;*/ |
- | |
234 | IF (strcmp(DSDWORD[tmp], DSDWORD[arg])) return ret; |
- | |
235 | } |
- | |
236 | args+=4; |
- | |
237 | count--; |
- | |
238 | } |
- | |
239 | DSDWORD[ret] = 1; |
- | |
240 | return ret; |
- | |
241 | } |
- | |
242 | - | ||
243 | :dword std_input(dword count, args) |
- | |
244 | { |
- | |
245 | dword buf = 0; |
166 | else |
246 | consoleInit(); |
- | |
247 | buf = malloc(100); |
- | |
248 | IF (count) std_print(count, args); |
- | |
249 | con_gets stdcall(buf, 100); |
- | |
250 | EDX = malloc(TLen); |
- | |
251 | DSDWORD[EDX] = buf; |
- | |
252 | DSDWORD[EDX+4] = TStr; |
- | |
253 | RETURN EDX; |
167 | { |
254 | } |
- | |
255 | - | ||
256 | void Init() |
168 | if (DSDWORD[first+4] != DSDWORD[buffer+4]) |
257 | { |
- | |
258 | functions.init(100); |
- | |
259 | 169 | { |
|
260 | /* Console functions */ |
- | |
261 | functions.set("print", #std_print); |
- | |
262 | functions.set("input", #std_input); |
- | |
263 | - | ||
264 | /* String functions */ |
- | |
265 | functions.set("str", #std_str); |
- | |
266 | functions.set("len", #std_len); |
- | |
267 | 170 | malloc(sizeStruct); |
|
268 | /* System functions */ |
- | |
269 | functions.set("exit", #std_exit); |
- | |
270 | - | ||
271 | /* Math functions */ |
- | |
272 | functions.set("+", #std_add); |
- | |
273 | functions.set("-", #std_sub); |
- | |
274 | functions.set("==", #std_cmp); |
171 | DSDWORD[EAX] = TSymbol; |
275 | 172 | DSDWORD[EAX+4] = NIL; |
|
Line 276... | Line 173... | ||
276 | /* Lisp functions */ |
173 | return EAX; |
277 | functions.set("set", #std_set); |
174 | } |
- | 175 | } |
|
278 | functions.set("get", #std_get); |
176 | } |
279 | functions.set("type", #std_type); |
177 | if (i == 1) error_message("*** - EVAL: too few arguments given to =: (=)"); |
- | 178 | malloc(sizeStruct); |
|
- | 179 | DSDWORD[EAX] = TSymbol; |
|
- | 180 | DSDWORD[EAX+4] = "T"; |
|
280 | functions.set("sleep", #std_sleep); |
181 | return EAX; |
281 | 182 | } |
|
282 | - |