Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 8475 → Rev 8474

/programs/develop/tinypy/modules/kolibri/net.c
File deleted
/programs/develop/tinypy/modules/kolibri/debug.c
File deleted
/programs/develop/tinypy/modules/kolibri/gui.c
File deleted
/programs/develop/tinypy/modules/kolibri/init.c
2,7 → 2,6
 
extern tp_obj kolibri_open(TP);
extern tp_obj kolibri_mainwindow(TP);
extern tp_obj kolibri_debug_print(TP);
extern tp_obj kolibri_socket_module(TP);
extern tp_obj tp_dict(TP);
extern tp_obj tp_fnc(TP,tp_obj v(TP));
14,8 → 13,6
 
tp_set(tp, kolibri_mod, tp_string("open"), tp_fnc(tp, kolibri_open));
tp_set(tp, kolibri_mod, tp_string("window"), tp_fnc(tp, kolibri_mainwindow));
/* debug */
tp_set(tp, kolibri_mod, tp_string("debug_print"), tp_fnc(tp, kolibri_debug_print));
/* socket is a separated module. */
tp_set(tp, kolibri_mod, tp_string("socket"), socket_mod);
 
/programs/develop/tinypy/tinypy/Makefile
13,24 → 13,21
INCLUDES= -I. -I$(SDK_DIR)/sources/newlib/libc/include
LIBPATH:= -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib
 
KOLIBRI_M_OBJ= ../modules/kolibri/init.o \
../modules/kolibri/fs.o \
../modules/kolibri/net.o \
../modules/kolibri/gui.o \
../modules/kolibri/debug.o \
OBJECTS = tpmain.o kolibri_init.o kolibri_fs.o kolibri_gui.o kolibri_net.o kolibri_dbg.obj
OBJECTS = tpmain.o $(KOLIBRI_M_OBJ)
 
all:$(NAME)
 
$(NAME): $(OBJECTS)
$(NAME): $(OBJECTS) Makefile
$(LD) $(LIBPATH) --subsystem native -o $@ $(OBJECTS) $(LDFLAGS) -n -Map $(NAME).map
kos32-objcopy $@ -O binary
kpack $@
 
