-! 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 ;
+! 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 ;
: 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.
--- /dev/null
+! 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
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;
+}