factor/library/compiler/assembler.factor

46 lines
1.4 KiB
Factor
Raw Normal View History

! Copyright (C) 2004, 2005 Slava Pestov.
2005-03-15 22:23:52 -05:00
! See http://factor.sf.net/license.txt for BSD license.
2005-01-06 21:42:07 -05:00
IN: assembler
2005-02-14 21:58:07 -05:00
USING: alien math memory kernel hashtables namespaces ;
2004-12-25 02:55:03 -05:00
SYMBOL: interned-literals
2004-12-25 02:55:03 -05:00
: cell 4 ; inline
: compiled-header HEX: 01c3babe ; inline
2005-03-15 22:23:52 -05:00
: compiled-byte ( a -- n ) <alien> 0 alien-1 ; inline
: set-compiled-byte ( n a -- ) <alien> 0 set-alien-1 ; inline
: compiled-cell ( a -- n ) <alien> 0 alien-cell ; inline
: set-compiled-cell ( n a -- ) <alien> 0 set-alien-cell ; inline
2004-12-24 02:52:02 -05:00
2004-09-11 15:26:24 -04:00
: compile-aligned ( n -- )
2004-12-25 02:55:03 -05:00
compiled-offset cell 2 * align set-compiled-offset ; inline
2004-09-11 15:26:24 -04:00
: intern-literal ( obj -- lit# )
2005-03-21 14:39:46 -05:00
dup interned-literals get hash [ ] [
2005-01-02 23:57:54 -05:00
[
2004-12-25 02:55:03 -05:00
address
literal-top set-compiled-cell
literal-top dup cell + set-literal-top
dup
] keep interned-literals get set-hash
2005-03-21 14:39:46 -05:00
] ?ifte ;
: compile-byte ( n -- )
compiled-offset set-compiled-byte
2004-12-24 02:52:02 -05:00
compiled-offset 1 + set-compiled-offset ; inline
: compile-cell ( n -- )
compiled-offset set-compiled-cell
2004-12-24 02:52:02 -05:00
compiled-offset cell + set-compiled-offset ; inline
2004-12-25 02:55:03 -05:00
: begin-assembly ( -- code-len-fixup reloc-len-fixup )
compiled-header compile-cell
compiled-offset 0 compile-cell
compiled-offset 0 compile-cell ;
: init-assembler ( -- )
global [ <namespace> interned-literals set ] bind ;
: w>h/h dup -16 shift HEX: ffff bitand >r HEX: ffff bitand r> ;