%.o : %.c Makefile
$(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $<
 
kolibri_dbg.obj: fasm_modules/kolibri_dbg.s
fasm fasm_modules/kolibri_dbg.s
cp fasm_modules/kolibri_dbg.obj .
 
clean:
rm -f *.o $(NAME).map $(KOLIBRI_M_OBJ)
-rm -f *.o $(NAME).map fasm_modules/kolibri_dbg.obj kolibri_dbg.obj
/programs/develop/tinypy/tinypy/kolibri_gui.c
0,0 → 1,163
#include "tp.h"
#include <kos32sys.h>
 
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
 
extern void _tp_raise(TP,tp_obj);
extern tp_obj tp_dict(TP);
extern tp_obj tp_method(TP,tp_obj self,tp_obj v(TP));
extern tp_obj tp_number(tp_num v);
extern tp_obj tp_list(TP);
extern void _tp_list_append(TP,_tp_list *self, tp_obj v);
extern tp_obj tp_call(TP, const char *mod, const char *fnc, tp_obj params);
extern void _tp_call(TP,tp_obj *dest, tp_obj fnc, tp_obj params);
extern int tp_bool(TP,tp_obj v);
extern tp_obj tp_has(TP,tp_obj self, tp_obj k);
// #define _cdecl __attribute__((cdecl))
extern int (* _cdecl con_printf)(const char* format,...);
static tp_obj kolibri_show(TP)
{
tp_obj self = TP_TYPE(TP_DICT);
uint16_t xpos = (uint16_t)(tp_get(tp, self, tp_string("x")).number.val);
uint16_t ypos = (uint16_t)tp_get(tp, self, tp_string("y")).number.val;
uint16_t height = (uint16_t)tp_get(tp, self, tp_string("height")).number.val;
uint16_t width = (uint16_t)tp_get(tp, self, tp_string("width")).number.val;
uint16_t fixedsize = (uint16_t)tp_get(tp, self, tp_string("fixedsize")).number.val;
uint32_t bgcolor = (uint32_t)tp_get(tp, self, tp_string("bgcolor")).number.val;
uint32_t status;
uint32_t style;
uint32_t x = xpos * 0x10000 + width;
uint32_t y = ypos * 0x10000 + height;
if (fixedsize)
style = 0;
else
style = 0x33000000 + (bgcolor & 0xFFFFFF);
asm volatile ("int $0x40"::"a"(12), "b"(1));
asm volatile ("int $0x40"::
"a"(0), "b"(x), "c"(y), "d"(style),
"S"(0), "D"(0));
asm volatile ("int $0x40"::"a"(12), "b"(2));
/* If window has additional handler, run it. */
if (tp_bool(tp, tp_has(tp, self, tp_string("on_show"))))
{
tp_obj result;
tp_obj fnc = tp_get(tp, self, tp_string("on_show"));
tp_obj param_list = tp_list(tp); /* Prepare parameters. */
_tp_list_append(tp, param_list.list.val, self);
_tp_call(tp, &result, fnc, param_list);
}
return tp_None;
}
 
static void window_function(void)
{
uint32_t ev;
/* Wait for event. */
do {
asm volatile("int $0x40":"=a"(ev):"a"(10));
} while(ev != 3);
asm volatile("int $040"::"a"(-1));
}
 
static tp_obj kolibri_default_handler(TP)
{
return tp_None;
}
 
/* Run window_function() in separated thread. */
static tp_obj kolibri_run(TP)
{
tp_obj self = TP_TYPE(TP_DICT);
tp_obj redraw = tp_get(tp, self, tp_string("show"));
tp_obj result;
tp_obj key_handler = tp_None;
tp_obj button_handler = tp_None;
int button_id;
uint32_t ev;
int leave=0;
tp_obj param_list;
/* Obtain handlers. */
if (tp_bool(tp, tp_has(tp, self, tp_string("on_key"))))
key_handler = tp_get(tp, self, tp_string("on_key"));
if (tp_bool(tp, tp_has(tp, self, tp_string("on_button"))))
button_handler = tp_get(tp, self, tp_string("on_button"));
 
while(!leave){
asm volatile("int $0x40":"=a"(ev):"a"(10));
switch (ev)
{
case 1:
_tp_call(tp, &result, redraw, tp_None);
break;
case 2:
if (key_handler.type == TP_FNC)
{
param_list = tp_list(tp); /* Prepare parameters. */
_tp_list_append(tp, param_list.list.val, self);
oskey_t key;
key = get_key();
_tp_list_append(tp, param_list.list.val, tp_number(key.code));
_tp_call(tp, &result, key_handler, param_list);
}
break;
case 3:
button_id = get_os_button();
if (button_id == 1)
leave = 1;
else if (button_handler.type == TP_FNC)
{
param_list = tp_list(tp); /* Prepare parameters. */
_tp_list_append(tp, param_list.list.val, self);
_tp_list_append(tp, param_list.list.val, tp_number(button_id));
_tp_call(tp, &result, button_handler, param_list);
}
break;
default:
con_printf("Got unknown event %d\n", ev);
break;
}
};
return tp_None;
}
 
static tp_obj kolibri_print_text(TP)
{
tp_obj self = TP_TYPE(TP_DICT);
uint32_t textcolor = (uint32_t)tp_get(tp, self, tp_string("textcolor")).number.val;
uint16_t x = (uint16_t)tp_get(tp, self, tp_string("curx")).number.val;
uint16_t y = (uint16_t)tp_get(tp, self, tp_string("cury")).number.val;
uint32_t ofs;
uint32_t width = (uint32_t)tp_get(tp, self, tp_string("width")).number.val;
tp_obj text = TP_TYPE(TP_STRING);
 
draw_text_sys((char *)text.string.val, x, y, text.string.len, textcolor);
/* Update cursor position. */
ofs = 6 * text.string.len;
tp_set(tp, self, tp_string("cury"), tp_number(y + 9 * ((x + ofs) / width)));
tp_set(tp, self, tp_string("curx"), tp_number((x + ofs)%width));
 
return tp_None;
}
 
tp_obj kolibri_mainwindow(TP)
{
tp_obj obj = tp_dict(tp);
obj = tp_dict(tp);
tp_set(tp, obj, tp_string("x"), TP_TYPE(TP_NUMBER));
tp_set(tp, obj, tp_string("y"), TP_TYPE(TP_NUMBER));
tp_set(tp, obj, tp_string("height"), TP_TYPE(TP_NUMBER));
tp_set(tp, obj, tp_string("width"), TP_TYPE(TP_NUMBER));
tp_set(tp, obj, tp_string("curx"), tp_number(0));
tp_set(tp, obj, tp_string("cury"), tp_number(0));
tp_set(tp, obj, tp_string("fixedsize"), TP_TYPE(TP_NUMBER));
tp_set(tp, obj, tp_string("textcolor"), tp_number(0x202020));
tp_set(tp, obj, tp_string("bgcolor"), tp_number(0xFFFFFF));
tp_set(tp, obj, tp_string("show"), tp_method(tp, obj, kolibri_show));
tp_set(tp, obj, tp_string("run"), tp_method(tp, obj, kolibri_run));
/*tp_set(tp, obj, tp_string("keyhandler"), tp_method(tp, obj, kolibri_default_handler));
tp_set(tp, obj, tp_string("buttonhandler"), tp_method(tp, obj, kolibri_default_handler));*/
tp_set(tp, obj, tp_string("print_text"), tp_method(tp, obj, kolibri_print_text));
return obj;
}
/programs/develop/tinypy/tinypy/kolibri_net.c
0,0 → 1,296
#include <sys/socket.h>
// #include <menuet/net.h>
 
#include "tp.h"
 
extern tp_obj tp_dict(TP);
extern tp_obj tp_method(TP,tp_obj self,tp_obj v(TP));
extern tp_obj tp_fnc(TP,tp_obj v(TP));
extern tp_obj tp_get(TP,tp_obj self, tp_obj k);
tp_obj tp_has(TP,tp_obj self, tp_obj k);
// #define _cdecl __attribute__((cdecl))
extern int (* _cdecl con_printf)(const char* format,...);
 
#define PRECISION 0.000001
 
#define GET_SOCKET_DESCRIPTOR(_obj, _sock) do{ \
if (fabs(tp_has(tp, _obj, tp_string("socket")).number.val) < PRECISION)\
tp_raise(tp_None, "Socket not open", tp_None); \
_sock = (__u32)(tp_get(tp, _obj, tp_string("socket")).number.val + PRECISION);\
} while(0)
 
