1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META name='Description' content='Ficl - embedded scripting with object oriented programming'>
<META name='Keywords' content='scripting prototyping tcl OOP Forth interpreter C'>
<LINK rel='SHORTCUT ICON' href='ficl.ico'>
<TITLE>ficl api</TITLE>
<style>
blockquote { margin-left: 1em }
</style>
</HEAD>
<BODY>
<table border=0 cellspacing=0 width=100%%><tr>
<td width=112 bgcolor=#004968 colspan=3>
<img src=graphics/ficl.4.96.jpg height=96 width=96>
</td>
<td bgcolor=#004968>
<font face=arial,helvetica color=white size=7><b><i>
ficl api
</i></b></font>
</td></tr>
<tr>
<td bgcolor=#004968 width=10></td>
<td bgcolor=#004968 valign=top>
<br><p>
<a href=index.html><font face=arial,helvetica color=white><b>Index</b></font></a><p>
<p><br>
<a href=dpans.html><font face=arial,helvetica color=white><b>ANS</b></font></a><br>
<a href=api.html><font face=arial,helvetica color=white><b>API</b></font></a><br>
<a href=debugger.html><font face=arial,helvetica color=white><b>Debugger</b></font></a><br>
<a href=http://sourceforge.net/project/showfiles.php?group_id=24441><font face=arial,helvetica color=white><b>Download</b></font></a><br>
<a href=license.html><font face=arial,helvetica color=white><b>Licensing</b></font></a><br>
<a href=links.html><font face=arial,helvetica color=white><b>Links</b></font></a><br>
<a href=locals.html><font face=arial,helvetica color=white><b>Locals</b></font></a><br>
<a href=oop.html><font face=arial,helvetica color=white><b>OOP In Ficl</b></font></a><br>
<a href=parsesteps.html><font face=arial,helvetica color=white><b>Parse Steps</b></font></a><br>
<a href=releases.html><font face=arial,helvetica color=white><b>Release History</b></font></a><br>
<a href=upgrading.html><font face=arial,helvetica color=white><b>Upgrading To 4.0</b></font></a><br>
</td><td bgcolor=#004968 width=5></td><td valign=top><blockquote><p>
<p>
</blockquote><table border=0 bgcolor=#a0a0a0 width=100%><tr>
<td width=1em></td>
<td>
<font face=arial,helvetica color=#004968 size=5><b><i>
<a name='QuickFiclProgrammingConceptsOverview'>
Quick Ficl Programming Concepts Overview
</a></i></b></font></td></tr></table><p><blockquote>
A Ficl <i>dictionary</i> is equivalent to the FORTH "dictionary"; it is where words are stored.
A single dictionary has a single <code>HERE</code> pointer.
<p>
A Ficl <i>system information</i> structure is used to change default values used
in initializing a Ficl <i>system</i>.
<p>
A Ficl <i>system</i> contains a single <i>dictionary</i>, and one or more <i>virtual machines</i>.
<p>
A Ficl <i>stack</i> is equivalent to a FORTH "stack". Ficl has three stacks:
<ul>
<li>
The <i>data</i> stack, where integer arguments are stored.
<li>
The <i>return</i> stack, where locals and return addresses for subroutine returns are stored.
<li>
The <i>float</i> stack, where floating-point arguments are stored. (This stack
is only enabled when <code>FICL_WANT_FLOAT</code> is nonzero.)
</ul>
<p>
A Ficl <i>virtual machine</i> (or <i>vm</i>) represents a single running instance of the Ficl interpreter.
All virtual machines in a single Ficl system see the same dictionary.
<p>
<p>
</blockquote><table border=0 bgcolor=#b8b8b8 width=100%><tr>
<td width=1em></td>
<td>
<font face=arial,helvetica color=#004968 size=4><b><i>
<a name='QuickFiclProgrammingTutorial'>
Quick Ficl Programming Tutorial
</a></i></b></font></td></tr></table><p><blockquote>
Though Ficl's API offers a great deal of flexibility, most programs
incorporating Ficl simply use it as follows:
<ol>
<li>
Create a single <code>ficlSystem</code> using <code>ficlSystemCreate(NULL)</code>.
<li>
Add native functions as necessary with <code>ficlDictionarySetPrimitive()</code>.
<li>
Add constants as necessary with <code>ficlDictionarySetConstant()</code>.
<li>
Create one (or more) virtual machine(s) with <code>ficlSystemCreateVm()</code>.
<li>
Add one or more scripted functions with <code>ficlVmEvaluate()</code>.
<li>
Execute code in a Ficl virtual machine, usually with <code>ficlVmEvaluate()</code>,
but perhaps with <code>ficlVmExecuteXT()</code>.
<li>
At shutdown, call <code>ficlSystemDestroy()</code> on the single Ficl system.
</ol>
<p>
</blockquote><table border=0 bgcolor=#a0a0a0 width=100%><tr>
<td width=1em></td>
<td>
<font face=arial,helvetica color=#004968 size=5><b><i>
<a name='FiclApplicationProgrammingInterface'>
Ficl Application Programming Interface
</a></i></b></font></td></tr></table><p><blockquote>
The following is a partial listing of functions that interface your
system or program to Ficl. For a complete listing, see <code>ficl.h</code>
(which is heavily commented). For a simple example, see <code>main.c</code>.
<p>
Note that as of Ficl 4, the API is internally consistent.
<i>Every</i> external entry point starts with the word
<code>ficl</code>, and the word after that also corresponds
with the first argument. For instance, a word that operates
on a <code>ficlSystem *</code> will be called <code>ficlSystem<i>Something</i>()</code>.
<dl>
<p><dt>
<code>void ficlSystemInformationInitialize(ficlSystemInformation *fsi)</code>
<dd>
Resets a <code>ficlSystemInformation</code> structure to all zeros.
(Actually implemented as a macro.) Use this to initialize a <code>ficlSystemInformation</code>
structure before initializing its members and passing it
into <code>ficlSystemCreate()</code> (below).
<p><dt>
<code>ficlSystem *ficlSystemCreate(ficlSystemInformation *fsi)</code>
<dd>
Initializes Ficl's shared system data structures, and creates the
dictionary allocating the specified number of cells from the heap
(by a call to <code>ficlMalloc()</code>). If you pass in a <code>NULL</code>
pointer, you will recieve a <code>ficlSystem</code> using the default
sizes for the dictionary and stacks.
<p><dt>
<code>void ficlSystemDestroy(ficlSystem *system)</code>
<dd>
Reclaims memory allocated for the Ficl system including all
dictionaries and all virtual machines created by
<code>ficlSystemCreateVm()</code>. Note that this will <i>not</i>
automatically free memory allocated by the FORTH memory allocation
words (<code>ALLOCATE</code> and <code>RESIZE</code>).
<p><dt>
<code>ficlWord *ficlDictionarySetPrimitive(ficlDictionary *dictionary, char *name, ficlCode code, ficlUnsigned8 flags)</code>
<dd>
Adds a new word to the dictionary with the given
name, code pointer, and flags. To add
<p>
The <code>flags</code> parameter is a bitfield. The valid
flags are:<ul>
<li>
FICL_WORD_IMMEDIATE
<li>
FICL_WORD_COMPILE_ONLY
<li>
FICL_WORD_SMUDGED
<li>
FICL_WORD_OBJECT
<li>
FICL_WORD_INSTRUCTION
</ul>
For more information on these flags, see <code>ficl.h</code>.
<p><dt>
<code>ficlVm *ficlSystemCreateVm(ficlSystem *system)</code>
<dd>
Creates a new virtual machine in the specified system.
<p><dt>
<code>int ficlVmEvaluate(ficlVm *vm, char *text)</code>
<dd>
the specified C string (zero-terminated) to the given
virtual machine for evaluation. Returns various exception codes (VM_XXXX
in ficl.h) to indicate the reason for returning. Normal exit
condition is VM_OUTOFTEXT, indicating that the VM consumed the string
successfully and is back for more. Calls to <code>ficlVmEvaluate()</code>
can be nested, and
the function itself is re-entrant, but note that a VM is
static, so you have to take reasonable precautions (for example, use one
VM per thread in a multithreaded system if you want multiple threads to
be able to execute commands).
<p><dt>
<code>int ficlVmExecuteXT(ficlVm *vm, ficlWord *pFW)</code>
<dd>
Same as ficlExec, but takes a pointer to a ficlWord instead of a
string. Executes the word and returns after it has finished. If
executing the word results in an exception, this function will
re-throw the same code if it is nested under another ficlExec family
function, or return the exception code directly if not. This function
is useful if you need to execute the same word repeatedly—you
save the dictionary search and outer interpreter overhead.
<p><dt>
<code>void ficlFreeVM(ficlVm *vm)</code>
<dd>
Removes the VM in question from the system VM list and deletes
the memory allocated to it. This is an optional call, since
ficlTermSystem will do this cleanup for you. This function is
handy if you're going to do a lot of dynamic creation of VMs.
<p><dt>
<code>ficlVm *ficlNewVM(ficlSystem *system)</code>
<dd>
Create, initialize, and return a VM from the heap using
ficlMalloc. Links the VM into the system VM list for later reclamation
by ficlTermSystem.
<p><dt>
<code>ficlWord *ficlSystemLookup(ficlSystem *system, char *name)</code>
<dd>
Returns the address of the specified word in the main dictionary.
If no such word is found, it returns <code>NULL</code>.
The address is also a valid execution token, and can be used in a call to <code>ficlVmExecuteXT()</code>.
<p><dt>
<code>ficlDictionary *ficlSystemGetDictionary(ficlSystem *system)<br>ficlDictionary *ficlVmGetDictionary(ficlVm *system)</code>
<dd>
Returns a pointer to the main system dictionary.
<p><dt>
<code>ficlDictionary *ficlSystemGetEnvironment(ficlSystem *system)</code>
<dd>
Returns a pointer to the environment dictionary. This dictionary
stores information that describes this implementation as required by the
Standard.
<p><dt>
<code>ficlDictionary *ficlSystemGetLocals(ficlSystem *system)</code>
<dd>
Returns a pointer to the locals dictionary. This function is
defined only if <code>FICL_WANT_LOCALS</code> is non-zero (see <code>ficl.h</code>).
The locals dictionary is the symbol table for
<a href="locals.html">local variables</a>.
</dl>
<p>
</blockquote><table border=0 bgcolor=#a0a0a0 width=100%><tr>
<td width=1em></td>
<td>
<font face=arial,helvetica color=#004968 size=5><b><i>
<a name='FiclCompile-TimeConstants'>
Ficl Compile-Time Constants
</a></i></b></font></td></tr></table><p><blockquote>
There are a lot of preprocessor constants you can set at compile-time
to modify Ficl's runtime behavior. Some are required, such as telling
Ficl whether or not the local platform supports double-width integers
(<code>FICL_PLATFORM_HAS_2INTEGER</code>);
some are optional, such as telling Ficl whether or not to use the
extended set of "prefixes" (<code>FICL_WANT_EXTENDED_PREFIXES</code>).
<p>
The best way to find out more about these constants is to read <code>ficl.h</code>
yourself. The settings that turn on or off Ficl modules all start with
<code>FICL_WANT</code>. The settings relating to functionality available
on the current platform all start with <code>FICL_PLATFORM</code>.
<p>
<p>
</blockquote><table border=0 bgcolor=#b8b8b8 width=100%><tr>
<td width=1em></td>
<td>
<font face=arial,helvetica color=#004968 size=4><b><i>
<a name='codeficllocalh/code'>
<code>ficllocal.h</code>
</a></i></b></font></td></tr></table><p><blockquote>
One more note about constants. Ficl now ships with a standard place for
you to tweak the Ficl compile-time preprocessor constants.
It's a file called <code>ficllocal.h</code>, and we guarantee that it
will always ship empty (or with only comments). We suggest that you
put all your local changes there, rather than editing <code>ficl.h</code>
or editing the makefile. That should make it much easier to integrate
future Ficl releases into your product—all you need do is preserve
your tweaked copy of <code>ficllocal.h</code> and replace the rest.
</blockquote><p></td></tr></table></body></html>
|