2009-07-14 20:17:12 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2008-10-19 02:10:21 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-09-02 07:22:37 -04:00
|
|
|
USING: accessors classes classes.algebra classes.parser
|
|
|
|
classes.tuple combinators combinators.short-circuit fry
|
|
|
|
generic.parser kernel math namespaces quotations sequences slots
|
|
|
|
splitting words compiler.cfg.instructions
|
|
|
|
compiler.cfg.instructions.syntax
|
2009-07-14 20:17:12 -04:00
|
|
|
compiler.cfg.value-numbering.graph ;
|
2008-10-19 02:10:21 -04:00
|
|
|
IN: compiler.cfg.value-numbering.expressions
|
|
|
|
|
2008-10-22 22:59:07 -04:00
|
|
|
TUPLE: constant-expr < expr value ;
|
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
C: <constant> constant-expr
|
2008-10-22 22:59:07 -04:00
|
|
|
|
|
|
|
M: constant-expr equal?
|
|
|
|
over constant-expr? [
|
2009-07-14 20:17:12 -04:00
|
|
|
{
|
|
|
|
[ [ value>> class ] bi@ = ]
|
|
|
|
[ [ value>> ] bi@ = ]
|
|
|
|
} 2&&
|
|
|
|
] [ 2drop f ] if ;
|
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
TUPLE: reference-expr < expr value ;
|
|
|
|
|
|
|
|
C: <reference> reference-expr
|
2009-07-14 20:17:12 -04:00
|
|
|
|
|
|
|
M: reference-expr equal?
|
|
|
|
over reference-expr? [
|
|
|
|
[ value>> ] bi@ {
|
|
|
|
{ [ 2dup eq? ] [ 2drop t ] }
|
|
|
|
{ [ 2dup [ float? ] both? ] [ fp-bitwise= ] }
|
|
|
|
[ 2drop f ]
|
|
|
|
} cond
|
2008-10-22 22:59:07 -04:00
|
|
|
] [ 2drop f ] if ;
|
|
|
|
|
|
|
|
: constant>vn ( constant -- vn ) <constant> expr>vn ; inline
|
2008-10-19 02:10:21 -04:00
|
|
|
|
|
|
|
GENERIC: >expr ( insn -- expr )
|
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
M: insn >expr drop next-input-expr ;
|
|
|
|
|
2008-10-22 22:59:07 -04:00
|
|
|
M: ##load-immediate >expr val>> <constant> ;
|
2008-10-19 02:10:21 -04:00
|
|
|
|
2009-07-14 20:17:12 -04:00
|
|
|
M: ##load-reference >expr obj>> <reference> ;
|
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
<<
|
|
|
|
|
|
|
|
: input-values ( slot-specs -- slot-specs' )
|
|
|
|
[ type>> { use literal constant } memq? ] filter ;
|
|
|
|
|
|
|
|
: expr-class ( insn -- expr )
|
|
|
|
name>> "##" ?head drop "-expr" append create-class-in ;
|
|
|
|
|
|
|
|
: define-expr-class ( insn expr slot-specs -- )
|
|
|
|
[ nip expr ] dip [ name>> ] map define-tuple-class ;
|
|
|
|
|
|
|
|
: >expr-quot ( expr slot-specs -- quot )
|
|
|
|
[
|
|
|
|
[ name>> reader-word 1quotation ]
|
|
|
|
[
|
|
|
|
type>> {
|
|
|
|
{ use [ [ vreg>vn ] ] }
|
|
|
|
{ literal [ [ ] ] }
|
|
|
|
{ constant [ [ constant>vn ] ] }
|
|
|
|
} case
|
|
|
|
] bi append
|
|
|
|
] map swap '[ _ cleave _ boa ] ;
|
|
|
|
|
|
|
|
: define->expr-method ( insn expr slot-specs -- )
|
|
|
|
[ 2drop \ >expr create-method-in ] [ >expr-quot nip ] 3bi define ;
|
|
|
|
|
|
|
|
: handle-pure-insn ( insn -- )
|
|
|
|
[ ] [ expr-class ] [ "insn-slots" word-prop input-values ] tri
|
|
|
|
[ define-expr-class ] [ define->expr-method ] 3bi ;
|
|
|
|
|
|
|
|
insn-classes get [ pure-insn class<= ] filter [ handle-pure-insn ] each
|
|
|
|
|
|
|
|
>>
|