/programs/cmm/lisp/lisp.c |
---|
50,7 → 50,8 |
dword p = 0; |
dataArgs = malloc(16*4); |
posArgs = dataArgs; |
name = malloc(100); |
pos = name; |
loop() |
{ |
s = DSBYTE[code]; |
60,46 → 61,36 |
code++; |
s = DSBYTE[code]; |
} |
if (!s) return 0; |
if (s==')') |
if (!s) || (s==')') |
{ |
code++; |
args--; |
ret = StdCall(args, name, dataArgs); |
free(name); |
//free(dataArgs); |
return ret; |
break; |
} |
if(s == '(') |
if (!args) |
{ |
code++; |
DSDWORD[posArgs] = evalLisp(); |
args++; |
posArgs += 4; |
continue; |
} |
else if (!args) |
{ |
if (s != ')') // name function |
{ |
name = malloc(100); |
pos = name; |
while (s) && (s != ' ') && (s != ')') |
while (s != ' ') && (s != ')') |
{ |
DSBYTE[pos] = s; |
pos++; |
code++; |
s = DSBYTE[code]; |
} |
DSBYTE[pos] = 0; |
args++; |
continue; |
} |
code--; |
} |
} |
else |
{ |
if (s >= '0') && (s <= '9') |
if(s == '(') |
{ |
code++; |
tmp = evalLisp(); |
} |
else if (s >= '0') && (s <= '9') |
{ |
tmp = 0; |
while (s >= '0') && (s <= '9') |
{ |
108,10 → 99,7 |
code++; |
s = DSBYTE[code]; |
} |
args++; |
DSDWORD[posArgs] = tmp; |
posArgs += 4; |
continue; |
code--; |
} |
else if (s == '"') |
{ |
142,10 → 130,6 |
s = DSBYTE[code]; |
} |
DSBYTE[p] = 0; |
args++; |
DSDWORD[posArgs] = tmp; |
posArgs += 4; |
continue; |
} |
DSDWORD[posArgs] = tmp; |
157,7 → 141,7 |
args--; |
ret = StdCall(args, name, dataArgs); |
free(name); |
//free(dataArgs); |
free(dataArgs); |
return ret; |
} |
165,7 → 149,7 |
{ |
dword brainFuckCode = 0; |
word maxLoop = 1000; |
dword txt = "(print (input \"test:\"))"; |
dword txt = " (print 1)(print 2)"; |
buffer = malloc(bufferSize); |
memory = malloc(memoryBrainfuck); |
193,7 → 177,7 |
else |
{ |
consoleInit(); |
con_printf stdcall ("Lisp interpreter v1.3"); |
con_printf stdcall ("Lisp interpreter v1.2"); |
while(maxLoop) |
{ |
con_printf stdcall ("\r\n\r\nEnter code: "); |
201,7 → 185,17 |
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,10 → 1,22 |
/* Lisp functions */ |
dword std_print(dword count, args) |
{ |
consoleInit(); |
count = 1; |
WHILE(count) |
{ |
con_printf stdcall (DSDWORD[args]); |
args+=4; |
count--; |
} |
} |
:dword std_set(dword count, args) |
{ |
dword name = 0; |
dword value = 0; |
WHILE(count > 0) |
WHILE(count>0) |
{ |
name = DSDWORD[args]; |
args += 4; |
11,13 → 23,12 |
value = DSDWORD[args]; |
args += 4; |
variables.set(name, value); |
count -= 2; |
count-=2; |
} |
} |
:dword std_get(dword count, args) |
{ |
IF(!count) RETURN 0; |
RETURN variables.get(DSDWORD[args]); |
} |
24,13 → 35,11 |
: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; |
55,19 → 64,6 |
WHILE(count) |
{ |
ret -= DSDWORD[args]; |
args += 4; |
count--; |
} |
RETURN ret; |
} |
/* Console functions */ |
:dword std_print(dword count, args) |
{ |
dword ret = 0; |
WHILE(count) |
{ |
con_printf stdcall (DSDWORD[args]); |
args+=4; |
count--; |
} |
74,28 → 70,13 |
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); |
115,8 → 96,21 |
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; |
} |