]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: rt-vm relocation now supports accessing a field directly
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 15 Oct 2009 00:24:23 +0000 (19:24 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 15 Oct 2009 00:24:23 +0000 (19:24 -0500)
14 files changed:
basis/bootstrap/image/image.factor
basis/compiler/codegen/codegen.factor
basis/compiler/codegen/fixup/fixup.factor
basis/cpu/x86/32/32.factor
basis/cpu/x86/64/bootstrap.factor
basis/cpu/x86/bootstrap.factor
basis/cpu/x86/x86.factor
core/quotations/quotations.factor
vm/arrays.cpp
vm/arrays.hpp
vm/code_block.cpp
vm/jit.hpp
vm/layouts.hpp
vm/quotations.cpp

index eee65c1eba719f5dbd293be9e888e1a417d93376..d90cd71bc4f4671dbae3d2d96cce6d7986cee8d4 100644 (file)
@@ -111,18 +111,25 @@ SYMBOL: jit-relocations
 : jit-rel ( rc rt -- )
     over compute-offset 3array jit-relocations get push-all ;
 
-: make-jit ( quot -- jit-data )
+SYMBOL: jit-literals
+
+: jit-literal ( literal -- )
+    jit-literals get push ;
+
+: make-jit ( quot -- jit-literals jit-data )
     [
+        V{ } clone jit-literals set
         V{ } clone jit-relocations set
         call( -- )
+        jit-literals get >array
         jit-relocations get >array
     ] B{ } make prefix ;
 
 : jit-define ( quot name -- )
-    [ make-jit ] dip set ;
+    [ make-jit nip ] dip set ;
 
 : define-sub-primitive ( quot word -- )
-    [ make-jit ] dip sub-primitives get set-at ;
+    [ make-jit 2array ] dip sub-primitives get set-at ;
 
 ! The image being constructed; a vector of word-size integers
 SYMBOL: image
index 467e8d9b8dad58a0d6583b32fcc29fb50ee54d2b..31918658c4979337ef49dbe13973a09db90ad994 100755 (executable)
@@ -63,7 +63,7 @@ M: ##no-tco generate-insn drop ;
 
 M: ##call generate-insn
     word>> dup sub-primitive>>
-    [ first % ] [ [ add-call ] [ %call ] bi ] ?if ;
+    [ second first % ] [ [ add-call ] [ %call ] bi ] ?if ;
 
 M: ##jump generate-insn word>> [ add-call ] [ %jump ] bi ;
 
index f56d654c77a0df9fbfee97eb351bde5bfab752d4..21a8db807bc77b141fb56797cb1e5f254cb9245f 100755 (executable)
@@ -77,8 +77,8 @@ SYMBOL: relocation-table
 : rel-here ( offset class -- )
     [ add-literal ] dip rt-here rel-fixup ;
 
-: rel-vm ( class -- )
-    rt-vm rel-fixup ;
+: rel-vm ( offset class -- )
+    [ add-literal ] dip rt-vm rel-fixup ;
 
 : rel-cards-offset ( class -- )
     rt-cards-offset rel-fixup ;
index 55e9448c7cde62e43dd5038e9900249fc8679764..c095f5493c5bf73dc4c57f0aa651e1e3ac760f87 100755 (executable)
@@ -50,7 +50,7 @@ M: x86.32 reserved-area-size 0 ;
 M: x86.32 %alien-invoke 0 CALL rc-relative rel-dlsym ;
 
 : push-vm-ptr ( -- )
-    0 PUSH rc-absolute-cell rel-vm ; ! push the vm ptr as an argument
+    0 PUSH rc-absolute-cell rel-vm ; ! push the vm ptr as an argument
 
 M: x86.32 return-struct-in-registers? ( c-type -- ? )
     c-type
index bffe056656a7c0b685fefed9b70b36c59f0b4445..e26e8042328e74e16f01265e581600c9fbc81207 100644 (file)
@@ -26,10 +26,10 @@ IN: bootstrap.x86
     temp0 temp0 [] MOV
     ! save stack pointer
     temp0 [] stack-reg MOV
-    ! load XT
-    temp1 0 MOV rc-absolute-cell rt-primitive jit-rel
     ! load vm ptr
     arg1 0 MOV rc-absolute-cell rt-vm jit-rel
+    ! load XT
+    temp1 0 MOV rc-absolute-cell rt-primitive jit-rel
     ! go
     temp1 JMP
 ] jit-primitive jit-define
