1 ///////////////////////////////////////////////////////////////////////////////
3 // This file describes the internal abstract machine of the
4 // constraint compiler, which is based (very) loosely on the Warren
5 // Abstract Machine (WAM). It also describes various other semantic
6 // objects used in the analysis of the logic clauses.
8 ///////////////////////////////////////////////////////////////////////////////
9 #ifndef WAM_definitions_h
10 #define WAM_definitions_h
14 ///////////////////////////////////////////////////////////////////////////////
16 // Forward type definitions.
18 ///////////////////////////////////////////////////////////////////////////////
19 datatype Ty // type expressions
20 and Cons // constructor descriptor
21 and Exp // expressions
22 and Stmt // statements
23 and Def // definitions
24 and Decl // declarations
27 ///////////////////////////////////////////////////////////////////////////////
29 // Kind of variables. These are characterized as follows, in order
31 // (a) Global variables are variables that occur as argument
32 // in a structural pattern. These may escape the life-time of
34 // (b) Local variables are variables that occur multiple times in a clause
35 // (if they don't satisfy condition (a)).
36 // (c) Void variables are variables with only one occurrence. These
37 // can be elided since they are always unifiable and never accessed.
39 ///////////////////////////////////////////////////////////////////////////////
40 datatype VarKind : MEM
46 ///////////////////////////////////////////////////////////////////////////////
48 // Instantiateness of a clause parameter.
50 ///////////////////////////////////////////////////////////////////////////////
53 | IDinst (Id) // named instness
54 | FREEinst (Ty) // free term
55 | GROUNDinst (Ty) // ground term
56 | BOUNDinst (Ty,List<Instness>) // bound term (disjunction)
57 | APPinst (Cons,List<Instness>) // functor application
58 | FUNinst (Instness, Instness) // instness mapping
59 | VARinst (Instness) // instness variable
61 ///////////////////////////////////////////////////////////////////////////////
63 // Determinism of a clause.
65 ///////////////////////////////////////////////////////////////////////////////
68 | DET // deterministic
69 | SEMI_DET // may succeed or fail once
70 | MULTI_DET // may succeed many times but only fail once
71 | NON_DET // non-deterministic
72 | FAIL_DET // always fail
73 | ERROR_DET // neither fail nor succeed
74 | VAR_DET (Determinism) // determinstic variable
76 ///////////////////////////////////////////////////////////////////////////////
80 ///////////////////////////////////////////////////////////////////////////////
81 and UnificationMode = READ_MODE | WRITE_MODE
83 ///////////////////////////////////////////////////////////////////////////////
85 // The WAM instruction set.
87 // Notice that our term representation is substantially different that
88 // the traditional WAM. This is mostly due to C++ interoperability
89 // constraints (for example, it is not too nice to have tagged integers
90 // if the user has to tag/untag them manually). In general, we make
91 // no distinction between structures or constants in the WAM level, since
92 // we'll be re-using the pattern matching compiler to perform indexing
93 // and semi-unification. Also notice that terms in Prop are statically
94 // typed in the style of ML.
96 ///////////////////////////////////////////////////////////////////////////////
100 | "proceed" // WAM return
101 | "fail" // WAM failure
105 | "unify_term" (Ty, Cons)
109 | "try_me_else" (Label)
110 | "retry_me_else" (Label)
111 | "trust_me_else_fail"
112 | "label" (Label) // label in the code
114 ///////////////////////////////////////////////////////////////////////////////
118 ///////////////////////////////////////////////////////////////////////////////
119 and Label : MEM = LABEL (Id) => _
121 ///////////////////////////////////////////////////////////////////////////////
123 // Miscellaneous types
125 ///////////////////////////////////////////////////////////////////////////////
126 where type WAMs = List<WAM> // a list of wam instructions.
127 and Labels = List<Label> // a list of labels.
130 ///////////////////////////////////////////////////////////////////////////////
132 // Optimization and manipulation of WAM code.
134 ///////////////////////////////////////////////////////////////////////////////
135 extern WAMs peep_hole (WAMs); // peep hole optimizer.
137 ///////////////////////////////////////////////////////////////////////////////
139 // Manipulation routines.
141 ///////////////////////////////////////////////////////////////////////////////
142 extern Instness deref (Instness);
143 extern Determinism deref (Determinism);
145 ///////////////////////////////////////////////////////////////////////////////
149 ///////////////////////////////////////////////////////////////////////////////
150 extern std::ostream& operator << (std::ostream&, WAM);
151 extern std::ostream& operator << (std::ostream&, WAMs);
152 extern std::ostream& operator << (std::ostream&, Label);
153 extern std::ostream& operator << (std::ostream&, Labels);
154 extern std::ostream& operator << (std::ostream&, Instness);
155 extern std::ostream& operator << (std::ostream&, Determinism);