/* Socket close method.
*
* Example:
* s.close() # s must be a socket object created by socket.
*
* Raises exception if socket was not opened. Otherwise returns True.
*/
static tp_obj kolibri_close_socket(TP)
{
// tp_obj self = TP_TYPE(TP_DICT);
// __u32 socktype;
// __u32 s;
 
// GET_SOCKET_DESCRIPTOR(self, s);
 
// socktype = (__u32)tp_get(tp, self, tp_string("type")).number.val;
// GET_SOCKET_DESCRIPTOR(self, s);
// if (socktype == SOCK_STREAM)
// __menuet__close_TCP_socket(s);
// else if (socktype == SOCK_DGRAM)
// __menuet__close_UDP_socket(s);
return tp_True;
}
 
/* Socket send method.
*
* Example:
* data="<html><head><title>Preved!!!</title></head><body>Example.</body></html>"
* s.send(data)
* or:
* s.send(data, 20) # Send just 20 bytes
*/
static tp_obj kolibri_send(TP)
{
// tp_obj self = TP_TYPE(TP_DICT);
// tp_obj data_obj = TP_TYPE(TP_STRING);
// __u32 datalen = TP_DEFAULT(tp_False).number.val;
// __u32 socktype = (__u32)tp_get(tp, self, tp_string("type")).number.val;
// __u32 s;
// int result;
 
// GET_SOCKET_DESCRIPTOR(self, s);
 
// if (datalen < 0 || datalen > data_obj.string.len)
// datalen = data_obj.string.len;
// if (socktype == SOCK_STREAM)
// result = __menuet__write_TCP_socket(s, datalen, (void *)data_obj.string.val);
// else if (socktype == SOCK_DGRAM)
// result = __menuet__write_UDP_socket(s, datalen, (void *)data_obj.string.val);
// return tp_number(!(result != 0));
return tp_number(0);
}
 
#define __u32 unsigned int
#define __u8 unsigned char
 
