2018-12-05 01:34:36 +03:00
|
|
|
/*
|
|
|
|
* Author Pavel Iakovlev
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MEMSIZE 4096*10
|
|
|
|
|
|
|
|
#include "../lib/io.h"
|
|
|
|
#include "../lib/obj/console.h"
|
2018-12-06 11:59:06 +03:00
|
|
|
#include "../lib/array.h"
|
2018-12-05 01:34:36 +03:00
|
|
|
|
|
|
|
byte initConsole = 0;
|
2018-12-06 11:59:06 +03:00
|
|
|
Dictionary functions = {0};
|
|
|
|
Dictionary variables = {0};
|
2018-12-05 01:34:36 +03:00
|
|
|
|
|
|
|
#include "stdcall.h"
|
|
|
|
|
|
|
|
#define bufferSize 10000;
|
|
|
|
#define memoryBrainfuck 30000*4
|
|
|
|
#define memoryByteBF 1
|
|
|
|
#define stackBrainFuck 4*1024
|
|
|
|
|
|
|
|
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;
|
|
|
|
dword dataArgs = 0;
|
|
|
|
dword posArgs = 0;
|
|
|
|
dword ret = 0;
|
2018-12-07 00:09:52 +03:00
|
|
|
dword p = 0;
|
2018-12-05 01:34:36 +03:00
|
|
|
dataArgs = malloc(16*4);
|
|
|
|
posArgs = dataArgs;
|
2018-12-07 14:22:15 +03:00
|
|
|
|
2018-12-05 01:34:36 +03:00
|
|
|
loop()
|
|
|
|
{
|
|
|
|
s = DSBYTE[code];
|
2018-12-07 00:09:52 +03:00
|
|
|
|
2018-12-05 01:34:36 +03:00
|
|
|
while(s == ' ')
|
|
|
|
{
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
|
|
|
}
|
2018-12-07 14:22:15 +03:00
|
|
|
if (!s) return 0;
|
|
|
|
if (s==')')
|
2018-12-05 01:34:36 +03:00
|
|
|
{
|
|
|
|
code++;
|
2018-12-07 14:22:15 +03:00
|
|
|
args--;
|
|
|
|
ret = StdCall(args, name, dataArgs);
|
|
|
|
free(name);
|
|
|
|
//free(dataArgs);
|
|
|
|
return ret;
|
2018-12-05 01:34:36 +03:00
|
|
|
}
|
2018-12-07 14:22:15 +03:00
|
|
|
if(s == '(')
|
|
|
|
{
|
|
|
|
code++;
|
|
|
|
DSDWORD[posArgs] = evalLisp();
|
|
|
|
args++;
|
|
|
|
posArgs += 4;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (!args)
|
2018-12-05 01:34:36 +03:00
|
|
|
{
|
2018-12-07 00:09:52 +03:00
|
|
|
if (s != ')') // name function
|
2018-12-05 01:34:36 +03:00
|
|
|
{
|
2018-12-07 14:22:15 +03:00
|
|
|
name = malloc(100);
|
|
|
|
pos = name;
|
|
|
|
while (s) && (s != ' ') && (s != ')')
|
2018-12-05 01:34:36 +03:00
|
|
|
{
|
|
|
|
DSBYTE[pos] = s;
|
2018-12-07 00:09:52 +03:00
|
|
|
pos++;
|
2018-12-05 01:34:36 +03:00
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
2018-12-07 14:22:15 +03:00
|
|
|
}
|
|
|
|
DSBYTE[pos] = 0;
|
|
|
|
args++;
|
|
|
|
continue;
|
2018-12-05 01:34:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-07 14:22:15 +03:00
|
|
|
if (s >= '0') && (s <= '9')
|
2018-12-05 01:34:36 +03:00
|
|
|
{
|
|
|
|
tmp = 0;
|
|
|
|
while (s >= '0') && (s <= '9')
|
|
|
|
{
|
|
|
|
tmp *= 10;
|
|
|
|
tmp += s-'0';
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
|
|
|
}
|
2018-12-07 14:22:15 +03:00
|
|
|
args++;
|
|
|
|
DSDWORD[posArgs] = tmp;
|
|
|
|
posArgs += 4;
|
|
|
|
continue;
|
2018-12-05 01:34:36 +03:00
|
|
|
}
|
2018-12-07 00:09:52 +03:00
|
|
|
else if (s == '"')
|
|
|
|
{
|
|
|
|
tmp = malloc(100);
|
|
|
|
p = tmp;
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
|
|
|
while (s != '"') && (s)
|
|
|
|
{
|
|
|
|
DSBYTE[p] = s;
|
|
|
|
p++;
|
|
|
|
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
|
|
|
}
|
|
|
|
DSBYTE[p] = 0;
|
|
|
|
}
|
|
|
|
else if(s >= 'A') && (s <= 'z')
|
|
|
|
{
|
|
|
|
tmp = malloc(100);
|
|
|
|
p = tmp;
|
|
|
|
while (s >= 'A') && (s <= 'z')
|
|
|
|
{
|
|
|
|
DSBYTE[p] = s;
|
|
|
|
p++;
|
|
|
|
|
|
|
|
code++;
|
|
|
|
s = DSBYTE[code];
|
|
|
|
}
|
|
|
|
DSBYTE[p] = 0;
|
2018-12-07 14:22:15 +03:00
|
|
|
args++;
|
|
|
|
DSDWORD[posArgs] = tmp;
|
|
|
|
posArgs += 4;
|
|
|
|
continue;
|
2018-12-07 00:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DSDWORD[posArgs] = tmp;
|
|
|
|
posArgs += 4;
|
2018-12-05 01:34:36 +03:00
|
|
|
}
|
|
|
|
code++;
|
|
|
|
args++;
|
|
|
|
}
|
2018-12-06 11:59:06 +03:00
|
|
|
args--;
|
2018-12-05 01:34:36 +03:00
|
|
|
ret = StdCall(args, name, dataArgs);
|
|
|
|
free(name);
|
2018-12-07 14:22:15 +03:00
|
|
|
//free(dataArgs);
|
2018-12-05 01:34:36 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
dword brainFuckCode = 0;
|
|
|
|
word maxLoop = 1000;
|
2018-12-07 14:40:32 +03:00
|
|
|
dword txt = "(set name (input \"Enter you name: \"))(print \"You name \" (get name))";
|
2018-12-05 01:34:36 +03:00
|
|
|
|
|
|
|
buffer = malloc(bufferSize);
|
|
|
|
memory = malloc(memoryBrainfuck);
|
|
|
|
stack = malloc(stackBrainFuck);
|
|
|
|
|
2018-12-06 11:59:06 +03:00
|
|
|
Init();
|
|
|
|
|
2018-12-05 01:34:36 +03:00
|
|
|
IF(DSBYTE[I_Param])
|
|
|
|
{
|
|
|
|
IF(io.read(I_Param))
|
|
|
|
{
|
|
|
|
code = EAX;
|
2018-12-07 14:40:32 +03:00
|
|
|
evalLisp();
|
2018-12-05 01:34:36 +03:00
|
|
|
}
|
|
|
|
}
|
2018-12-06 11:59:06 +03:00
|
|
|
else
|
2018-12-05 01:34:36 +03:00
|
|
|
{
|
|
|
|
consoleInit();
|
2018-12-07 14:22:15 +03:00
|
|
|
con_printf stdcall ("Lisp interpreter v1.3");
|
2018-12-07 00:09:52 +03:00
|
|
|
while(maxLoop)
|
2018-12-05 01:34:36 +03:00
|
|
|
{
|
|
|
|
con_printf stdcall ("\r\n\r\nEnter code: ");
|
|
|
|
con_gets stdcall(buffer, bufferSize);
|
|
|
|
code = EAX;
|
2018-12-07 14:40:32 +03:00
|
|
|
code = txt;
|
2018-12-05 01:34:36 +03:00
|
|
|
con_printf stdcall ("Output: ");
|
|
|
|
evalLisp();
|
|
|
|
maxLoop--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IF(initConsole) con_exit stdcall (0);
|
|
|
|
ExitProcess();
|
|
|
|
}
|
|
|
|
|