Changeset 619


Ignore:
Timestamp:
08/01/10 18:12:03 (18 months ago)
Author:
mooneer
Message:

Converted Kite from linked list based virtual machine to a segmented VM (all bytecodes share one common text segment) for optimal cache locality. One million iteration basic loop now runs in ~0.725sec on a Core i7 MacBook? Pro. Bugs that cropped up in other areas of Kite as a result of this (and previous) changes were also fixed.

Location:
interpreter/trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • interpreter/trunk/backend/common/kite_compiler.c

    r594 r619  
    3232#include "objs/kite_object.h" 
    3333#include "kite_vm.h" 
     34#include "../kite-vm-1.0/kite_opcodes.h" 
    3435 
    3536typedef void* yyscan_t; 
     
    9192    kite_compiler_t *compiler; 
    9293    kite_object_t *ret; 
     94    kite_opcode_t *end_inst = kite_compile_return(); 
    9395     
    9496#ifndef HAVE_GC_H 
     
    117119         
    118120    ret = kite_pop_stack(&compiler->obj_created); 
     121    COMPILE_INSTRUCTION2(thd, compiler, end_inst, 0, &ret->builtin_data.funcvalue.funcptr); 
    119122    kite_destroy_stack(&compiler->obj_created); 
    120123    kite_destroy_stack(&compiler->decide_exits); 
     
    147150{ 
    148151    kite_object_t *ret; 
     152    kite_opcode_t *end_inst = kite_compile_return(); 
    149153    yyscan_t scanner; 
    150154    kite_compiler_t *compiler; 
     
    178182 
    179183    ret = kite_pop_stack(&compiler->obj_created); 
     184    COMPILE_INSTRUCTION2(thd, compiler, end_inst, 0, &ret->builtin_data.funcvalue.funcptr);  
    180185    ret->builtin_data.funcvalue.functype = FUNC_BYTECODE; 
    181186#ifndef HAVE_GC_H 
  • interpreter/trunk/backend/common/kite_parser.y

    r597 r619  
    3434#include "objs/kite_object.h" 
    3535#include "kite_vm.h" 
     36#include "../kite-vm-1.0/kite_opcodes.h" 
    3637 
    3738#define YYPARSE_PARAM parm 
     
    200201        kite_thread_t *thd = compiler->thd; 
    201202        kite_object_t *obj = kite_top_stack(compiler->obj_created); 
    202  
     203        kite_opcode_t *opc; 
     204         
    203205#ifndef HAVE_GC_H 
    204206        kite_funccall_info_t *fcall = (kite_funccall_info_t*)malloc(sizeof(kite_funccall_info_t)); 
     
    215217        kite_push_stack(&thd->func_stack, FALSE, fcall); 
    216218         
     219        /* Skip over import statement when executing so that the code inside 
     220           the import doesn't get executed twice. */ 
     221        COMPILE_INSTRUCTION2(thd, compiler, kite_compile_jump_uncond(NULL), @2.first_line, &obj->builtin_data.funcvalue.funcptr); 
     222        opc = (void*)thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     223         
    217224        kite_dereference_and_load(thd, $<stringValue>2); 
     225         
     226        COMPILE_INSTRUCTION2(thd, compiler, kite_compile_nop(), @2.first_line, &obj->builtin_data.funcvalue.funcptr); 
     227        opc = (void*)opc + (long)thd->vm->text_segment; 
     228        opc->op_arg.jumpto = (void*)thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     229         
    218230        free($<stringValue>2); 
    219231 
     
    635647 
    636648optional_param_list: { 
    637         $<opValue>$ = (*kite_compiler_actions[COMPILE_EMPTY_PARAM_LIST])((kite_compiler_t*)yyget_extra(parm), 0); 
     649        $<opValue>$ = (*kite_compiler_actions[COMPILE_EMPTY_PARAM_LIST])((kite_compiler_t*)yyget_extra(parm), @0.first_line); 
    638650    } 
    639651    | param_list { 
  • interpreter/trunk/backend/common/kite_vm.c

    r599 r619  
    3131#include "objs/kite_gc.h" 
    3232#include "kite_vm.h" 
     33#include "../kite-vm-1.0/kite_opcodes.h" 
    3334 
    3435#ifdef WIN32 
     
    7778    kite_vm_t *ret; 
    7879    kite_thread_t *thd; 
     80    pthread_mutexattr_t compile_mtx_attr; 
    7981    int i = 0; 
    8082#ifdef WIN32 
     
    100102#ifndef WIN32 
    101103    pthread_mutex_init(&ret->gc_mtx, NULL); 
     104    pthread_mutexattr_init(&compile_mtx_attr); 
     105    pthread_mutexattr_settype(&compile_mtx_attr, PTHREAD_MUTEX_RECURSIVE); 
     106    pthread_mutex_init(&ret->compile_mtx, &compile_mtx_attr); 
    102107#else 
    103108    ret->gc_mtx = CreateMutex(NULL, FALSE, NULL); 
     109    /* Compile mutex is automatically recursive. */ 
     110    ret->compile_mtx = CreateMutex(NULL, FALSE, NULL); 
    104111#endif /* WIN32 */ 
    105112 
     
    112119#endif 
    113120 
     121    /* Initialize VM-wide text segment. */ 
     122#ifndef HAVE_GC_H 
     123    ret->text_segment = (kite_opcode_t*)calloc(1, sizeof(kite_opcode_t)); 
     124#else 
     125    ret->text_segment = (kite_opcode_t*)GC_malloc(sizeof(kite_opcode_t)); 
     126#endif /* HAVE_GC_H */ 
     127    ret->text_segment_length = sizeof(kite_opcode_t); 
     128    ret->cur_text_segment = 0; 
     129     
    114130    /* Force linkage of built-in modules */ 
    115131    kite_module_initialize_now(thd); 
     
    180196#ifndef WIN32 
    181197    pthread_mutex_destroy(&cur->gc_mtx); 
     198    pthread_mutex_destroy(&cur->compile_mtx); 
    182199#else 
    183200    CloseHandle(cur->gc_mtx); 
     201    CloseHandle(cur->compile_mtx); 
    184202#endif /* WIN32 */ 
    185203 
  • interpreter/trunk/backend/common/kite_vm.h

    r601 r619  
    270270#ifdef WIN32 
    271271    HANDLE gc_mtx /*! \private */; 
     272    HANDLE compile_mtx /*! \private */; 
    272273#else 
    273274    pthread_mutex_t gc_mtx /*! \private */; 
     275    pthread_mutex_t compile_mtx /*! \private */; 
    274276#endif /* WIN32 */ 
    275277#ifdef HAVE_GC_H 
     
    277279#endif /* HAVE_GC_H */ 
    278280    char **args /*! \private */; 
     281    struct kite_opcode_t *text_segment /*! \private */; 
     282    size_t cur_text_segment /*! \private */; 
     283    size_t text_segment_length /*! \private */; 
    279284} kite_vm_t /*! Virtual machine instance object. */; 
    280285 
     
    293298    kite_stack_t *obj_created /*! Currently created object. */; 
    294299    kite_stack_t *decide_exits /*! \private */; /* to fix ticket #17 and short-circuiting */ 
     300    kite_stack_t *decide_exit_locs /*! \private */; 
     301    kite_stack_t *decide_begins /*! \private */; 
     302    kite_stack_t *func_skip_locs /*! \private */; 
    295303    char *curStr /*! Current string being read. */; 
    296304} kite_compiler_t; 
     
    568576     fc_entry->this = t; \ 
    569577     fc_entry->locals = NULL; \ 
    570      fc_entry->file = ins->common.file; \ 
    571      fc_entry->line = ins->common.line; \ 
     578     fc_entry->file = ins->file; \ 
     579     fc_entry->line = ins->line; \ 
    572580     fc_entry->last_deref = NULL; \ 
    573581     fc_entry->last_deref_obj = NULL; \ 
     
    593601     fc_entry->this = t; \ 
    594602     fc_entry->locals = NULL; \ 
    595      fc_entry->file = ins->common.file; \ 
    596      fc_entry->line = ins->common.line; \ 
     603     fc_entry->file = ins->file; \ 
     604     fc_entry->line = ins->line; \ 
    597605     fc_entry->last_deref = NULL; \ 
    598606     fc_entry->last_deref_obj = NULL; \ 
     
    628636     fc_entry->this = t; \ 
    629637     fc_entry->locals = NULL; \ 
    630      fc_entry->file = ins->common.file; \ 
    631      fc_entry->line = ins->common.line; \ 
     638     fc_entry->file = ins->file; \ 
     639     fc_entry->line = ins->line; \ 
    632640     fc_entry->last_deref = NULL; \ 
    633641     fc_entry->last_deref_obj = NULL; \ 
     
    653661     fc_entry->this = t; \ 
    654662     fc_entry->locals = NULL; \ 
    655      fc_entry->file = ins->common.file; \ 
    656      fc_entry->line = ins->common.line; \ 
     663     fc_entry->file = ins->file; \ 
     664     fc_entry->line = ins->line; \ 
    657665     fc_entry->last_deref = NULL; \ 
    658666     fc_entry->last_deref_obj = NULL; \ 
  • interpreter/trunk/backend/kite-vm-1.0/kite_compile_bytecode.c

    r602 r619  
    1111        kite_thread_t *thd = compiler->thd; \ 
    1212        kite_object_t *cur = (kite_object_t*)kite_top_stack(compiler->obj_created); \ 
    13         COMPILE_INSTRUCTION2(compiler, i, j, &cur->builtin_data.funcvalue.funcptr); \ 
    14         (void)thd; \ 
     13        COMPILE_INSTRUCTION2(thd, compiler, i, j, &cur->builtin_data.funcvalue.funcptr); \ 
    1514        (void)cur; \ 
    1615    } 
    1716     
    18 void COMPILE_INSTRUCTION2(kite_compiler_t *compiler, kite_opcode_t *inst, int lno, void **dest)  
     17void COMPILE_INSTRUCTION2(kite_thread_t *thd, kite_compiler_t *compiler, kite_opcode_t *inst, int lno, void **dest)  
    1918    {  
    2019        kite_opcode_t *fptr = *dest; 
    2120        inst->file = strdup(compiler->file);  
    2221        inst->line = lno;  
    23         kite_add_to_instruction_list(&fptr, inst); 
     22        kite_add_to_instruction_list(thd, &fptr, inst); 
    2423        *dest = fptr; 
    2524    } 
     
    2726static void kite_optimize_increment(kite_compiler_t *compiler, kite_opcode_t *o1, kite_opcode_t *o2) 
    2827{ 
    29     kite_thread_t *thd = compiler->thd; 
     28    /*kite_thread_t *thd = compiler->thd; 
    3029    kite_opcode_push *p1 = (kite_opcode_push*)o1; 
    3130    kite_opcode_push *p2 = (kite_opcode_push*)o2; 
     
    4948            } 
    5049        } 
    51     } 
     50    }*/ 
    5251} 
    5352 
     
    8180        kite_new_method_bytecode(thd, NULL,  
    8281            kite_list_count(thd, param_list)); 
     82             
     83    /* Bypass declaration so we don't accidentally run the method. */         
     84    COMPILE_INSTRUCTION(kite_compile_jump_uncond(NULL), line); 
     85    kite_push_stack(&compiler->func_skip_locs, FALSE, compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t)); 
     86     
    8387    kite_push_stack(&compiler->obj_created, FALSE, 
    8488                    method); 
     
    9195{ 
    9296    kite_thread_t *thd = compiler->thd; 
    93     kite_object_t *obj = kite_pop_stack(&compiler->obj_created); 
    94     kite_object_t *parent = (kite_object_t*)kite_top_stack(compiler->obj_created); 
    95  
    96     (void)line; 
     97    kite_object_t *obj; 
     98    kite_object_t *parent; 
     99    void *pc; 
     100    kite_opcode_t *opc; 
     101     
     102    COMPILE_INSTRUCTION(kite_compile_return(), line); 
     103     
     104    obj = kite_pop_stack(&compiler->obj_created); 
     105    parent = (kite_object_t*)kite_top_stack(compiler->obj_created); 
     106     
    97107    obj->parent = kite_reference_object(parent); 
    98108    kite_add_method(thd, parent, func_name, obj); 
    99109    kite_set_docstring(obj, doc_string); 
     110     
     111    pc = kite_top_stack(compiler->func_skip_locs); 
     112    if (pc) 
     113    { 
     114        COMPILE_INSTRUCTION(kite_compile_nop(), line); 
     115        opc = (void*)thd->vm->text_segment + (long)pc; 
     116        opc->op_arg.jumpto = thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     117        kite_pop_stack(&compiler->func_skip_locs); 
     118    } 
     119     
    100120    return NULL; 
    101121} 
     
    107127        kite_new_method_bytecode(thd, NULL,  
    108128            kite_list_count(thd,param_list)); 
     129     
     130    /* Bypass declaration so we don't accidentally run the method. */         
     131    COMPILE_INSTRUCTION(kite_compile_jump_uncond(NULL), line); 
     132    kite_push_stack(&compiler->func_skip_locs, FALSE, compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t)); 
     133         
    109134    kite_push_stack(&compiler->obj_created, FALSE, 
    110135                    method); 
     
    116141static void *kite_compile_instruction_anon_func_body(kite_compiler_t *compiler, int line) 
    117142{ 
    118     kite_object_t *obj = kite_pop_stack(&compiler->obj_created); 
     143    kite_object_t *obj; 
     144    kite_opcode_t *opc; 
     145    void *pc; 
     146 
     147    COMPILE_INSTRUCTION(kite_compile_return(), line); 
     148    obj = kite_pop_stack(&compiler->obj_created); 
    119149    COMPILE_INSTRUCTION(kite_compile_push(obj), line); 
     150     
     151    pc = kite_top_stack(compiler->func_skip_locs); 
     152    if (pc) 
     153    { 
     154        opc = (void*)compiler->thd->vm->text_segment + (long)pc; 
     155        opc->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     156        kite_pop_stack(&compiler->func_skip_locs); 
     157    } 
     158 
    120159    return NULL; 
    121160} 
     
    125164    kite_thread_t *thd = compiler->thd; 
    126165    (void)line; 
     166     
     167    /* Bypass declaration so we don't accidentally run the class. */         
     168    COMPILE_INSTRUCTION(kite_compile_jump_uncond(NULL), line); 
     169    kite_push_stack(&compiler->func_skip_locs, FALSE, compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t)); 
     170     
    127171    kite_push_stack(&compiler->obj_created, FALSE, 
    128172                    kite_new_class(thd, NULL, name)); 
     
    133177{ 
    134178    kite_thread_t *thd = compiler->thd; 
    135     kite_object_t *obj = kite_pop_stack(&compiler->obj_created); 
     179    kite_object_t *obj; 
    136180    kite_funccall_info_t *fcall; 
    137181    kite_object_t *parent; 
    138  
     182    kite_opcode_t *opc; 
     183    void *pc; 
     184     
     185    COMPILE_INSTRUCTION(kite_compile_return(), line); 
     186    obj = kite_pop_stack(&compiler->obj_created); 
     187     
     188    pc = kite_top_stack(compiler->func_skip_locs); 
     189    if (pc) 
     190    { 
     191        COMPILE_INSTRUCTION(kite_compile_nop(), line); 
     192        opc = (void*)compiler->thd->vm->text_segment + (long)pc; 
     193        opc->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     194        kite_pop_stack(&compiler->func_skip_locs); 
     195    } 
     196     
    139197    obj->builtin_data.funcvalue.functype = FUNC_BYTECODE; 
    140198    parent = (kite_object_t*)kite_top_stack(compiler->obj_created); 
     
    199257            void *opc = NULL; 
    200258            int idx; 
    201  
    202259            kite_thread_t *thd = compiler->thd; 
    203             COMPILE_INSTRUCTION2(compiler, kite_compile_push(kite_new_ident(thd, name)),  
     260            int old_offset = thd->vm->cur_text_segment; 
     261             
     262            COMPILE_INSTRUCTION2(thd, compiler, kite_compile_push(kite_new_ident(thd, name)),  
    204263                                 line, &opc); 
    205             COMPILE_INSTRUCTION2(compiler, kite_compile_deref_1(TRUE), line, &opc); 
    206  
     264            COMPILE_INSTRUCTION2(thd, compiler, kite_compile_deref_1(TRUE), line, &opc); 
     265            COMPILE_INSTRUCTION2(thd, compiler, kite_compile_return(), line, &opc); 
     266             
     267            if (old_offset == 0) 
     268                opc -= sizeof(kite_opcode_t); 
     269             
    207270            fcall->file = compiler->file; 
    208271            fcall->line = line; 
     
    240303    kite_funccall_info_t *fcall = (kite_funccall_info_t*)GC_malloc(sizeof(kite_funccall_info_t)); 
    241304#endif /* HAVE_GC_H */ 
    242     COMPILE_INSTRUCTION2(compiler, kite_compile_push(obj),  
     305    COMPILE_INSTRUCTION2(thd, compiler, kite_compile_push(obj),  
    243306                         line, &opc); 
    244     COMPILE_INSTRUCTION2(compiler, kite_compile_push(kite_new_ident(thd, name)),  
     307    COMPILE_INSTRUCTION2(thd, compiler, kite_compile_push(kite_new_ident(thd, name)),  
    245308                         line, &opc); 
    246     COMPILE_INSTRUCTION2(compiler, kite_compile_deref_2(), line, &opc); 
    247  
     309    COMPILE_INSTRUCTION2(thd, compiler, kite_compile_deref_2(), line, &opc); 
     310    COMPILE_INSTRUCTION2(thd, compiler, kite_compile_return(), line, &opc); 
     311     
    248312    fcall->file = compiler->file; 
    249313    fcall->line = line; 
     
    274338{ 
    275339    kite_thread_t *thd = compiler->thd; 
     340     
     341    /* Bypass declaration so we don't accidentally run the method. */         
     342    COMPILE_INSTRUCTION(kite_compile_jump_uncond(NULL), line); 
     343    kite_push_stack(&compiler->func_skip_locs, FALSE, compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t)); 
     344     
    276345    kite_push_stack(&compiler->obj_created, FALSE, 
    277346                     kite_new_method_bytecode(thd, NULL,  
     
    284353{ 
    285354    kite_thread_t *thd = compiler->thd; 
    286     kite_object_t *obj = kite_pop_stack(&compiler->obj_created); 
    287     kite_object_t *parent = (kite_object_t*)kite_top_stack(compiler->obj_created); 
    288      
    289     (void)line; 
     355    kite_object_t *obj; 
     356    kite_object_t *parent; 
     357    kite_opcode_t *opc; 
     358    void *pc; 
     359     
     360    COMPILE_INSTRUCTION(kite_compile_return(), line); 
     361     
     362    obj = kite_pop_stack(&compiler->obj_created); 
     363    parent = (kite_object_t*)kite_top_stack(compiler->obj_created); 
     364     
    290365    obj->parent = kite_reference_object(parent); 
    291366    kite_add_method(thd, parent, "__construct__", obj); 
    292367    kite_set_docstring(obj, doc_str); 
    293368    kite_set_arginfo(obj, func_args); 
     369     
     370    pc = kite_top_stack(compiler->func_skip_locs); 
     371    if (pc) 
     372    { 
     373        COMPILE_INSTRUCTION(kite_compile_nop(), line); 
     374        opc = (void*)compiler->thd->vm->text_segment + (long)pc; 
     375        opc->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     376        kite_pop_stack(&compiler->func_skip_locs); 
     377    } 
     378     
    294379    return NULL; 
    295380} 
     
    299384    kite_thread_t *thd = compiler->thd; 
    300385    (void)line; 
     386     
     387    /* Bypass declaration so we don't accidentally run the method. */         
     388    COMPILE_INSTRUCTION(kite_compile_jump_uncond(NULL), line); 
     389    kite_push_stack(&compiler->func_skip_locs, FALSE, compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t)); 
    301390     
    302391    kite_push_stack(&compiler->obj_created, FALSE, 
     
    308397{ 
    309398    kite_thread_t *thd = compiler->thd; 
    310     kite_object_t *obj = kite_pop_stack(&compiler->obj_created); 
    311     kite_object_t *parent = (kite_object_t*)kite_top_stack(compiler->obj_created); 
    312     (void)line; 
     399    kite_object_t *obj; 
     400    kite_object_t *parent; 
     401    kite_opcode_t *opc; 
     402    void *pc; 
     403     
     404    COMPILE_INSTRUCTION(kite_compile_return(), line); 
     405     
     406    obj = kite_pop_stack(&compiler->obj_created); 
     407    parent = (kite_object_t*)kite_top_stack(compiler->obj_created); 
     408     
     409    pc = kite_top_stack(compiler->func_skip_locs); 
     410    if (pc) 
     411    { 
     412        COMPILE_INSTRUCTION(kite_compile_nop(), line); 
     413        opc = (void*)compiler->thd->vm->text_segment + (long)pc; 
     414        opc->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     415        kite_pop_stack(&compiler->func_skip_locs); 
     416    } 
    313417     
    314418    obj->parent = kite_reference_object(parent); 
     
    369473{ 
    370474    kite_thread_t *thd = compiler->thd; 
     475     
     476    /* Bypass declaration so we don't accidentally run the method. */         
     477    COMPILE_INSTRUCTION(kite_compile_jump_uncond(NULL), line); 
     478    kite_push_stack(&compiler->func_skip_locs, FALSE, compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t)); 
     479     
    371480    kite_push_stack(&compiler->obj_created, FALSE, 
    372481                     kite_new_method_bytecode(thd, NULL,  
     
    380489{ 
    381490    kite_thread_t *thd = compiler->thd; 
    382     kite_object_t *obj = kite_pop_stack(&compiler->obj_created); 
    383     kite_object_t *parent = (kite_object_t*)kite_top_stack(compiler->obj_created); 
    384      
    385     (void)line; 
     491    kite_object_t *obj; 
     492    kite_object_t *parent; 
     493    kite_opcode_t *opc; 
     494    void *pc; 
     495         
     496    COMPILE_INSTRUCTION(kite_compile_return(), line); 
     497     
     498    obj = kite_pop_stack(&compiler->obj_created); 
     499    parent = (kite_object_t*)kite_top_stack(compiler->obj_created); 
     500     
    386501    kite_add_operator(thd, parent, op_type, obj); 
    387502    kite_set_docstring(obj, doc_str); 
    388503     
     504    pc = kite_top_stack(compiler->func_skip_locs); 
     505    if (pc) 
     506    { 
     507        COMPILE_INSTRUCTION(kite_compile_nop(), line); 
     508        opc = (void*)compiler->thd->vm->text_segment + (long)pc; 
     509        opc->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     510        kite_pop_stack(&compiler->func_skip_locs); 
     511    } 
     512     
    389513    return NULL; 
    390514} 
     
    393517{ 
    394518    kite_object_t *cur = (kite_object_t*)kite_top_stack(compiler->obj_created); 
    395     kite_opcode_t *opc = cur->builtin_data.funcvalue.funcptr; 
     519    kite_opcode_t *opc; 
     520    void *pc = cur->builtin_data.funcvalue.funcptr; 
    396521    (void)line; 
    397522     
    398     while(opc->next) opc = opc->next; 
    399      
    400     if (opc->opcode == ARITH_OP && ((kite_opcode_arithop*)opc)->operation == OP_ARRAY_DEREF) 
    401         return opc; 
     523    opc = (void*)compiler->thd->vm->text_segment + (long)pc + cur->builtin_data.funcvalue.length - sizeof(kite_opcode_t); 
     524         
     525    if (opc->opcode == ARITH_OP && ((kite_opcode_arithop*)opc)->op_arg.operation == OP_ARRAY_DEREF) 
     526        return opc - compiler->thd->vm->text_segment; 
    402527    else 
    403528        return NULL; 
     
    408533    kite_opcode_t *op2; 
    409534     
    410     if (op1 && op1->next && op1->next->next)  
     535    /*if (op1 && op1->next && op1->next->next)  
    411536    { 
    412537        op2 = op1->next->next; 
    413538        kite_optimize_increment(compiler, op1, op2); 
    414     } 
     539    }*/ 
    415540     
    416541    if (!orig_op2) 
     
    432557    COMPILE_INSTRUCTION(kite_compile_dupe_top(FALSE), line); 
    433558    COMPILE_INSTRUCTION(opc, line); 
    434     return opc; 
     559    return compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    435560} 
    436561 
     
    444569 
    445570    COMPILE_INSTRUCTION(kite_compile_arithop(OP_OR), line); 
    446     ((kite_opcode_jump_true*)lhs_opc)->jumpto = opc; 
    447     COMPILE_INSTRUCTION(opc, line); 
     571    COMPILE_INSTRUCTION(opc, line); 
     572    lhs_opc = (void*)lhs_opc + (long)compiler->thd->vm->text_segment; 
     573    ((kite_opcode_jump_true*)lhs_opc)->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    448574     
    449575    return NULL; 
     
    461587    COMPILE_INSTRUCTION(kite_compile_dupe_top(FALSE), line); 
    462588    COMPILE_INSTRUCTION(opc, line); 
    463     return opc; 
     589    return compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    464590} 
    465591 
     
    473599 
    474600    COMPILE_INSTRUCTION(kite_compile_arithop(OP_AND), line); 
    475     ((kite_opcode_jump_true*)lhs_opc)->jumpto = opc; 
    476     COMPILE_INSTRUCTION(opc, line); 
    477  
     601    COMPILE_INSTRUCTION(opc, line); 
     602    lhs_opc = (void*)lhs_opc + (long)compiler->thd->vm->text_segment; 
     603    ((kite_opcode_jump_true*)lhs_opc)->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     604     
    478605    return NULL; 
    479606} 
     
    656783    kite_opcode_t *opc = kite_compile_push(kite_new_list(thd)); 
    657784    (void)line; 
    658     COMPILE_INSTRUCTION(opc, 0); 
     785    COMPILE_INSTRUCTION(opc, line); 
    659786    return opc; 
    660787} 
     
    779906    (void)line; 
    780907    kite_push_stack(&compiler->decide_exits, FALSE, kite_compile_nop()); 
     908    kite_push_stack(&compiler->decide_begins, FALSE, compiler->thd->vm->cur_text_segment); 
    781909    return NULL; 
    782910} 
     
    786914    kite_opcode_t *tmpopc = kite_pop_stack(&compiler->decide_exits); 
    787915    COMPILE_INSTRUCTION(tmpopc, line); 
     916    void *pc; 
     917    void *tos = kite_pop_stack(&compiler->decide_begins); 
     918     
     919    while ((pc = kite_top_stack(compiler->decide_exit_locs)) >= tos) 
     920    { 
     921        tmpopc = (void*)compiler->thd->vm->text_segment + (long)pc; 
     922        tmpopc->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     923        kite_pop_stack(&compiler->decide_exit_locs); 
     924    } 
    788925    return NULL; 
    789926} 
     
    793930    kite_opcode_t *opc = kite_compile_jump_false(NULL); 
    794931    COMPILE_INSTRUCTION(opc, line); 
    795     return opc; 
     932    return compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    796933} 
    797934 
     
    799936{ 
    800937    kite_opcode_jump_false *c = (kite_opcode_jump_false*)begin_opc; 
    801     c->jumpto = kite_compile_nop(); 
     938    kite_opcode_t *obj = kite_compile_nop(); 
    802939     
    803940    COMPILE_INSTRUCTION( 
     
    808945    ); 
    809946     
    810     COMPILE_INSTRUCTION(c->jumpto, line); 
     947    kite_push_stack(&compiler->decide_exit_locs, FALSE, (void*)compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t)); 
     948     
     949    COMPILE_INSTRUCTION(obj, line); 
     950    c = (void*)c + (long)compiler->thd->vm->text_segment; 
     951    c->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     952     
    811953    return NULL; 
    812954} 
     
    834976    kite_opcode_t *loop_bottom_cont = kite_compile_jump_uncond(opc); 
    835977    kite_opcode_t *loop_bottom_end = kite_compile_nop(); 
    836  
     978    kite_opcode_t *tmpopc; 
     979     
    837980    COMPILE_INSTRUCTION(loop_bottom_cont, line); 
    838      
     981    loop_bottom_cont = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     982    COMPILE_INSTRUCTION(loop_bottom_end, line); 
     983    loop_bottom_end = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     984 
    839985    /* Fix jump destination */ 
    840     while(opc && opc != loop_bottom_cont) 
     986    opc = (void*)opc + (long)compiler->thd->vm->text_segment; 
     987    while(opc < (void*)compiler->thd->vm->text_segment + (long)loop_bottom_end) 
    841988    { 
    842         if ((opc->opcode == JUMP_TRUE && ((kite_opcode_jump_true*)opc)->jumpto == NULL) || 
    843             (opc->opcode == JUMP_FALSE && ((kite_opcode_jump_false*)opc)->jumpto == NULL))  
     989        if ((opc->opcode == JUMP_TRUE && ((kite_opcode_jump_true*)opc)->op_arg.jumpto == NULL) || 
     990            (opc->opcode == JUMP_FALSE && ((kite_opcode_jump_false*)opc)->op_arg.jumpto == NULL))  
    844991        { 
    845             ((kite_opcode_jump_true*)opc)->jumpto = loop_bottom_end; 
     992            ((kite_opcode_jump_true*)opc)->op_arg.jumpto = loop_bottom_end; 
    846993        } 
    847994        else if (opc->opcode == TEMP_BREAK) 
    848995        { 
    849996            opc->opcode = JUMP_UNCOND; 
    850             ((kite_opcode_jump_true*)opc)->jumpto = loop_bottom_end; 
     997            ((kite_opcode_jump_true*)opc)->op_arg.jumpto = loop_bottom_end; 
    851998        } 
    852999        else if (opc->opcode == TEMP_CONTINUE) 
    8531000        { 
    8541001            opc->opcode = JUMP_UNCOND; 
    855             ((kite_opcode_jump_true*)opc)->jumpto = loop_bottom_cont; 
     1002            ((kite_opcode_jump_true*)opc)->op_arg.jumpto = loop_bottom_cont; 
    8561003        } 
    857         opc = opc->next; 
    858     } 
    859      
    860     COMPILE_INSTRUCTION(loop_bottom_end, line); 
     1004        opc++; 
     1005    } 
     1006 
    8611007    return NULL; 
    8621008} 
     
    8661012    kite_opcode_t *opc = kite_compile_nop(); 
    8671013    COMPILE_INSTRUCTION(opc, line); 
    868     return opc; 
     1014    return compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    8691015} 
    8701016 
     
    8791025    kite_opcode_t *opc = kite_compile_nop(); 
    8801026    COMPILE_INSTRUCTION(opc, line); 
    881     return opc; 
     1027    return compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    8821028} 
    8831029 
     
    8921038    kite_opcode_t *opc = kite_compile_exception_hndl(NULL); 
    8931039    COMPILE_INSTRUCTION(opc, line); 
    894     return opc; 
     1040    return compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    8951041} 
    8961042 
     
    9001046    COMPILE_INSTRUCTION(kite_compile_push(kite_new_boolean(thd, TRUE)), line); 
    9011047    COMPILE_INSTRUCTION(opc, line); 
    902     return opc; 
     1048    return compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    9031049} 
    9041050 
     
    9061052{ 
    9071053    kite_opcode_t *opc = kite_compile_nop(); 
    908     ((kite_opcode_exception_hndl*)run_opc)->handler = opc; 
    909     COMPILE_INSTRUCTION(opc, line); 
     1054    COMPILE_INSTRUCTION(opc, line); 
     1055     
     1056    run_opc = (void*)compiler->thd->vm->text_segment + (long)run_opc; 
     1057    ((kite_opcode_exception_hndl*)run_opc)->op_arg.handler = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    9101058    return NULL; 
    9111059} 
     
    9151063    kite_opcode_t *opc = kite_compile_pop_exception_hndl(); 
    9161064    kite_opcode_t *nop = kite_compile_nop(); 
    917     ((kite_opcode_jump_true*)run_opc)->jumpto = opc; 
     1065    kite_opcode_t *jump; 
    9181066    COMPILE_INSTRUCTION(kite_compile_push(kite_new_boolean(thd, TRUE)), line); 
     1067 
    9191068    COMPILE_INSTRUCTION(kite_compile_jump_true(nop), line); 
    920     COMPILE_INSTRUCTION(opc, line); 
     1069    jump = (void*)compiler->thd->vm->text_segment + (compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t)); 
     1070 
     1071    COMPILE_INSTRUCTION(opc, line); 
     1072    run_opc = (void*)compiler->thd->vm->text_segment + (long)run_opc; 
     1073    ((kite_opcode_jump_true*)run_opc)->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
     1074     
    9211075    COMPILE_INSTRUCTION(nop, line); 
     1076    jump->op_arg.jumpto = compiler->thd->vm->cur_text_segment - sizeof(kite_opcode_t); 
    9221077    return NULL; 
    9231078} 
  • interpreter/trunk/backend/kite-vm-1.0/kite_execute.c

    r618 r619  
    134134kite_vm_execute_push(kite_thread_t *thd, kite_opcode_push *ins) 
    135135{ 
    136     assert(ins->obj != NULL); 
    137     kite_vm_push(thd, ins->obj); 
    138     return ins->common.next; 
     136    assert(ins->op_arg.obj != NULL); 
     137    kite_vm_push(thd, ins->op_arg.obj); 
     138    return ins + 1; 
    139139} 
    140140 
     
    149149    kite_funccall_info_t *stackentry; 
    150150    int deref_array = 0; 
    151     assert(ins->args != NULL); 
     151    assert(ins->op_arg.args != NULL); 
    152152     
    153153    args = kite_vm_pop(thd); 
     
    158158 
    159159    cur_array = args; 
    160     cur_args = ins->args; 
     160    cur_args = ins->op_arg.args; 
    161161     
    162162    while(cur_array && cur_args) { 
     
    187187    if (deref_array) kite_dereference_object(args); 
    188188    assert(cur_array == NULL && cur_args == NULL); 
    189     return ins->common.next; 
     189    return ins + 1; 
    190190} 
    191191 
     
    218218        kite_reference_object(found->value); 
    219219        kite_push_stack(&thd->running_stack, TRUE, found); 
    220         return ins->common.next; 
     220        return ins + 1; 
    221221    } else if (strcmp("this", ident_string) == 0) { 
    222222        res = kite_reference_object(((kite_funccall_info_t*)cur->obj)->this); 
     
    273273        } 
    274274         
    275         if (res == NULL && ins->create) { 
     275        if (res == NULL && ins->op_arg.create) { 
    276276            /* Create entry in symbol table */ 
    277277            stackentry = (kite_funccall_info_t*)kite_top_stack(thd->func_stack); 
     
    290290            kite_symtab_insert(thd, &stackentry->locals, found); 
    291291            res = found->value; 
    292         } else if (res == NULL && !ins->create) { 
     292        } else if (res == NULL && !ins->op_arg.create) { 
    293293            char buf[1024]; 
    294294            fc = kite_top_stack(thd->func_stack); 
    295             PUSH_FUNC_STACK_WITH_RET_VALUE(NULL, ins->common.next); 
     295            PUSH_FUNC_STACK_WITH_RET_VALUE(NULL, ins + 1); 
    296296            fc_entry->sys_or_user = fc->sys_or_user; 
    297297             
     
    302302            kite_vm_call_method(thd, exc, "throw", kite_new_list(thd), TRUE); 
    303303            POP_FUNC_STACK; 
    304             return ins->common.next; 
     304            return ins + 1; 
    305305        } 
    306306         
     
    314314        } 
    315315 
    316         if (!found->value->shareable && found->value->owner_thread != thd)  
    317             goto thread_access_err; 
     316        if (found->value->type != OBJ_BOOLEAN && 
     317            found->value->type != OBJ_INTEGER && 
     318            found->value->type != OBJ_FLOAT) 
     319        { 
     320            if (!found->value->shareable && found->value->owner_thread != thd)  
     321                goto thread_access_err; 
     322        } 
    318323         
    319324        kite_reference_object(found->value); 
     
    325330        stackentry->last_deref_ident = ident; 
    326331         
    327         return ins->common.next; 
     332        return ins + 1; 
    328333    } 
    329334 
    330335    /* Wrap it in a reference */ 
    331     if (!res->shareable && res->owner_thread != thd)  
    332         goto thread_access_err; 
    333          
     336    if (res->type != OBJ_BOOLEAN && 
     337        res->type != OBJ_INTEGER && 
     338        res->type != OBJ_FLOAT) 
     339    { 
     340        if (!res->shareable && res->owner_thread != thd)  
     341            goto thread_access_err; 
     342    } 
     343     
    334344    kite_dereference_object(ident); 
    335345    kite_vm_push(thd, res); 
    336     return ins->common.next; 
     346    return ins + 1; 
    337347 
    338348thread_access_err: 
    339349    { 
    340         PUSH_FUNC_STACK_WITH_RET_VALUE(NULL, ins->common.next); 
     350        PUSH_FUNC_STACK_WITH_RET_VALUE(NULL, ins + 1); 
    341351        exc =  
    342352            kite_new_exception( 
     
    347357        kite_vm_call_method(thd, exc, "throw", kite_new_list(thd), TRUE); 
    348358    } 
    349     return ins->common.next; 
     359    return ins + 1; 
    350360} 
    351361 
     
    386396 
    387397    kite_dereference_object(ident); 
    388     return ins->common.next; 
     398    return ins + 1; 
    389399} 
    390400 
     
    446456            else kite_reference_object(entry->value); 
    447457             
    448             if (!entry->value->shareable && entry->value->owner_thread != thd) goto thread_access_err; 
     458            if (entry->value->type != OBJ_BOOLEAN && 
     459                entry->value->type != OBJ_INTEGER && 
     460                entry->value->type != OBJ_FLOAT) 
     461            { 
     462                if (!entry->value->shareable && entry->value->owner_thread != thd) 
     463                    goto thread_access_err; 
     464            } 
    449465             
    450466            kite_push_stack(&thd->running_stack, TRUE, entry); 
    451467            kite_dereference_object(ident); 
    452468            kite_dereference_object(obj); 
    453             return ins->common.next; 
     469            return ins + 1; 
    454470        } 
    455471         
     
    476492        KITE_FIND_IN_SYMTAB(entry, obj->object_data.properties, name, 0); 
    477493         
    478         if (!entry->value->shareable && entry->value->owner_thread != thd) goto thread_access_err; 
     494        if (entry->value->type != OBJ_BOOLEAN && 
     495            entry->value->type != OBJ_INTEGER && 
     496            entry->value->type != OBJ_FLOAT) 
     497        { 
     498            if (!entry->value->shareable && entry->value->owner_thread != thd)  
     499                goto thread_access_err; 
     500        } 
    479501         
    480502        kite_push_stack(&thd->running_stack, TRUE, entry); 
     
    482504        kite_dereference_object(ident); 
    483505        kite_dereference_object(obj); 
    484         return ins->common.next; 
     506        return ins + 1; 
    485507    } 
    486508     
     
    491513    if (kite_vm_call_operator(thd, obj, OP_PROPERTY, curr, 0)) { 
    492514        kite_dereference_object(curr); 
    493         return ins->common.next; 
     515        return ins + 1; 
    494516    } 
    495517         
     
    499521        kite_funccall_info_t *fc =  
    500522            kite_top_stack(thd->func_stack); 
    501         PUSH_FUNC_STACK_WITH_RET_VALUE(obj, ins->common.next); 
     523        PUSH_FUNC_STACK_WITH_RET_VALUE(obj, ins + 1); 
    502524        fc_entry->sys_or_user = fc->sys_or_user; 
    503525         
     
    506528                                 buf); 
    507529        kite_vm_call_method(thd, exc, "throw", kite_new_list(thd), TRUE); 
    508         return ins->common.next; 
     530        return ins + 1; 
    509531    } 
    510532 
    511533thread_access_err: 
    512534    { 
    513         PUSH_FUNC_STACK_WITH_RET_VALUE(NULL, ins->common.next); 
     535        PUSH_FUNC_STACK_WITH_RET_VALUE(NULL, ins + 1); 
    514536        exc =  
    515537            kite_new_exception( 
     
    520542        kite_vm_call_method(thd, exc, "throw", kite_new_list(thd), TRUE); 
    521543    } 
    522     return ins->common.next; 
     544    return ins + 1; 
    523545} 
    524546 
     
    546568     
    547569    fc = kite_top_stack(thd->func_stack); 
    548     PUSH_FUNC_STACK_WITH_RET_VALUE(this, ins->common.next); 
     570    PUSH_FUNC_STACK_WITH_RET_VALUE(this, ins + 1); 
    549571    fc_entry->sys_or_user = fc->sys_or_user; 
    550572     
     
    556578                                     "Specified arguments do not match."); 
    557579            kite_vm_call_method(thd, exc, "throw", kite_new_list(thd), TRUE); 
    558             return ins->common.next; 
     580            return ins + 1; 
    559581        } 
    560582        kite_vm_call_object(thd, this, method, args); 
     
    566588                                 "Cannot call object as a method."); 
    567589        kite_vm_call_method(thd, exc, "throw", kite_new_list(thd), TRUE); 
    568         return ins->common.next; 
     590        return ins + 1; 
    569591    } 
    570592     
     
    572594    kite_dereference_object(method); 
    573595 
    574     if (thd->exception) return ins->common.next; 
     596    if (thd->exception) return ins + 1; 
    575597 
    576598    /* Remove anything other than the return value from the top of the stack */ 
     
    597619            } 
    598620        } 
    599         if (strcmp("__construct__", method->builtin_data.stringvalue.string) != 0) 
     621        if (method->type != OBJ_IDENT || 
     622            strcmp("__construct__", method->builtin_data.stringvalue.string) != 0) 
    600623        { 
    601624            if (ret != NULL) kite_vm_push(thd, ret); 
     
    605628    } else { 
    606629        POP_FUNC_STACK; 
    607         if (strcmp("__construct__", method->builtin_data.stringvalue.string) != 0) 
     630        if (method->type != OBJ_IDENT || 
     631            strcmp("__construct__", method->builtin_data.stringvalue.string) != 0) 
    608632        { 
    609633            kite_vm_push(thd, kite_new_null(thd)); 
    610             return ins->common.next; 
    611         } 
    612     } 
    613      
    614     return ins->common.next; 
     634            return ins + 1; 
     635        } 
     636    } 
     637     
     638    return ins + 1; 
    615639} 
    616640 
     
    628652    kite_dereference_object(code);       
    629653     
    630     return ins->common.next;           
     654    return ins + 1;           
    631655} 
    632656 
     
    655679    kite_vm_push(thd, res); 
    656680    kite_dereference_object(res); 
    657     return ins->common.next; 
     681    return ins + 1; 
    658682} 
    659683 
     
    675699    kite_dereference_object(res); 
    676700     
    677     return ins->common.next; 
     701    return ins + 1; 
    678702} 
    679703 
     
    693717    kite_dereference_object(res); 
    694718     
    695     return ins->common.next; 
     719    return ins + 1; 
    696720} 
    697721 
     
    707731    if (thd->running_stack->stack[thd->running_stack->length - 1].reference) { 
    708732        symt = (kite_symtab_t*)(thd->running_stack->stack[thd->running_stack->length - 1].obj); 
    709         if (!ins->dupe_ref) kite_reference_object(symt->value); 
     733        if (!ins->op_arg.dupe_ref) kite_reference_object(symt->value); 
    710734        kite_push_stack(&thd->running_stack, TRUE, symt); 
    711735    } else { 
     
    716740    } 
    717741     
    718     return ins->common.next; 
     742    return ins + 1; 
    719743} 
    720744     
     
    727751    kite_object_t *obj, *onstack; 
    728752    void *newpc; 
    729     assert(ins->jumpto != NULL && thd->func_stack != NULL); 
     753    assert(ins->op_arg.jumpto != NULL && thd->func_stack != NULL); 
    730754 
    731755    onstack = kite_vm_pop(thd); 
     
    733757    if (obj->builtin_data.intvalue) 
    734758    { 
    735         newpc = ins->jumpto; 
     759        newpc = (void*)thd->vm->text_segment + (long)ins->op_arg.jumpto; 
    736760    } 
    737761    else 
    738762    { 
    739         newpc = ins->common.next; 
     763        newpc = ins + 1; 
    740764    } 
    741765    kite_dereference_object(obj); 
     
    752776    kite_object_t *obj, *onstack; 
    753777    void *newpc; 
    754     assert(ins->jumpto != NULL && thd->func_stack != NULL); 
     778    assert(ins->op_arg.jumpto != NULL && thd->func_stack != NULL); 
    755779  
    756780    onstack = kite_vm_pop(thd); 
     
    758782    if (!obj->builtin_data.intvalue) 
    759783    { 
    760         newpc = ins->jumpto; 
     784        newpc = (void*)thd->vm->text_segment + (long)ins->op_arg.jumpto; 
    761785    } 
    762786    else 
    763787    { 
    764         newpc = ins->common.next; 
     788        newpc = ins + 1; 
    765789    } 
    766790    kite_dereference_object(obj); 
     
    775799kite_vm_execute_jumpuncond(kite_thread_t *thd, kite_opcode_jump_unconditional *ins) 
    776800{ 
    777     assert(ins->jumpto != NULL && thd->func_stack != NULL); 
    778     return ins->jumpto; 
     801    assert(ins->op_arg.jumpto != NULL && thd->func_stack != NULL); 
     802    return (void*)thd->vm->text_segment + (long)ins->op_arg.jumpto; 
    779803} 
    780804 
     
    790814    kite_funccall_info_t *current; 
    791815 
    792     kite_vm_execute_user_method(thd, ins->common.next); 
     816    kite_vm_execute_user_method(thd, (void*)(ins + 1) - (long)thd->vm->text_segment); 
    793817    if (thd->exception) 
    794818    { 
     
    831855 
    832856        thd->exception = NULL; 
    833         return ins->handler; 
     857        return (void*)thd->vm->text_segment + (long)ins->op_arg.handler; 
    834858    } 
    835859     
     
    851875    if (symt) kite_symtab_remove(thd, &current->locals, "__exc", 0); 
    852876     
    853     return ins->common.next; 
     877    return ins + 1; 
    854878} 
    855879 
     
    861885    kite_vm_push(thd,  
    862886        ((kite_funccall_info_t*)kite_top_stack(thd->func_stack))->this); 
    863     return ins->common.next; 
     887    return ins + 1; 
    864888} 
    865889 
     
    10011025    int curstack; 
    10021026 
    1003     assert(ins->operation < NUM_OPERATORS); 
     1027    assert(ins->op_arg.operation < NUM_OPERATORS); 
    10041028    rhs = kite_vm_pop(thd); 
    10051029 
    1006     if (ins->operation == OP_ARRAY_SET) 
     1030    if (ins->op_arg.operation == OP_ARRAY_SET) 
    10071031        idx = kite_vm_pop(thd); 
    10081032 
    10091033    if (thd->running_stack->stack[thd->running_stack->length - 1].reference && 
    1010         ins->operation == OP_ASSIGNMENT) { 
     1034        ins->op_arg.operation == OP_ASSIGNMENT) { 
    10111035        kite_symtab_t *symt =  
    10121036            (kite_symtab_t*)thd->running_stack->stack[thd->running_stack->length - 1].obj; 
     
    10321056        } 
    10331057        kite_dereference_object(kite_vm_pop(thd)); 
    1034         return ins->common.next; 
     1058        return ins + 1; 
    10351059    } 
    10361060    lhs = kite_vm_pop(thd); 
     
    10441068            lhs->type == OBJ_BOOLEAN 
    10451069        ) && 
    1046         ins->operation != OP_ASSIGNMENT) 
    1047     { 
    1048         kite_compiled_func_t func = _operationArray[lhs->type][ins->operation]; 
     1070        ins->op_arg.operation != OP_ASSIGNMENT) 
     1071    { 
     1072        kite_compiled_func_t func = _operationArray[lhs->type][ins->op_arg.operation]; 
    10491073         
    10501074        if (func == NULL) 
     
    10541078            KITE_FIND_ANY_IN_SYMTAB(st,  
    10551079                lhs->object_data.inherit_from->object_data.properties,  
    1056                 OP_TO_METHOD(ins->operation)); 
     1080                OP_TO_METHOD(ins->op_arg.operation)); 
    10571081         
    10581082            if (st) 
     
    10681092            kite_dereference_object(lhs); 
    10691093            kite_dereference_object(rhs); 
    1070             return ins->common.next; 
     1094            return ins + 1; 
    10711095        } 
    10721096    } 
    10731097 
    10741098    fc = kite_top_stack(thd->func_stack); 
    1075     PUSH_FUNC_STACK_WITH_RET_VALUE(lhs, ins->common.next); 
     1099    PUSH_FUNC_STACK_WITH_RET_VALUE(lhs, ins + 1); 
    10761100    fc_entry->sys_or_user = fc->sys_or_user; 
    10771101 
     
    10811105        idx = kite_list_object(thd, idx); 
    10821106        kite_append_list(thd, idx, rhs); 
    1083         kite_vm_call_operator(thd, lhs, ins->operation, idx, TRUE); 
     1107        kite_vm_call_operator(thd, lhs, ins->op_arg.operation, idx, TRUE); 
    10841108    } 
    10851109    else 
    1086         kite_vm_call_operator(thd, lhs, ins->operation, rhs, TRUE); 
    1087     if (thd->exception) return ins->common.next; 
     1110        kite_vm_call_operator(thd, lhs, ins->op_arg.operation, rhs, TRUE); 
     1111    if (thd->exception) return ins + 1; 
    10881112 
    10891113    kite_dereference_object(lhs); 
     
    11211145    } 
    11221146     
    1123     return ins->common.next; 
     1147    return ins + 1; 
    11241148} 
    11251149 
     
    11311155{ 
    11321156    (void)thd; 
    1133     return ins->common.next; 
     1157    return ins + 1; 
    11341158} 
    11351159 
     
    11501174 
    11511175    fc = kite_top_stack(thd->func_stack); 
    1152     PUSH_FUNC_STACK_WITH_RET_VALUE(obj, ins->common.next); 
     1176    PUSH_FUNC_STACK_WITH_RET_VALUE(obj, ins + 1); 
    11531177    fc_entry->sys_or_user = fc->sys_or_user; 
    11541178     
    11551179    newobj = kite_new_instance_with_constructor(thd, obj, args); 
    1156     if (thd->exception) return ins->common.next; 
     1180    if (thd->exception) return ins + 1; 
    11571181    POP_FUNC_STACK; 
    11581182 
     
    11661190    kite_vm_push(thd, newobj); 
    11671191    kite_dereference_object(newobj); 
    1168     return ins->common.next; 
     1192    return ins + 1; 
    11691193} 
    11701194 
     
    12161240         
    12171241        cur = cur->object_data.inherit_from; 
    1218     } while(cur && !res && ins->isof); 
     1242    } while(cur && !res && ins->op_arg.isof); 
    12191243 
    12201244    obj = kite_new_boolean(thd, res); 
    12211245    kite_vm_push(thd, obj); 
    1222     return ins->common.next; 
     1246    return ins + 1; 
    12231247    //kite_dereference_object(obj); 
    12241248} 
     
    14231447static void kite_vm_execute_user_method_debug(kite_thread_t *thd, void *pc) 
    14241448{ 
    1425     kite_opcode_t *cur = (kite_opcode_t*)pc; 
     1449    kite_opcode_t *cur = (kite_opcode_t*)((char*)thd->vm->text_segment + (long)pc); 
    14261450    kite_funccall_info_t *fc_entry, *oldentry; 
    14271451    int old_sys; 
     
    14821506void kite_vm_execute_user_method(kite_thread_t *thd, void *pc) 
    14831507{ 
    1484     kite_opcode_t *cur = (kite_opcode_t*)pc; 
     1508    kite_opcode_t *cur = (kite_opcode_t*)((char*)thd->vm->text_segment + (long)pc); 
    14851509    kite_funccall_info_t *fc = kite_top_stack(thd->func_stack); 
    14861510 
  • interpreter/trunk/backend/kite-vm-1.0/kite_instr.c

    r594 r619  
    5656{ 
    5757    kite_opcode_arithop *op = ALLOCATE_OPCODE(kite_opcode_arithop); 
    58     op->operation = operation; 
    59     op->common.opcode = ARITH_OP; 
     58    op->op_arg.operation = operation; 
     59    op->opcode = ARITH_OP; 
    6060    return (kite_opcode_t*)op; 
    6161} 
     
    6767{ 
    6868    kite_opcode_push *op = ALLOCATE_OPCODE(kite_opcode_push); 
    69     op->obj = obj; 
    70     op->common.opcode = PUSH; 
     69    op->op_arg.obj = obj; 
     70    op->opcode = PUSH; 
    7171    return (kite_opcode_t*)op; 
    7272} 
     
    122122{ 
    123123    kite_opcode_deref_1 *opc = ALLOCATE_OPCODE(kite_opcode_deref_1); 
    124     opc->common.opcode = DEREF_1; 
    125     opc->create = create; 
     124    opc->opcode = DEREF_1; 
     125    opc->op_arg.create = create; 
    126126    return (kite_opcode_t*)opc; 
    127127} 
     
    153153{ 
    154154    kite_opcode_jump_true *op = ALLOCATE_OPCODE(kite_opcode_jump_true); 
    155     op->jumpto = jumpto; 
    156     op->common.opcode = JUMP_TRUE; 
     155    op->op_arg.jumpto = jumpto; 
     156    op->opcode = JUMP_TRUE; 
    157157    return (kite_opcode_t*)op; 
    158158} 
     
    164164{ 
    165165    kite_opcode_jump_false *op = ALLOCATE_OPCODE(kite_opcode_jump_false); 
    166     op->jumpto = jumpto; 
    167     op->common.opcode = JUMP_FALSE; 
     166    op->op_arg.jumpto = jumpto; 
     167    op->opcode = JUMP_FALSE; 
    168168    return (kite_opcode_t*)op; 
    169169} 
     
    175175{ 
    176176    kite_opcode_jump_unconditional *op = ALLOCATE_OPCODE(kite_opcode_jump_unconditional); 
    177     op->jumpto = jumpto; 
    178     op->common.opcode = JUMP_UNCOND; 
     177    op->op_arg.jumpto = jumpto; 
     178    op->opcode = JUMP_UNCOND; 
    179179    return (kite_opcode_t*)op; 
    180180} 
     
    187187    kite_opcode_exception_hndl *op =  
    188188        ALLOCATE_OPCODE(kite_opcode_exception_hndl); 
    189     op->handler = handler; 
    190     op->common.opcode = EXCEPTION_HNDL; 
     189    op->op_arg.handler = handler; 
     190    op->opcode = EXCEPTION_HNDL; 
    191191    return (kite_opcode_t*)op; 
    192192} 
     
    210210    kite_opcode_dupe_top *opc =  
    211211        (kite_opcode_dupe_top*)ALLOCATE_OPCODE(kite_opcode_dupe_top); 
    212     opc->common.opcode = DUPE_TOP; 
    213     opc->dupe_ref = dupe_ref; 
     212    opc->opcode = DUPE_TOP; 
     213    opc->op_arg.dupe_ref = dupe_ref; 
    214214    return (kite_opcode_t*)opc; 
    215215} 
     
    221221{ 
    222222    kite_opcode_funcargs *op = ALLOCATE_OPCODE(kite_opcode_funcargs); 
    223     op->args = args; 
    224     op->common.opcode = FUNCARGS; 
     223    op->op_arg.args = args; 
     224    op->opcode = FUNCARGS; 
    225225    return (kite_opcode_t*)op; 
    226226} 
     
    282282{ 
    283283    kite_opcode_objis *op = ALLOCATE_OPCODE(kite_opcode_objis); 
    284     op->isof = isof; 
    285     op->common.opcode = IS_ISOF; 
     284    op->op_arg.isof = isof; 
     285    op->opcode = IS_ISOF; 
    286286    return (kite_opcode_t*)op; 
    287287} 
     
    291291 ****************************************************************************/ 
    292292kite_opcode_t * 
    293 kite_add_to_instruction_list(kite_opcode_t **list, kite_opcode_t *opc) 
    294 { 
     293kite_add_to_instruction_list(kite_thread_t *thd, kite_opcode_t **list, kite_opcode_t *opc) 
     294{ 
     295#if 0 
    295296    kite_opcode_t *cur = *list; 
    296297     
     
    307308    cur->next = opc; 
    308309    return opc; 
     310#else 
     311    char *insert_loc; 
     312     
     313    #ifdef WIN32 
     314    WaitForSingleObject(thd->vm->compile_mtx, INFINITE); 
     315    #else 
     316    pthread_mutex_lock(&thd->vm->compile_mtx); 
     317    #endif /* WIN32 */ 
     318     
     319    if (sizeof(kite_opcode_t) + thd->vm->cur_text_segment >= thd->vm->text_segment_length) 
     320    { 
     321        thd->vm->text_segment_length *= 2; 
     322        #ifndef HAVE_GC_H 
     323        thd->vm->text_segment = (kite_vm_t*)realloc(thd->vm->text_segment, thd->vm->text_segment_length); 
     324        #else 
     325        thd->vm->text_segment = (kite_vm_t*)GC_realloc(thd->vm->text_segment, thd->vm->text_segment_length); 
     326        #endif /* HAVE_GC_H */ 
     327    } 
     328     
     329    insert_loc = (char*)thd->vm->text_segment + thd->vm->cur_text_segment; 
     330    if (*list == NULL) 
     331    { 
     332        *list = insert_loc - (char*)thd->vm->text_segment; 
     333    } 
     334     
     335    memcpy(insert_loc, opc, sizeof(kite_opcode_t)); 
     336#ifndef HAVE_GC_H 
     337    free(opc); 
     338#endif /* HAVE_GC_H */ 
     339 
     340    thd->vm->cur_text_segment += sizeof(kite_opcode_t); 
     341     
     342    #ifdef WIN32 
     343    ReleaseMutex(thd->vm->compile_mtx); 
     344    #else 
     345    pthread_mutex_unlock(&thd->vm->compile_mtx); 
     346    #endif /* WIN32 */ 
     347     
     348    return insert_loc - (char*)thd->vm->text_segment; 
     349#endif /* 0 */ 
    309350} 
    310351 
     
    314355void kite_free_instruction_list(kite_thread_t *thd, kite_opcode_t *opc) 
    315356{ 
     357#if 0 
    316358    kite_opcode_t *tmp; 
    317359    (void)thd; 
     
    326368#endif /* HAVE_GC_H */ 
    327369    } 
     370#endif /* 0 */ 
    328371} 
    329372 
     
    331374 * Copy instruction list 
    332375 ****************************************************************************/ 
    333 kite_opcode_t *kite_copy_instruction_list(kite_thread_t *thd, kite_opcode_t *opc) 
    334 { 
     376kite_opcode_t *kite_copy_instruction_list(kite_thread_t *thd, kite_object_t *obj, kite_opcode_t *opc) 
     377{ 
     378#if 0 
    335379    kite_opcode_t *ret, *cur; 
    336380    (void)thd; 
     
    373417 
    374418    return ret; 
    375 } 
    376  
     419#else 
     420    char *insert_loc; 
     421     
     422    #ifdef WIN32 
     423    WaitForSingleObject(thd->vm->compile_mtx, INFINITE); 
     424    #else 
     425    pthread_mutex_lock(&thd->vm->compile_mtx); 
     426    #endif /* WIN32 */ 
     427     
     428    insert_loc = opc - (long)thd->vm->text_segment; 
     429     
     430    #ifdef WIN32 
     431    ReleaseMutex(thd->vm->compile_mtx); 
     432    #else 
     433    pthread_mutex_unlock(&thd->vm->compile_mtx); 
     434    #endif /* WIN32 */ 
     435     
     436    return insert_loc; 
     437#endif /* 0 */ 
     438} 
     439 
  • interpreter/trunk/backend/kite-vm-1.0/kite_opcodes.h

    r594 r619  
    2828 ****************************************************************************/ 
    2929 
     30struct kite_object_t; 
     31 
    3032/* 
    3133 * Base VM opcode object 
     
    3537    unsigned int opcode; 
    3638    unsigned int length; 
     39    union 
     40    { 
     41        unsigned int operation; /* arthop */ 
     42        struct kite_object_t *obj; /* push */ 
     43        int create; /* deref_1 */ 
     44        struct kite_opcode_t *jumpto; /* jump_* */ 
     45        struct kite_opcode_t *handler; /* exception_hndl */ 
     46        int dupe_ref; /* dupe_top */ 
     47        int isof; /* objis */ 
     48        struct kite_object_t *args; /* funcargs */ 
     49    } op_arg; 
    3750    char *file; 
    38     int line; 
    39     struct kite_opcode_t *next; 
     51    int line; /* For alignment purposes */ 
    4052} kite_opcode_t; 
    4153 
     
    4355 * VM arithmetic operation 
    4456 */ 
    45 typedef struct kite_opcode_arithop 
    46 { 
    47     kite_opcode_t common; 
    48     unsigned int operation; 
    49 } kite_opcode_arithop; 
     57typedef struct kite_opcode_t kite_opcode_arithop; 
    5058 
    5159/* 
    5260 * Push object onto execution stack 
    5361 */ 
    54 struct kite_object_t; 
    55 typedef struct kite_opcode_push 
    56 { 
    57     kite_opcode_t common; 
    58     struct kite_object_t *obj; 
    59 } kite_opcode_push; 
     62typedef struct kite_opcode_t kite_opcode_push; 
    6063 
    6164/* 
    6265 * Combine two elements (or an element and a list) into a single list 
    6366 */ 
    64 typedef struct kite_opcode_list_cons 
    65 { 
    66     kite_opcode_t common; 
    67 } kite_opcode_list_cons; 
     67typedef struct kite_opcode_t kite_opcode_list_cons; 
    6868 
    6969/* 
    7070 * Create an empty list. 
    7171 */ 
    72 typedef struct kite_opcode_list_cons_0 
    73 { 
    74     kite_opcode_t common; 
    75 } kite_opcode_list_cons_0; 
     72typedef struct kite_opcode_t kite_opcode_list_cons_0; 
    7673 
    7774/* 
    7875 * Make list out of a single element 
    7976 */ 
    80 typedef struct kite_opcode_list_cons_1 
    81 { 
    82     kite_opcode_t common; 
    83 } kite_opcode_list_cons_1; 
     77typedef struct kite_opcode_t kite_opcode_list_cons_1; 
    8478 
    8579/* 
    8680 * Dereference an object 
    8781 */ 
    88 typedef struct kite_opcode_deref_1 
    89 { 
    90     kite_opcode_t common; 
    91     int create; 
    92 } kite_opcode_deref_1; 
     82typedef struct kite_opcode_t kite_opcode_deref_1; 
    9383 
    9484/* 
    9585 * Dereference an object (and retrieve property) 
    9686 */ 
    97 typedef struct kite_opcode_deref_2 
    98 { 
    99     kite_opcode_t common; 
    100 } kite_opcode_deref_2; 
     87typedef struct kite_opcode_t kite_opcode_deref_2; 
    10188 
    10289/* 
    10390 * Call method 
    10491 */ 
    105 typedef struct kite_opcode_call 
    106 { 
    107     kite_opcode_t common; 
    108 } kite_opcode_call; 
     92typedef struct kite_opcode_t kite_opcode_call; 
    10993 
    11094/* 
    11195 * Jump if true 
    11296 */ 
    113 typedef struct kite_opcode_jump_true 
    114 { 
    115     kite_opcode_t common; 
    116     kite_opcode_t *jumpto; 
    117 } kite_opcode_jump_true; 
     97typedef struct kite_opcode_t kite_opcode_jump_true; 
    11898 
    11999/* 
    120100 * Jump if false 
    121101 */ 
    122 typedef struct kite_opcode_jump_false 
    123 { 
    124     kite_opcode_t common; 
    125     kite_opcode_t *jumpto; 
    126 } kite_opcode_jump_false; 
     102typedef struct kite_opcode_t kite_opcode_jump_false; 
    127103 
    128104/* 
    129105 * Jump unconditional 
    130106 */ 
    131 typedef struct kite_opcode_jump_unconditional 
    132 { 
    133     kite_opcode_t common; 
    134     kite_opcode_t *jumpto; 
    135 } kite_opcode_jump_unconditional; 
     107typedef struct kite_opcode_t kite_opcode_jump_unconditional; 
    136108 
    137109/* 
    138110 * Handle exception 
    139111 */ 
    140 typedef struct kite_opcode_exception_hndl 
    141 { 
    142     kite_opcode_t common; 
    143     kite_opcode_t *handler; 
    144 } kite_opcode_exception_hndl; 
     112typedef struct kite_opcode_t kite_opcode_exception_hndl; 
    145113 
    146114/* 
    147115 * Handle exception 
    148116 */ 
    149 typedef struct kite_opcode_pop_exception_hndl 
    150 { 
    151     kite_opcode_t common; 
    152 } kite_opcode_pop_exception_hndl; 
     117typedef struct kite_opcode_t kite_opcode_pop_exception_hndl; 
    153118 
    154119/* 
    155120 * Duplicate top of stack 
    156121 */ 
    157 typedef struct kite_opcode_dupe_top 
    158 { 
    159     kite_opcode_t common; 
    160     int dupe_ref; 
    161 } kite_opcode_dupe_top; 
     122typedef struct kite_opcode_t kite_opcode_dupe_top; 
    162123 
    163124/* 
    164125 * Create instance of object 
    165126 */ 
    166 typedef struct kite_opcode_make 
    167 { 
    168     kite_opcode_t common; 
    169 } kite_opcode_make; 
     127typedef struct kite_opcode_t kite_opcode_make; 
    170128 
    171129/* 
    172130 * is/isof evaluation 
    173131 */ 
    174 typedef struct kite_opcode_objis 
    175 { 
    176     kite_opcode_t common; 
    177     int isof; 
    178 } kite_opcode_objis; 
     132typedef struct kite_opcode_t kite_opcode_objis; 
    179133 
    180134/* 
    181135 * Evaluate code 
    182136 */ 
    183 typedef struct kite_opcode_eval 
    184 { 
    185     kite_opcode_t common; 
    186 } kite_opcode_eval; 
     137typedef struct kite_opcode_t kite_opcode_eval; 
    187138 
    188139/* 
    189140 * No op. 
    190141 */ 
    191 typedef struct kite_opcode_nop 
    192 { 
    193     kite_opcode_t common; 
    194 } kite_opcode_nop; 
     142typedef struct kite_opcode_t kite_opcode_nop; 
    195143 
    196144/* 
    197145 * Return 
    198146 */ 
    199 typedef struct kite_opcode_return 
    200 { 
    201     kite_opcode_t common; 
    202 } kite_opcode_return; 
     147typedef struct kite_opcode_t kite_opcode_return; 
    203148 
    204149/* 
    205150 * Put variables onto function stack 
    206151 */ 
    207 typedef struct kite_opcode_funcargs 
    208 { 
    209     kite_opcode_t common; 
    210     struct kite_object_t *args; 
    211 } kite_opcode_funcargs; 
     152typedef struct kite_opcode_t kite_opcode_funcargs; 
    212153 
    213154/* 
    214155 * Define property/variable. 
    215156 */ 
    216 typedef struct kite_opcode_defprop 
    217 { 
    218     kite_opcode_t common; 
    219 } kite_opcode_defprop; 
     157typedef struct kite_opcode_t kite_opcode_defprop; 
    220158 
    221159/* 
    222160 * Get "this". 
    223161 */ 
    224 typedef struct kite_opcode_this 
    225 { 
    226     kite_opcode_t common; 
    227 } kite_opcode_this; 
     162typedef struct kite_opcode_t kite_opcode_this; 
    228163 
    229164/* 
     
    290225 */ 
    291226struct kite_thread_t; 
     227#if 0 
    292228KITE_EXPORT kite_opcode_t *kite_add_to_instruction_list(kite_opcode_t **, kite_opcode_t *); 
    293229void kite_free_instruction_list(struct kite_thread_t *, kite_opcode_t *); 
    294230kite_opcode_t *kite_copy_instruction_list(struct kite_thread_t *, kite_opcode_t *); 
     231#else 
     232KITE_EXPORT kite_opcode_t *kite_add_to_instruction_list(struct kite_thread_t *, kite_opcode_t **, kite_opcode_t *); 
     233void kite_free_instruction_list(struct kite_thread_t *, kite_opcode_t *); 
     234kite_opcode_t *kite_copy_instruction_list(struct kite_thread_t *, kite_object_t *, kite_opcode_t *); 
     235void COMPILE_INSTRUCTION2(kite_thread_t *thd, kite_compiler_t *compiler, kite_opcode_t *inst, int lno, void **dest); 
     236#endif /* 0 */ 
    295237 
    296238#endif /* KITE_VM__KITE_OPCODES_H */ 
  • interpreter/trunk/modules/System.kt

    r478 r619  
    3838import "System.object"; 
    3939import "System.string"; 
     40import "System.regex"; 
  • interpreter/trunk/modules/System/integer.c

    r594 r619  
    3131/* Common code for the integer operations */ 
    3232#define PERFORM_INTEGER_OPERATION(op) \ 
    33     result = this->builtin_data.intvalue op rhs->builtin_data.intvalue; \ 
     33    result = KITE_GET_INTEGER(this) op KITE_GET_INTEGER(rhs); \ 
    3434    kite_vm_return(thd, kite_new_integer(thd, result)); 
    3535 
    3636#define PERFORM_INTEGER_BOOLEAN_OPERATION(op) \ 
    37     result = this->builtin_data.intvalue op rhs->builtin_data.intvalue; \ 
     37    result = KITE_GET_INTEGER(this) op KITE_GET_INTEGER(rhs); \ 
    3838    kite_vm_return(thd, kite_new_boolean(thd, result)); 
    3939     
  • interpreter/trunk/modules/System/object.c

    r617 r619  
    6262 
    6363struct kite_opcode_t; 
    64 extern struct kite_opcode_t *kite_copy_instruction_list(kite_thread_t *thd, struct kite_opcode_t *opc); 
     64extern struct kite_opcode_t *kite_copy_instruction_list(kite_thread_t *thd, kite_object_t *obj, struct kite_opcode_t *opc); 
    6565 
    6666/***************************************************************************** 
     
    264264    kite_object_t *rhs = args; 
    265265     
    266     assert(rhs && this->owner_thread->vm == rhs->owner_thread->vm); 
     266    assert(rhs && this->owner_thread == thd); 
    267267     
    268268    kite_dereference_object(this->parent); 
     
    292292               this->builtin_data.funcvalue.funcptr != NULL) { 
    293293        this->builtin_data.funcvalue.funcptr =  
    294             kite_copy_instruction_list(thd, this->builtin_data.funcvalue.funcptr); 
     294            kite_copy_instruction_list(thd, this, this->builtin_data.funcvalue.funcptr); 
    295295    } 
    296296     
    297297    free(this->object_data.name); 
    298     if (rhs->object_data.name) { 
    299         this->object_data.name = strdup(rhs->object_data.name); 
    300     } else { 
    301         this->object_data.name = NULL; 
    302     } 
    303     if (this->object_data.inherit_from) { 
    304         kite_dereference_object(this->object_data.inherit_from); 
    305     } 
    306     this->object_data.inherit_from =  
    307         kite_reference_object(rhs->object_data.inherit_from); 
    308     if (this->object_data.properties) { 
    309         kite_destruct_symtab(thd, &this->object_data.properties, FALSE); 
    310         this->object_data.properties = NULL; 
    311     } 
    312     if (rhs->object_data.properties) 
    313         kite_copy_symtab(&this->object_data.properties,  
    314                         rhs->object_data.properties); 
     298    if (rhs->type != OBJ_INTEGER && 
     299        rhs->type != OBJ_FLOAT && 
     300        rhs->type != OBJ_BOOLEAN) 
     301    { 
     302        if (rhs->object_data.name) { 
     303            this->object_data.name = strdup(rhs->object_data.name); 
     304        } else { 
     305            this->object_data.name = NULL; 
     306        } 
     307        if (this->object_data.inherit_from) { 
     308            kite_dereference_object(this->object_data.inherit_from); 
     309        } 
     310        this->object_data.inherit_from =  
     311            kite_reference_object(rhs->object_data.inherit_from); 
     312        if (this->object_data.properties) { 
     313            kite_destruct_symtab(thd, &this->object_data.properties, FALSE); 
     314            this->object_data.properties = NULL; 
     315        } 
     316        if (rhs->object_data.properties) 
     317            kite_copy_symtab(&this->object_data.properties,  
     318                             rhs->object_data.properties); 
     319    } 
    315320     
    316321    kite_vm_return(thd, this); 
  • interpreter/trunk/objs/kite_obj_create.c

    r601 r619  
    4949 * Create a new instance of a class which doesn't call destructors. 
    5050 ****************************************************************************/ 
    51 static kite_object_t *kite_new_instance_nodestruct(kite_thread_t *thd, kite_object_t *class) { 
     51static kite_basic_object_t *kite_new_instance_nodestruct(kite_thread_t *thd, kite_basic_object_t *class) { 
    5252    kite_object_t *newobj = NULL; 
    5353     
     
    8686 ****************************************************************************/ 
    8787kite_object_t *kite_new_integer(kite_thread_t *thd, long val) { 
    88     kite_object_t *newobj = NULL, *cls; 
     88    kite_basic_object_t *newobj = NULL; 
     89    kite_object_t *cls; 
    8990    assert(thd != NULL); 
    9091     
     
    110111 ****************************************************************************/ 
    111112kite_object_t *kite_new_float(kite_thread_t *thd, double val) { 
    112     kite_object_t *newobj = NULL, *cls; 
     113    kite_basic_object_t *newobj = NULL; 
     114    kite_object_t *cls; 
    113115    assert(thd != NULL); 
    114116     
     
    226228 ****************************************************************************/ 
    227229kite_object_t *kite_new_boolean(kite_thread_t *thd, int val) { 
    228     kite_object_t *newobj = NULL, *cls; 
     230    kite_basic_object_t *newobj = NULL; 
     231    kite_object_t *cls; 
    229232    assert(thd != NULL); 
    230233 
     
    492495#endif /* HAVE_GC_H */ 
    493496 
    494     if (us->parent && r) { 
    495         kite_dereference_object(us->parent); 
    496         us->parent = NULL; 
    497     } 
    498  
     497    if (us->type != OBJ_BOOLEAN && 
     498        us->type != OBJ_INTEGER && 
     499        us->type != OBJ_FLOAT) 
     500    { 
     501        if (us->parent && r) { 
     502            kite_dereference_object(us->parent); 
     503            us->parent = NULL; 
     504        } 
     505    } 
     506     
    499507    /* Free list objects and string values */ 
    500508    if (us->type == OBJ_LIST && r) { 
  • interpreter/trunk/objs/kite_obj_manip.c

    r506 r619  
    166166             
    167167            if (entry->value) kite_dereference_object(entry->value); 
    168             else val->parent = kite_reference_object(obj); 
     168            else  
     169            { 
     170                if (val->type != OBJ_BOOLEAN && 
     171                    val->type != OBJ_INTEGER && 
     172                    val->type != OBJ_FLOAT) 
     173                { 
     174                    val->parent = kite_reference_object(obj); 
     175                } 
     176            } 
    169177            entry->value = kite_reference_object(val); 
    170178            return; 
  • interpreter/trunk/objs/kite_object.h

    r618 r619  
    119119    int numargs /*! The number of arguments for the given method. */; 
    120120    struct kite_object_t *arginfo /*! A Kite list with names and documentation for each argument. */; 
     121    size_t length /*! Length of function, in bytes. */; 
    121122} kite_function_t; 
    122123 
     
    912913 *          and OBJ_BOOLEAN. No error checking is performed. 
    913914 */ 
    914 #define KITE_GET_INTEGER(v) ((v)->builtin_data.intvalue) 
     915#define KITE_GET_INTEGER(v) (((kite_basic_object_t*)v)->builtin_data.intvalue) 
    915916 
    916917/** 
     
    920921 *          No error checking is performed. 
    921922 */ 
    922 #define KITE_GET_FLOAT(v) ((v)->builtin_data.floatvalue) 
     923#define KITE_GET_FLOAT(v) (((kite_basic_object_t*)v)->builtin_data.floatvalue) 
    923924 
    924925/** 
  • interpreter/trunk/objs/kite_stack.c

    r601 r619  
    3939    kite_stack_entry_t *entry; 
    4040 
    41     assert(st != NULL && obj != NULL); 
     41    assert(st != NULL && (ref == FALSE || obj != NULL)); 
    4242    cur = *st; 
    4343 
  • interpreter/trunk/objs/kite_symtab.c

    r523 r619  
    9595#endif /* HAVE_GC_H */ 
    9696    kite_reference_object(newVal->value); 
    97     newVal->value->parent = p; 
     97    if (newVal->value->type != OBJ_BOOLEAN && 
     98        newVal->value->type != OBJ_INTEGER && 
     99        newVal->value->type != OBJ_FLOAT) 
     100    { 
     101        newVal->value->parent = p; 
     102    } 
    98103    kite_reference_object(p); 
    99104    kite_symtab_insert(thd, dest, newVal); 
Note: See TracChangeset for help on using the changeset viewer.