git-svn-id: svn://kolibrios.org@7309 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pavelyakov 2018-08-07 08:25:02 +00:00
parent 5ac7a40ca7
commit eb70351e10
7 changed files with 1773 additions and 0 deletions

View File

@ -0,0 +1,266 @@
:dword arrayInit(dword len)
{
dword alloc = 0;
dword position = 0;
alloc = malloc(len*4+MEMBUF);
position = alloc;
DSDWORD[position] = 0;
position+=4;
DSDWORD[position] = len;
return alloc;
}
:dword ReallocArray(dword array,nMem)
{
dword NEW = 0;
dword OLD = 0;
dword FLEN = 0;
dword LEN = 0;
//test2("relloc",0);
OLD = array;
FLEN = nMem*4+8;
LEN = DSDWORD[array];
NEW = arrayInit(nMem);
array+=8;
while(LEN)
{
A = DSDWORD[array];
IF(A)
{
arraySet(#NEW,DSDWORD[A],DSDWORD[A+4]);
free(A);
}
LEN--;
array+=4;
}
free(OLD);
return NEW;
}
:byte arraySet(dword array,key,value)
{
dword NEW = 0;
dword LEN = 0;
dword FLEN = 0;
dword POSITION = 0;
dword VKEY = 0;
dword FULL = 0;
dword OST = 0;
dword BEGIN = 0;
dword gArray = 0;
gArray = DSDWORD[array];
IF(gArray)
{
LEN = DSDWORD[gArray];
OST = DSDWORD[gArray+4];
}
ELSE
{
LEN = 0;
OST = 8;
}
IF(LEN)
{
IF(!(LEN%OST))
{
gArray = ReallocArray(gArray,OST<<1);
DSDWORD[array] = gArray;
}
}
ELSE
{
gArray = arrayInit(OST);
DSDWORD[array] = gArray;
}
BEGIN = gArray;
gArray+=4;
FLEN = DSDWORD[gArray];
gArray+=4;
POSITION = key%FLEN*4+gArray;
FULL = FLEN*4+gArray;
LOOP_COL2:
VKEY = DSDWORD[POSITION];
IF(!VKEY)
{
NEW = malloc(8);
DSDWORD[NEW] = key;
DSDWORD[NEW+4] = value;
DSDWORD[POSITION] = NEW;
DSDWORD[BEGIN] = DSDWORD[BEGIN]+1;
return 1;
}
IF(DSDWORD[VKEY] == key)
{
DSDWORD[VKEY+4] = value;
return 2;
}
// collision
POSITION+=4;
IF(POSITION>FULL) POSITION = gArray+8;
goto LOOP_COL2;
return 3;
}
:dword arrayGet(dword array,key)
{
dword NEW = 0;
dword LEN = 0;
dword MEMLEN = 0;
dword POSITION = 0;
dword VKEY = 0;
dword FULL = 0;
LEN = DSDWORD[array];
array+=4;
MEMLEN = DSDWORD[array];
array+=4;
POSITION = key%MEMLEN*4+array;
FULL = LEN*4+array;
Z = 2;
LOOP_COL1:
VKEY = DSDWORD[POSITION];
IF(!VKEY) return 0;
IF(DSDWORD[VKEY] == key) return DSDWORD[VKEY+4];
// collision
POSITION+=4;
IF(POSITION>FULL)
{
POSITION = array+8;
Z--;
IF(!Z) return 0;
}
goto LOOP_COL1;
}
:dword arrayDelete(dword array,key)
{
dword NEW = 0;
dword LEN = 0;
dword MEMLEN = 0;
dword POSITION = 0;
dword VKEY = 0;
dword FULL = 0;
dword TMP = 0;
LEN = DSDWORD[array];
array+=4;
MEMLEN = DSDWORD[array];
array+=4;
POSITION = key%MEMLEN*4+array;
FULL = LEN*4+array;
Z = 2;
LOOP_COL1:
VKEY = DSDWORD[POSITION];
IF(!VKEY) return 0;
IF(DSDWORD[VKEY] == key)
{
TMP = DSDWORD[VKEY+4];
free(VKEY);
DSDWORD[POSITION] = 0;
DSDWORD[array] = DSDWORD[array]-1;
return TMP;
}
// collision
POSITION+=4;
IF(POSITION>FULL)
{
POSITION = array+8;
Z--;
IF(!Z) return 0;
}
goto LOOP_COL1;
}
// dict
:dword hash(dword str)
{
byte S = 0;
dword s1 = 0;
dword s2 = 0;
S = DSBYTE[str];
WHILE(S)
{
s1 += S;
s2 += s1;
S = DSBYTE[str];
str++;
}
s1<<=16;
RETURN s1|s2;
}
:byte dictSet(dword array,key,data)
{
RETURN arraySet(array,hash(key),data);
}
:byte dictDel(dword array,key)
{
RETURN arrayDelete(array,hash(key));
}
:dword dictGet(dword array,key)
{
RETURN arrayGet(array,hash(key));
}
// list
:void listAppend(dword position,data) // TODO Fixed!!
{
dword len = 0;
dword flen = 0;
dword news = 0;
dword array = 0;
dword i = 0;
array = DSDWORD[position];
len = DSDWORD[array];
flen = DSDWORD[array+4];
IF(len>=flen)
{
news = malloc(flen<<3+8);
DSDWORD[position] = news;
i = flen<<1+2;
while(i)
{
DSDWORD[news] = DSDWORD[array];
news+=4;
array+=4;
i--;
}
array = news;
}
DSDWORD[len*4+array+8] = data;
DSDWORD[array] = DSDWORD[array]+1;
}
:dword listGet(dword array,key)
{
return DSDWORD[key*4+array+8];
}

View File

@ -0,0 +1,114 @@
:void copyVariable(dword x)
{
load_const(DSDWORD[x],DSBYTE[x+4],DSDWORD[x+5]);
}
:dword LenStdout = 0;
:void _stdout(dword txt)
{
dword addr = txt;
WHILE(DSBYTE[addr]) addr++;
IF(!LenStdout)
{
LenStdout = addr-txt;
CreateFile(LenStdout,txt,"/sys/stdout");
}
ELSE
{
AddFile(LenStdout,addr-txt,txt,"/sys/stdout");
LenStdout+=addr-txt;
}
}
:dword std__stdStr(dword count)
{
return _str(popFast());
}
:dword stdcall std__stdout(dword count)
{
std__str(count);
popStack();
_stdout(DSDWORD[EAX]);
}
:dword stdcall std__len(dword c)
{
popFast();
load_const(DSDWORD[EAX+5],PY_INT,0);
RETURN 0;
}
:dword stdcall std__INT40(dword c)
{
X = popFast();
Y = DSDWORD[X+5];
X = DSDWORD[X];
X = DSDWORD[X];
X = DSDWORD[X];
test(X,1);
RETURN 0;
}
:void hexAddress(dword x,y)
{
dword i = 0;
i = 8;
WHILE(i)
{
DSBYTE[x] = DSBYTE[y&0xF+#arraySymbolHEX];
y>>=4;
x--;
i--;
}
}
#define rSize DSBYTE[#RDATA+5]
#define rData DSBYTE[#RDATA]
#define rType DSBYTE[#RDATA+4]
:dword stdcall std__str(dword c)
{
dword n = 0;
dword m = 0;
dword l = 0;
dword v = 0;
dword f = "<function a at 0x00000000>";
dword t = 0;
dword o = 0;
v = popFast();
IF(DSBYTE[v+4] == PY_STR)
{
copyVariable(v);
return 0;
}
switch(DSBYTE[v+4])
{
case PY_BOOL:
if(DSDWORD[v])
{
load_const("True",PY_STR,4);
return 0;
}
load_const("False",PY_STR,5);
return 0;
break;
case PY_INT:
m = malloc(MEMBUF);
l = itoa(DSDWORD[v],m);
load_const(m,PY_STR,l);
return 0;
break;
case PY_NONE:
load_const("None",PY_STR,4);
return 0;
break;
case PY_FNC:
hexAddress(f+24,v);
load_const(f,PY_STR,26);
return 0;
break;
}
}

View File

View File

@ -0,0 +1,100 @@
#pragma option OST
#pragma option ON
#pragma option cri-
#pragma option -CPA
#initallvar 0
#jumptomain FALSE
#startaddress 65536
#code32 TRUE
#define PY_NONE 0
#define PY_BOOL 1
#define PY_INT 2
#define PY_FLT 3
#define PY_STR 4
#define PY_FNC 6
#define PY_CPL 7
#define PY_LST 8
#define PY_TPL 9
#define PY_RNG 10
#define PY_BTS 11
#define PY_BTA 12
#define PY_MVW 13
#define PY_SET 14
#define PY_FST 15
#define PY_DCT 16
#define PY_CLS 17
#define PY_MDL 18
#define PY_STD_FNC 30
#define PY_NA_STR 32
#define PY_SYM_STR 33
#define PY_ADD 0
#define PY_POW 1
#define PY_MUL 2
#define PY_SUB 3
#define PY_DIV 4
#define PY_MOD 5
#define PY_XOR 6
#define PY_AND 7
#define PY__OR 8
#define PY_LSH 9
#define PY_RSH 10
#define PY_FDV 11
#define PY_TDV 12
#define MEMBUF 0xF
#define MEMARR 0xF
char os_name[8] = {'M','E','N','U','E','T','0','1'};
dword os_version = 0x00000001;
dword start_addr = #______INIT______;
dword final_addr = #______STOP______+32;
dword alloc_mem = 160000;
dword x86esp_reg = 160000;
dword I_Param = #param;
dword I_Path = #program_path;
char param[4096]={0};
char program_path[4096]={0};
:dword arraySymbolHEX = "0123456789ABCDEF";
:dword libPath = "/sys/lib/";
:dword HASH = 0;
:dword TEMP = 0;
:dword RDATA[30] = {0};
// global variable
:dword X = 0;
:dword Y = 0;
:dword Z = 0;
:dword A = 0;
:dword B = 0;
:dword C = 0;
:dword D = 0;
:dword E = 0;
:dword F = 0;
:dword beginStack = 0;
:dword COUNT_CONST = 0;
:byte std__STRING = 0;
:byte std__INTEGER = 1;
:byte S = 0;
//--------------
:struct f70{
dword func;
dword param1;
dword param2;
dword param3;
dword param4;
char rezerv;
dword name;
};

View File

@ -0,0 +1,375 @@
:void ExitProcess()
{
EAX = -1;
$int 0x40
}
:f70 write_file_70;
:int CreateFile(dword data_size, buffer, file_path)
{
write_file_70.func = 2;
write_file_70.param1 = 0;
write_file_70.param2 = 0;
write_file_70.param3 = data_size;
write_file_70.param4 = buffer;
write_file_70.rezerv = 0;
write_file_70.name = file_path;
$mov eax,70
$mov ebx,#write_file_70.func
$int 0x40
}
:int AddFile(dword begin,data_size, buffer, file_path)
{
write_file_70.func = 3;
write_file_70.param1 = begin;
write_file_70.param2 = 0;
write_file_70.param3 = data_size;
write_file_70.param4 = buffer;
write_file_70.rezerv = 0;
write_file_70.name = file_path;
$mov eax,70
$mov ebx,#write_file_70.func
$int 0x40
}
dword malloc(dword size)
{
$push ebx
$push ecx
$mov eax, 68
$mov ebx, 12
$mov ecx, size
$int 0x40
$pop ecx
$pop ebx
return EAX;
}
dword free(dword mptr)
{
$push ebx
$push ecx
$mov eax, 68
$mov ebx, 13
$mov ecx, mptr
$test ecx, ecx
$jz end0
$int 0x40
@end0:
$pop ecx
$pop ebx
return 0;
}
stdcall dword realloc(dword mptr, size)
{
$push ebx
$push ecx
$push edx
$mov eax, 68
$mov ebx, 20
$mov ecx, size
$mov edx, mptr
$int 0x40
$pop edx
$pop ecx
$pop ebx
return EAX;
}
:void memcpy(dword x,y,size)
{
dword ost = 0;
dword del = 0;
del = size/4;
ost = size%4;
WHILE(del)
{
DSDWORD[x] = DSDWORD[y];
del--;
x+=4;
y+=4;
}
IF(ost>1)
{
DSWORD[x] = DSWORD[y];
x+=2;
y+=2;
ost-=2;
}
IF(ost==1) DSBYTE[x] = DSBYTE[y];
}
:dword sleep(dword x)
{
EAX = 5;
EBX = x;
$int 0x40
}
:dword memInit()
{
$push ebx
$mov eax, 68
$mov ebx, 11
$int 0x40
$pop ebx
return EAX;
}
:dword itoa(signed long number,dword p)
{
dword ret=0;
byte cmd=0;
long mask=0;
long tmp=0;
IF(!number)
{
DSBYTE[p] = '0';
p++;
DSBYTE[p] = 0;
return 1;
}
mask = 1000000000;
cmd = 1;
if(!number){
ESBYTE[p] = '0';
ESBYTE[p+1] = 0;
return p;
}
ret = p;
if(number<0)
{
$neg number
ESBYTE[p] = '-';
$inc p
}
while(mask)
{
tmp = number / mask;
tmp = tmp%10;
if(cmd){
if(tmp){
ESBYTE[p] = tmp + '0';
$inc p
cmd = 0;
}
}
else {
ESBYTE[p] = tmp + '0';
$inc p
}
mask /= 10;
}
ESBYTE[p] = 0;
return p - ret;
}
:dword strcpy(dword s1,s2)
{
X = s1;
WHILE(DSBYTE[s2])
{
DSBYTE[s1] = DSBYTE[s2];
s1++;
s2++;
}
RETURN s1-X;
}
:dword strlcpy(dword s1,s2,l)
{
X = l;
WHILE(l)
{
DSBYTE[s1] = DSBYTE[s2];
s1++;
s2++;
l--;
}
RETURN X;
}
:dword _str(dword v)
{
SWITCH(DSBYTE[v+4])
{
CASE PY_STR:
RETURN DSDWORD[v];
CASE PY_BOOL:
IF(DSDWORD[v]) RETURN "True";
RETURN "False";
}
}
:dword stack = 0;
:dword popStack()
{
stack-=4;
RETURN DSDWORD[stack];
}
:void pushStack(dword x)
{
dword tmp = 0;
IF(!DSDWORD[stack]) tmp = malloc(30);
ELSE tmp = DSDWORD[stack];
IF(x) memcpy(tmp,x,30);
DSDWORD[stack] = tmp;
stack+=4;
}
:dword stackFast = 0;
:dword beginStackFast = 0;
:dword popFast()
{
stackFast-=4;
RETURN DSDWORD[stackFast];
}
:void pushFast(dword x)
{
dword tmp = 0;
IF(!DSDWORD[stackFast]) tmp = malloc(30);
ELSE tmp = DSDWORD[stackFast];
IF(x) memcpy(tmp,x,30);
DSDWORD[stackFast] = tmp;
stackFast+=4;
}
:dword stackLoop = 0;
:dword popLoop()
{
stackLoop-=4;
RETURN DSDWORD[stackLoop];
}
:void pushLoop(dword x)
{
DSDWORD[stackLoop] = x;
stackLoop+=4;
}
:void checkType(dword x,y)
{
IF(DSBYTE[x+4]!=DSBYTE[y+4])
{
_stdout("Error type!");
ExitProcess();
}
}
:void sprintf(dword str, ...)
{
//S = DSBYTE[format];
X = DSDWORD[ESP]-ESP-8;
X += ESP;
A = DSDWORD[X];
X-=4;
B = DSDWORD[X];
S = DSBYTE[B];
while(S)
{
if(S=='%')
{
B++;
S = DSBYTE[B];
IF(S=='s')
{
X-=4;
strcpy(A,DSDWORD[X]);
A+=EAX;
B++;
S = DSBYTE[B];
continue;
}
IF(S=='c')
{
X-=4;
EAX = DSDWORD[X];
test(EAX,1);
A++;
B++;
S = DSBYTE[B];
continue;
}
ELSE IF(S=='d')
{
}
ELSE
{
DSBYTE[A] = S;
A++;
}
}
else
{
DSBYTE[A] = S;
A++;
}
B++;
S = DSBYTE[B];
}
}
:byte BUFTST[15] = {0};
:void test1(dword x,y)
{
IF(y)
{
itoa(x,#BUFTST);
_stdout(#BUFTST);
}
ELSE _stdout(x);
EAX = -1;
$int 0x40;
}
:void test2(dword x,y)
{
_stdout("[");
IF(y)
{
itoa(x,#BUFTST);
_stdout(#BUFTST);
}
ELSE _stdout(x);
_stdout("]");
}
:void ______INIT______()
{
dword o = 0;
dword o2 = 0;
memInit();
stack = malloc(1000);
beginStack = stack;
stackFast = malloc(1000);
beginStackFast = stackFast;
stackLoop = malloc(1000);
TEMP = malloc(500);
//o = malloc(16*4);
//memcpy(o,"test123456789",9);
//test(123);
//sprintf(TEMP,"asd%sa=%c123","ok",123);
//test(TEMP,0);
//importLibrary("console");
main();
ExitProcess();
}
:void ______STOP______()
{
ExitProcess();
}

View File

@ -0,0 +1,201 @@
:dword strcmp(dword str1,str2)
{
LOOPCMP:
IF(DSBYTE[str1]!=DSBYTE[str2]) RETURN DSBYTE[str1]-DSBYTE[str2];
IF(!DSBYTE[str1]) RETURN DSBYTE[str1]-DSBYTE[str2];
IF(!DSBYTE[str2]) RETURN DSBYTE[str1]-DSBYTE[str2];
str1++;
str2++;
GOTO LOOPCMP;
}
/*
void dll_Load() {
asm {
push ebp
mov ebp, esp
mov esi, SSDWORD[EBP+8]
@next_lib:
mov edx, DSDWORD[ESI]
or edx, edx
jz exit
push esi
mov esi, DSDWORD[ESI+4]
mov edi, #libPath
add edi,9
@loc01:
lodsb
stosb
or al, al
jnz loc01
mov eax, 68
mov ebx, 19
mov ecx, #libPath
int 0x40
or eax, eax
jz fail
push edx
push eax
call dll_Link
push eax
mov eax, DSDWORD[eax]
cmp DSDWORD[EAX], '_bil' // somehow this needs to be reversed..
pop eax
jnz loc02
push DSDWORD[EAX+4]
call dll_Init
@loc02:
pop esi
add esi, 8
jmp next_lib
@exit:
xor eax, eax
leave
ret 4
@fail:
add esp, 4
xor eax, eax
inc eax
leave
ret 4
}
}
void dll_GetProcAddress(){
asm {
push ebp
mov ebp, esp
mov edx, CSDWORD[EBP+8]
xor eax, eax
@next:
or edx, edx
jz end
cmp CSDWORD[edx], 0
jz end
push CSDWORD[EBP+12]
push CSDWORD[EDX]
call dll_StrCmp
test eax, eax
jz ok
add edx, 8
jmp next
@ok:
mov eax, DSDWORD[EDX+4]
@end:
leave
ret 8
}
}
void dll_StrCmp() {
asm {
push ebp
mov ebp, esp
push esi
push edi
mov esi, CSDWORD[EBP+8]
mov edi, CSDWORD[EBP+12]
xor eax, eax
@label1:
lodsb
scasb
jne fail
or al, al
jnz label1
jmp label_ok
@fail:
or eax, -1
@label_ok:
pop edi
pop esi
leave
ret 8
}
}
void dll_Link() {
asm {
push ebp
mov ebp, esp
push eax
mov esi, SSDWORD[EBP+12]
test esi, esi
jz done
@next:
lodsd
test eax, eax
jz done
push eax
push SSDWORD[EBP+8]
call dll_GetProcAddress
or eax, eax
jz loc03
mov DSDWORD[esi-4], eax
jmp next
@loc03:
mov SSDWORD[esp], 0
@done:
pop eax
leave
ret 8
}
}
void dll_Init() {
asm {
push ebp
mov ebp, esp
pushad
mov eax, #malloc
mov ebx, #free;
mov ecx, #realloc;
mov edx, #dll_Load;
call SSDWORD[EBP+8]
popad
leave
ret 4
}
}
*/
:dword importLibrary(dword name)
{
dword l = 0;
dword i = 0;
dword list = 0;
dword key = 0;
dword data = 0;
dword ret = 0;
i = malloc(1000);
l = strcpy(TEMP,#libPath);
l += strcpy(TEMP+l,name);
memcpy(TEMP+l,".obj",5);
EAX = 68;
EBX = 19;
ECX = TEMP;
$int 0x40;
list = EAX;
while(DSDWORD[list])
{
test2(DSDWORD[list],0);
IF(!strcmp(DSDWORD[list],"con_init"))
{
//dll_Init(DSDWORD[list+4]);
}
ELSE dictSet(ret,DSDWORD[list],DSDWORD[list+4]);
list+=8;
}
EAX = DSDWORD[i+92];
i = malloc(10);
strcpy(i,"test");
i = realloc(i,19);
test1(i,0);
}

View File

@ -0,0 +1,717 @@
#define buffer 1024
:struct VAR
{
dword data;
byte type;
dword length;
dword stack;
};
:dword build_map(dword count)
{
dword o = 0;
dword a1 = 0;
dword a2 = 0;
IF(count>8) o = arrayInit(count);
ELSE o = arrayInit(8);
WHILE(count)
{
a1 = popStack();
a2 = popStack();
SWITCH(DSBYTE[a2+4])
{
CASE PY_STR:
dictSet(#o,DSDWORD[a2],a1);
BREAK;
CASE PY_INT:
arraySet(#o,1,a1);
BREAK;
}
count--;
}
load_const(o,PY_DCT,0);
}
:void load_const(dword data,type,length)
{
DSDWORD[#RDATA] = data;
DSBYTE[#RDATA+4] = type;
DSDWORD[#RDATA+5] = length;
DSDWORD[#RDATA+9] = 0;
pushStack(#RDATA);
}
:void compare_op(byte cmd)
{
dword n = 0;
dword y = popStack();
dword x = popStack();
dword dx = 0;
dword dy = 0;
dword i = 0;
checkType(x,y);
IF(DSBYTE[x+4] == PY_STR)
{
IF(DSDWORD[x+5] == DSDWORD[y+5])
{
dx = DSDWORD[x];
dy = DSDWORD[y];
i = DSDWORD[x+5];
WHILE(i)
{
IF(DSBYTE[dx]!=DSBYTE[dy]) BREAK;
dx++;
dy++;
i--;
}
IF(!i) load_const(1,PY_BOOL,0);
ELSE load_const(0,PY_BOOL,0);
}
return;
}
IF(!cmd)IF(DSDWORD[x] == DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==1)IF(DSDWORD[x] != DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==2)IF(DSDWORD[x] >= DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==3)IF(DSDWORD[x] <= DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==4)IF(DSDWORD[x] > DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==5)IF(DSDWORD[x] < DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
load_const(0,PY_BOOL,0);
}
:byte pop_jump_if(byte cmd)
{
dword x = 0;
x = popStack();
//test(DSDWORD[x+4],1);
SWITCH(DSBYTE[x+4])
{
CASE PY_INT:
CASE PY_BOOL:
IF(cmd){ IF (DSDWORD[x]) RETURN 1;}
IF(!cmd){ IF (!DSDWORD[x]) RETURN 1;}
BREAK;
CASE PY_STR:
IF(cmd){ IF (DSDWORD[x+5]) RETURN 1;}
IF(!cmd){ IF (!DSDWORD[x+5]) RETURN 1;}
BREAK;
}
RETURN 0;
}
:void pop_block()
{
stackLoop-=4;
}
:void unary_invert()
{
dword x = 0;
x = DSDWORD[stack-4];
EAX = DSDWORD[x];
$not eax;
DSDWORD[x] = EAX;
}
:void inplace(byte cmd)
{
dword buffer = 0;
dword length = 0;
Y = popStack();
X = DSDWORD[stack-4];
IF(cmd==PY_ADD) checkType(X,Y);
E = DSBYTE[X+4];
if(E==PY_STR)
{
A = DSDWORD[X+5];
IF(cmd==PY_ADD) B = DSDWORD[Y+5];
ELSE
{
C = DSDWORD[Y];
B = C*A;
}
length = A+B;
buffer = length+MEMBUF;
D = malloc(buffer);
IF(cmd==PY_ADD)
{
memcpy(D,DSDWORD[X],A);
memcpy(D+A,DSDWORD[Y],B);
}
ELSE IF(cmd==PY_MUL)
{
B = D;
E = DSDWORD[X];
WHILE(C)
{
memcpy(B,E,A);
B+=4;
C--;
}
}
DSDWORD[#RDATA] = D;
DSBYTE[#RDATA+4] = PY_STR;
DSDWORD[#RDATA+5] = length;
DSDWORD[#RDATA+9] = buffer;
pushStack(#RDATA);
return;
}
if(E==PY_INT)
{
switch(cmd)
{
case PY_ADD:
DSDWORD[X] += DSDWORD[Y];
break;
case PY_POW:
length = DSDWORD[Y];
D = DSDWORD[X];
DSDWORD[X] = 1;
WHILE(length) {DSDWORD[X]*=D; length--;}
break;
case PY_SUB:
DSDWORD[X] -= DSDWORD[Y];
break;
case PY_MUL:
DSDWORD[X] *= DSDWORD[Y];
break;
case PY_MOD:
DSDWORD[X] = DSDWORD[X]%DSDWORD[Y];
break;
case PY_XOR:
DSDWORD[X] ^= DSDWORD[Y];
break;
case PY_AND:
DSDWORD[X] &= DSDWORD[Y];
break;
case PY__OR:
DSDWORD[X] |= DSDWORD[Y];
break;
case PY_LSH:
DSDWORD[X] <<= DSDWORD[Y];
break;
case PY_RSH:
DSDWORD[X] >>= DSDWORD[Y];
break;
case PY_FDV:
DSDWORD[X] /= DSDWORD[Y];
break;
case PY_TDV:
DSDWORD[X] /= DSDWORD[Y];
break;
}
}
}
:void binary(byte cmd)
{
dword buffer = 0;
dword length = 0;
Y = popStack();
X = popStack();
IF(cmd==PY_ADD) checkType(X,Y);
E = DSBYTE[X+4];
if(E==PY_STR)
{
A = DSDWORD[X+5];
IF(cmd==PY_ADD) B = DSDWORD[Y+5];
ELSE
{
C = DSDWORD[Y];
B = C*A;
}
length = A+B;
buffer = length+MEMBUF;
D = malloc(buffer);
IF(cmd==PY_ADD)
{
memcpy(D,DSDWORD[X],A);
memcpy(D+A,DSDWORD[Y],B);
}
ELSE IF(cmd==PY_MUL)
{
B = D;
E = DSDWORD[X];
WHILE(C)
{
memcpy(B,E,A);
B+=4;
C--;
}
}
DSDWORD[#RDATA] = D;
DSBYTE[#RDATA+4] = PY_STR;
DSDWORD[#RDATA+5] = length;
DSDWORD[#RDATA+9] = buffer;
pushStack(#RDATA);
return;
}
if(E==PY_INT)
{
switch(cmd)
{
case PY_ADD:
A = DSDWORD[X] + DSDWORD[Y];
break;
case PY_POW:
length = DSDWORD[Y];
D = DSDWORD[X];
DSDWORD[Z] = 1;
WHILE(length) {A*=D; length--;}
break;
case PY_SUB:
A = DSDWORD[X] - DSDWORD[Y];
break;
case PY_MUL:
A = DSDWORD[X] * DSDWORD[Y];
break;
case PY_MOD:
A = DSDWORD[X] % DSDWORD[Y];
break;
case PY_XOR:
A = DSDWORD[X] ^ DSDWORD[Y];
break;
case PY_AND:
A = DSDWORD[X] & DSDWORD[Y];
break;
case PY__OR:
A = DSDWORD[X] | DSDWORD[Y];
break;
case PY_LSH:
A = DSDWORD[X] << DSDWORD[Y];
break;
case PY_RSH:
A = DSDWORD[X] >> DSDWORD[Y];
break;
case PY_FDV:
A = DSDWORD[X] / DSDWORD[Y];
break;
case PY_TDV:
A = DSDWORD[X] / DSDWORD[Y];
break;
}
load_const(A,PY_INT,0);
}
}
:byte del(dword v)
{
dword x = 0;
x = DSDWORD[v];
IF(x)
{
IF(DSDWORD[x+9]) free(DSDWORD[x]);
free(x);
DSDWORD[v] = 0;
RETURN 1;
}
RETURN 0;
}
:void build_class(dword count)
{
dword name = 0;
dword func = 0;
func = popFast();
name = popFast();
load_const(func,PY_CLS,0);
}
:void load_build_class()
{
load_const(#build_class,PY_FNC,0);
}
:void make_function()
{
stack-=4;
}
:void store_name(dword x)
{
dword tmp = 0;
dword stk = 0;
stk = popStack();
IF(!DSDWORD[x])
{
tmp = malloc(30);
memcpy(tmp,stk,30);
DSDWORD[x] = tmp;
return;
}
memcpy(DSDWORD[x],stk,30);
}
:void rot(dword x,y)
{
EAX = DSDWORD[stack-8];
DSDWORD[stack-8] = DSDWORD[stack-4];
DSDWORD[stack-4] = EAX;
}
:void build_tuple(dword len)
{
dword tuple = 0;
dword buf = 0;
dword l = 0;
l = len;
tuple = malloc(4*len+MEMBUF);
buf = tuple;
WHILE(len)
{
DSDWORD[buf] = popStack();
buf+=4;
len--;
}
load_const(tuple,PY_TPL,l);
}
:void unpack_sequence(dword len)
{
dword tuple = 0;
dword x = 0;
popStack();
tuple = DSDWORD[EAX];
WHILE(len)
{
pushStack(DSDWORD[tuple]);
tuple+=4;
len--;
}
}
:void rot_two()
{
rot(DSDWORD[stack-8],DSDWORD[stack-4]);
}
:void rot_three()
{
rot(DSDWORD[stack-12],DSDWORD[stack-4]);
rot(DSDWORD[stack-8],DSDWORD[stack-4]);
}
:void load_name(dword addr)
{
pushStack(addr);
}
:void load_global(dword addr)
{
pushStack(addr);
}
:dword strlen(dword txt)
{
dword i = 0;
i = txt;
WHILE(DSBYTE[i]) i++;
RETURN i - txt;
}
:dword hashString(dword x)
{
dword l = 0;
dword h = 0;
l = x;
WHILE(DSBYTE[x])
{
h+=DSBYTE[x];
h<<=1;
x++;
h/=x-l;
}
return h;
}
:void pop_top()
{
stack-=4;
}
:void load_fast(dword addr)
{
dword x = 0;
IF(!DSDWORD[addr])
{
x = popFast();
DSDWORD[addr] = x;
}
ELSE x = DSDWORD[addr];
pushStack(x);
}
:void call_function(dword arg)
{
dword count = 0;
dword func = 0;
byte type = 0;
dword stackRet = 0;
count = arg;
WHILE(count)
{
pushFast(popStack());
count--;
}
func = popStack();
//IF(DSBYTE[Z+4]!=PY_FNC) test("No function!",0);
type = DSBYTE[func+4];
func = DSDWORD[func];
IF(!func)
{
test1("Null function!",0);
pushStack(0);
return;
}
IF(type==PY_FNC)
{
stackRet = stack;
func(arg);
IF(stackRet == stack) load_const(0,PY_NONE,0);
}
ELSE IF(type==PY_CLS)
{
stackRet = stack;
func(arg);
IF(stackRet == stack) load_const(0,PY_NONE,0);
}
stackFast = beginStackFast;
}
:void call_method(dword arg)
{
dword count = 0;
dword func = 0;
byte type = 0;
dword stackRet = 0;
count = arg;
WHILE(count)
{
pushFast(popStack());
count--;
}
func = popStack();
//IF(DSBYTE[Z+4]!=PY_FNC) test("No function!",0);
type = DSBYTE[func+4];
func = DSDWORD[func];
IF(!func)
{
test1("Null function!",0);
pushStack(0);
return;
}
IF(type==PY_FNC)
{
stackRet = stack;
func(arg);
IF(stackRet == stack) load_const(0,PY_NONE,0);
}
ELSE IF(type==PY_CLS)
{
func(arg);
pushStack(EAX);
}
stackFast = beginStackFast;
}
:void load_method(dword name)
{
dword x = 0;
dword data = 0;
dword get = 0;
x = popStack();
data = DSDWORD[x];
get = dictGet(DSDWORD[data],name);
pushStack(get);
}
:void append(dword count)
{
dword x = 0;
dword y = 0;
x = popFast();
y = popFast();
test1(DSBYTE[x+4],1);
}
:void build_list(dword count)
{
dword n = 0;
dword mem = 0;
dword i = 0;
dword tmp = 0;
dword method = 0;
mem = malloc(count*4+MEMBUF);
i = count;
n = i*4+mem+4;
load_const(#append,PY_FNC,0);
dictSet(#method,"append",popStack());
DSDWORD[mem] = method;
WHILE(i)
{
n-=4;
tmp = malloc(30);
memcpy(tmp,popStack(),30);
DSDWORD[n] = tmp;
i--;
}
load_const(mem,PY_LST,count);
}
:dword store_fast()
{
return popStack();
}
:void binary_subscr()
{
dword x = 0;
dword y = 0;
dword l1 = 0;
dword l2 = 0;
dword tmp = 0;
dword ret = 0;
byte t = 0;
x = popStack();
y = popStack();
//IF(DSBYTE[x+4]!=PY_INT) error type;
l1 = DSDWORD[y+5];
t = DSBYTE[y+4];
IF(t==PY_LST)
{
IF(l1<=x) test1("error max list",0);
IF(0>l1) test1("error min list",0);
y = DSDWORD[y];
pushStack(DSDWORD[x*4+y]);
return;
}
IF(t==PY_DCT)
{
y = DSDWORD[y]; // data object
SWITCH(DSBYTE[x+4])
{
CASE PY_INT:
test1(DSDWORD[y],1);
x = arrayGet(DSDWORD[y],DSDWORD[x]);
BREAK;
CASE PY_STR:
x = dictGet(DSDWORD[y],DSDWORD[x]);
BREAK;
}
pushStack(x);
//test1(DSBYTE[x+4],1);
return;
}
IF(t==PY_STR)
{
x = DSDWORD[x];
IF (l1<=x)||(l1<0) test1("IndexError: string index out of range",0);
y = DSDWORD[y];
tmp = malloc(MEMBUF);
ret = malloc(30);
DSBYTE[tmp] = DSBYTE[x+y];
DSDWORD[ret] = tmp;
DSBYTE[ret+4] = PY_STR;
DSDWORD[ret+5] = 1;
DSDWORD[ret+9] = MEMBUF;
pushStack(ret);
return;
}
}
:void build_slice(dword count)
{
}
/*
:void call_function(dword arg)
{
dword x = 0;
dword c = arg;
dword o = 0;
dword v = 0;
WHILE(c)
{
o+=4;
popStack();
$push eax
c--;
}
$push arg
v = popStack();
IF(DSBYTE[v+4]!=PY_FNC) test("No function!",0);
v = DSDWORD[v];
IF(!v)
{
test(1,1);
pushStack(0);
return;
}
$call v
ESP+=o;
pushStack(EAX);
}
*/