/* Socket recv method.
*
* data="<html><head><title>Preved!!!</title></head><body>Example.</body></html>"
* s.recv(data)
* or:
* s.recv(data, 20) # Send just 20 bytes
*/
static tp_obj kolibri_recv(TP)
{
tp_obj self = TP_TYPE(TP_DICT);
__u32 datalen = TP_DEFAULT(tp_False).number.val;
__u32 s;
__u8 c;
__u8 *buf, *p;
__u32 buf_size;
__u32 bytes_read = 0;
int i;
 
// GET_SOCKET_DESCRIPTOR(self, s);
 
// if (datalen)
// buf_size = datalen;
// else
// buf_size = 2048;
// if (!(buf = malloc(datalen)))
// tp_raise(tp_None, "Cannot allocate buffer for received data", tp_None);
// p = buf;
// while (__menuet__read_socket(s, &c) && bytes_read < buf_size)
// {
// *p++ = c;
// bytes_read++;
// if (bytes_read >= buf_size && !datalen)
// {
// buf_size += 1024;
// buf = realloc(buf, buf_size);
// }
// }
return tp_string_n(buf, bytes_read);
}
 
static void inet_pton(TP, const char *buf, int len, __u32 *addr)
{
char *p = (char *)buf;
int i = 0;
__u32 val = 0;
*addr = 0;
while (*p && p < buf + len && i < 4)
{
if (*p == '.' || !*p)
{
if (val > 255)
tp_raise(tp_None, "ValueError: number > 255 in IP address", tp_None);
*addr += (val << ((i++) << 3));
val = 0;
}
else
{
if (*p < '0' || *p > '9')
tp_raise(tp_None, "ValueError: bad char in IP address, digit expected", tp_None);
val = val * 10 + *p - '0';
}
p++;
}
if (!*p)
{
if (i == 3)
*addr += (val << ((i++) << 3));
else
tp_raise(tp_None, "ValueError: bad IP address", tp_None);
}
 
}
 
/* Converter from string presentation to binary address. */
static tp_obj kolibri_inet_pton(TP)
{
tp_obj obj;
__u32 addr;
obj = TP_TYPE(TP_STRING);
// inet_pton(tp, (char *)obj.string.val, (int)obj.string.len, &addr);
return tp_number(addr);
}
 
/* Socket bind method.
*
* In KolibriOS it just sets local address and port.
*
* Example:
* s.bind('10.10.1.2', 6000) #Connects to 10.10.1.2:6000
*/
tp_obj kolibri_bind(TP)
{
// tp_obj self = TP_TYPE(TP_DICT);
// tp_obj local_addr_obj = TP_OBJ();
// __u32 local_port = (__u32)TP_TYPE(TP_NUMBER).number.val;
// __u32 local_addr;
 
// if (local_addr_obj.type == TP_NUMBER)
// local_addr = local_addr_obj.number.val;
// else if (local_addr_obj.type == TP_STRING)
// inet_pton(tp, (const char *)local_addr_obj.string.val, local_addr_obj.string.len, &local_addr);
 
// tp_set(tp, self, tp_string("local_addr"), tp_number(local_addr));
// tp_set(tp, self, tp_string("local_port"), tp_number(local_port));
return tp_None;
}
 
/* Socket connect method.
*
* Example:
* s.connect('10.10.1.1', 7000) #Connects to 10.10.1.1:7000
*/
tp_obj kolibri_connect(TP)
{
// tp_obj self = TP_TYPE(TP_DICT);
// tp_obj remote_addr_obj = TP_OBJ();
// __u32 remote_addr;
// __u32 remote_port = (__u32)TP_TYPE(TP_NUMBER).number.val;
// __u32 local_port = tp_get(tp, self, tp_string("local_port")).number.val;
// __u32 socktype = (__u32)tp_get(tp, self, tp_string("type")).number.val;
// int s = -1; /* Socket descriptor */
 
 
// if (remote_addr_obj.type == TP_NUMBER)
// remote_addr = remote_addr_obj.number.val;
// else if (remote_addr_obj.type == TP_STRING)
// inet_pton(tp, (const char *)remote_addr_obj.string.val, remote_addr_obj.string.len, &remote_addr);
 
// if (socktype == SOCK_STREAM)
// s = __menuet__open_TCP_socket(local_port, remote_port, remote_addr, 1);
// else if (socktype == SOCK_DGRAM)
// s = __menuet__open_UDP_socket(local_port, remote_port, remote_addr);
// if (s >= 0)
// {
// tp_set(tp, self, tp_string("socket"), tp_number(s));
// return tp_True;
// }
// else
return tp_False;
}
 
