Lisp v1.2

git-svn-id: svn://kolibrios.org@7563 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pavelyakov 2018-12-06 08:59:06 +00:00
parent 0cb21a159b
commit a592ede59c
2 changed files with 86 additions and 26 deletions

View File

@ -6,8 +6,11 @@
#include "../lib/io.h" #include "../lib/io.h"
#include "../lib/obj/console.h" #include "../lib/obj/console.h"
#include "../lib/array.h"
byte initConsole = 0; byte initConsole = 0;
Dictionary functions = {0};
Dictionary variables = {0};
#include "stdcall.h" #include "stdcall.h"
@ -63,9 +66,9 @@ dword evalLisp()
} }
if (!args) if (!args)
{ {
if(s>='A') && (s<='z') // name function if(s!=' ') && (s!=')') // name function
{ {
while (s>='A') && (s<='z') while (s!=' ') && (s!=')')
{ {
DSBYTE[pos] = s; DSBYTE[pos] = s;
code++; code++;
@ -101,23 +104,25 @@ dword evalLisp()
code++; code++;
args++; args++;
} }
args -= 2; args--;
ret = StdCall(args, name, dataArgs); ret = StdCall(args, name, dataArgs);
free(name); free(name);
free(dataArgs); free(dataArgs);
return ret; return ret;
} }
void main() void main()
{ {
dword brainFuckCode = 0; dword brainFuckCode = 0;
word maxLoop = 1000; word maxLoop = 1000;
dword txt = "(print (str 1) (str 2))";
buffer = malloc(bufferSize); buffer = malloc(bufferSize);
memory = malloc(memoryBrainfuck); memory = malloc(memoryBrainfuck);
stack = malloc(stackBrainFuck); stack = malloc(stackBrainFuck);
Init();
IF(DSBYTE[I_Param]) IF(DSBYTE[I_Param])
{ {
IF(io.read(I_Param)) IF(io.read(I_Param))
@ -125,6 +130,7 @@ void main()
code = EAX; code = EAX;
loop() loop()
{ {
while(DSBYTE[code] == ' ') code++;
if(DSBYTE[code]!='(') break; if(DSBYTE[code]!='(') break;
else code++; else code++;
evalLisp(); evalLisp();
@ -133,17 +139,19 @@ void main()
} }
} }
} }
ELSE else
{ {
consoleInit(); consoleInit();
con_printf stdcall ("Lisp interpreter v1.0"); con_printf stdcall ("Lisp interpreter v1.2");
WHILE(maxLoop) WHILE(maxLoop)
{ {
con_printf stdcall ("\r\n\r\nEnter code: "); con_printf stdcall ("\r\n\r\nEnter code: ");
con_gets stdcall(buffer, bufferSize); con_gets stdcall(buffer, bufferSize);
code = EAX; code = EAX;
code = txt;
con_printf stdcall ("Output: "); con_printf stdcall ("Output: ");
nextLispLine: nextLispLine:
while(DSBYTE[code] == ' ') code++;
if(DSBYTE[code]!='(') continue; if(DSBYTE[code]!='(') continue;
else code++; else code++;
evalLisp(); evalLisp();

View File

@ -1,24 +1,76 @@
:dword std_print(dword count, args)
{
consoleInit();
WHILE(count)
{
con_printf stdcall (DSDWORD[args]);
args+=4;
count--;
}
}
:dword std_str(dword count, args)
{
dword tmp = 0;
tmp = malloc(15);
itoa_(tmp,DSDWORD[args]);
RETURN tmp;
}
:dword std_add(dword count, args)
{
dword ret = 0;
WHILE(count)
{
ret += DSDWORD[args];
args+=4;
count--;
}
RETURN ret;
}
:dword std_sub(dword count, args)
{
dword ret = 0;
IF(count)
{
ret = DSDWORD[args];
count--;
args+=4;
}
WHILE(count)
{
ret -= DSDWORD[args];
args+=4;
count--;
}
RETURN ret;
}
void Init()
{
functions.init(100);
/* Console functions */
functions.set("print", #std_print);
/* String functions */
functions.set("str", #std_str);
/* System functions */
functions.set("exit", #ExitProcess);
/* Math functions */
functions.set("+", #std_add);
functions.set("-", #std_sub);
variables.init(100);
}
dword StdCall(dword count, name, args) dword StdCall(dword count, name, args)
{ {
dword tmp = 0; dword tmp = 0;
if(!strcmp(name, "print")) functions.get(name);
{ IF(EAX)RETURN EAX(count, args);
consoleInit(); RETURN 0;
con_printf stdcall (DSDWORD[args]);
}
else if(!strcmp(name, "input"))
{
}
else if(!strcmp(name, "str"))
{
tmp = malloc(15);
itoa_(tmp,DSDWORD[args]);
return tmp;
}
else if(!strcmp(name, "exit"))
{
ExitProcess();
}
return 0;
} }