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-09-30 03:18:29 -04:00
|
|
|
[ value>> ] bi@
|
|
|
|
2dup [ float? ] both? [ fp-bitwise= ] [
|
|
|
|
{ [ [ class ] bi@ = ] [ = ] } 2&&
|
|
|
|
] if
|
2009-07-14 20:17:12 -04:00
|
|
|
] [ 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?
|
2009-09-30 03:18:29 -04:00
|
|
|
over reference-expr? [ [ value>> ] bi@ eq? ] [ 2drop f ] if ;
|
2008-10-22 22:59:07 -04:00
|
|
|
|
2009-11-10 22:06:36 -05:00
|
|
|
M: reference-expr hashcode*
|
|
|
|
nip value>> identity-hashcode ;
|
|
|
|
|
2008-10-22 22:59:07 -04:00
|
|
|
: 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-30 03:18:29 -04:00
|
|
|
M: ##load-constant >expr obj>> <constant> ;
|
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
<<
|
|
|
|
|
|
|
|
: input-values ( slot-specs -- slot-specs' )
|
2009-10-28 16:02:00 -04:00
|
|
|
[ type>> { use literal constant } member-eq? ] filter ;
|
2009-09-02 07:22:37 -04:00
|
|
|
|
|
|
|
: 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
|
2009-09-04 04:01:18 -04:00
|
|
|
] map cleave>quot swap suffix \ boa suffix ;
|
2009-09-02 07:22:37 -04:00
|
|
|
|
|
|
|
: 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
|
|
|
|
|
|
|
|
>>
|