factor/library/compiler/x86/alien.factor

37 lines
978 B
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
2005-05-08 20:30:38 -04:00
M: %alien-invoke generate-node
#! call a C function.
2005-12-07 21:46:54 -05:00
drop 0 input 1 input load-library compile-c-call ;
2005-05-08 20:30:38 -04:00
M: %parameter generate-node
#! x86 does not pass parameters in registers
drop ;
GENERIC: reg-size ( reg-class -- n )
GENERIC: push-reg ( reg-class -- )
M: int-regs reg-size drop cell ;
M: int-regs push-reg drop EAX PUSH ;
2005-06-15 16:34:16 -04:00
M: float-regs reg-size float-regs-size ;
M: float-regs push-reg
2005-12-02 02:25:44 -05:00
ESP swap reg-size [ SUB { ESP } ] keep
2005-09-24 15:21:17 -04:00
4 = [ FSTPS ] [ FSTPL ] if ;
2005-04-23 19:34:06 -04:00
M: %unbox generate-node
2005-12-07 21:46:54 -05:00
drop 1 input f compile-c-call 2 input push-reg ;
2005-05-08 20:30:38 -04:00
M: %box generate-node
2005-12-07 21:46:54 -05:00
drop
1 input push-reg
0 input f compile-c-call
ESP 1 input reg-size ADD ;
2005-04-23 19:34:06 -04:00
2005-05-08 20:30:38 -04:00
M: %cleanup generate-node
2005-12-07 21:46:54 -05:00
drop 0 input dup 0 = [ drop ] [ ESP swap ADD ] if ;