factor/library/compiler/x86/alien.factor

68 lines
1.7 KiB
Factor
Raw Normal View History

2005-04-23 19:34:06 -04:00
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
2005-05-09 02:34:15 -04:00
IN: compiler-backend
USING: alien assembler compiler inference kernel
kernel-internals lists math memory namespaces words ;
2005-04-23 19:34:06 -04:00
2006-02-15 00:20:35 -05:00
GENERIC: push-return-reg ( reg-class -- )
GENERIC: pop-return-reg ( reg-class -- )
2006-02-15 00:20:35 -05:00
M: int-regs push-return-reg drop EAX PUSH ;
M: int-regs pop-return-reg drop EAX POP ;
2006-02-15 00:20:35 -05:00
: FSTP 4 = [ FSTPS ] [ FSTPL ] if ;
M: float-regs push-return-reg
ESP swap reg-size [ SUB { ESP } ] keep FSTP ;
: FLD 4 = [ FLDS ] [ FLDL ] if ;
M: float-regs pop-return-reg
reg-size { ESP } over FLD ESP swap ADD ;
2005-04-23 19:34:06 -04:00
M: %unbox generate-node
2006-02-15 00:20:35 -05:00
drop 2 input f compile-c-call 1 input push-return-reg ;
M: %unbox-struct generate-node ( vop -- )
drop
! Increase stack size
ESP 2 input SUB
! Save destination address in EAX
EAX ESP MOV
! Load struct size
2 input PUSH
! Load destination address
EAX PUSH
! Copy the struct to the stack
"unbox_value_struct" f compile-c-call
! Clean up
EAX POP
ECX POP ;
2005-05-08 20:30:38 -04:00
M: %box generate-node
2005-12-07 21:46:54 -05:00
drop
2006-02-15 00:20:35 -05:00
1 input push-return-reg
2 input f compile-c-call
ESP 1 input reg-size ADD ;
M: %alien-callback generate-node ( vop -- )
drop
EAX 0 input load-indirect
EAX PUSH
"run_callback" f compile-c-call
EAX POP ;
M: %callback-value generate-node ( vop -- )
drop
! Call the unboxer
1 input f compile-c-call
2006-02-15 00:20:35 -05:00
! Save return register
0 input push-return-reg
! Restore data/callstacks
"unnest_stacks" f compile-c-call
! Restore return register
0 input pop-return-reg ;
2005-04-23 19:34:06 -04:00
2005-05-08 20:30:38 -04:00
M: %cleanup generate-node
2006-01-28 15:49:31 -05:00
drop 0 input dup zero? [ drop ] [ ESP swap ADD ] if ;