/* Socket listen method.
*
* Example:
* s.listen('10.10.1.1', 5000)
*/
tp_obj kolibri_listen(TP)
{
// tp_obj self = TP_TYPE(TP_DICT);
// tp_obj remote_addr_obj = TP_OBJ();
// __u32 remote_addr;
// __u32 remote_port = (__u32)TP_TYPE(TP_NUMBER).number.val;
// __u32 local_port = tp_get(tp, self, tp_string("local_port")).number.val;
// __u32 socktype = (__u32)tp_get(tp, self, tp_string("type")).number.val;
// int s = -1; /* Socket descriptor */
 
// if (socktype != SOCK_STREAM)
// tp_raise(tp_None, "IOError: attempt to listen on non-TCP socket", tp_None);
 
// if (remote_addr_obj.type == TP_NUMBER)
// remote_addr = remote_addr_obj.number.val;
// else if (remote_addr_obj.type == TP_STRING)
// inet_pton(tp, (const char *)remote_addr_obj.string.val, remote_addr_obj.string.len, &remote_addr);
 
// if ((s = __menuet__open_TCP_socket(local_port, remote_port, remote_addr, 0)) >= 0)
// {
// tp_set(tp, self, tp_string("socket"), tp_number(s));
// return tp_True;
// }
// else
return tp_False;
}
 
 
/* Exported function.
*
* Example:
*
* s = socket(socket.AF_INET, socket.SOCK_DGRAM)
*
* Returns socket object.
*/
tp_obj kolibri_socket(TP)
{
tp_obj s;
tp_obj sockfamily = TP_TYPE(TP_NUMBER);
tp_obj socktype = TP_TYPE(TP_NUMBER);
 
// if (fabs(sockfamily.number.val - AF_INET) > PRECISION ||
// (fabs(socktype.number.val - SOCK_STREAM) > PRECISION &&
// fabs(socktype.number.val - SOCK_DGRAM) > PRECISION))
// return tp_None;
s = tp_dict(tp);
// tp_set(tp, s, tp_string("family"), sockfamily);
// tp_set(tp, s, tp_string("type"), socktype);
// tp_set(tp, s, tp_string("bind"), tp_method(tp, s, kolibri_bind));
// tp_set(tp, s, tp_string("connect"), tp_method(tp, s, kolibri_connect));
// tp_set(tp, s, tp_string("send"), tp_method(tp, s, kolibri_send));
// tp_set(tp, s, tp_string("recv"), tp_method(tp, s, kolibri_recv));
// tp_set(tp, s, tp_string("close"), tp_method(tp, s, kolibri_close_socket));
// if (fabs(socktype.number.val - SOCK_STREAM) < PRECISION)
// tp_set(tp, s, tp_string("listen"), tp_method(tp, s, kolibri_listen));
return s;
}
 
tp_obj kolibri_socket_module(TP)
{
tp_obj socket_mod = tp_dict(tp);
 
// tp_set(tp, socket_mod, tp_string("AF_INET"), tp_number(AF_INET));
// tp_set(tp, socket_mod, tp_string("SOCK_STREAM"), tp_number(SOCK_STREAM));
// tp_set(tp, socket_mod, tp_string("SOCK_DGRAM"), tp_number(SOCK_DGRAM));
tp_set(tp, socket_mod, tp_string("AF_INET"), tp_number(0));
tp_set(tp, socket_mod, tp_string("SOCK_STREAM"), tp_number(0));
tp_set(tp, socket_mod, tp_string("SOCK_DGRAM"), tp_number(0));
tp_set(tp, socket_mod, tp_string("inet_pton"), tp_fnc(tp, kolibri_inet_pton));
tp_set(tp, socket_mod, tp_string("socket"), tp_fnc(tp, kolibri_socket));
return socket_mod;
}
/programs/develop/tinypy/tinypy/fasm_modules/kolibri_dbg.s
0,0 → 1,155
; TinyPy module
; Name: kolibri_dbg
;
; Exports:
; debug_print(msg) - prints a message to debug board.
 
format coff
use32 ; Tell compiler to use 32 bit instructions
 
section '.init' code ; Keep this line before includes or GCC messes up call addresses
 
include '../../../proc32.inc'
include '../../../struct.inc'
purge section,mov,add,sub
include 'tinypy.inc'
 
include '../../../../programs/dll.inc'
 
