Lisp v1.3 stable version

git-svn-id: svn://kolibrios.org@7565 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pavelyakov 2018-12-07 11:22:15 +00:00
parent 1ffceb0340
commit 5cafe795a0
2 changed files with 71 additions and 59 deletions

View File

@ -50,8 +50,7 @@ dword evalLisp()
dword p = 0;
dataArgs = malloc(16*4);
posArgs = dataArgs;
name = malloc(100);
pos = name;
loop()
{
s = DSBYTE[code];
@ -61,35 +60,45 @@ dword evalLisp()
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++;
code++;
s = DSBYTE[code];
}
code--;
}
DSBYTE[pos] = 0;
args++;
continue;
}
}
else
{
if(s == '(')
{
code++;
tmp = evalLisp();
}
else if (s >= '0') && (s <= '9')
if (s >= '0') && (s <= '9')
{
tmp = 0;
while (s >= '0') && (s <= '9')
@ -99,7 +108,10 @@ dword evalLisp()
code++;
s = DSBYTE[code];
}
code--;
args++;
DSDWORD[posArgs] = tmp;
posArgs += 4;
continue;
}
else if (s == '"')
{
@ -130,6 +142,10 @@ dword evalLisp()
s = DSBYTE[code];
}
DSBYTE[p] = 0;
args++;
DSDWORD[posArgs] = tmp;
posArgs += 4;
continue;
}
DSDWORD[posArgs] = tmp;
@ -141,7 +157,7 @@ dword evalLisp()
args--;
ret = StdCall(args, name, dataArgs);
free(name);
free(dataArgs);
//free(dataArgs);
return ret;
}
@ -149,7 +165,7 @@ void main()
{
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 @@ void main()
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 @@ void main()
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--;
}
}

View File

@ -1,45 +1,36 @@
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;
dword value = 0;
WHILE(count>0)
WHILE(count > 0)
{
name = DSDWORD[args];
args += 4;
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]);
}
: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;
@ -64,18 +55,46 @@ dword std_print(dword count, args)
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--;
}
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 @@ void Init()
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;
}