]> gitweb.factorcode.org Git - factor.git/blob - unfinished/compiler/cfg/vn/expressions/expressions.factor
ogg plays but 1) sound is broken and 2) it doesn't recognize EOF anymore, so it hangs...
[factor.git] / unfinished / compiler / cfg / vn / expressions / expressions.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors classes kernel math namespaces sorting
4 compiler.vops compiler.cfg.vn.graph ;
5 IN: compiler.cfg.vn.expressions
6
7 ! Referentially-transparent expressions
8 TUPLE: expr op ;
9 TUPLE: nullary-expr < expr ;
10 TUPLE: unary-expr < expr in ;
11 TUPLE: binary-expr < expr in1 in2 ;
12 TUPLE: commutative-expr < binary-expr ;
13 TUPLE: boolean-expr < unary-expr code ;
14 TUPLE: constant-expr < expr value ;
15 TUPLE: literal-expr < unary-expr object ;
16
17 ! op is always %peek
18 TUPLE: peek-expr < expr loc ;
19
20 SYMBOL: input-expr-counter
21
22 : next-input-expr ( -- n )
23     input-expr-counter [ dup 1 + ] change ;
24
25 ! Expressions whose values are inputs to the basic block. We
26 ! can eliminate a second computation having the same 'n' as
27 ! the first one; we can also eliminate input-exprs whose
28 ! result is not used.
29 TUPLE: input-expr < expr n ;
30
31 GENERIC: >expr ( insn -- expr )
32
33 M: %literal-table >expr
34     class nullary-expr boa ;
35
36 M: constant-op >expr
37     [ class ] [ value>> ] bi constant-expr boa ;
38
39 M: %literal >expr
40     [ class ] [ in>> vreg>vn ] [ object>> ] tri literal-expr boa ;
41
42 M: unary-op >expr
43     [ class ] [ in>> vreg>vn ] bi unary-expr boa ;
44
45 M: binary-op >expr
46     [ class ] [ in1>> vreg>vn ] [ in2>> vreg>vn ] tri
47     binary-expr boa ;
48
49 M: commutative-op >expr
50     [ class ] [ in1>> vreg>vn ] [ in2>> vreg>vn ] tri
51     sort-pair commutative-expr boa ;
52
53 M: boolean-op >expr
54     [ class ] [ in>> vreg>vn ] [ code>> ] tri
55     boolean-expr boa ;
56
57 M: %peek >expr
58     [ class ] [ stack-loc ] bi peek-expr boa ;
59
60 M: flushable-op >expr
61     class next-input-expr input-expr boa ;
62
63 : init-expressions ( -- )
64     0 input-expr-counter set ;