extrn '_tp_dict' as tp_dict
extrn '_tp_set' as tp_set
extrn '_tp_get' as tp_get
extrn '_tp_None' as tp_None
extrn '_tp_fnc' as tp_fnc
 
public kolibri_dbg_init as '_kolibri_dbg_init'
 
; Module name
modname db "kolibri_dbg"
modnamelen = $-modname
 
; Exported function name
debug_print_name db "debug_print"
debug_print_namelen = $-debug_print_name
; Export dictionary for module
kolibri_dbg_dict rb sizeof.tp_obj
; tp_obj of exported function
debug_print_obj rb sizeof.tp_obj
 
; Function debug_print(tp_vm *tp)
; return nothing
debug_print:
push ebp
mov ebp, esp
; Store registers
push eax
push ebx
push ecx
push edx
sub esp, sizeof.tp_obj; Reserve tp_obj tmp
mov edx, esp
push edx ;Store &tmp
; Obtain tp_string parameter
; tp_get(&tmp, tp, *(tp_obj *)(tp_vm->params), tp_None)
push_tp_none
mov eax, dword[ebp+12] ;4 for return address, 4 for result pointer; 4 for tp_vm
add eax, tp_vm.params
push_tp_obj_at_reg eax
push dword[ebp+12]
push edx ;ebx contains address of reserved tp_obj variable
call tp_get
 
;Restore stack
add esp, sizeof.tp_obj*2+4;2 tp_obj's and 2 pointers in parameters minus 1 pointer to result (cleared inside tp_get)
 
;Leave if parameter is not a string. tp_raise() should be called here.
pop edx; edx = &tmp
cmp dword[edx], TP_STRING ; Check that function returned a TP_STRING
jne .exit
mov ecx, dword[edx+tp_string_.len] ; String length
mov edx, dword[edx+tp_string_.val] ;
mov eax, 63
mov ebx, 1
.cont:
; Print message.
push ecx ; Store ecx to use it in inner loop
mov cl, byte[edx]
inc edx
int 40h
pop ecx ; Get ecx back
loop .cont
.exit:
add esp, sizeof.tp_obj ; Release tp_obj reserved in stack.
; Returning tp_None
mov eax, dword[ebp+8]
mov dword[eax], 0
; Restore registers
pop edx
pop ecx
pop ebx
pop eax
mov esp, ebp
pop ebp
ret
 
;void kolibri_dbg_init(tp_vm *tp);
kolibri_dbg_init:
push ebp
mov ebp, esp
;Save registers
push eax
push ebx
push ecx
; Create module dictionary and store its address in kolibri_dbg_str
mov eax, dword [ebp + 8]
push eax
push kolibri_dbg_dict
call tp_dict
add esp, 4 ;Clear stack
; Push tp_obj structure pointed by kolibri_dbg_dict
push_tp_obj kolibri_dbg_dict
; Push modname as a tp_obj object
push modnamelen; len
push modname ; val
push 0 ;_tp_string info
push TP_STRING ; type
; Push tp_obj structure pointed by tp->modules
mov eax, dword [ebp + 8]
add eax, tp_vm.modules + 16
mov ecx, 4
.push_tpobj1:
sub eax, 4
push dword[eax]
loop .push_tpobj1
push eax
call tp_set
add esp, sizeof.tp_obj*3+4
; Register "debug_print" function
;Reserve memory for function tp_obj object
sub esp, sizeof.tp_obj
mov eax, esp
push debug_print
push dword[ebp+8]
push eax
call tp_fnc
add esp, 8; tp_obj is already in stack, adding other arguments
;Pushing function name tp_obj
;mov eax, esp
;push_tp_obj_at_reg eax
push debug_print_namelen
push debug_print_name
push 0
push TP_STRING
;Pushing module dictionary tp_obj
push_tp_obj kolibri_dbg_dict
;Pushing tp_vm
push dword[ebp+8]
call tp_set
add esp, sizeof.tp_obj*3+4
; Leaving function
pop ecx
pop ebx
pop eax
mov esp, ebp
pop ebp
ret
/programs/develop/tinypy/tinypy/fasm_modules/tinypy.inc
0,0 → 1,184
; Python object types
TP_NONE equ 0
TP_NUMBER equ 1
TP_STRING equ 2
TP_DICT equ 3
TP_LIST equ 4
TP_FNC equ 5
TP_DATA equ 6
 
