]> gitweb.factorcode.org Git - factor.git/commitdiff
2generic is compiled
authorSlava Pestov <slava@factorcode.org>
Sat, 2 Oct 2004 02:46:12 +0000 (02:46 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 2 Oct 2004 02:46:12 +0000 (02:46 +0000)
Makefile
TODO.FACTOR.txt
library/compiler/compiler-macros.factor
library/compiler/generic.factor
library/compiler/interpret-only.factor
library/test/x86-compiler/generic.factor
native/arithmetic.c
native/arithmetic.h

index e166402b4b020a5a4a3eb1c42e81d05d7af2ed5a..249cb0ef0a603699b81016283a800bea7194f451 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,11 @@
-CC = gcc
+CC = gcc34
 
 # On FreeBSD, to use SDL and other libc_r libs:
-CFLAGS = -g -Wall -export-dynamic -pthread
+CFLAGS = -g -Wall -export-dynamic -pthread
 # On PowerPC G5:
 # CFLAGS = -mcpu=970 -mtune=970 -mpowerpc64 -ffast-math -O3
 # On Pentium 4:
-# CFLAGS = -march=pentium4 -ffast-math -O3 -fomit-frame-pointer -export-dynamic
+CFLAGS = -march=pentium4 -ffast-math -Os -fomit-frame-pointer -export-dynamic -pthread
 # Add -fomit-frame-pointer if you don't care about debugging
 # CFLAGS = -Os -g -Wall
 
index 276e6f6f00a6f3515ac7b71e0d3ac4795988e5f6..21e3ac3c57cfcc5c0a8d35f9a5735148e834ef3b 100644 (file)
@@ -3,19 +3,13 @@ FFI:
 \r
 - BIN: 2: bad\r
 \r
-- symbols are not primitives\r
+- compile word twice; no more 'cannot compile' error!\r
+\r
 - compiled? messy\r
 - compiler: drop literal peephole optimization\r
-- compiler: type-of { ... } call\r
-            type-of { ... } execute\r
-           arithmetic-type { ... } call\r
-           arithmetic-type { ... } execute\r
-- ditch ds/cs envs, just use dlsym instead\r
+- compiler: arithmetic-type { ... } execute\r
 - getenv/setenv: if literal arg, compile as a load/store\r
 - inline words\r
-- raise an error when compiling something we can't\r
-  call, datastack/callstack, set-datastack/callstack,\r
-  execute\r
 \r
 [error] SideKick$BufferChangeHandler: We have cplusplus.xml (/home/slava/jEdit/modes/) but got event for DefaultInputHandler.java (/home/slava/jEdit/org/gjt/sp/jedit/gui/)\r
 [error] SideKick$BufferChangeHandler: We have cplusplus.xml (/home/slava/jEdit/modes/) but got event for DefaultInputHandler.java (/home/slava/jEdit/org/gjt/sp/jedit/gui/)\r
index d941319e314d66956192f55131c5ae87041fa07c..f210a5ba803319106aa450f72e83e76d72cf8d89 100644 (file)
@@ -75,9 +75,18 @@ USE: alien
     #! Call named C function in Factor interpreter executable.
     dlsym-self CALL JUMP-FIXUP ;
 
-: TYPE-OF ( -- )
+: TYPE ( -- )
     #! Peek datastack, store type # in EAX.
     PEEK-DS
     EAX PUSH-[R]
     "type_of" SELF-CALL
     4 ESP R+I ;
+
+: ARITHMETIC-TYPE ( -- )
+    #! Peek top two on datastack, store arithmetic type # in EAX.
+    PEEK-DS
+    EAX PUSH-[R]
+    4 EAX R-I
+    EAX PUSH-[R]
+    "arithmetic_type" SELF-CALL
+    8 ESP R+I ;
index 93345781afd256b9e245e5c9b0dce2a82b796d6f..893d1aca8a6b59eb7f96ef38f9a56b63d07913c9 100644 (file)
@@ -34,37 +34,27 @@ USE: math
 USE: lists
 USE: vectors
 
+: begin-jump-table ( -- start-fixup end-fixup )
+    2 EAX R<<I
+    EAX+/PARTIAL
+    tail? [ 0 ] [ 0 PUSH-I compiled-offset 4 - ] ifte ;
+
 : compile-table-jump ( start-fixup -- end-fixup )
+    #! Compile a piece of code that jumps to an offset in a
+    #! jump table indexed by the type of the Factor object in
+    #! EAX.
     #! The 32-bit address of the code after the jump table
     #! should be written to end-fixup.
     #! The jump table must immediately follow this macro.
-    tail? [ 0 ] [ 0 PUSH-I compiled-offset 4 - ] ifte >r
-    ( start-fixup r:end-fixup )
     EAX JUMP-[R]
     cell compile-aligned
-    compiled-offset swap set-compiled-cell ( update the ADD )
-    r> ;
-
-: begin-jump-table ( -- end-fixup )
-    #! Compile a piece of code that jumps to an offset in a
-    #! jump table indexed by the type of the Factor object in
-    #! EAX.
-    TYPE-OF
-    2 EAX R<<I
-    EAX+/PARTIAL
-    compile-table-jump ;
+    compiled-offset swap set-compiled-cell ( update the ADD ) ;
 
 : jump-table-entry ( word -- )
     #! Jump table entries are absolute addresses.
     dup postpone-word
     compiled-offset 0 compile-cell 0 fixup-deferred-xt ;
 
-: compile-jump-table ( vtable -- )
-    #! Compile a table of words as a word-array of XTs.
-    num-types [
-        over ?vector-nth jump-table-entry
-    ] times* drop ;
-
 : end-jump-table ( end-fixup -- )
     #! update the PUSH.
     dup 0 = [
@@ -73,12 +63,31 @@ USE: vectors
         compiled-offset swap set-compiled-cell
     ] ifte ;
 
+: (compile-jump-table) ( vtable -- )
+    num-types [
+        over ?vector-nth jump-table-entry
+    ] times* drop ;
+
+: compile-jump-table ( vtable -- )
+    #! Compile a table of words as a word-array of XTs.
+    begin-jump-table >r
+    compile-table-jump
+    (compile-jump-table)
+    r> end-jump-table ;
+
 : compile-generic ( compile-time: vtable -- )
     #! Compile a faster alternative to
     #! : generic ( obj vtable -- )
     #!     >r dup type r> vector-nth execute ;
-    begin-jump-table
-    pop-literal compile-jump-table
-    end-jump-table ;
+    pop-literal commit-literals
+    TYPE  compile-jump-table ;
+
+: compile-2generic ( compile-time: vtable -- )
+    #! Compile a faster alternative to
+    #! : 2generic ( obj vtable -- )
+    #!     >r 2dup arithmetic-type r> vector-nth execute ;
+    pop-literal commit-literals
+    ARITHMETIC-TYPE  compile-jump-table ;
 
 [ compile-generic ] \ generic "compiling" set-word-property
+[ compile-2generic ] \ 2generic "compiling" set-word-property
index 35adf3eea8a1259765b8100d90a13b8bd31ff6e4..54c67d3bea0cd34141b5fbe2f8476eef983dacc1 100644 (file)
@@ -43,8 +43,8 @@ USE: words
     "compiling" set-word-property ;
 
 \ call word-interpret-only
+\ execute word-interpret-only
 \ datastack word-interpret-only
 \ callstack word-interpret-only
 \ set-datastack word-interpret-only
 \ set-callstack word-interpret-only
-\ 2generic word-interpret-only
index 22bbdc0b81e37b5e7e5b17fa1bd50fc7513b1b1f..58a7359535ea8dd8ff6097f90f18a491c23f9dd1 100644 (file)
@@ -8,7 +8,7 @@ USE: logic
 USE: combinators
 USE: words
 
-: generic-test ( obj -- hash )
+: generic-test
     {
         drop
         drop
@@ -33,7 +33,30 @@ USE: words
 [ 2 3 ] [ 2 3 4 generic-test ] unit-test
 [ 2 f ] [ 2 3 f generic-test ] unit-test
 
-: generic-test-alt ( obj -- hash )
+: generic-literal-test
+    4 {
+        drop
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+        nip
+    } generic ; compiled
+
+[ ] [ generic-literal-test ] unit-test
+
+: generic-test-alt
     {
         drop
         drop
index 330a7f13068b3c574e6415f4a2837cc89cf714b4..4bf226947eb94d4cb2851a529596342041e1241a 100644 (file)
@@ -1,9 +1,9 @@
 #include "factor.h"
 
-void primitive_arithmetic_type(void)
+CELL arithmetic_type(CELL obj1, CELL obj2)
 {
-       CELL type2 = type_of(dpop());
-       CELL type1 = type_of(dpop());
+       CELL type1 = type_of(obj1);
+       CELL type2 = type_of(obj2);
        CELL type;
 
        switch(type1)
@@ -65,7 +65,15 @@ void primitive_arithmetic_type(void)
                type = type1;
                break;
        }
-       dpush(tag_fixnum(type));
+
+       return type;
+}
+
+void primitive_arithmetic_type(void)
+{
+       CELL obj2 = dpop();
+       CELL obj1 = dpop();
+       dpush(tag_fixnum(arithmetic_type(obj1,obj2)));
 }
 
 bool realp(CELL tagged)
index 8aa16028fb008ef633510f7ec7cd96ecf7f17898..840810d54ae2eb6deee5f3407a7e3d7dbdaecd5c 100644 (file)
@@ -1,5 +1,6 @@
 #include "factor.h"
 
+CELL arithmetic_type(CELL obj1, CELL obj2);
 void primitive_arithmetic_type(void);
 
 bool realp(CELL tagged);