RPA Toolkit
work on RJS object system
authorMartin Stoilov <martin@rpasearch.com>
Sun, 7 Aug 2011 01:38:44 +0000 (18:38 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Sun, 7 Aug 2011 01:38:44 +0000 (18:38 -0700)
rjs/rjscompiler.c
rlib/robject.h
rvm/rvmcpu.c
rvm/rvmcpu.h
tests/testmisc/rpagen-test.c

index c84660b..48e9e5f 100644 (file)
@@ -594,7 +594,7 @@ int rjs_compiler_rh_stringliteral(rjs_compiler_t *co, rarray_t *records, long re
 #if 0
        rvm_codegen_addins(co->cg, rvm_asmp(RVM_MOV, R1, DA, XX, co->stringcharacters.str));
        rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R2, DA, XX, co->stringcharacters.size));
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_ALLOCSTR, R0, R1, R2, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_STRALLOC, R0, R1, R2, 0));
 #else
        strreg = (rvmreg_t *)r_carray_slot(co->cg->dynamicdata, r_carray_add(co->cg->dynamicdata, NULL));
        s = r_string_create_from_rstr(&co->stringcharacters);
index d9802b2..56de1eb 100644 (file)
@@ -51,7 +51,9 @@ typedef robject_t* (*r_object_copyfun)(const robject_t *ptr);
 
 struct robject_s {
        rlink_t lnk;
-       rpointer *gc;
+       rpointer gc;
+       rpointer gprops;
+       rpointer lprops;
        ruint32 type;
        ruint32 size;
        r_object_cleanupfun cleanup;
index fdaeef2..d8de3db 100644 (file)
@@ -146,8 +146,10 @@ static const char *stropcalls[] = {
        "ELESSEQ",
        "ECMP",
        "ECMN",
-       "ALLOCSTR",
-       "ALLOCARR",
+       "PROPLKUP",
+       "PROPLDR",
+       "STRALLOC",
+       "ARRALLOC",
        "ADDRA",
        "LDA",
        "STA",
@@ -1503,7 +1505,7 @@ static void rvm_op_ecmn(rvmcpu_t *cpu, rvm_asmins_t *ins)
 }
 
 
-static void rvm_op_allocstr(rvmcpu_t *cpu, rvm_asmins_t *ins)
+static void rvm_op_stralloc(rvmcpu_t *cpu, rvm_asmins_t *ins)
 {
        rvmreg_t *arg1 = RVM_CPUREG_PTR(cpu, ins->op1);
        rstring_t *s = r_string_create_strsize((const char*)RVM_CPUREG_GETP(cpu, ins->op2), (unsigned long)RVM_CPUREG_GETU(cpu, ins->op3));
@@ -1527,7 +1529,7 @@ static void rvm_op_mapalloc(rvmcpu_t *cpu, rvm_asmins_t *ins)
 }
 
 
-static void rvm_op_allocarr(rvmcpu_t *cpu, rvm_asmins_t *ins)
+static void rvm_op_arralloc(rvmcpu_t *cpu, rvm_asmins_t *ins)
 {
        rvmreg_t *arg1 = RVM_CPUREG_PTR(cpu, ins->op1);
        ruword size = RVM_CPUREG_GETU(cpu, ins->op2);
@@ -1541,6 +1543,41 @@ static void rvm_op_allocarr(rvmcpu_t *cpu, rvm_asmins_t *ins)
 }
 
 
+static void rvm_op_proplookup(rvmcpu_t *cpu, rvm_asmins_t *ins)
+{
+       long index;
+       rvmreg_t *arg1 = RVM_CPUREG_PTR(cpu, ins->op1);
+       rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
+       rvmreg_t *arg3 = RVM_CPUREG_PTR(cpu, ins->op3);
+       rmap_t *a = (rmap_t*)RVM_REG_GETP(arg2);
+
+       if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_STRING) {
+               index = r_map_lookup(a, -1, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.str, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.size);
+       } else {
+               index = -1;
+       }
+
+       RVM_REG_CLEAR(arg1);
+       RVM_REG_SETTYPE(arg1, RVM_DTYPE_SIGNED);
+       RVM_REG_SETL(arg1, index);
+}
+
+
+static void rvm_op_propldr(rvmcpu_t *cpu, rvm_asmins_t *ins)
+{
+       long index;
+       rvmreg_t tmp = rvm_reg_create_signed(0);
+       rvmreg_t *arg1 = RVM_CPUREG_PTR(cpu, ins->op1);
+//     rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
+//     rmap_t *a = NULL;
+//     rpointer value;
+
+       rvm_opmap_invoke_binary_handler(cpu->opmap, RVM_OPID_CAST, cpu, &tmp, RVM_CPUREG_PTR(cpu, ins->op3), &tmp);
+       index = (long)RVM_REG_GETL(&tmp);
+       rvm_reg_setundef(arg1);
+}
+
+
 static void rvm_op_maplookup(rvmcpu_t *cpu, rvm_asmins_t *ins)
 {
        long index;
@@ -1960,8 +1997,10 @@ static rvm_cpu_op ops[] = {
        rvm_op_elesseq,         // RVM_ELESSEQ
        rvm_op_ecmp,            // RVM_ECMP
        rvm_op_ecmn,            // RVM_ECMN
-       rvm_op_allocstr,        // RVM_ALLOCSTR
-       rvm_op_allocarr,        // RVM_ALLOCARR
+       rvm_op_proplookup,      // RVM_PROPLKUP
+       rvm_op_propldr,         // RVM_PROPLDR
+       rvm_op_stralloc,        // RVM_STRALLOC
+       rvm_op_arralloc,        // RVM_ARRALLOC
        rvm_op_addra,           // RVM_ADDRA
        rvm_op_lda,                     // RVM_LDA
        rvm_op_sta,                     // RVM_STA
index 73f8c13..77c791b 100644 (file)
@@ -150,8 +150,10 @@ enum {
 
        RVM_ECMP,               /* Compare: status register is updated based on the result: op1 - op2 */
        RVM_ECMN,               /* Compare Negative: status register is updated based on the result: op1 + op2 */
-       RVM_ALLOCSTR,   /* Allocate string in op1, op2 is pointer (char*) to string, op3 is the size */
-       RVM_ALLOCARR,   /* Allocate array in op1, op2 is the size */
+       RVM_PROPLKUP,   /* Lookup r_object property */
+       RVM_PROPLDR,    /* Load r_object property */
+       RVM_STRALLOC,   /* Allocate string in op1, op2 is pointer (char*) to string, op3 is the size */
+       RVM_ARRALLOC,   /* Allocate array in op1, op2 is the size */
        RVM_ADDRA,              /* op1 is the destination memory, op2 is the array, op3 is the offset */
        RVM_LDA,                /* op1 is the destination, op2 is the array, op3 is the offset */
        RVM_STA,                /* op1 is the source, op2 is the array, op3 is the offset */
@@ -281,7 +283,8 @@ do { \
 #define RVM_E_NOMEM                    (7)
 #define RVM_E_NOTFUNCTION      (8)
 #define RVM_E_NOTOBJECT                (9)
-#define RVM_E_USERABORT                (10)
+#define RVM_E_NOTSTRING                (10)
+#define RVM_E_USERABORT                (11)
 
 typedef struct rvm_asmins_s rvm_asmins_t;
 typedef struct rvmcpu_s rvmcpu_t;
index edd6835..1fe24f6 100644 (file)
@@ -648,7 +648,7 @@ int codegen_string_callback(rpa_stat_handle stat, const char *name, void *userda
 
        rvm_codegen_addins(co->cg, rvm_asmp(RVM_MOV, R1, DA, XX, (void*)input));
        rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R2, DA, XX, size));
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_ALLOCSTR, R0, R1, R2, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_STRALLOC, R0, R1, R2, 0));
 
        codegen_print_callback(stat, name, userdata, input, size, reason);
        codegen_dump_code(rvm_codegen_getcode(co->cg, off), rvm_codegen_getcodesize(co->cg) - off);