index 3cc71d22f7417301d873d62bf70f91b40b3b2db5..eb4da296dc9d85601a76d3a0bf44c178262b80b3 100644 (file)
@@ -252,7 +252,7 @@ big-endian off
     ! pop stack
     ds-reg bootstrap-cell SUB
     ! pass vm pointer
-    arg2 0 MOV rc-absolute-cell rt-vm jit-rel
+    arg2 0 MOV 0 jit-literal rc-absolute-cell rt-vm jit-rel
     ! call quotation
     arg1 quot-xt-offset [+] JMP
 ] \ (call) define-sub-primitive
@@ -402,6 +402,7 @@ big-endian off
 ! Comparisons
 : jit-compare ( insn -- )
     ! load t
+    t jit-literal
     temp3 0 MOV rc-absolute-cell rt-immediate jit-rel
     ! load f
     temp1 \ f tag-number MOV
index 9b063d59e849060f9369d176323e4af6cbb92c2a..4a3545a5ba48554f564206eb36dbe07d58bbd19c 100644 (file)
@@ -370,10 +370,10 @@ M: x86 %shr int-rep two-operand [ SHR ] emit-shift ;
 M: x86 %sar int-rep two-operand [ SAR ] emit-shift ;
 
 : %mov-vm-ptr ( reg -- )
-    0 MOV rc-absolute-cell rel-vm ;
+    0 MOV rc-absolute-cell rel-vm ;
 
 M: x86 %vm-field-ptr ( dst field -- )
-    [ drop %mov-vm-ptr ] [ vm-field-offset ADD ] 2bi ;
+    [ 0 MOV ] dip vm-field-offset rc-absolute-cell rel-vm ;
 
 : load-allot-ptr ( nursery-ptr allot-ptr -- )
     [ drop "nursery" %vm-field-ptr ] [ swap [] MOV ] 2bi ;
index af3c110d61db516a333fa34cc20daf2a75d4caf6..f2b17b3f9da989da2b5e86d88a3a387401979072 100644 (file)
@@ -8,10 +8,10 @@ IN: quotations
 <PRIVATE
 
 : uncurry ( curry -- obj quot )
-    dup 2 slot swap 3 slot ; inline
+    { curry } declare dup 2 slot swap 3 slot ; inline
 
 : uncompose ( compose -- quot quot2 )
-    dup 2 slot swap 3 slot ; inline
+    { compose } declare dup 2 slot swap 3 slot ; inline
 
 PRIVATE>
 
index af8e0c82d5a4c05fc6e5d8847bef67914871d2ad..b09ff5c5afed55e7e024a58b6d49e995a33945f9 100644 (file)
@@ -64,14 +64,14 @@ cell factor_vm::allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_)
 
 void factor_vm::primitive_resize_array()
 {
-       arraya = untag_check<array>(dpop());
+       array *a = untag_check<array>(dpop());
        cell capacity = unbox_array_size();
        dpush(tag<array>(reallot_array(a,capacity)));
 }
 
 void growable_array::add(cell elt_)
 {
-       factor_vmparent_vm = elements.parent_vm;
+       factor_vm *parent_vm = elements.parent_vm;
        gc_root<object> elt(elt_,parent_vm);
        if(count == array_capacity(elements.untagged()))
                elements = parent_vm->reallot_array(elements.untagged(),count * 2);
@@ -79,6 +79,21 @@ void growable_array::add(cell elt_)
        parent_vm->set_array_nth(elements.untagged(),count++,elt.value());
 }
 
