/programs/cmm/lisp/lisp.c |
---|
50,8 → 50,7 |
dword p = 0; |
dataArgs = malloc(16*4); |
posArgs = dataArgs; |
name = malloc(100); |
pos = name; |
loop() |
{ |
s = DSBYTE[code]; |
61,18 → 60,31 |
code++; |
s = DSBYTE[code]; |
} |
if (!s) || (s==')') |
if (!s) return 0; |
if (s==')') |
{ |
code++; |
break; |
args--; |
ret = StdCall(args, name, dataArgs); |
free(name); |
//free(dataArgs); |
return ret; |
} |
if (!args) |
if(s == '(') |
{ |
code++; |
DSDWORD[posArgs] = evalLisp(); |
args++; |
posArgs += 4; |
continue; |
} |
else if (!args) |
{ |
if (s != ')') // name function |
{ |
while (s != ' ') && (s != ')') |
name = malloc(100); |
pos = name; |
while (s) && (s != ' ') && (s != ')') |
{ |
DSBYTE[pos] = s; |
pos++; |
79,18 → 91,15 |
code++; |
s = DSBYTE[code]; |
} |
code--; |
DSBYTE[pos] = 0; |
args++; |
continue; |
} |
} |
else |
{ |
if(s == '(') |
if (s >= '0') && (s <= '9') |
{ |
code++; |
tmp = evalLisp(); |
} |
else if (s >= '0') && (s <= '9') |
{ |
tmp = 0; |
while (s >= '0') && (s <= '9') |
{ |
99,7 → 108,10 |
code++; |
s = DSBYTE[code]; |
} |
code--; |
args++; |
DSDWORD[posArgs] = tmp; |
posArgs += 4; |
continue; |
} |
else if (s == '"') |
{ |
130,6 → 142,10 |
s = DSBYTE[code]; |
} |
DSBYTE[p] = 0; |
args++; |
DSDWORD[posArgs] = tmp; |
posArgs += 4; |
continue; |
} |
DSDWORD[posArgs] = tmp; |
141,7 → 157,7 |
args--; |
ret = StdCall(args, name, dataArgs); |
free(name); |
free(dataArgs); |
//free(dataArgs); |
return ret; |
} |
149,7 → 165,7 |
{ |
dword brainFuckCode = 0; |
word maxLoop = 1000; |
dword txt = " (print 1)(print 2)"; |
dword txt = "(print (input \"test:\"))"; |
buffer = malloc(bufferSize); |
memory = malloc(memoryBrainfuck); |
177,7 → 193,7 |
else |
{ |
consoleInit(); |
con_printf stdcall ("Lisp interpreter v1.2"); |
con_printf stdcall ("Lisp interpreter v1.3"); |
while(maxLoop) |
{ |
con_printf stdcall ("\r\n\r\nEnter code: "); |
185,17 → 201,7 |
code = EAX; |
//code = txt; |
con_printf stdcall ("Output: "); |
nextLispLine: |
while(DSBYTE[code] == ' ') code++; |
if(DSBYTE[code] == '(') code++; |
else goto endNext; |
evalLisp(); |
code--; |
if(DSBYTE[code]==')') code++; |
else goto endNext; |
IF(!DSBYTE[code]) goto endNext; |
goto nextLispLine; |
endNext: |
maxLoop--; |
} |
} |
/programs/cmm/lisp/stdcall.h |
---|
1,17 → 1,5 |
dword std_print(dword count, args) |
{ |
consoleInit(); |
count = 1; |
WHILE(count) |
{ |
con_printf stdcall (DSDWORD[args]); |
args+=4; |
count--; |
} |
} |
/* Lisp functions */ |
:dword std_set(dword count, args) |
{ |
dword name = 0; |
29,6 → 17,7 |
:dword std_get(dword count, args) |
{ |
IF(!count) RETURN 0; |
RETURN variables.get(DSDWORD[args]); |
} |
35,11 → 24,13 |
:dword std_str(dword count, args) |
{ |
dword tmp = 0; |
IF(!count) RETURN ""; |
tmp = malloc(15); |
itoa_(tmp,DSDWORD[args]); |
RETURN tmp; |
} |
/* Math functions */ |
:dword std_add(dword count, args) |
{ |
dword ret = 0; |
70,13 → 61,41 |
RETURN ret; |
} |
/* Console functions */ |
:dword std_print(dword count, args) |
{ |
dword ret = 0; |
WHILE(count) |
{ |
con_printf stdcall (DSDWORD[args]); |
args+=4; |
count--; |
} |
RETURN ret; |
} |
:dword std_input(dword count, args) |
{ |
dword buf = 0; |
buf = malloc(100); |
WHILE(count) |
{ |
con_printf stdcall (DSDWORD[args]); |
args+=4; |
count--; |
} |
con_gets stdcall(buf, 100); |
RETURN EAX; |
} |
void Init() |
{ |
functions.init(100); |
/* Console functions */ |
functions.set("print", #std_print); |
functions.set("input", #std_input); |
/* String functions */ |
functions.set("str", #std_str); |
96,21 → 115,8 |
dword StdCall(dword count, name, args) |
{ |
dword tmp = 0; |
functions.get(name); |
IF(EAX) RETURN EAX(count, args); |
IF(!strcmp(name, "print")) |
{ |
consoleInit(); |
count = 1; |
WHILE(count) |
{ |
con_printf stdcall (DSDWORD[args]); |
args += 4; |
count--; |
} |
} |
RETURN 0; |
} |