factor/library/compiler/x86/alien.factor

76 lines
1.9 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
2006-02-18 01:58:08 -05:00
USING: alien arrays 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-18 01:58:08 -05:00
GENERIC: load-return-reg ( stack@ reg-class -- )
: drop-return-reg ESP swap reg-size ADD ;
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 ;
M: int-regs load-return-reg drop EAX ESP rot [+] MOV ;
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 ;
2006-02-15 00:20:35 -05:00
: FLD 4 = [ FLDS ] [ FLDL ] if ;
M: float-regs pop-return-reg
ESP [] over reg-size FLD drop-return-reg ;
M: float-regs load-return-reg
reg-size >r ESP swap [+] r> FLD ;
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
0 input [ 4 + 1 input load-return-reg ] when*
2006-02-15 00:20:35 -05:00
1 input push-return-reg
2 input f compile-c-call
1 input drop-return-reg ;
2006-02-15 00:20:35 -05:00
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 ;