]> gitweb.factorcode.org Git - factor.git/commitdiff
FFI work
authorSlava Pestov <slava@factorcode.org>
Wed, 25 Jan 2006 00:56:08 +0000 (00:56 +0000)
committerSlava Pestov <slava@factorcode.org>
Wed, 25 Jan 2006 00:56:08 +0000 (00:56 +0000)
library/bootstrap/boot-stage1.factor
library/compiler/amd64/alien.factor
library/compiler/amd64/architecture.factor
library/compiler/amd64/generator.factor [new file with mode: 0644]
library/compiler/x86/generator.factor
library/test/compiler/alien.factor
native/ffi_test.c

index cb4331a40086cf98ea2db0fc6f7b4410c8715e8d..1737ba017c0f7e79bc6f6d13cc805cba4a65a375 100644 (file)
@@ -309,6 +309,7 @@ vectors words ;
                     "/library/compiler/amd64/assembler.factor"
                     "/library/compiler/amd64/architecture.factor"
                     "/library/compiler/x86/generator.factor"
+                    "/library/compiler/amd64/generator.factor"
                     "/library/compiler/x86/slots.factor"
                     "/library/compiler/x86/stack.factor"
                     "/library/compiler/x86/fixnum.factor"
index e89c6f318a6f8e975b61bd0779b3711ba7d6d53b..88b73fb931abdbba544d0606073a3890aefbdc47 100644 (file)
@@ -1,31 +1,36 @@
-! Copyright (C) 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
+! Copyright (C) 2005, 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
 IN: compiler-backend
-USING: alien assembler kernel math sequences ;
-
-! GENERIC: store-insn ( offset reg-class -- )
-! 
-! GENERIC: load-insn ( elt parameter reg-class -- )
-! 
-! M: int-regs store-insn drop >r 3 1 r> stack@ STW ;
-! 
-! M: int-regs load-insn drop 3 + 1 rot stack@ LWZ ;
-! 
-! M: %unbox generate-node ( vop -- )
-!     drop
-!     ! Call the unboxer
-!     1 input f compile-c-call
-!     ! Store the return value on the C stack
-!     0 input 2 input store-insn ;
-! 
-! M: %parameter generate-node ( vop -- )
-!     ! Move a value from the C stack into the fastcall register
-!     drop 0 input 1 input 2 input load-insn ;
-! 
-! M: %box generate-node ( vop -- )
-!     drop
-!     ! Move return value of C function into input register
-!     param-regs first RAX MOV
-!     0 input f compile-c-call ;
-! 
-! M: %cleanup generate-node ( vop -- ) drop ;
+USING: alien arrays assembler kernel kernel-internals math
+sequences ;
+
+GENERIC: store-insn ( offset reg-class -- )
+
+GENERIC: load-insn ( elt parameter reg-class -- )
+
+: stack@ RCX RSP MOV  RCX swap 2array ;
+
+M: int-regs store-insn
+    drop stack@ RAX MOV ;
+
+M: int-regs load-insn
+    drop param-regs nth swap stack@ MOV ;
+
+M: %unbox generate-node ( vop -- )
+    drop
+    ! Call the unboxer
+    1 input f compile-c-call
+    ! Store the return value on the C stack
+    0 input 2 input store-insn ;
+
+M: %parameter generate-node ( vop -- )
+    ! Move a value from the C stack into the fastcall register
+    drop 0 input 1 input 2 input load-insn ;
+
+M: %box generate-node ( vop -- )
+    drop
+    ! Move return value of C function into input register
+    param-regs first RAX MOV
+    0 input f compile-c-call ;
+
+M: %cleanup generate-node ( vop -- ) drop ;
index 080ff57f25a8874bf6201dcd1f58cb907802bb9c..8aff995125dd5f7317c06dc07da966aa5945ebb8 100644 (file)
@@ -1,3 +1,5 @@
+! Copyright (C) 2005, 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
 IN: compiler-backend
 USING: alien arrays assembler compiler compiler-backend kernel
 kernel-internals math sequences ;
@@ -44,10 +46,6 @@ M: float-regs fastcall-regs drop 0 ;
 
 : prepare-division CQO ; inline
 
-: compile-prologue RSP 8 SUB ; inline
-
-: compile-epilogue RSP 8 ADD ; inline
-
 : load-indirect ( dest literal -- )
     #! We use RIP-relative addressing. The '3' is a hardcoded
     #! instruction length.
diff --git a/library/compiler/amd64/generator.factor b/library/compiler/amd64/generator.factor
new file mode 100644 (file)
index 0000000..2a79727
--- /dev/null
@@ -0,0 +1,12 @@
+! Copyright (C) 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: compiler-backend
+USING: assembler kernel math namespaces ;
+
+: stack-increment \ stack-reserve get 16 align 8 + ;
+
+M: %prologue generate-node ( vop -- )
+    drop RSP stack-increment SUB ;
+
+: compile-epilogue ( -- )
+    RSP stack-increment ADD ; inline
index 12bf29f9effd5b86c3af55bd241667ea0824428d..6e2e93735aee7ee5316f1a0928a0ad6cf777a9ce 100644 (file)
@@ -5,8 +5,7 @@ USING: alien arrays assembler compiler inference kernel
 kernel-internals lists math memory namespaces sequences words ;
 
 ! Not used on x86
-M: %prologue generate-node ( vop -- ) 
-    drop compile-prologue ;
+M: %prologue generate-node ( vop -- )  drop ;
 
 : (%call)
     label dup postpone-word
index c25bb060126052e8c6041338de48872fd9f091c2..cb4396a7a6501393cc2a6c0db736886678b12743 100644 (file)
@@ -6,3 +6,9 @@ FUNCTION: void ffi_test_0 ; compiled
 FUNCTION: int ffi_test_1 ; compiled
 [ 3 ] [ ffi_test_1 ] unit-test
 
+FUNCTION: int ffi_test_2 int x int y ; compiled
+[ 5 ] [ 2 3 ffi_test_2 ] unit-test
+
+FUNCTION: int ffi_test_3 int x int y int z int t ; compiled
+[ 25 ] [ 2 3 4 5 ffi_test_3 ] unit-test
+
index d24625d2efdb6768dbf6b83873d1029f5e929172..12e56a2a925a030c0dfa5b7d1b9cc39ff0100cd4 100644 (file)
@@ -17,3 +17,9 @@ int ffi_test_2(int x, int y)
        printf("ffi_test_2(%d,%d)\n",x,y);
        return x + y;
 }
+
+int ffi_test_3(int x, int y, int z, int t)
+{
+       printf("ffi_test_3(%d,%d,%d,%d)\n",x,y,z,t);
+       return x + y + z * t;
+}