2006-04-01 19:50:33 -05:00
|
|
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2006-04-03 02:18:56 -04:00
|
|
|
IN: compiler
|
|
|
|
USING: arrays assembler generic hashtables
|
2005-09-11 20:46:55 -04:00
|
|
|
inference kernel kernel-internals lists math math-internals
|
|
|
|
namespaces sequences words ;
|
2005-05-06 18:33:40 -04:00
|
|
|
|
|
|
|
\ slot [
|
2006-04-17 18:25:38 -04:00
|
|
|
{ { any-reg "obj" } { any-reg "n" } } { "obj" } [
|
2006-04-19 16:19:26 -04:00
|
|
|
"obj" get %untag ,
|
|
|
|
"n" get "obj" get %slot ,
|
2006-04-17 17:17:34 -04:00
|
|
|
] with-template
|
2005-05-17 16:13:08 -04:00
|
|
|
] "intrinsic" set-word-prop
|
2005-05-13 20:37:28 -04:00
|
|
|
|
|
|
|
\ set-slot [
|
2006-04-17 18:25:38 -04:00
|
|
|
{ { any-reg "val" } { any-reg "obj" } { any-reg "slot" } }
|
|
|
|
{ } [
|
2006-04-19 16:19:26 -04:00
|
|
|
"obj" get %untag ,
|
|
|
|
"val" get "obj" get "slot" get %set-slot ,
|
2006-04-17 18:25:38 -04:00
|
|
|
end-basic-block
|
|
|
|
"obj" get %write-barrier ,
|
2006-04-17 17:17:34 -04:00
|
|
|
] with-template
|
2005-05-17 16:13:08 -04:00
|
|
|
] "intrinsic" set-word-prop
|
2005-05-06 19:49:07 -04:00
|
|
|
|
2006-01-31 21:31:53 -05:00
|
|
|
\ char-slot [
|
2006-04-17 18:25:38 -04:00
|
|
|
{ { any-reg "n" } { any-reg "str" } } { "str" } [
|
2006-04-19 16:19:26 -04:00
|
|
|
"n" get "str" get %char-slot ,
|
2006-04-01 23:42:36 -05:00
|
|
|
] with-template
|
2006-01-31 21:31:53 -05:00
|
|
|
] "intrinsic" set-word-prop
|
|
|
|
|
|
|
|
\ set-char-slot [
|
2006-04-17 18:25:38 -04:00
|
|
|
{ { any-reg "ch" } { any-reg "n" } { any-reg "str" } } { } [
|
2006-04-19 16:19:26 -04:00
|
|
|
"ch" get "str" get "n" get %set-char-slot ,
|
2006-04-01 23:42:36 -05:00
|
|
|
] with-template
|
2006-01-31 21:31:53 -05:00
|
|
|
] "intrinsic" set-word-prop
|
2005-11-13 22:04:14 -05:00
|
|
|
|
2005-05-06 19:49:07 -04:00
|
|
|
\ type [
|
2006-04-11 02:45:24 -04:00
|
|
|
{ { any-reg "in" } } { "in" }
|
2006-04-19 16:19:26 -04:00
|
|
|
[ end-basic-block "in" get %type , ] with-template
|
2005-08-15 15:34:00 -04:00
|
|
|
] "intrinsic" set-word-prop
|
|
|
|
|
|
|
|
\ tag [
|
2006-04-19 16:19:26 -04:00
|
|
|
{ { any-reg "in" } } { "in" }
|
|
|
|
[ "in" get %tag , ] with-template
|
2005-05-17 16:13:08 -04:00
|
|
|
] "intrinsic" set-word-prop
|
2005-05-07 22:39:00 -04:00
|
|
|
|
2006-04-17 17:17:34 -04:00
|
|
|
: binary-op ( op -- )
|
|
|
|
{ { 0 "x" } { 1 "y" } } { "x" } [
|
2006-04-19 16:19:26 -04:00
|
|
|
end-basic-block >r "y" get "x" get dup r> execute ,
|
2006-04-01 23:42:36 -05:00
|
|
|
] with-template ; inline
|
2005-06-07 23:29:47 -04:00
|
|
|
|
2005-10-29 23:25:38 -04:00
|
|
|
{
|
|
|
|
{ fixnum+ %fixnum+ }
|
|
|
|
{ fixnum- %fixnum- }
|
|
|
|
{ fixnum-bitand %fixnum-bitand }
|
|
|
|
{ fixnum-bitor %fixnum-bitor }
|
|
|
|
{ fixnum-bitxor %fixnum-bitxor }
|
2006-04-17 17:17:34 -04:00
|
|
|
{ fixnum/i %fixnum/i }
|
|
|
|
{ fixnum* %fixnum* }
|
2005-10-29 23:25:38 -04:00
|
|
|
} [
|
2006-04-19 16:19:26 -04:00
|
|
|
first2 [ binary-op ] curry
|
2006-04-17 17:17:34 -04:00
|
|
|
"intrinsic" set-word-prop
|
2005-05-06 19:49:07 -04:00
|
|
|
] each
|
2005-05-07 22:39:00 -04:00
|
|
|
|
2006-04-17 17:17:34 -04:00
|
|
|
: binary-jump ( label op -- )
|
|
|
|
{ { any-reg "x" } { any-reg "y" } } { } [
|
2006-04-19 16:19:26 -04:00
|
|
|
end-basic-block >r >r "y" get "x" get r> r> execute ,
|
2006-04-01 23:42:36 -05:00
|
|
|
] with-template ; inline
|
2005-10-04 03:16:50 -04:00
|
|
|
|
2005-10-29 23:25:38 -04:00
|
|
|
{
|
|
|
|
{ fixnum<= %jump-fixnum<= }
|
|
|
|
{ fixnum< %jump-fixnum< }
|
|
|
|
{ fixnum>= %jump-fixnum>= }
|
|
|
|
{ fixnum> %jump-fixnum> }
|
|
|
|
{ eq? %jump-eq? }
|
|
|
|
} [
|
2006-04-19 16:19:26 -04:00
|
|
|
first2 [ binary-jump ] curry
|
2006-04-17 17:17:34 -04:00
|
|
|
"if-intrinsic" set-word-prop
|
2005-09-09 18:00:38 -04:00
|
|
|
] each
|
|
|
|
|
2005-05-07 22:39:00 -04:00
|
|
|
\ fixnum-mod [
|
|
|
|
! This is not clever. Because of x86, %fixnum-mod is
|
|
|
|
! hard-coded to put its output in vreg 2, which happends to
|
|
|
|
! be EDX there.
|
2006-04-01 23:42:36 -05:00
|
|
|
{ { 0 "x" } { 1 "y" } } { "out" } [
|
2006-04-03 03:22:33 -04:00
|
|
|
end-basic-block
|
2006-04-01 23:42:36 -05:00
|
|
|
T{ vreg f 2 } "out" set
|
2006-04-19 16:19:26 -04:00
|
|
|
"y" get "x" get "out" get %fixnum-mod ,
|
2006-04-01 23:42:36 -05:00
|
|
|
] with-template
|
2005-05-17 16:13:08 -04:00
|
|
|
] "intrinsic" set-word-prop
|
2005-05-07 22:39:00 -04:00
|
|
|
|
|
|
|
\ fixnum/mod [
|
|
|
|
! See the remark on fixnum-mod for vreg usage
|
2006-04-01 23:42:36 -05:00
|
|
|
{ { 0 "x" } { 1 "y" } } { "quo" "rem" } [
|
2006-04-03 03:22:33 -04:00
|
|
|
end-basic-block
|
2006-04-01 23:42:36 -05:00
|
|
|
T{ vreg f 0 } "quo" set
|
|
|
|
T{ vreg f 2 } "rem" set
|
2006-04-19 16:19:26 -04:00
|
|
|
"y" get "x" get 2array
|
|
|
|
"rem" get "quo" get 2array %fixnum/mod ,
|
2006-04-01 23:42:36 -05:00
|
|
|
] with-template
|
2005-05-17 16:13:08 -04:00
|
|
|
] "intrinsic" set-word-prop
|
2005-05-07 22:39:00 -04:00
|
|
|
|
|
|
|
\ fixnum-bitnot [
|
2006-04-17 18:25:38 -04:00
|
|
|
{ { any-reg "x" } } { "x" } [
|
2006-04-19 16:19:26 -04:00
|
|
|
"x" get dup %fixnum-bitnot ,
|
2006-04-01 23:42:36 -05:00
|
|
|
] with-template
|
2005-05-17 16:13:08 -04:00
|
|
|
] "intrinsic" set-word-prop
|