tinypy: can now run from shell and use command line parameters.

git-svn-id: svn://kolibrios.org@2073 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
jaeger 2011-08-18 21:08:16 +00:00
parent c4601c7bd9
commit c27ead6711
4 changed files with 14 additions and 27 deletions

View File

@ -1,7 +1,7 @@
export MENUETDEV=../../libraries/menuetlibc export MENUETDEV=../../libraries/menuetlibc
OUTFILE = tpmain OUTFILE = tpmain
OBJS = tpmain.o kolibri_init.o kolibri_fs.o kolibri_gui.o kolibri_dbg.o OBJS = tpmain.o kolibri_init.o kolibri_fs.o kolibri_gui.o kolibri_dbg.o
CFLAGS = -I. CFLAGS = -I. -mpreferred-stack-boundary=2 -mincoming-stack-boundary=2
include $(MENUETDEV)/makefiles/Makefile_for_program include $(MENUETDEV)/makefiles/Makefile_for_program
kolibri_dbg.o: fasm_modules/kolibri_dbg.s kolibri_dbg.o: fasm_modules/kolibri_dbg.s
fasm fasm_modules/kolibri_dbg.s fasm fasm_modules/kolibri_dbg.s

View File

@ -15,7 +15,6 @@ def _import(name):
return MODULES[name] return MODULES[name]
py = name+".py" py = name+".py"
tpc = name+".tpc" tpc = name+".tpc"
print("CP")
if exists(py): if exists(py):
if not exists(tpc) or mtime(py) > mtime(tpc): if not exists(tpc) or mtime(py) > mtime(tpc):
s = load(py) s = load(py)
@ -43,7 +42,6 @@ def import_fname(fname,name):
return g return g
def tinypy(): def tinypy():
print("tinypy called")
return import_fname(ARGV[0],'__main__') return import_fname(ARGV[0],'__main__')
def main(src,dest): def main(src,dest):
@ -52,5 +50,4 @@ def main(src,dest):
save(dest,r) save(dest,r)
if __name__ == '__main__': if __name__ == '__main__':
print("Running main")
main(ARGV[1],ARGV[2]) main(ARGV[1],ARGV[2])

View File

