Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; Python object types
  2. TP_NONE         equ 0
  3. TP_NUMBER       equ 1
  4. TP_STRING       equ 2
  5. TP_DICT         equ 3
  6. TP_LIST         equ 4
  7. TP_FNC          equ 5
  8. TP_DATA         equ 6
  9.  
  10. ; Python "number" object. Can be treated as integer or float.
  11. struct tp_number_
  12.   type rd 1
  13.   val  rd 1
  14. ends
  15.  
  16. ; GC information for "string" object
  17. struct _tp_string
  18.   gci rd 1
  19.   s   rb 1
  20. ends
  21.  
  22. ; Python "string" object
  23. struct tp_string_
  24.   type rd 1
  25.   info rd 1 ;pointer to _tp_string
  26.   val  rd 1
  27.   len  rd 1
  28. ends
  29.  
  30. ; GC information for "list" object
  31. struct _tp_list
  32.   gci   rd 1
  33.   items rd 1
  34.   len   rd 1
  35.   alloc rd 1
  36. ends
  37.  
  38. ; Python "list" object
  39. struct tp_list_
  40.   type  rd 1
  41.   val   rd 1 ;pointer to _tp_list
  42. ends
  43.  
  44.  
  45. ; GC information for "dict" object
  46. struct _tp_dict
  47.   gci   rd 1
  48.   items rd 1
  49.   len   rd 1
  50.   alloc rd 1
  51.   cur   rd 1
  52.   mask  rd 1
  53.   used  rd 1
  54. ends
  55.  
  56. ; Python "dict" object
  57. struct tp_dict_
  58.   type  rd 1
  59.   val   rd 1 ;pointer to _tp_dict
  60. ends
  61.  
  62. ; GC information for "function" object
  63. ; todo
  64.  
  65. ; Python "function" object
  66. struct tp_fnc_
  67.   type  rd 1
  68.   info  rd 1
  69.   ftype rd 1
  70.   val   rd 1
  71. ends
  72.  
  73. ; Python "data" object
  74. struct tp_data_
  75.   type  rd 1
  76.   info  rd 1
  77.   val   rd 1
  78.   magic rd 1
  79. ends
  80.  
  81. struct tp_gc_info
  82.   type  rd 1
  83.   data  rd 1
  84. ends
  85.  
  86. ; Generic Python object
  87. struct tp_obj
  88. union
  89.   type  rd 1
  90.   string tp_string_
  91.   number tp_number_
  92.   gc_info tp_gc_info
  93.   dict tp_dict_
  94.   list tp_list_
  95.   fnc  tp_fnc_
  96.   dat tp_data_
  97. ends
  98. ends
  99.  
  100. ; Bytecode element
  101. struct sregs
  102.   .i rb 1
  103.   .a rb 1
  104.   .b rb 1
  105.   .c rb 1
  106. ends
  107.  
  108. struct tp_code
  109. union
  110.   i      rb 1
  111.   regs   sregs
  112.   string rb 4
  113.   number rp 1
  114. ends
  115. ends
  116.  
  117. ; TinyPy VM frame
  118. struct tp_frame_
  119.   .codes    rd      1
  120.   .cur      rd      1
  121.   .jump     rd      1
  122.   .regs     rd      1
  123.   .ret_dest rd      1
  124.   .fname    rb      sizeof.tp_obj
  125.   .name     rb      sizeof.tp_obj
  126.   .line     rb      sizeof.tp_obj
  127.   .globals  rb      sizeof.tp_obj
  128.   .lineno   rd      1
  129.   .cregs    rd      1
  130. ends
  131.  
  132. ; TinyPy VM
  133. TP_FRAMES equ 256
  134. struct tp_vm
  135.   builtins rb  sizeof.tp_obj
  136.   modules  rb  sizeof.tp_obj
  137.   frames   rb  TP_FRAMES*sizeof.tp_frame_
  138.   _params  rb  sizeof.tp_obj
  139.   params   rb  sizeof.tp_obj
  140.   _regs    rb  sizeof.tp_obj
  141.   regs     rq  1
  142.   root     rb  sizeof.tp_obj
  143.   jmp_buf  rd     1
  144.   jump     rd     1
  145.   ex       rb  sizeof.tp_obj
  146.   chars    rb  512
  147.   cur      rd     1
  148.   white    rb  sizeof._tp_list
  149.   grey     rb  sizeof._tp_list
  150.   black    rb  sizeof._tp_list
  151.   strings  rb  sizeof._tp_dict
  152.   steps    rd     1
  153. ends
  154.  
  155. macro push_tp_obj obj
  156. {
  157.     local .push_more
  158.     mov  ebx, obj + 12
  159.     mov  ecx, 4
  160. .push_more:
  161.     push dword[ebx]
  162.     sub  ebx, 4
  163.     loop .push_more
  164. }
  165.  
  166. macro push_tp_obj_at_reg reg
  167. {
  168.     local .push_more
  169.     add reg, 12
  170.     mov ecx, 4
  171. .push_more:
  172.     push dword[reg]
  173.     sub  reg, 4
  174.     loop .push_more
  175. }
  176.