RPA Toolkit
RJS changes...
authorMartin Stoilov <martin@rpasearch.com>
Tue, 23 Aug 2011 04:44:11 +0000 (21:44 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Tue, 23 Aug 2011 04:44:11 +0000 (21:44 -0700)
13 files changed:
build/unix/build.mk
rjs/ecma262.rpa
rjs/rjs.c
rjs/rjs.h
rjs/rjscompiler.c
rjs/rjsuids.h
tests/testmisc/asm-callback.c
tests/testmisc/build/unix/misc-tests.mk
tests/testmisc/codegen-test.c
tests/testmisc/funcarg-test.c
tests/testmisc/loop-test.c
tests/testmisc/speed-test.c
tests/testmisc/test-asm.sh

index 8612690..99c966d 100644 (file)
@@ -3,11 +3,11 @@ all:
        +make -C $(SRCDIR)/rpa/build/unix/$(ARCHDIR) all
        +make -C $(SRCDIR)/rvm/build/unix/$(ARCHDIR) all
        +make -C $(SRCDIR)/rgrep/build/unix/$(ARCHDIR) all
-#      +make -C $(SRCDIR)/tests/testmisc/build/unix/$(ARCHDIR) all
+       +make -C $(SRCDIR)/tests/testmisc/build/unix/$(ARCHDIR) all
        +make -C $(SRCDIR)/tests/testrpa/build/unix/$(ARCHDIR) all
        +make -C $(SRCDIR)/rjs/build/unix/$(ARCHDIR) all
 ifeq ($(OS), linux)
-#      +make -C $(SRCDIR)/tests/testrjs/build/unix/$(ARCHDIR) all
+       +make -C $(SRCDIR)/tests/testrjs/build/unix/$(ARCHDIR) all
 endif
 
 distclean: clean
index d8c926e..ca3db6c 100644 (file)
@@ -99,6 +99,7 @@
 #!emitid DefaultClause                                 UID_DEFAULTCLAUSE                                       69
 #!emitid CaseCode                                              UID_CASECODE                                            70
 #!emitid CaseBlock                                             UID_CASEBLOCK                                           71
+#!emitid HexIntegerLiteral                             UID_HEXINTEGERLITERAL                           72
 
 #!abort SC
 
index 583aacc..41fbb04 100644 (file)
--- a/rjs/rjs.c
+++ b/rjs/rjs.c
@@ -327,17 +327,34 @@ static long rjs_op_mapproplookup(rmap_t *map, rvmcpu_t *cpu, rvm_asmins_t *ins)
 }
 
 