@ -1,25 +1,16 @@
#include "tp.c" #include "tp.c"
/* INCLUDE */ /* INCLUDE */
const char header[]="TinyPy for kolibriOS"; const char header[]="TinyPy for kolibriOS";
const int argc = 2;
extern _stdcall void kolibri_dbg_init(tp_vm *tp); extern _stdcall void kolibri_dbg_init(tp_vm *tp);
void main(void) { void main(int argc, const char *argv[]) {
char *argv[2]={"tpmain", "test.py"};
CONSOLE_INIT(header);
con_printf("TinyPy console, version 1.1.\n");
con_printf("Enter program file:");
if (!(argv[1] = malloc(256)))
con_printf("Memory error\n");
con_gets(argv[1], 256);
argv[1][strlen(argv[1]) - 1] = '\0';
con_printf("Running file %s\n", argv[1]);
tp_vm *tp = tp_init(argc, argv); tp_vm *tp = tp_init(argc, argv);
kolibri_dbg_init(tp); kolibri_dbg_init(tp);
kolibri_init(tp); kolibri_init(tp);
CONSOLE_INIT(header);
/* INIT */ /* INIT */
tp_call(tp,"py2bc","tinypy",tp_None); tp_call(tp,"py2bc","tinypy",tp_None);
con_printf("Done");
tp_deinit(tp); tp_deinit(tp);
kol_exit(); kol_exit();
return; return;

View File

@ -84,12 +84,7 @@ TP_FNC, TP_DATA.
- ¨â¥à â®àë ¨ ᮯணࠬ¬; - ¨â¥à â®àë ¨ ᮯணࠬ¬;
- ᨭ⠪á¨ç¥áª¨© "á å à" ¤«ï ®¡ê¥­¨ï ᯨ᪮¢ ¨ á«®¢ à¥©, ­ ¯®¤®¡¨¥ - ᨭ⠪á¨ç¥áª¨© "á å à" ¤«ï ®¡ê¥­¨ï ᯨ᪮¢ ¨ á«®¢ à¥©, ­ ¯®¤®¡¨¥
odd_squares = [a*a for a in range(100) if a%2]; odd_squares = [a*a for a in range(100) if a%2];
- ¨­â¥à ªâ¨¢­ ï ª®­á®«ì - ¨­â¥à ªâ¨¢­ ï ª®­á®«ì.
- ¯¥à¥¤ ç  ¯ à ¬¥â஢ ç¥à¥§ ARGV
¡¨¡«¨®â¥ª¥ menuetlibc ¯à®æ¥¤ãà  à §¡®à  ¯ à ¬¥â஢ ª®¬ ­¤­®© áâப¨ ¯®ª 
­¥  ¤ ¯â¨à®¢ ­  ¤«ï Š®«¨¡à¨Ž‘, ¯®í⮬㠯ਠ§ ¯ã᪥ TinyPy ¯à¨å®¤¨âáï ¢¢®¤¨âì
¨¬ï ä ©«  ¢àãç­ãî, â ª¦¥ ­¥«ì§ï ¯¥à¥¤ ¢ âì ¯ à ¬¥âàë ¢ ª®¬ ­¤­®© áâப¥.
ˆ ª®­¥ç­®, ­¥ 墠⠥⠮᭮¢­®© ᨫë Python - ¥£® áâ ­¤ àâ­®© ¡¨¡«¨®â¥ª¨. ˆ ª®­¥ç­®, ­¥ 墠⠥⠮᭮¢­®© ᨫë Python - ¥£® áâ ­¤ àâ­®© ¡¨¡«¨®â¥ª¨.
@ -116,11 +111,15 @@ if __name__=="__main__":
math.square(12) math.square(12)
‚­ ç «¥ ­ã¦­® ᪮¬¯¨«¨à®¢ âì ¬®¤ã«ì math.py ¢ ¡ ©â-ª®¤ ¯à¨ ¯®¬®é¨ ¯à®£à ¬¬ë ‚­ ç «¥ ­ã¦­® ᪮¬¯¨«¨à®¢ âì ¬®¤ã«ì math.py ¢ ¡ ©â-ª®¤ ¯à¨ ¯®¬®é¨ ¯à®£à ¬¬ë
py2bc.py, ®­  à ¡®â ¥â ª ª ¢ Python, â ª ¨ ¢ TinyPy. ¯®á«¥¤­¥¬ á«ãç ¥ ­ã¦­® py2bc.py, ®­  à ¡®â ¥â ª ª ¢ Python, â ª ¨ ¢ TinyPy. ‡ ¯ã᪠¥¬ shell ¨ ¢ë¯®«­ï¥¬ ª®¬ ­¤ã
㪠§ âì £«®¡ «ì­ë© ¬ áᨢ ARGV=[0, 'math.py', 'math.tpc'], â ª ª ª ¯¥à¥¤ âì # tinypy py2bc.py math.py math.tpc
¯ à ¬¥âàë ç¥à¥§ ª®¬ ­¤­ãî áâப㠯®ª  ­¥«ì§ï. <20>®á«¥ í⮣® ¬®¦­® § ¯ãáâ¨âì
prog.py ¨§ TinyPy. ‘¨­â ªá¨á "from module import function" ¯®ª  ­¥ <20>®á«¥ í⮣® ¬®¦­® § ¯ãáâ¨âì prog.py ¨§ TinyPy.
¯®¤¤¥à¦¨¢ ¥âáï.
# tinypy prog.py
144
‡ ¬¥ç ­¨¥: ᨭ⠪á¨á "from module import function" ¯®ª  ­¥ ¯®¤¤¥à¦¨¢ ¥âáï.
3.2 Œ®¤ã«¨ ­  C. 3.2 Œ®¤ã«¨ ­  C.