; Python "number" object. Can be treated as integer or float.
struct tp_number_
type rd 1
val rd 1
ends
 
; GC information for "string" object
struct _tp_string
gci rd 1
s rb 1
ends
 
; Python "string" object
struct tp_string_
type rd 1
info rd 1 ;pointer to _tp_string
val rd 1
len rd 1
ends
 
; GC information for "list" object
struct _tp_list
gci rd 1
items rd 1
len rd 1
alloc rd 1
ends
 
; Python "list" object
struct tp_list_
type rd 1
val rd 1 ;pointer to _tp_list
ends
 
 
; GC information for "dict" object
struct _tp_dict
gci rd 1
items rd 1
len rd 1
alloc rd 1
cur rd 1
mask rd 1
used rd 1
ends
 
; Python "dict" object
struct tp_dict_
type rd 1
val rd 1 ;pointer to _tp_dict
ends
 
; GC information for "function" object
; todo
 
; Python "function" object
struct tp_fnc_
type rd 1
info rd 1
ftype rd 1
val rd 1
ends
 
; Python "data" object
struct tp_data_
type rd 1
info rd 1
val rd 1
magic rd 1
ends
 
struct tp_gc_info
type rd 1
data rd 1
ends
 
; Generic Python object
struct tp_obj
union
type rd 1
string tp_string_
number tp_number_
gc_info tp_gc_info
dict tp_dict_
list tp_list_
fnc tp_fnc_
dat tp_data_
ends
ends
 
; Bytecode element
struct sregs
.i rb 1
.a rb 1
.b rb 1
.c rb 1
ends
 
struct tp_code
union
i rb 1
regs sregs
string rb 4
number rp 1
ends
ends
 
; TinyPy VM frame
struct tp_frame_
.codes rd 1
.cur rd 1
.jump rd 1
.regs rd 1
.ret_dest rd 1
.fname rb sizeof.tp_obj
.name rb sizeof.tp_obj
.line rb sizeof.tp_obj
.globals rb sizeof.tp_obj
.lineno rd 1
.cregs rd 1
ends
 
; TinyPy VM
TP_FRAMES equ 256
struct tp_vm
builtins rb sizeof.tp_obj
modules rb sizeof.tp_obj
frames rb TP_FRAMES*sizeof.tp_frame_
_params rb sizeof.tp_obj
params rb sizeof.tp_obj
_regs rb sizeof.tp_obj
regs rq 1
root rb sizeof.tp_obj
jmp_buf rd 1
jump rd 1
ex rb sizeof.tp_obj
chars rb 512
cur rd 1
white rb sizeof._tp_list
grey rb sizeof._tp_list
black rb sizeof._tp_list
strings rb sizeof._tp_dict
steps rd 1
ends
 
macro push_tp_none
{
local .push_more
mov ecx, 4
.push_more:
push 0
loop .push_more
}
 
macro push_tp_obj obj
{
local .push_more
mov ebx, obj + 12
mov ecx, 4
.push_more:
push dword[ebx]
sub ebx, 4
loop .push_more
}
 
macro push_tp_obj_at_reg reg
{
local .push_more
add reg, 12
mov ecx, 4
.push_more:
push dword[reg]
sub reg, 4
loop .push_more
}
/programs/develop/tinypy/tinypy/tpmain.c
2,10 → 2,11
/* INCLUDE */
const char header[]="TinyPy for kolibriOS";
 
//extern void kolibri_dbg_init(tp_vm *tp); //__attribute__((__stdcall__));
extern void (*kolibri_dbg_init)(tp_vm *tp) __attribute__((__stdcall__));
 
void main(int argc, const char *argv[]) {
tp_vm *tp = tp_init(argc, argv);
// kolibri_dbg_init(tp);
kolibri_init(tp);
CONSOLE_INIT(header);
/* INIT */
/programs/develop/tinypy/tinypy/kolibri_fs.c
0,0 → 1,0
#include "../modules/kolibri/fs.c"
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/tinypy/tinypy/kolibri_init.c
0,0 → 1,0
#include "../modules/kolibri/init.c"
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/tinypy/tinypy/test.py
10,7 → 10,6
print("Button pressed")
 
if __name__=="__main__":
kolibri.debug_print("Debug test line\n")
w = kolibri.window(10,10,400, 400, False)
w.on_show = onshow
w.on_key = onkey