+void growable_array::append(array *elts_)
+{
+       factor_vm *parent_vm = elements.parent_vm;
+       gc_root<array> elts(elts_,parent_vm);
+       cell capacity = array_capacity(elts.untagged());
+       if(count + capacity > array_capacity(elements.untagged()))
+       {
+               elements = parent_vm->reallot_array(elements.untagged(),
+                       (count + capacity) * 2);
+       }
+
+       for(cell index = 0; index < capacity; index++)
+               parent_vm->set_array_nth(elements.untagged(),count++,array_nth(elts.untagged(),index));
+}
+
 void growable_array::trim()
 {
        factor_vm *parent_vm = elements.parent_vm;
index 79f31573f427f12c712483459bd16a12a9aadc79..accf8b3b04dcfc1b7cedadb1a7e5e01663087d57 100755 (executable)
@@ -29,6 +29,7 @@ struct growable_array {
        explicit growable_array(factor_vm *myvm, cell capacity = 10) : count(0), elements(myvm->allot_array(capacity,F),myvm) {}
 
        void add(cell elt);
+       void append(array *elts);
        void trim();
 };
 
index 69622f48a1a89a764a6414c4e0ee8f3a5782d57f..7214aa235e38d1d72646a76040ad489f951b0042 100755 (executable)
@@ -34,13 +34,13 @@ int factor_vm::number_of_parameters(relocation_type type)
        case RT_IMMEDIATE:
        case RT_HERE:
        case RT_UNTAGGED:
+       case RT_VM:
                return 1;
        case RT_DLSYM:
                return 2;
        case RT_THIS:
        case RT_STACK_CHAIN:
        case RT_MEGAMORPHIC_CACHE_HITS:
-       case RT_VM:
        case RT_CARDS_OFFSET:
        case RT_DECKS_OFFSET:
                return 0;
@@ -181,7 +181,7 @@ cell factor_vm::compute_relocation(relocation_entry rel, cell index, code_block
        case RT_MEGAMORPHIC_CACHE_HITS:
                return (cell)&megamorphic_cache_hits;
        case RT_VM:
-               return (cell)this;
+               return (cell)this + untag_fixnum(ARG);
        case RT_CARDS_OFFSET:
                return cards_offset;
        case RT_DECKS_OFFSET:
index 789f68e22be359b0209c53cde0b2107895fda05d..63b4454514bc8ef245aab1cc286be84821c31a23 100644 (file)
@@ -41,9 +41,9 @@ struct jit {
 
        void emit_subprimitive(cell word_) {
                gc_root<word> word(word_,parent_vm);
-               gc_root<array> code_template(word->subprimitive,parent_vm);
-               if(array_capacity(code_template.untagged()) > 1) literal(parent_vm->T);
-               emit(code_template.value());
+               gc_root<array> code_pair(word->subprimitive,parent_vm);
+               literals.append(parent_vm->untag<array>(array_nth(code_pair.untagged(),0)));
+               emit(array_nth(code_pair.untagged(),1));
        }
 
        void emit_class_lookup(fixnum index, cell type);
index 988fc99ec5755a0a51eeb6c630646bd04002060a..2fba97d74736164b9fd9be6b7fe48a80c3dd4050 100644 (file)
@@ -199,9 +199,6 @@ struct string : public object {
 /* The compiled code heap is structured into blocks. */
 struct heap_block
 {
-       /* Bit 0: mark
-          Bit 1-7: type
-          Bit 8-...: size */
        cell header;
 
        bool marked_p() { return header & 1; }
index afb02bb48545bdd3c7eb32704f314d556846408b..2823d5cb7818cfc85108ffc8a69a8e71caa31e7e 100755 (executable)
@@ -199,7 +199,9 @@ void quotation_jit::iterate_quotation()
                        /* Primitive calls */
                        if(primitive_call_p(i,length))
                        {
-                               emit_with(parent_vm->userenv[JIT_PRIMITIVE],obj.value());
+                               literal(tag_fixnum(0));
+                               literal(obj.value());
+                               emit(parent_vm->userenv[JIT_PRIMITIVE]);
 
                                i++;