2010-04-01 20:06:18 -04:00
|
|
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
2008-12-06 10:16:29 -05:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2016-03-08 08:38:48 -05:00
|
|
|
USING: accessors classes.algebra classes.struct
|
2015-12-14 03:29:18 -05:00
|
|
|
compiler.cfg.builder.blocks compiler.cfg.comparisons compiler.cfg.hats
|
2015-08-30 20:08:01 -04:00
|
|
|
compiler.cfg.instructions compiler.cfg.stacks compiler.constants
|
2015-12-14 03:29:18 -05:00
|
|
|
compiler.tree.propagation.info cpu.architecture kernel layouts math
|
|
|
|
namespaces sequences vm ;
|
2008-12-06 10:16:29 -05:00
|
|
|
IN: compiler.cfg.intrinsics.misc
|
|
|
|
|
|
|
|
: emit-tag ( -- )
|
2010-04-22 04:21:23 -04:00
|
|
|
[ ^^tagged>integer tag-mask get ^^and-imm ] unary-op ;
|
|
|
|
|
|
|
|
: emit-eq ( node -- )
|
|
|
|
node-input-infos first2 [ class>> fixnum class<= ] both?
|
|
|
|
[ [ cc= ^^compare-integer ] binary-op ] [ [ cc= ^^compare ] binary-op ] if ;
|
2008-12-06 10:16:29 -05:00
|
|
|
|
2016-03-08 08:38:48 -05:00
|
|
|
: emit-special-object ( block node -- block' )
|
2010-03-26 23:11:05 -04:00
|
|
|
dup node-input-infos first literal>> [
|
2010-04-01 20:06:18 -04:00
|
|
|
ds-drop
|
2015-08-30 20:08:01 -04:00
|
|
|
vm-special-object-offset ^^vm-field
|
2010-03-26 23:11:05 -04:00
|
|
|
ds-push
|
2016-03-08 08:38:48 -05:00
|
|
|
] [ emit-primitive ] ?if ;
|
2010-03-26 23:11:05 -04:00
|
|
|
|
2016-03-08 08:38:48 -05:00
|
|
|
: emit-set-special-object ( block node -- block' )
|
2010-04-01 20:06:18 -04:00
|
|
|
dup node-input-infos second literal>> [
|
|
|
|
ds-drop
|
2015-08-30 20:08:01 -04:00
|
|
|
[ ds-pop ] dip vm-special-object-offset ##set-vm-field,
|
2016-03-08 08:38:48 -05:00
|
|
|
] [ emit-primitive ] ?if ;
|
2010-04-01 20:06:18 -04:00
|
|
|
|
|
|
|
: context-object-offset ( n -- n )
|
2015-12-14 03:29:18 -05:00
|
|
|
cells "context-objects" context offset-of + ;
|
2010-03-26 23:11:05 -04:00
|
|
|
|
2016-03-08 08:38:48 -05:00
|
|
|
: emit-context-object ( block node -- block' )
|
2010-03-26 23:11:05 -04:00
|
|
|
dup node-input-infos first literal>> [
|
2015-12-14 03:29:18 -05:00
|
|
|
"ctx" vm offset-of ^^vm-field
|
2010-04-01 20:06:18 -04:00
|
|
|
ds-drop swap context-object-offset cell /i 0 ^^slot-imm ds-push
|
2016-03-08 08:38:48 -05:00
|
|
|
] [ emit-primitive ] ?if ;
|
2009-11-11 01:50:57 -05:00
|
|
|
|
|
|
|
: emit-identity-hashcode ( -- )
|
2010-04-22 04:21:23 -04:00
|
|
|
[
|
|
|
|
^^tagged>integer
|
|
|
|
tag-mask get bitnot ^^load-integer ^^and
|
2010-04-23 18:42:09 -04:00
|
|
|
0 int-rep f ^^load-memory-imm
|
2010-04-22 04:21:23 -04:00
|
|
|
hashcode-shift ^^shr-imm
|
|
|
|
] unary-op ;
|
2010-05-19 00:33:36 -04:00
|
|
|
|
2016-03-08 08:38:48 -05:00
|
|
|
: emit-local-allot ( block node -- block' )
|
2010-05-22 01:25:10 -04:00
|
|
|
dup node-input-infos first2 [ literal>> ] bi@ 2dup [ integer? ] both?
|
|
|
|
[ ds-drop ds-drop f ^^local-allot ^^box-alien ds-push drop ]
|
2016-03-08 08:38:48 -05:00
|
|
|
[ 2drop emit-primitive ] if ;
|
2010-05-22 01:25:10 -04:00
|
|
|
|
2016-03-08 08:38:48 -05:00
|
|
|
: emit-cleanup-allot ( block node -- block' )
|
|
|
|
drop [ drop ##no-tco, ] emit-trivial-block ;
|