Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2. ================================================================================
  3.  
  4. tinypy contains tinypy code licensed in a MIT format license.  It also
  5. contains some goodies grabbed from Python, so that license is included
  6. as well.
  7.  
  8. ================================================================================
  9.  
  10. The tinypy License
  11.  
  12. Copyright (c) 2008 Phil Hassey
  13.  
  14. Permission is hereby granted, free of charge, to any person obtaining a copy
  15. of this software and associated documentation files (the "Software"), to deal
  16. in the Software without restriction, including without limitation the rights
  17. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  18. copies of the Software, and to permit persons to whom the Software is
  19. furnished to do so, subject to the following conditions:
  20.  
  21. The above copyright notice and this permission notice shall be included in
  22. all copies or substantial portions of the Software.
  23.  
  24. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30. THE SOFTWARE.
  31.  
  32. ================================================================================
  33.  
  34. PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
  35. --------------------------------------------
  36.  
  37. 1. This LICENSE AGREEMENT is between the Python Software Foundation
  38. ("PSF"), and the Individual or Organization ("Licensee") accessing and
  39. otherwise using this software ("Python") in source or binary form and
  40. its associated documentation.
  41.  
  42. 2. Subject to the terms and conditions of this License Agreement, PSF
  43. hereby grants Licensee a nonexclusive, royalty-free, world-wide
  44. license to reproduce, analyze, test, perform and/or display publicly,
  45. prepare derivative works, distribute, and otherwise use Python
  46. alone or in any derivative version, provided, however, that PSF's
  47. License Agreement and PSF's notice of copyright, i.e., "Copyright (c)
  48. 2001, 2002, 2003, 2004, 2005, 2006, 2007 Python Software Foundation;
  49. All Rights Reserved" are retained in Python alone or in any derivative
  50. version prepared by Licensee.
  51.  
  52. 3. In the event Licensee prepares a derivative work that is based on
  53. or incorporates Python or any part thereof, and wants to make
  54. the derivative work available to others as provided herein, then
  55. Licensee hereby agrees to include in any such work a brief summary of
  56. the changes made to Python.
  57.  
  58. 4. PSF is making Python available to Licensee on an "AS IS"
  59. basis.  PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
  60. IMPLIED.  BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
  61. DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
  62. FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
  63. INFRINGE ANY THIRD PARTY RIGHTS.
  64.  
  65. 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
  66. FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
  67. A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
  68. OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
  69.  
  70. 6. This License Agreement will automatically terminate upon a material
  71. breach of its terms and conditions.
  72.  
  73. 7. Nothing in this License Agreement shall be deemed to create any
  74. relationship of agency, partnership, or joint venture between PSF and
  75. Licensee.  This License Agreement does not grant permission to use PSF
  76. trademarks or trade name in a trademark sense to endorse or promote
  77. products or services of Licensee, or any third party.
  78.  
  79. 8. By copying, installing or otherwise using Python, Licensee
  80. agrees to be bound by the terms and conditions of this License
  81. Agreement.
  82.  
  83. ================================================================================
  84. */
  85.  
  86. #ifndef TINYPY_H
  87. #define TINYPY_H
  88. /* File: General
  89.  * Things defined in tp.h.
  90.  */
  91. #ifndef TP_H
  92. #define TP_H
  93.  
  94. #include <setjmp.h>
  95. #include <sys/stat.h>
  96. #ifndef __USE_ISOC99
  97. #define __USE_ISOC99
  98. #endif
  99. #include <stdio.h>
  100. #include <stdlib.h>
  101. #include <string.h>
  102. #include <stdarg.h>
  103. #include <math.h>
  104. #include <time.h>
  105.  
  106. #ifdef __GNUC__
  107. #define tp_inline __inline__
  108. #endif
  109.  
  110. #ifdef _MSC_VER
  111. #ifdef NDEBUG
  112. #define tp_inline __inline
  113. #else
  114. /* don't inline in debug builds (for easier debugging) */
  115. #define tp_inline
  116. #endif
  117. #endif
  118.  
  119. #ifndef tp_inline
  120. #error "Unsuported compiler"
  121. #endif
  122.  
  123. /*  #define tp_malloc(x) calloc((x),1)
  124.     #define tp_realloc(x,y) realloc(x,y)
  125.     #define tp_free(x) free(x) */
  126.  
  127. /* #include <gc/gc.h>
  128.    #define tp_malloc(x) GC_MALLOC(x)
  129.    #define tp_realloc(x,y) GC_REALLOC(x,y)
  130.    #define tp_free(x)*/
  131.  
  132. enum {
  133.     TP_NONE,TP_NUMBER,TP_STRING,TP_DICT,
  134.     TP_LIST,TP_FNC,TP_DATA,
  135. };
  136.  
  137. typedef double tp_num;
  138.  
  139. typedef struct tp_number_ {
  140.     int type;
  141.     tp_num val;
  142. } tp_number_;
  143. typedef struct tp_string_ {
  144.     int type;
  145.     struct _tp_string *info;
  146.     char const *val;
  147.     int len;
  148. } tp_string_;
  149. typedef struct tp_list_ {
  150.     int type;
  151.     struct _tp_list *val;
  152. } tp_list_;
  153. typedef struct tp_dict_ {
  154.     int type;
  155.     struct _tp_dict *val;
  156.     int dtype;
  157. } tp_dict_;
  158. typedef struct tp_fnc_ {
  159.     int type;
  160.     struct _tp_fnc *info;
  161.     int ftype;
  162.     void *cfnc;
  163. } tp_fnc_;
  164. typedef struct tp_data_ {
  165.     int type;
  166.     struct _tp_data *info;
  167.     void *val;
  168.     int magic;
  169. } tp_data_;
  170.  
  171. /* Type: tp_obj
  172.  * Tinypy's object representation.
  173.  *
  174.  * Every object in tinypy is of this type in the C API.
  175.  *
  176.  * Fields:
  177.  * type - This determines what kind of objects it is. It is either TP_NONE, in
  178.  *        which case this is the none type and no other fields can be accessed.
  179.  *        Or it has one of the values listed below, and the corresponding
  180.  *        fields can be accessed.
  181.  * number - TP_NUMBER
  182.  * number.val - A double value with the numeric value.
  183.  * string - TP_STRING
  184.  * string.val - A pointer to the string data.
  185.  * string.len - Length in bytes of the string data.
  186.  * dict - TP_DICT
  187.  * list - TP_LIST
  188.  * fnc - TP_FNC
  189.  * data - TP_DATA
  190.  * data.val - The user-provided data pointer.
  191.  * data.magic - The user-provided magic number for identifying the data type.
  192.  */
  193. typedef union tp_obj {
  194.     int type;
  195.     tp_number_ number;
  196.     struct { int type; int *data; } gci;
  197.     tp_string_ string;
  198.     tp_dict_ dict;
  199.     tp_list_ list;
  200.     tp_fnc_ fnc;
  201.     tp_data_ data;
  202. } tp_obj;
  203.  
  204. typedef struct _tp_string {
  205.     int gci;
  206.     int len;
  207.     char s[1];
  208. } _tp_string;
  209. typedef struct _tp_list {
  210.     int gci;
  211.     tp_obj *items;
  212.     int len;
  213.     int alloc;
  214. } _tp_list;
  215. typedef struct tp_item {
  216.     int used;
  217.     int hash;
  218.     tp_obj key;
  219.     tp_obj val;
  220. } tp_item;
  221. typedef struct _tp_dict {
  222.     int gci;
  223.     tp_item *items;
  224.     int len;
  225.     int alloc;
  226.     int cur;
  227.     int mask;
  228.     int used;
  229.     tp_obj meta;
  230. } _tp_dict;
  231. typedef struct _tp_fnc {
  232.     int gci;
  233.     tp_obj self;
  234.     tp_obj globals;
  235.     tp_obj code;
  236. } _tp_fnc;
  237.  
  238.  
  239. typedef union tp_code {
  240.     unsigned char i;
  241.     struct { unsigned char i,a,b,c; } regs;
  242.     struct { char val[4]; } string;
  243.     struct { float val; } number;
  244. } tp_code;
  245.  
  246. typedef struct tp_frame_ {
  247. /*    tp_code *codes; */
  248.     tp_obj code;
  249.     tp_code *cur;
  250.     tp_code *jmp;
  251.     tp_obj *regs;
  252.     tp_obj *ret_dest;
  253.     tp_obj fname;
  254.     tp_obj name;
  255.     tp_obj line;
  256.     tp_obj globals;
  257.     int lineno;
  258.     int cregs;
  259. } tp_frame_;
  260.  
  261. #define TP_GCMAX 4096
  262. #define TP_FRAMES 256
  263. #define TP_REGS_EXTRA 2
  264. /* #define TP_REGS_PER_FRAME 256*/
  265. #define TP_REGS 16384
  266.  
  267. /* Type: tp_vm
  268.  * Representation of a tinypy virtual machine instance.
  269.  *
  270.  * A new tp_vm struct is created with <tp_init>, and will be passed to most
  271.  * tinypy functions as first parameter. It contains all the data associated
  272.  * with an instance of a tinypy virtual machine - so it is easy to have
  273.  * multiple instances running at the same time. When you want to free up all
  274.  * memory used by an instance, call <tp_deinit>.
  275.  *
  276.  * Fields:
  277.  * These fields are currently documented:
  278.  *
  279.  * builtins - A dictionary containing all builtin objects.
  280.  * modules - A dictionary with all loaded modules.
  281.  * params - A list of parameters for the current function call.
  282.  * frames - A list of all call frames.
  283.  * cur - The index of the currently executing call frame.
  284.  * frames[n].globals - A dictionary of global sybmols in callframe n.
  285.  */
  286. typedef struct tp_vm {
  287.     tp_obj builtins;
  288.     tp_obj modules;
  289.     tp_frame_ frames[TP_FRAMES];
  290.     tp_obj _params;
  291.     tp_obj params;
  292.     tp_obj _regs;
  293.     tp_obj *regs;
  294.     tp_obj root;
  295.     jmp_buf buf;
  296. #ifdef CPYTHON_MOD
  297.     jmp_buf nextexpr;
  298. #endif
  299.     int jmp;
  300.     tp_obj ex;
  301.     char chars[256][2];
  302.     int cur;
  303.     /* gc */
  304.     _tp_list *white;
  305.     _tp_list *grey;
  306.     _tp_list *black;
  307.     int steps;
  308.     /* sandbox */
  309.     clock_t clocks;
  310.     double time_elapsed;
  311.     double time_limit;
  312.     unsigned long mem_limit;
  313.     unsigned long mem_used;
  314.     int mem_exceeded;
  315. } tp_vm;
  316.  
  317. #define TP tp_vm *tp
  318. typedef struct _tp_data {
  319.     int gci;
  320.     void (*free)(TP,tp_obj);
  321. } _tp_data;
  322.  
  323. #define tp_True tp_number(1)
  324. #define tp_False tp_number(0)
  325.  
  326. extern tp_obj tp_None;
  327.  
  328. #ifdef TP_SANDBOX
  329. void *tp_malloc(TP, unsigned long);
  330. void *tp_realloc(TP, void *, unsigned long);
  331. void tp_free(TP, void *);
  332. #else
  333. #define tp_malloc(TP,x) calloc((x),1)
  334. #define tp_realloc(TP,x,y) realloc(x,y)
  335. #define tp_free(TP,x) free(x)
  336. #endif
  337.  
  338. void tp_sandbox(TP, double, unsigned long);
  339. void tp_time_update(TP);
  340. void tp_mem_update(TP);
  341.  
  342. void tp_run(TP,int cur);
  343. void tp_set(TP,tp_obj,tp_obj,tp_obj);
  344. tp_obj tp_get(TP,tp_obj,tp_obj);
  345. tp_obj tp_has(TP,tp_obj self, tp_obj k);
  346. tp_obj tp_len(TP,tp_obj);
  347. void tp_del(TP,tp_obj,tp_obj);
  348. tp_obj tp_str(TP,tp_obj);
  349. int tp_bool(TP,tp_obj);
  350. int tp_cmp(TP,tp_obj,tp_obj);
  351. void _tp_raise(TP,tp_obj);
  352. tp_obj tp_printf(TP,char const *fmt,...);
  353. tp_obj tp_track(TP,tp_obj);
  354. void tp_grey(TP,tp_obj);
  355. tp_obj tp_call(TP, tp_obj fnc, tp_obj params);
  356. tp_obj tp_add(TP,tp_obj a, tp_obj b) ;
  357.  
  358. /* __func__ __VA_ARGS__ __FILE__ __LINE__ */
  359.  
  360. /* Function: tp_raise
  361.  * Macro to raise an exception.
  362.  *
  363.  * This macro will return from the current function returning "r". The
  364.  * remaining parameters are used to format the exception message.
  365.  */
  366.  
  367. #define tp_raise_f(r,fmt,...) { \
  368.     _tp_raise(tp,tp_printf(tp,fmt,__VA_ARGS__)); \
  369.     return r; \
  370. }
  371.  
  372. #define tp_raise(r,v) { \
  373.     _tp_raise(tp,v); \
  374.     return r; \
  375. }
  376.  
  377. /* Function: tp_string
  378.  * Creates a new string object from a C string.
  379.  *
  380.  * Given a pointer to a C string, creates a tinypy object representing the
  381.  * same string.
  382.  *
  383.  * *Note* Only a reference to the string will be kept by tinypy, so make sure
  384.  * it does not go out of scope, and don't de-allocate it. Also be aware that
  385.  * tinypy will not delete the string for you. In many cases, it is best to
  386.  * use <tp_string_t> or <tp_string_slice> to create a string where tinypy
  387.  * manages storage for you.
  388.  */
  389. tp_inline static tp_obj tp_string(char const *v) {
  390.     tp_obj val;
  391.     tp_string_ s = {TP_STRING, 0, v, 0};
  392.     s.len = strlen(v);
  393.     val.string = s;
  394.     return val;
  395. }
  396.  
  397. #define TP_CSTR_LEN 256
  398. #define TP_CSTR(v) ((tp_str(tp,(v))).string.val)
  399.  
  400. tp_inline static void tp_cstr(TP,tp_obj v, char *s, int l) {
  401.     if (v.type != TP_STRING) {
  402.         tp_raise(,tp_string("(tp_cstr) TypeError: value not a string"));
  403.     }
  404.     if (v.string.len >= l) {
  405.         tp_raise(,tp_string("(tp_cstr) TypeError: value too long"));
  406.     }
  407.     memset(s,0,l);
  408.     memcpy(s,v.string.val,v.string.len);
  409. }
  410.  
  411.  
  412. #define TP_OBJ() (tp_get(tp,tp->params,tp_None))
  413. tp_inline static tp_obj tp_type(TP,int t,tp_obj v) {
  414.     if (v.type != t) { tp_raise(tp_None,tp_string("(tp_type) TypeError: unexpected type")); }
  415.     return v;
  416. }
  417.  
  418.  
  419.  
  420. #define TP_NO_LIMIT 0
  421. #define TP_TYPE(t) tp_type(tp,t,TP_OBJ())
  422. #define TP_NUM() (TP_TYPE(TP_NUMBER).number.val)
  423. /* #define TP_STR() (TP_CSTR(TP_TYPE(TP_STRING))) */
  424. #define TP_STR() (TP_TYPE(TP_STRING))
  425. #define TP_DEFAULT(d) (tp->params.list.val->len?tp_get(tp,tp->params,tp_None):(d))
  426.  
  427. /* Macro: TP_LOOP
  428.  * Macro to iterate over all remaining arguments.
  429.  *
  430.  * If you have a function which takes a variable number of arguments, you can
  431.  * iterate through all remaining arguments for example like this:
  432.  *
  433.  * > tp_obj *my_func(tp_vm *tp)
  434.  * > {
  435.  * >     // We retrieve the first argument like normal.
  436.  * >     tp_obj first = TP_OBJ();
  437.  * >     // Then we iterate over the remaining arguments.
  438.  * >     tp_obj arg;
  439.  * >     TP_LOOP(arg)
  440.  * >         // do something with arg
  441.  * >     TP_END
  442.  * > }
  443.  */
  444. #define TP_LOOP(e) \
  445.     int __l = tp->params.list.val->len; \
  446.     int __i; for (__i=0; __i<__l; __i++) { \
  447.     (e) = _tp_list_get(tp,tp->params.list.val,__i,"TP_LOOP");
  448. #define TP_END \
  449.     }
  450.  
  451. tp_inline static int _tp_min(int a, int b) { return (a<b?a:b); }
  452. tp_inline static int _tp_max(int a, int b) { return (a>b?a:b); }
  453. tp_inline static int _tp_sign(tp_num v) { return (v<0?-1:(v>0?1:0)); }
  454.  
  455. /* Function: tp_number
  456.  * Creates a new numeric object.
  457.  */
  458. tp_inline static tp_obj tp_number(tp_num v) {
  459.     tp_obj val = {TP_NUMBER};
  460.     val.number.val = v;
  461.     return val;
  462. }
  463.  
  464. tp_inline static void tp_echo(TP,tp_obj e) {
  465.     e = tp_str(tp,e);
  466.     fwrite(e.string.val,1,e.string.len,stdout);
  467. }
  468.  
  469. /* Function: tp_string_n
  470.  * Creates a new string object from a partial C string.
  471.  *
  472.  * Like <tp_string>, but you specify how many bytes of the given C string to
  473.  * use for the string object. The *note* also applies for this function, as the
  474.  * string reference and length are kept, but no actual substring is stored.
  475.  */
  476. tp_inline static tp_obj tp_string_n(char const *v,int n) {
  477.     tp_obj val;
  478.     tp_string_ s = {TP_STRING, 0,v,n};
  479.     val.string = s;
  480.     return val;
  481. }
  482.  
  483. #endif
  484. void _tp_list_realloc(TP, _tp_list *self,int len) ;
  485. void _tp_list_set(TP,_tp_list *self,int k, tp_obj v, const char *error) ;
  486. void _tp_list_free(TP, _tp_list *self) ;
  487. tp_obj _tp_list_get(TP,_tp_list *self,int k,const char *error) ;
  488. void _tp_list_insertx(TP,_tp_list *self, int n, tp_obj v) ;
  489. void _tp_list_appendx(TP,_tp_list *self, tp_obj v) ;
  490. void _tp_list_insert(TP,_tp_list *self, int n, tp_obj v) ;
  491. void _tp_list_append(TP,_tp_list *self, tp_obj v) ;
  492. tp_obj _tp_list_pop(TP,_tp_list *self, int n, const char *error) ;
  493. int _tp_list_find(TP,_tp_list *self, tp_obj v) ;
  494. tp_obj tp_index(TP) ;
  495. _tp_list *_tp_list_new(TP) ;
  496. tp_obj _tp_list_copy(TP, tp_obj rr) ;
  497. tp_obj tp_append(TP) ;
  498. tp_obj tp_pop(TP) ;
  499. tp_obj tp_insert(TP) ;
  500. tp_obj tp_extend(TP) ;
  501. tp_obj tp_list_nt(TP) ;
  502. tp_obj tp_list(TP) ;
  503. tp_obj tp_list_n(TP,int n,tp_obj *argv) ;
  504. int _tp_sort_cmp(tp_obj *a,tp_obj *b) ;
  505. tp_obj tp_sort(TP) ;
  506. int tp_lua_hash(void const *v,int l) ;
  507. void _tp_dict_free(TP, _tp_dict *self) ;
  508. int tp_hash(TP,tp_obj v) ;
  509. void _tp_dict_hash_set(TP,_tp_dict *self, int hash, tp_obj k, tp_obj v) ;
  510. void _tp_dict_tp_realloc(TP,_tp_dict *self,int len) ;
  511. int _tp_dict_hash_find(TP,_tp_dict *self, int hash, tp_obj k) ;
  512. int _tp_dict_find(TP,_tp_dict *self,tp_obj k) ;
  513. void _tp_dict_setx(TP,_tp_dict *self,tp_obj k, tp_obj v) ;
  514. void _tp_dict_set(TP,_tp_dict *self,tp_obj k, tp_obj v) ;
  515. tp_obj _tp_dict_get(TP,_tp_dict *self,tp_obj k, const char *error) ;
  516. void _tp_dict_del(TP,_tp_dict *self,tp_obj k, const char *error) ;
  517. _tp_dict *_tp_dict_new(TP) ;
  518. tp_obj _tp_dict_copy(TP,tp_obj rr) ;
  519. int _tp_dict_next(TP,_tp_dict *self) ;
  520. tp_obj tp_merge(TP) ;
  521. tp_obj tp_dict(TP) ;
  522. tp_obj tp_dict_n(TP,int n, tp_obj* argv) ;
  523. tp_obj _tp_dcall(TP,tp_obj fnc(TP)) ;
  524. tp_obj _tp_tcall(TP,tp_obj fnc) ;
  525. tp_obj tp_fnc_new(TP,int t, void *v, tp_obj c,tp_obj s, tp_obj g) ;
  526. tp_obj tp_def(TP,tp_obj code, tp_obj g) ;
  527. tp_obj tp_fnc(TP,tp_obj v(TP)) ;
  528. tp_obj tp_method(TP,tp_obj self,tp_obj v(TP)) ;
  529. tp_obj tp_data(TP,int magic,void *v) ;
  530. tp_obj tp_params(TP) ;
  531. tp_obj tp_params_n(TP,int n, tp_obj argv[]) ;
  532. tp_obj tp_params_v(TP,int n,...) ;
  533. tp_obj tp_string_t(TP, int n) ;
  534. tp_obj tp_string_copy(TP, const char *s, int n) ;
  535. tp_obj tp_string_sub(TP, tp_obj s, int a, int b) ;
  536. int _tp_str_index(tp_obj s, tp_obj k) ;
  537. tp_obj tp_join(TP) ;
  538. tp_obj tp_split(TP) ;
  539. tp_obj tp_find(TP) ;
  540. tp_obj tp_str_index(TP) ;
  541. tp_obj tp_str2(TP) ;
  542. tp_obj tp_chr(TP) ;
  543. tp_obj tp_ord(TP) ;
  544. tp_obj tp_strip(TP) ;
  545. tp_obj tp_replace(TP) ;
  546. tp_obj tp_print(TP) ;
  547. tp_obj tp_bind(TP) ;
  548. tp_obj tp_min(TP) ;
  549. tp_obj tp_max(TP) ;
  550. tp_obj tp_copy(TP) ;
  551. tp_obj tp_len_(TP) ;
  552. tp_obj tp_assert(TP) ;
  553. tp_obj tp_range(TP) ;
  554. tp_obj tp_system(TP) ;
  555. tp_obj tp_istype(TP) ;
  556. tp_obj tp_float(TP) ;
  557. tp_obj tp_save(TP) ;
  558. tp_obj tp_load(TP) ;
  559. tp_obj tp_fpack(TP) ;
  560. tp_obj tp_abs(TP) ;
  561. tp_obj tp_int(TP) ;
  562. tp_num _roundf(tp_num v) ;
  563. tp_obj tp_round(TP) ;
  564. tp_obj tp_exists(TP) ;
  565. tp_obj tp_mtime(TP) ;
  566. int _tp_lookup_(TP,tp_obj self, tp_obj k, tp_obj *meta, int depth) ;
  567. int _tp_lookup(TP,tp_obj self, tp_obj k, tp_obj *meta) ;
  568. tp_obj tp_setmeta(TP) ;
  569. tp_obj tp_getmeta(TP) ;
  570. tp_obj tp_object(TP) ;
  571. tp_obj tp_object_new(TP) ;
  572. tp_obj tp_object_call(TP) ;
  573. tp_obj tp_getraw(TP) ;
  574. tp_obj tp_class(TP) ;
  575. tp_obj tp_builtins_bool(TP) ;
  576. void tp_follow(TP,tp_obj v) ;
  577. void tp_reset(TP) ;
  578. void tp_gc_init(TP) ;
  579. void tp_gc_deinit(TP) ;
  580. void tp_delete(TP,tp_obj v) ;
  581. void tp_collect(TP) ;
  582. void _tp_gcinc(TP) ;
  583. void tp_full(TP) ;
  584. void tp_gcinc(TP) ;
  585. tp_obj tp_iter(TP,tp_obj self, tp_obj k) ;
  586. int tp_iget(TP,tp_obj *r, tp_obj self, tp_obj k) ;
  587. tp_obj tp_mul(TP,tp_obj a, tp_obj b) ;
  588. tp_obj tp_bitwise_not(TP, tp_obj a) ;
  589. tp_vm *_tp_init(void) ;
  590. void tp_deinit(TP) ;
  591. void tp_frame(TP,tp_obj globals,tp_obj code,tp_obj *ret_dest) ;
  592. void tp_print_stack(TP) ;
  593. void tp_handle(TP) ;
  594. void tp_return(TP, tp_obj v) ;
  595. int tp_step(TP) ;
  596. void _tp_run(TP,int cur) ;
  597. tp_obj tp_ez_call(TP, const char *mod, const char *fnc, tp_obj params) ;
  598. tp_obj _tp_import(TP, tp_obj fname, tp_obj name, tp_obj code) ;
  599. tp_obj tp_import(TP, const char * fname, const char * name, void *codes, int len) ;
  600. tp_obj tp_exec_(TP) ;
  601. tp_obj tp_import_(TP) ;
  602. void tp_builtins(TP) ;
  603. void tp_args(TP,int argc, char *argv[]) ;
  604. tp_obj tp_main(TP,char *fname, void *code, int len) ;
  605. tp_obj tp_compile(TP, tp_obj text, tp_obj fname) ;
  606. tp_obj tp_exec(TP, tp_obj code, tp_obj globals) ;
  607. tp_obj tp_eval(TP, const char *text, tp_obj globals) ;
  608. tp_vm *tp_init(int argc, char *argv[]) ;
  609. void tp_compiler(TP) ;
  610. tp_obj tp_sandbox_(TP) ;
  611. void tp_bounds(TP, tp_code *cur, int n) ;
  612. #endif
  613.