0
|
1 Tokio / Prolog Compiler
|
|
2
|
|
3 Fri Aug 5 19:35:55 JST 2005
|
|
4 Shinji KONO
|
|
5 kono@ie.u-ryukyu.ac.jp
|
|
6 University of the Ryukyus
|
|
7
|
|
8 1. Change -D flag in Makefile
|
|
9
|
|
10 Supporting Prologs PROLOG_TYPE PROLOG
|
|
11 SICStus SICSTUS sicstus
|
|
12 Quintus QUINTUS quintus
|
|
13 SWI-Prolog SWIPROLOG swipl
|
|
14
|
|
15 2. File List
|
|
16
|
|
17 call prolog bootup file
|
|
18 cp.pl file for compatiblities
|
|
19 cp.pl.c file for compatiblities (no longer used)
|
|
20 tc.pl tokio clause compiler
|
|
21 td.pl debugger
|
|
22 te.pl expression basics
|
|
23 tf.pl predicates compiler
|
|
24 tg.pl one line compiler
|
|
25 th.pl head unification
|
|
26 tm.pl basic macros
|
|
27 to.pl tokio compiler main routines
|
|
28 tp.pl macro expansion
|
|
29 tr.pl runtime support
|
|
30 ts.pl system definition & operator
|
|
31 tu.pl temporal logic unification
|
|
32 xf.pl system-predicates list
|
|
33 tokio.pl module definition
|
|
34 call iall lall mall load file
|
|
35
|
|
36 3. How to run
|
|
37
|
|
38 In SICStus, use tokio module.
|
|
39
|
|
40 % sicstus
|
|
41 SICStus 3.12.1 (powerpc-darwin-7.8.0): Mon Apr 18 20:00:24 CEST 2005
|
|
42 Licensed to ie.u-ryukyu.ac.jp
|
|
43 | ?- use_module(tokio).
|
|
44 % compiling /Users/kono/ITL/Tokio/tokio.pl...
|
|
45 % compiled /Users/kono/ITL/Tokio/tp.pl in module tokio, 60 msec 19832 bytes
|
|
46 END
|
|
47 0.0 sec.
|
|
48 % compiled /Users/kono/ITL/Tokio/tokio.pl in module tokio, 350 msec 153404 bytes
|
|
49 yes
|
|
50 | ?- com(example).
|
|
51 Compiling: t0/0
|
|
52 Compiling: test/0
|
|
53 END
|
|
54 0.10999999999999999 sec.
|
|
55 % compiling /Users/kono/ITL/Tokio/#temp.tokio...
|
|
56 * [E] - singleton variables in (tokio):t1/2
|
|
57 * Approximate lines: 873-877, file: '/Users/kono/ITL/Tokio/#temp.tokio'
|
|
58 % compiled /Users/kono/ITL/Tokio/#temp.tokio in module tokio, 210 msec 57528 bytes
|
|
59 yes
|
|
60 | ?- tokio.
|
|
61
|
|
62 tokio: test.
|
|
63
|
|
64 t0:1
|
|
65 t1:1
|
|
66 ...
|
|
67 t90:[100]
|
|
68 t91:[]
|
|
69 91 clock and 0.010000000000000009 sec.
|
|
70
|
|
71 tokio: ^D
|
|
72 yes
|
|
73 | ?- ^D
|
|
74
|
|
75 In SWI Prolog, use tokio_swi.pl script.
|
|
76
|
|
77 % swipl
|
|
78 Welcome to SWI-Prolog (Multi-threaded, Version 5.4.7)
|
|
79 Copyright (c) 1990-2003 University of Amsterdam.
|
|
80 SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
|
|
81 and you are welcome to redistribute it under certain conditions.
|
|
82 Please visit http://www.swi-prolog.org for details.
|
|
83
|
|
84 For help, use ?- help(Topic). or ?- apropos(Word).
|
|
85
|
|
86 ?- [tokio_swi].
|
|
87 % ts compiled into tokio 0.00 sec, 1,984 bytes
|
|
88 ...
|
|
89 % tp compiled into tokio 0.00 sec, 18,668 bytes
|
|
90 END
|
|
91 0 sec.
|
|
92 % tokio compiled into tokio 0.06 sec, 142,720 bytes
|
|
93 % ts compiled 0.00 sec, 840 bytes
|
|
94 % tokio_swi compiled 0.06 sec, 143,952 bytes
|
|
95
|
|
96 Yes
|
|
97 tokio: ?- com(example).
|
|
98 Compiling: t0/0
|
|
99 Compiling: t1/0
|
|
100 Compiling: test/0
|
|
101 END
|
|
102 0.14 sec.
|
|
103 Warning: (/Users/kono/ITL/Tokio/#temp.tokio:18):
|
|
104 Singleton variables: [E]
|
|
105 ...
|
|
106 Warning: (/Users/kono/ITL/Tokio/#temp.tokio:873):
|
|
107 Singleton variables: [E]
|
|
108 % #temp.tokio compiled into tokio 0.02 sec, 68,272 bytes
|
|
109
|
|
110 Yes
|
|
111 tokio: ?- tokio.
|
|
112
|
|
113 tokio: test.
|
|
114
|
|
115 t0:1
|
|
116 t1:1
|
|
117 t2:1
|
|
118 t90:[100]
|
|
119 t91:[]
|
|
120 91 clock and 0.02 sec.
|
|
121
|
|
122 tokio:
|
|
123
|
|
124 Yes
|
|
125 tokio: ?-
|
|
126 % halt
|
|
127
|
|
128 You can run each small test in example file,
|
|
129 ?- tokio t0.
|
|
130 or in tokio top level,
|
|
131 ?- tokio.
|
|
132 tokio: t0.
|
|
133
|
|
134 To try more examles,
|
|
135
|
|
136 % cd Examples/6502
|
|
137 % sicstus
|
|
138 ?-use_module('../../Tokio/tokiko').
|
|
139 ?-com(mc6502).
|
|
140 ?-com(run).
|
|
141 ?-tokio run(a).
|
|
142
|
|
143 Some of them may not work, such as toy.
|
|
144
|
|
145 3. Notice
|
|
146
|
|
147 If you are going to create very large program in Tokio,
|
|
148 use com/2 instead of com/1. It greatly reduces compile time and you
|
|
149 can use Prolog output for debugging purpose.
|
|
150
|
|
151 Converting Tokio Program into Prolog is quite fast. But
|
|
152 compiling the output by Prolog compiler takes long time (in some prolog).
|
|
153 Execution speed of Tokio program mainly depends on runtime library, so
|
|
154 Tokio code can run reasonably fast even if generated code is not compiled.
|
|
155
|
|
156 "com(file)" command translates and compiles Tokio program, but
|
|
157 "com(file,output)" translates and consults Tokio program.
|
|
158 In this reason, it is better to use com(file,output) than com(file) to
|
|
159 speed up Tokio to Prolog translation.
|
|
160
|
|
161 When you exit Prolog top level, use ``tokio'' to reenter Tokio top level.
|
|
162
|
|
163 In SICStus/Quintus, com/2 automatically try to add '.tokio' postfix,
|
|
164 but SWI-Prolog does not. You need type com('mc6502.tokio') in SWI-Prolog.
|
|
165
|
|
166 SICStus/Quintus complains,
|
|
167 * nofileerrors/0 - NOT redefined
|
|
168 Please ignore.
|
|
169
|
|
170 4. Module
|
|
171
|
|
172 ?- use_module(tokio).
|
|
173 ?- com(example).
|
|
174 ?- tokio test.
|
|
175
|
|
176 will work on SICStus Prolog.
|
|
177
|
|
178 In SWI-Prolog,
|
|
179
|
|
180 ?- use_module(tokio).
|
|
181 ?- [ts].
|
|
182 ?- module(tokio).
|
|
183 ?- com(example).
|
|
184 ?- tokio test.
|
|
185
|
|
186 Yes, we should have seprate space for compiled tokio clauses.
|
|
187
|
|
188 5. Sample Run
|
|
189
|
|
190 Here is an example script....
|
|
191
|
|
192
|
|
193 Script started on Fri Aug 5 19:39:20 2005
|
|
194 % swipl
|
|
195
|
|
196 Welcome to SWI-Prolog (Multi-threaded, Version 5.4.7)
|
|
197 Copyright (c) 1990-2003 University of Amsterdam.
|
|
198 SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
|
|
199 and you are welcome to redistribute it under certain conditions.
|
|
200 Please visit http://www.swi-prolog.org for details.
|
|
201
|
|
202 For help, use ?- help(Topic). or ?- apropos(Word).
|
|
203
|
|
204 ?- [call].
|
|
205 % ts compiled 0.00 sec, 1,880 bytes
|
|
206 % to compiled 0.01 sec, 16,656 bytes
|
|
207 ...
|
|
208 % tp compiled 0.01 sec, 18,156 bytes
|
|
209 END
|
|
210 0 sec.
|
|
211
|
|
212 Tokio to prolog compiler $Revision$ $Date$
|
|
213 try ?- tokio_help.
|
|
214
|
|
215 % call compiled 0.08 sec, 257,608 bytes
|
|
216
|
|
217 Yes
|
|
218 ?- com(example)
|
|
219
|
|
220 ?- com
|
|
221 ?- com(example).
|
|
222 Compiling: t0/0
|
|
223 Compiling: t1/0
|
|
224 ....
|
|
225 Compiling: append/3
|
|
226 Compiling: test/0
|
|
227 END
|
|
228 0.14 sec.
|
|
229 Warning: (/Users/kono/ITL/Tokio/#temp.tokio:18):
|
|
230 Singleton variables: [E]
|
|
231 ...
|
|
232 Warning: (/Users/kono/ITL/Tokio/#temp.tokio:873):
|
|
233 Singleton variables: [E]
|
|
234 % #temp.tokio compiled 0.02 sec, 68,272 bytes
|
|
235
|
|
236 Yes
|
|
237 ?- tokio test.
|
|
238
|
|
239 t0:1
|
|
240 t1:1
|
|
241 t2:1
|
|
242 t3:1
|
|
243 t4:1
|
|
244 ...
|
|
245 t89:[20]
|
|
246 t90:[100]
|
|
247 t91:[]
|
|
248 91 clock and 0.02 sec.
|
|
249
|
|
250 Yes
|
|
251 ?- tokiodebug.
|
|
252 Tokio debug mode switched on.
|
|
253 All computation will be traced.
|
|
254 ERROR: Undefined procedure: ttynl/0
|
|
255 ?- tokio t0.
|
|
256
|
|
257 Tokio Trace t0:h.
|
|
258 help/h/? print this
|
|
259 next/n skip to next clock
|
|
260 dump/d dump current static value
|
|
261 all all history of static value
|
|
262 save(file) save current state
|
|
263 skip(n)/s(n)/+-Number goto +-Number clock
|
|
264 abort/a abort tokio execution
|
|
265 break/b break to prolog
|
|
266 value(Name)/*Name examine static value
|
|
267 queue/q show current process queue
|
|
268 trace/t enter prolog tracer
|
|
269
|
|
270 Tokio Trace t0:next.
|
|
271
|
|
272 t0:1
|
|
273 Tokio Trace t1:next.
|
|
274
|
|
275 t1:1
|
|
276 Tokio Trace t2:q.
|
|
277
|
|
278 :-abolish(restart, 1), recorda(time, 2, _G415).
|
|
279 restart:-r_solve_t((r_0t00(['$t'(B, C, D, $(5, 2, A))|E], ['$t'(true, true, true, $(5, 2, A))|F]), true), 5, 2, ['$t'(B, C, D, $(5, 2, A))|E], ['$t'(true, true, true, $(5, 2, A))|F]).
|
|
280
|
|
281 Tokio Trace t2:skip(3).
|
|
282
|
|
283 t2:1
|
|
284 t3:1
|
|
285 t4:1
|
|
286
|
|
287
|
|
288 Script done on Fri Aug 5 19:41:30 2005
|
|
289
|