+static long rjs_op_stringproplookup(rstring_t *str, rvmcpu_t *cpu, rvm_asmins_t *ins)
+{
+       long index = -1;
+       rvmreg_t *arg3 = RVM_CPUREG_PTR(cpu, ins->op3);
+
+       if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_SIGNED || RVM_REG_GETTYPE(arg3) == RVM_DTYPE_UNSIGNED) {
+               index = RVM_REG_GETL(arg3);
+       } else if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_DOUBLE) {
+               index = (long)RVM_REG_GETD(arg3);
+       } else if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_STRING) {
+               index = r_strtol(((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.str, NULL, 10);
+       }
+       return index;
+}
+
+
 static void rjs_op_proplookup(rvmcpu_t *cpu, rvm_asmins_t *ins)
 {
        long index = -1;
        rvmreg_t *arg1 = RVM_CPUREG_PTR(cpu, ins->op1);
        rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
-       rmap_t *map = (rmap_t*)RVM_REG_GETP(arg2);
 
        if (rvm_reg_gettype(arg2) == RVM_DTYPE_MAP) {
+               rmap_t *map = (rmap_t*)RVM_REG_GETP(arg2);
                index = rjs_op_mapproplookup(map, cpu, ins);
-       } else {
-
+       } else if (rvm_reg_gettype(arg2) == RVM_DTYPE_STRING) {
+               rstring_t *str = (rstring_t*)RVM_REG_GETP(arg2);
+               index = rjs_op_stringproplookup(str, cpu, ins);
        }
        RVM_REG_CLEAR(arg1);
        RVM_REG_SETTYPE(arg1, RVM_DTYPE_SIGNED);
@@ -515,7 +532,6 @@ static void rjs_op_propldr(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rvmreg_t *arg1 = RVM_CPUREG_PTR(cpu, ins->op1);
        rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
        rvmreg_t tmp = rvm_reg_create_signed(0);
-       rmap_t *a = NULL;
        rpointer value;
        long index;
 
@@ -523,11 +539,20 @@ static void rjs_op_propldr(rvmcpu_t *cpu, rvm_asmins_t *ins)
        index = (long)RVM_REG_GETL(&tmp);
        rvm_reg_setundef(arg1);
        if (rvm_reg_gettype(arg2) == RVM_DTYPE_MAP) {
-               a = (rmap_t*)RVM_REG_GETP(arg2);
+               rmap_t *a = (rmap_t*)RVM_REG_GETP(arg2);
                value = r_map_value(a, index);
                if (value) {
                        *arg1 = *((rvmreg_t*)value);
                }
+       } else if (rvm_reg_gettype(arg2) == RVM_DTYPE_STRING) {
+               rstring_t *s = (rstring_t*)RVM_REG_GETP(arg2);
+               if (index >= s->s.size) {
+                       rvm_reg_setundef(arg1);
+               } else {
+                       rstring_t *allocstr = r_string_create_strsize(&s->s.str[index], 1);
+                       r_gc_add(cpu->gc, (robject_t*)allocstr);
+                       rvm_reg_setstring(arg1, allocstr);
+               }
        }
 }
 
@@ -923,6 +948,10 @@ rjs_engine_t *rjs_engine_create()
        rjs_op_not_init(RJS_USERDATA2MAP(cpu->userdata2));
        rjs_op_logicnot_init(RJS_USERDATA2MAP(cpu->userdata2));
 
+
+       jse->props[RVM_DTYPE_STRING] = r_map_create(sizeof(rvmreg_t), 3);
+       r_gc_add(jse->cpu->gc, (robject_t*)jse->props[RVM_DTYPE_STRING]);
+
        return jse;
 error:
        rjs_engine_destroy(jse);
index f91454c..e0bedd9 100644 (file)
--- a/rjs/rjs.h
+++ b/rjs/rjs.h
@@ -39,6 +39,7 @@ typedef struct rjs_engine_s {
        rjs_compiler_t *co;
        rarray_t *cgs;
        rarray_t *errors;
+       rmap_t *props[RVM_DTYPE_SIZE];
        rvmcpu_t *cpu;
        long debugcompile:1;
        long debugexec:1;
@@ -94,6 +95,7 @@ typedef struct rjs_engine_s {
 
 #define RJS_GPKEY_NONE 0
 #define RJS_GPKEY_TYPES 1
+#define RJS_GPKEY_PROPS 2
 
 const char *rjs_version();
 
index 5af7790..5329443 100644 (file)
@@ -532,6 +532,25 @@ int rjs_compiler_rh_decimalintegerliteral(rjs_compiler_t *co, rarray_t *records,
 }
 
 
+int rjs_compiler_rh_hexintegerliteral(rjs_compiler_t *co, rarray_t *records, long rec)
+{
+       rparecord_t *prec;
+       prec = (rparecord_t *)r_array_slot(records, rec);
+       rjs_compiler_debughead(co, records, rec);
+       rjs_compiler_debugtail(co, records, rec);
+
+       if (rjs_compiler_playchildrecords(co, records, rec) < 0)
+               return -1;
+
+       rec = rpa_recordtree_get(records, rec, RPA_RECORD_END);
+       prec = (rparecord_t *)r_array_slot(records, rec);
+       rjs_compiler_debughead(co, records, rec);
+       rvm_codegen_addins(co->cg, rvm_asml(RVM_MOV, R0, DA, XX, r_strtol(prec->input, NULL, 16)));
+       rjs_compiler_debugtail(co, records, rec);
+       return 0;
+}
+
+
 int rjs_compiler_rh_decimalnonintegerliteral(rjs_compiler_t *co, rarray_t *records, long rec)
 {
        rparecord_t *prec;
@@ -1896,6 +1915,7 @@ rjs_compiler_t *rjs_compiler_create(rvmcpu_t *cpu)
        co->handlers[UID_LEFTHANDSIDEEXPRESSION] = rjs_compiler_rh_lefthandsideexpression;
        co->handlers[UID_LEFTHANDSIDEEXPRESSIONADDR] = rjs_compiler_rh_lefthandsideexpressionaddr;
        co->handlers[UID_DECIMALINTEGERLITERAL] = rjs_compiler_rh_decimalintegerliteral;
+       co->handlers[UID_HEXINTEGERLITERAL] = rjs_compiler_rh_hexintegerliteral;
        co->handlers[UID_DECIMALNONINTEGERLITERAL] = rjs_compiler_rh_decimalnonintegerliteral;
        co->handlers[UID_STRINGCHARACTERS] = rjs_compiler_rh_stringcharacters;
        co->handlers[UID_STRINGLITERAL] = rjs_compiler_rh_stringliteral;
index 9f1d341..7f9f87b 100644 (file)
@@ -86,3 +86,4 @@
 #define UID_DEFAULTCLAUSE 69
 #define UID_CASECODE 70
 #define UID_CASEBLOCK 71
+#define UID_HEXINTEGERLITERAL 72
index 3d1ad3c..93b4e17 100644 (file)
@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
        vmcode[off++] = rvm_asm(RVM_EXT, R0, XX, XX, 0);
        fprintf(stdout, "sizeof rvm_asmins_t is: %d:\n", (unsigned int) sizeof(rvm_asmins_t));
        fprintf(stdout, "Code List (sizeof rvmreg_t is: %d(%d)):\n", (unsigned int) sizeof(rvmreg_t), (unsigned int) sizeof(vm->r[0].v));
-       rvm_asm_dump(vmcode, off);
+       rvm_asm_dump(vm, vmcode, off);
        fprintf(stdout, "Code Execution:\n");
 #ifdef EXECDEBUG
        ret = rvm_cpu_exec_debug(vm, vmcode, 0);
index f137abe..b59ca20 100644 (file)
@@ -18,20 +18,13 @@ LIBS += -lrpa -lrvm -lrlib -lpthread -lm
 TESTS  += $(OUTDIR)/funcarg-test
 TESTS   += $(OUTDIR)/codegen-test
 TESTS   += $(OUTDIR)/codemap-test
-TESTS   += $(OUTDIR)/opmap-test
-TESTS   += $(OUTDIR)/string-test
 TESTS   += $(OUTDIR)/rlock-test
-TESTS   += $(OUTDIR)/rarray-test
-TESTS   += $(OUTDIR)/rcarray-test
-TESTS   += $(OUTDIR)/rharray-test
-TESTS   += $(OUTDIR)/rmap-test
 TESTS   += $(OUTDIR)/scope-test
 TESTS   += $(OUTDIR)/rhash-test
 TESTS   += $(OUTDIR)/rvm-test
 TESTS   += $(OUTDIR)/loop-test
 TESTS   += $(OUTDIR)/speed-test
 TESTS   += $(OUTDIR)/memalloc-test
-TESTS   += $(OUTDIR)/asm-cast
 TESTS   += $(OUTDIR)/asm-add
 TESTS   += $(OUTDIR)/asm-adds
 TESTS   += $(OUTDIR)/asm-b
@@ -46,10 +39,17 @@ TESTS   += $(OUTDIR)/asm-sbc
 TESTS   += $(OUTDIR)/asm-shiftops
 TESTS   += $(OUTDIR)/asm-stack
 TESTS   += $(OUTDIR)/asm-bl
-TESTS   += $(OUTDIR)/asm-ecmp
-TESTS   += $(OUTDIR)/asm-esub
-TESTS   += $(OUTDIR)/asm-eadd
 
+ETESTS   += $(OUTDIR)/asm-ecmp
+ETESTS   += $(OUTDIR)/asm-esub
+ETESTS   += $(OUTDIR)/asm-eadd
+ETESTS   += $(OUTDIR)/rarray-test
+ETESTS   += $(OUTDIR)/rcarray-test
+ETESTS   += $(OUTDIR)/rharray-test
+ETESTS   += $(OUTDIR)/rmap-test
+ETESTS   += $(OUTDIR)/string-test
+ETESTS   += $(OUTDIR)/opmap-test
+ETESTS   += $(OUTDIR)/asm-cast
 
 all : $(OUTDIR) $(TESTS)
 
index 438e682..8abe7d1 100644 (file)
@@ -116,7 +116,7 @@ int main(int argc, char *argv[])
                r_printf("Unresolved symbol: %s\n", err->name->str);
                goto end;
        }
-       rvm_asm_dump(rvm_codegen_getcode(cg, 0), rvm_codegen_getcodesize(cg));
+       rvm_asm_dump(cpu, rvm_codegen_getcode(cg, 0), rvm_codegen_getcodesize(cg));
        rvm_cpu_exec_debug(cpu, rvm_codegen_getcode(cg, 0), 0);
 
 end:
index a4cf669..36c4764 100644 (file)
@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
                goto end;
        }
 
-       rvm_asm_dump(rvm_codegen_getcode(cg, 0), rvm_codegen_getcodesize(cg));
+       rvm_asm_dump(cpu, rvm_codegen_getcode(cg, 0), rvm_codegen_getcodesize(cg));
        rvm_cpu_exec_debug(cpu, rvm_codegen_getcode(cg, 0), 0);
 end:
        rvm_cpu_destroy(cpu);
index e90bc5b..3053e0b 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include "common.h"
-#include "rvm/rvmoperator.h"
-
-
-static void rvm_eadd(rvmcpu_t *cpu, rvm_asmins_t *ins)
-{
-       rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
-       rvmreg_t *arg3 = RVM_CPUREG_PTR(cpu, ins->op3);
-
-       rvm_opmap_invoke_binary_handler(RJS_USERDATA2MAP(cpu->userdata2), RVM_OPID_ADD, cpu, RVM_CPUREG_PTR(cpu, ins->op1), arg2, arg3);
-//     fprintf(stdout, "%s %ld\n", __FUNCTION__, RVM_CPUREG_GETU(cpu, ins->op1));
-}
 
 
 static void rvm_callback_two(rvmcpu_t *vm, rvm_asmins_t *ins)
@@ -42,7 +31,6 @@ static void rvm_callback_two(rvmcpu_t *vm, rvm_asmins_t *ins)
 
 static rvm_switable_t calltable[] = {
        {"rvm_callback_two", rvm_callback_two},
-       {"rvm_eadd", rvm_eadd},
        {NULL, NULL},
 };
 
@@ -64,19 +52,13 @@ int main(int argc, char *argv[])
 
        vmcode[off++] = rvm_asm(RVM_MOV, R4, DA, XX, 0);
        vmcode[off++] = rvm_asm(RVM_MOV, R5, DA, XX, iter);
-       vmcode[off++] = rvm_asmd(RVM_EMUL, R4, R4, DA, 2.0);
-       vmcode[off++] = rvm_asmd(RVM_EDIV, R4, R4, DA, 2.0);
-       vmcode[off++] = rvm_asm(RVM_EADD, R4, R4, DA, 2);
-       vmcode[off++] = rvm_asm(RVM_ESUB, R4, R4, DA, 1);
-//     vmcode[off++] = rvm_asm(RVM_MOV, R1, DA, XX, 1);
-//     vmcode[off++] = rvm_asm(RVM_MOV, R2, DA, XX, 2);
-//     vmcode[off++] = rvm_asm(RVM_EADD, R0, R1, R2, 0);
-//     vmcode[off++] = rvm_asm(RVM_OPSWI(rvm_cpu_swilookup(vm, "rvm_eadd")), R0, R1, R2, 0);
-//     vmcode[off++] = rvm_asm(RVM_PUSH, DA, XX, XX, 1);
-//     vmcode[off++] = rvm_asm(RVM_POP, R1, XX, XX, 0);
+       vmcode[off++] = rvm_asmd(RVM_MUL, R4, R4, DA, 2);
+       vmcode[off++] = rvm_asmd(RVM_DIV, R4, R4, DA, 2);
+       vmcode[off++] = rvm_asm(RVM_ADD, R4, R4, DA, 2);
+       vmcode[off++] = rvm_asm(RVM_SUB, R4, R4, DA, 1);
        vmcode[off++] = rvm_asm(RVM_PUSH, R4, XX, XX, 0);
        vmcode[off++] = rvm_asm(RVM_POP, R4, XX, XX, 0);
-       vmcode[off++] = rvm_asm(RVM_ECMP, R4, R5, XX, 0);
+       vmcode[off++] = rvm_asm(RVM_CMP, R4, R5, XX, 0);
        vmcode[off++] = rvm_asml(RVM_BLES, DA, XX, XX, -7);
        vmcode[off++] = rvm_asm(RVM_MOV, R0, R4, XX, 0);
        vmcode[off++] = rvm_asm(RVM_PRN, R0, XX, XX, 0);
index ed188a6..eb93116 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include "common.h"
-#include "rvm/rvmoperator.h"
-
-
-static void rvm_eadd(rvmcpu_t *cpu, rvm_asmins_t *ins)
-{
-       rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
-       rvmreg_t *arg3 = RVM_CPUREG_PTR(cpu, ins->op3);
-
-       rvm_opmap_invoke_binary_handler(RJS_USERDATA2MAP(cpu->userdata2), RVM_OPID_ADD, cpu, RVM_CPUREG_PTR(cpu, ins->op1), arg2, arg3);
-//     fprintf(stdout, "%s %ld\n", __FUNCTION__, RVM_CPUREG_GETU(cpu, ins->op1));
-}
 
 
 static void rvm_callback_two(rvmcpu_t *vm, rvm_asmins_t *ins)
@@ -42,7 +31,6 @@ static void rvm_callback_two(rvmcpu_t *vm, rvm_asmins_t *ins)
 
 static rvm_switable_t calltable[] = {
        {"rvm_callback_two", rvm_callback_two},
-       {"rvm_eadd", rvm_eadd},
        {NULL, NULL},
 };
 
index 6e925f2..28eea25 100755 (executable)
@@ -3,5 +3,6 @@
 F=`find build/ -name "asm*"`; 
 for f in $F; 
 do 
+    echo "Running: $f"
     $f; 
 done