2018-12-04 23:34:36 +01:00
|
|
|
/*
|
|
|
|
* Author Pavel Iakovlev
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MEMSIZE 4096*10
|
|
|
|
|
|
|
|
#include "../lib/io.h"
|
|
|
|
#include "../lib/obj/console.h"
|
2018-12-06 09:59:06 +01:00
|
|
|
#include "../lib/array.h"
|
2018-12-04 23:34:36 +01:00
|
|
|
|
|
|
|
byte initConsole = 0;
|
2018-12-06 09:59:06 +01:00
|
|
|
Dictionary functions = {0};
|
|
|
|
Dictionary variables = {0};
|
2018-12-04 23:34:36 +01:00
|
|
|
|
|
|
|
#include "stdcall.h"
|
|
|
|
|
|
|
|
#define bufferSize 10000;
|
|
|
|
#define memoryBrainfuck 30000*4
|
|
|
|
#define memoryByteBF 1
|
|
|
|
#define stackBrainFuck 4*1024
|
|
|
|
|
2020-03-22 00:26:21 +01:00
|
|
|
#define TStr 1
|
|
|
|
#define TInt 2
|
|
|
|
#define TSym 3
|
|
|
|
#define TBol 4
|
|
|
|
|
|
|
|
#define TLen 4*5
|
|
|
|
|
2018-12-04 23:34:36 +01:00
|
|
|
dword buffer = 0;
|
|
|
|
word bufferSymbol = 0;
|
|
|
|
dword memory = 0;
|
|
|
|
|
|
|
|
dword stack = 0;
|
|
|
|
dword code = 0;
|
|
|
|
byte tempBuffer[100] = {0};
|
|
|
|
|
|
|
|
void consoleInit()
|
|
|
|
{
|
|
|
|
IF(!initConsole)
|
|
|
|
{
|
|
|
|
load_dll(libConsole, #con_init, 0);
|
|
|
|
con_init stdcall (-1, -1, -1, -1, "Lisp interpreter");
|
|
|
|
initConsole = 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dword evalLisp()
|
|
|
|
{
|
|
|
|
byte s = 0;
|
|
|
|
byte args = 0;
|
|
|
|
dword pos = 0;
|
|
|
|
dword name = 0;
|
|
|
|
dword tmp = 0;
|
2020-03-22 00:26:21 +01:00
|
|
|
dword tmp2 = 0;
|
2018-12-04 23:34:36 +01:00
|
|
|
dword dataArgs = 0;
|
|
|
|
dword posArgs = 0;
|
|
|
|
dword ret = 0;
|
2018-12-06 22:09:52 +01:00
|
|
|
dword p = 0;
|
2020-03-22 00:26:21 +01:00
|
|
|
dword i = 0;
|
|
|
|
dword ii = 0;
|
2018-12-04 23:34:36 +01:00
|
|
|
dataArgs = malloc(16*4);
|
|
|
|
posArgs = dataArgs;
|
2018-12-07 12:22:15 +01:00
|
|
|
|
2018-12-04 23:34:36 +01:00
|
|
|
loop()
|
|
|
|
{
|
|
|
|
s = DSBYTE[code];
|
2020-03-22 00:26:21 +01:00
|
|
|
while (s == ' ') || (s == 9) || (s == 10) || (s == 13)
|
2018-12-04 23:34:36 +01:00
|
|
|
{
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
|
|
|
}
|
2018-12-07 12:22:15 +01:00
|
|
|
if (!s) return 0;
|
|
|
|
if (s==')')
|
2018-12-04 23:34:36 +01:00
|
|
|
{
|
|
|
|
code++;
|
2018-12-07 12:22:15 +01:00
|
|
|
args--;
|
|
|
|
ret = StdCall(args, name, dataArgs);
|
|
|
|
free(name);
|
|
|
|
//free(dataArgs);
|
|
|
|
return ret;
|
2018-12-04 23:34:36 +01:00
|
|
|
}
|
2018-12-07 12:22:15 +01:00
|
|
|
if(s == '(')
|
|
|
|
{
|
|
|
|
code++;
|
|
|
|
DSDWORD[posArgs] = evalLisp();
|
|
|
|
args++;
|
|
|
|
posArgs += 4;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (!args)
|
2018-12-04 23:34:36 +01:00
|
|
|
{
|
2018-12-06 22:09:52 +01:00
|
|
|
if (s != ')') // name function
|
2018-12-04 23:34:36 +01:00
|
|
|
{
|
2018-12-07 12:22:15 +01:00
|
|
|
name = malloc(100);
|
|
|
|
pos = name;
|
|
|
|
while (s) && (s != ' ') && (s != ')')
|
2018-12-04 23:34:36 +01:00
|
|
|
{
|
|
|
|
DSBYTE[pos] = s;
|
2018-12-06 22:09:52 +01:00
|
|
|
pos++;
|
2018-12-04 23:34:36 +01:00
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
2018-12-07 12:22:15 +01:00
|
|
|
}
|
|
|
|
DSBYTE[pos] = 0;
|
|
|
|
args++;
|
|
|
|
continue;
|
2018-12-04 23:34:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-07 12:22:15 +01:00
|
|
|
if (s >= '0') && (s <= '9')
|
2018-12-04 23:34:36 +01:00
|
|
|
{
|
|
|
|
tmp = 0;
|
|
|
|
while (s >= '0') && (s <= '9')
|
|
|
|
{
|
|
|
|
tmp *= 10;
|
|
|
|
tmp += s-'0';
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
|
|
|
}
|
2018-12-07 12:22:15 +01:00
|
|
|
args++;
|
2020-03-22 00:26:21 +01:00
|
|
|
EDX = malloc(TLen);
|
|
|
|
DSDWORD[EDX] = tmp;
|
|
|
|
DSDWORD[EDX+4] = TInt;
|
|
|
|
DSDWORD[posArgs] = EDX;
|
2018-12-07 12:22:15 +01:00
|
|
|
posArgs += 4;
|
|
|
|
continue;
|
2018-12-04 23:34:36 +01:00
|
|
|
}
|
2018-12-06 22:09:52 +01:00
|
|
|
else if (s == '"')
|
|
|
|
{
|
2020-03-22 00:26:21 +01:00
|
|
|
i = 1;
|
|
|
|
tmp = malloc(1<<i);
|
2018-12-06 22:09:52 +01:00
|
|
|
p = tmp;
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
2020-03-22 00:26:21 +01:00
|
|
|
ii = 0;
|
2018-12-06 22:09:52 +01:00
|
|
|
while (s != '"') && (s)
|
|
|
|
{
|
2020-03-22 00:26:21 +01:00
|
|
|
ii++;
|
|
|
|
if (1<<i < ii)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
tmp2 = p-tmp;
|
|
|
|
tmp = realloc(tmp, 1<<i);
|
|
|
|
p = tmp+tmp2;
|
|
|
|
}
|
2018-12-06 22:09:52 +01:00
|
|
|
DSBYTE[p] = s;
|
|
|
|
p++;
|
|
|
|
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
|
|
|
}
|
|
|
|
DSBYTE[p] = 0;
|
2020-03-22 00:26:21 +01:00
|
|
|
EDX = malloc(TLen);
|
|
|
|
DSDWORD[EDX] = tmp;
|
|
|
|
DSDWORD[EDX+4] = TStr;
|
|
|
|
DSDWORD[EDX+8] = p-tmp;
|
|
|
|
DSDWORD[posArgs] = EDX;
|
|
|
|
posArgs += 4;
|
|
|
|
code++;
|
|
|
|
args++;
|
|
|
|
continue;
|
2018-12-06 22:09:52 +01:00
|
|
|
}
|
2020-03-22 00:26:21 +01:00
|
|
|
else
|
2018-12-06 22:09:52 +01:00
|
|
|
{
|
2020-03-22 00:26:21 +01:00
|
|
|
tmp = malloc(20);
|
2018-12-06 22:09:52 +01:00
|
|
|
p = tmp;
|
2020-03-22 00:26:21 +01:00
|
|
|
while (s) && (s != ')') && (s != '(') && (s != ' ') && (s != 10) && (s != 13)
|
2018-12-06 22:09:52 +01:00
|
|
|
{
|
|
|
|
DSBYTE[p] = s;
|
|
|
|
p++;
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
|
|
|
}
|
|
|
|
DSBYTE[p] = 0;
|
2018-12-07 12:22:15 +01:00
|
|
|
args++;
|
2020-03-22 00:26:21 +01:00
|
|
|
EDX = malloc(TLen);
|
|
|
|
DSDWORD[EDX] = tmp;
|
|
|
|
DSDWORD[EDX+4] = TSym;
|
|
|
|
DSDWORD[posArgs] = EDX;
|
2018-12-07 12:22:15 +01:00
|
|
|
posArgs += 4;
|
|
|
|
continue;
|
2018-12-06 22:09:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DSDWORD[posArgs] = tmp;
|
|
|
|
posArgs += 4;
|
2018-12-04 23:34:36 +01:00
|
|
|
}
|
|
|
|
code++;
|
|
|
|
args++;
|
|
|
|
}
|
2018-12-06 09:59:06 +01:00
|
|
|
args--;
|
2018-12-04 23:34:36 +01:00
|
|
|
ret = StdCall(args, name, dataArgs);
|
|
|
|
free(name);
|
2018-12-07 12:22:15 +01:00
|
|
|
//free(dataArgs);
|
2018-12-04 23:34:36 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
dword brainFuckCode = 0;
|
|
|
|
word maxLoop = 1000;
|
2018-12-07 12:40:32 +01:00
|
|
|
dword txt = "(set name (input \"Enter you name: \"))(print \"You name \" (get name))";
|
2018-12-04 23:34:36 +01:00
|
|
|
|
|
|
|
buffer = malloc(bufferSize);
|
|
|
|
memory = malloc(memoryBrainfuck);
|
|
|
|
stack = malloc(stackBrainFuck);
|
|
|
|
|
2018-12-06 09:59:06 +01:00
|
|
|
Init();
|
|
|
|
|
2018-12-04 23:34:36 +01:00
|
|
|
IF(DSBYTE[I_Param])
|
|
|
|
{
|
|
|
|
IF(io.read(I_Param))
|
|
|
|
{
|
|
|
|
code = EAX;
|
2018-12-07 12:40:32 +01:00
|
|
|
evalLisp();
|
2018-12-04 23:34:36 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-06 09:59:06 +01:00
|
|
|
else
|
2018-12-04 23:34:36 +01:00
|
|
|
{
|
|
|
|
consoleInit();
|
2020-03-22 00:26:21 +01:00
|
|
|
con_printf stdcall ("Lisp interpreter v1.5\r\n");
|
2018-12-06 22:09:52 +01:00
|
|
|
while(maxLoop)
|
2018-12-04 23:34:36 +01:00
|
|
|
{
|
2018-12-27 12:27:01 +01:00
|
|
|
con_printf stdcall ("\r\n$ ");
|
2018-12-04 23:34:36 +01:00
|
|
|
con_gets stdcall(buffer, bufferSize);
|
|
|
|
code = EAX;
|
2018-12-27 12:27:01 +01:00
|
|
|
//code = txt;
|
2018-12-04 23:34:36 +01:00
|
|
|
con_printf stdcall ("Output: ");
|
|
|
|
evalLisp();
|
|
|
|
maxLoop--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 12:50:49 +01:00
|
|
|
IF(initConsole) con_exit stdcall (1);
|
2018-12-04 23:34:36 +01:00
|
|
|
ExitProcess();
|
|
|
|
}
|
|
|
|
|