]> gitweb.factorcode.org Git - factor.git/commitdiff
fixes
authorSlava Pestov <slava@factorcode.org>
Sat, 21 Jan 2006 02:37:38 +0000 (02:37 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 21 Jan 2006 02:37:38 +0000 (02:37 +0000)
Makefile
library/compiler/amd64/alien.factor
library/compiler/amd64/architecture.factor
library/compiler/ppc/alien.factor
library/test/compiler/alien.factor [new file with mode: 0644]
native/ffi_test.c [new file with mode: 0644]

index 0144cdbb529015d4267202eb69c40db428a8dc51..9f6356b8564cd04466c02b1a77619e5532ff8fde 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,8 @@ OBJS = $(PLAF_OBJS) native/array.o native/bignum.o \
        native/hashtable.o \
        native/icache.o \
        native/io.o \
-       native/wrapper.o
+       native/wrapper.o \
+       native/ffi_test.o
 
 default:
        @echo "Run 'make' with one of the following parameters:"
index d6b496e28538a4331b1a79773eee6c0b6621080c..bd0df2d9bf783770c5a3a9ecd3211c1c561b2f46 100644 (file)
@@ -1,15 +1,31 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: compiler-backend
-USING: alien assembler kernel math ;
+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 ;
+    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 ;
+    drop 0 input 1 input 2 input load-insn ;
 
-M: %box generate-node ( vop -- ) drop ;
+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 325d2394e2a0fe8d24d92d8a45cba0d0729c55fe..080ff57f25a8874bf6201dcd1f58cb907802bb9c 100644 (file)
@@ -17,8 +17,6 @@ kernel-internals math sequences ;
 
 : vregs { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ; inline
 
-: alien-regs { RDI RSI RDX RCX R8 R9 } ; inline
-
 : param-regs { RDI RSI RDX RCX R8 R9 } ; inline
 
 : compile-c-call ( symbol dll -- )
@@ -29,7 +27,7 @@ kernel-internals math sequences ;
     param-regs swap [ MOV ] 2each compile-c-call ;
 
 M: int-regs return-reg drop RAX ;
-M: int-regs fastcall-regs drop alien-regs length ;
+M: int-regs fastcall-regs drop param-regs length ;
 
 M: float-regs fastcall-regs drop 0 ;
 
index b5d48ce92a3d26f68945a8094cff153247793484..35ff721e682b5711e64949017b904b1731055407 100644 (file)
@@ -3,7 +3,7 @@
 IN: compiler-backend
 USING: alien assembler kernel math ;
 
-GENERIC: store-insn ( to offset reg-class -- )
+GENERIC: store-insn ( offset reg-class -- )
 
 GENERIC: load-insn ( elt parameter reg-class -- )
 
diff --git a/library/test/compiler/alien.factor b/library/test/compiler/alien.factor
new file mode 100644 (file)
index 0000000..c25bb06
--- /dev/null
@@ -0,0 +1,8 @@
+USING: compiler test ;
+
+FUNCTION: void ffi_test_0 ; compiled
+[ ] [ ffi_test_0 ] unit-test
+
+FUNCTION: int ffi_test_1 ; compiled
+[ 3 ] [ ffi_test_1 ] unit-test
+
diff --git a/native/ffi_test.c b/native/ffi_test.c
new file mode 100644 (file)
index 0000000..d24625d
--- /dev/null
@@ -0,0 +1,19 @@
+/* This file is linked into the runtime for the sole purpose
+ * of testing FFI code. */
+
+void ffi_test_0(void)
+{
+       printf("ffi_test_0()\n");
+}
+
+int ffi_test_1(void)
+{
+       printf("ffi_test_1()\n");
+       return 3;
+}
+
+int ffi_test_2(int x, int y)
+{
+       printf("ffi_test_2(%d,%d)\n",x,y);
+       return x + y;
+}