2018-12-07 00:09:52 +03:00
|
|
|
|
2018-12-07 14:22:15 +03:00
|
|
|
/* Lisp functions */
|
2018-12-27 14:27:01 +03:00
|
|
|
:dword std_exit()
|
|
|
|
{
|
|
|
|
con_exit stdcall (1);
|
|
|
|
ExitProcess();
|
|
|
|
}
|
|
|
|
|
2018-12-07 00:09:52 +03:00
|
|
|
:dword std_set(dword count, args)
|
|
|
|
{
|
|
|
|
dword name = 0;
|
|
|
|
dword value = 0;
|
2018-12-07 14:22:15 +03:00
|
|
|
WHILE(count > 0)
|
2018-12-07 00:09:52 +03:00
|
|
|
{
|
|
|
|
name = DSDWORD[args];
|
2020-03-22 02:26:21 +03:00
|
|
|
IF (DSDWORD[name+4] == TSym) name = DSDWORD[name];
|
|
|
|
ELSE
|
|
|
|
{
|
|
|
|
con_printf stdcall ("Error variable!");
|
|
|
|
ExitProcess();
|
|
|
|
}
|
2018-12-07 00:09:52 +03:00
|
|
|
args += 4;
|
|
|
|
value = DSDWORD[args];
|
|
|
|
args += 4;
|
|
|
|
variables.set(name, value);
|
2018-12-07 14:22:15 +03:00
|
|
|
count -= 2;
|
2018-12-07 00:09:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
:dword std_get(dword count, args)
|
|
|
|
{
|
2020-03-22 02:26:21 +03:00
|
|
|
dword name = 0;
|
2018-12-07 14:22:15 +03:00
|
|
|
IF(!count) RETURN 0;
|
2020-03-22 02:26:21 +03:00
|
|
|
name = DSDWORD[args];
|
|
|
|
IF (DSDWORD[name+4] != TSym)
|
|
|
|
{
|
|
|
|
con_printf stdcall ("Error variable!");
|
|
|
|
ExitProcess();
|
|
|
|
}
|
|
|
|
RETURN variables.get(DSDWORD[name]);
|
2018-12-07 00:09:52 +03:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:59:06 +03:00
|
|
|
:dword std_str(dword count, args)
|
|
|
|
{
|
|
|
|
dword tmp = 0;
|
2018-12-07 14:22:15 +03:00
|
|
|
IF(!count) RETURN "";
|
2018-12-06 11:59:06 +03:00
|
|
|
tmp = malloc(15);
|
|
|
|
itoa_(tmp,DSDWORD[args]);
|
|
|
|
RETURN tmp;
|
|
|
|
}
|
|
|
|
|
2018-12-07 14:22:15 +03:00
|
|
|
/* Math functions */
|
2018-12-06 11:59:06 +03:00
|
|
|
:dword std_add(dword count, args)
|
|
|
|
{
|
|
|
|
dword ret = 0;
|
|
|
|
WHILE(count)
|
2018-12-05 01:34:36 +03:00
|
|
|
{
|
2018-12-06 11:59:06 +03:00
|
|
|
ret += DSDWORD[args];
|
|
|
|
args+=4;
|
|
|
|
count--;
|
2018-12-05 01:34:36 +03:00
|
|
|
}
|
2018-12-06 11:59:06 +03:00
|
|
|
RETURN ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
:dword std_sub(dword count, args)
|
|
|
|
{
|
|
|
|
dword ret = 0;
|
|
|
|
IF(count)
|
|
|
|
{
|
|
|
|
ret = DSDWORD[args];
|
|
|
|
count--;
|
|
|
|
args+=4;
|
2018-12-05 01:34:36 +03:00
|
|
|
}
|
2018-12-06 11:59:06 +03:00
|
|
|
WHILE(count)
|
2018-12-05 01:34:36 +03:00
|
|
|
{
|
2018-12-06 11:59:06 +03:00
|
|
|
ret -= DSDWORD[args];
|
2018-12-07 14:22:15 +03:00
|
|
|
args += 4;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
RETURN ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Console functions */
|
|
|
|
:dword std_print(dword count, args)
|
|
|
|
{
|
|
|
|
dword ret = 0;
|
2020-03-22 02:26:21 +03:00
|
|
|
dword arg = 0;
|
|
|
|
dword val = 0;
|
2018-12-07 14:40:32 +03:00
|
|
|
consoleInit();
|
2020-03-22 02:26:21 +03:00
|
|
|
IF (!count) con_printf stdcall ("nil");
|
2018-12-07 14:22:15 +03:00
|
|
|
WHILE(count)
|
|
|
|
{
|
2020-03-22 02:26:21 +03:00
|
|
|
arg = DSDWORD[args];
|
|
|
|
REPEAT1:
|
|
|
|
IF (DSDWORD[arg+4] == TInt) val = itoa(DSDWORD[arg]);
|
|
|
|
ELSE IF (DSDWORD[arg+4] == TStr) val = DSDWORD[arg];
|
|
|
|
ELSE IF (DSDWORD[arg+4] == TSym)
|
|
|
|
{
|
|
|
|
arg = std_get(1, args);
|
|
|
|
goto REPEAT1;
|
|
|
|
}
|
|
|
|
IF(!arg) con_printf stdcall ("nil");
|
|
|
|
ELSE con_printf stdcall (val);
|
2018-12-06 11:59:06 +03:00
|
|
|
args+=4;
|
|
|
|
count--;
|
2018-12-05 01:34:36 +03:00
|
|
|
}
|
2018-12-06 11:59:06 +03:00
|
|
|
RETURN ret;
|
|
|
|
}
|
|
|
|
|
2020-03-22 02:26:21 +03:00
|
|
|
:dword std_len(dword count, args)
|
2018-12-07 14:22:15 +03:00
|
|
|
{
|
2020-03-22 02:26:21 +03:00
|
|
|
dword ret = 0;
|
|
|
|
dword arg = 0;
|
|
|
|
dword val = 0;
|
|
|
|
ret = malloc(TLen);
|
|
|
|
DSDWORD[ret] = 0;
|
|
|
|
DSDWORD[ret+4] = TInt;
|
2018-12-07 14:22:15 +03:00
|
|
|
WHILE(count)
|
|
|
|
{
|
2020-03-22 02:26:21 +03:00
|
|
|
arg = DSDWORD[args];
|
|
|
|
REPEAT1:
|
|
|
|
IF (DSDWORD[arg+4] == TStr) val = DSDWORD[arg];
|
|
|
|
ELSE IF (DSDWORD[arg+4] == TSym)
|
|
|
|
{
|
|
|
|
arg = std_get(1, args);
|
|
|
|
goto REPEAT1;
|
|
|
|
}
|
|
|
|
ELSE return ret;
|
|
|
|
DSDWORD[ret] += DSDWORD[arg+8];
|
2018-12-07 14:22:15 +03:00
|
|
|
args+=4;
|
|
|
|
count--;
|
|
|
|
}
|
2020-03-22 02:26:21 +03:00
|
|
|
RETURN ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
:dword std_cmp(dword count, args)
|
|
|
|
{
|
|
|
|
dword ret = 0;
|
|
|
|
dword arg = 0;
|
|
|
|
dword val = 0;
|
|
|
|
dword tmp = 0;
|
|
|
|
dword x = 0;
|
|
|
|
dword y = 0;
|
|
|
|
byte start = 0;
|
|
|
|
ret = malloc(TLen);
|
|
|
|
DSDWORD[ret] = 0;
|
|
|
|
DSDWORD[ret+4] = TInt;
|
|
|
|
IF (!count) return ret;
|
|
|
|
while(count)
|
|
|
|
{
|
|
|
|
arg = DSDWORD[args];
|
|
|
|
REPEAT2:
|
|
|
|
IF (DSDWORD[arg+4] == TSym)
|
|
|
|
{
|
|
|
|
arg = std_get(1, args);
|
|
|
|
goto REPEAT2;
|
|
|
|
}
|
|
|
|
IF (!start)
|
|
|
|
{
|
|
|
|
start = 1;
|
|
|
|
tmp = arg;
|
|
|
|
args+=4;
|
|
|
|
count--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
IF (DSDWORD[tmp+4] != DSDWORD[arg+4]) return ret;
|
|
|
|
IF (DSDWORD[tmp+4] == TInt)
|
|
|
|
{
|
|
|
|
IF (DSDWORD[tmp] != DSDWORD[arg]) return ret;
|
|
|
|
}
|
|
|
|
ELSE IF (DSDWORD[tmp+4] == TStr)
|
|
|
|
{
|
|
|
|
/*IF (!DSDWORD[tmp+8]) DSDWORD[tmp+8] = crc32(DSDWORD[tmp]);
|
|
|
|
IF (!DSDWORD[arg+8]) DSDWORD[arg+8] = crc32(DSDWORD[arg]);
|
|
|
|
IF (DSDWORD[tmp+8] != DSDWORD[arg+8]) return ret;*/
|
|
|
|
IF (strcmp(DSDWORD[tmp], DSDWORD[arg])) return ret;
|
|
|
|
}
|
|
|
|
args+=4;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
DSDWORD[ret] = 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
:dword std_input(dword count, args)
|
|
|
|
{
|
|
|
|
dword buf = 0;
|
|
|
|
consoleInit();
|
|
|
|
buf = malloc(100);
|
|
|
|
IF (count) std_print(count, args);
|
2018-12-07 14:22:15 +03:00
|
|
|
con_gets stdcall(buf, 100);
|
2020-03-22 02:26:21 +03:00
|
|
|
EDX = malloc(TLen);
|
|
|
|
DSDWORD[EDX] = buf;
|
|
|
|
DSDWORD[EDX+4] = TStr;
|
|
|
|
RETURN EDX;
|
2018-12-07 14:22:15 +03:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:59:06 +03:00
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
functions.init(100);
|
|
|
|
|
|
|
|
/* Console functions */
|
2018-12-07 14:22:15 +03:00
|
|
|
functions.set("print", #std_print);
|
|
|
|
functions.set("input", #std_input);
|
2018-12-06 11:59:06 +03:00
|
|
|
|
|
|
|
/* String functions */
|
|
|
|
functions.set("str", #std_str);
|
2020-03-22 02:26:21 +03:00
|
|
|
functions.set("len", #std_len);
|
2018-12-06 11:59:06 +03:00
|
|
|
|
|
|
|
/* System functions */
|
2018-12-27 14:27:01 +03:00
|
|
|
functions.set("exit", #std_exit);
|
2018-12-06 11:59:06 +03:00
|
|
|
|
|
|
|
/* Math functions */
|
|
|
|
functions.set("+", #std_add);
|
|
|
|
functions.set("-", #std_sub);
|
2020-03-22 02:26:21 +03:00
|
|
|
functions.set("==", #std_cmp);
|
2018-12-06 11:59:06 +03:00
|
|
|
|
2018-12-07 00:09:52 +03:00
|
|
|
/* Lisp functions */
|
|
|
|
functions.set("set", #std_set);
|
|
|
|
functions.set("get", #std_get);
|
|
|
|
|
2018-12-06 11:59:06 +03:00
|
|
|
variables.init(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
dword StdCall(dword count, name, args)
|
|
|
|
{
|
|
|
|
functions.get(name);
|
2018-12-07 00:09:52 +03:00
|
|
|
IF(EAX) RETURN EAX(count, args);
|
2018-12-06 11:59:06 +03:00
|
|
|
RETURN 0;
|
2018-12-07 00:09:52 +03:00
|
|
|
}
|
|
|
|
|