-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPORTING
250 lines (156 loc) · 6.24 KB
/
PORTING
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
THREADED INTERPRETIVE LANGUAGE ENVIRONMENT (TILE) PORTING
RELEASE 2.1
August 20, 1990
Mikael R.K. Patel
Computer Aided Design Laboratory (CADLAB)
Department of Computer and Information Science
Linkoping University
S-581 83 LINKOPING
SWEDEN
Email: [email protected]
INTRODUCTION
This brief document describes some to the sections in the tile forth
kernel which may have to be changed to port the code to other machines.
Any changes made should be made in a "#ifdef" section and reported back to
the author in "diff" format.
1. KERNEL DEFINITIONS
1.1 Vocabulary listing parameters (File: kernel.c)
The column and line width used by "words" may be altered by changing
the lines:
#define COLUMNWIDTH 15
#define LINEWIDTH 75
1.2 Set of search vocabularies (File: kernel.c)
The set of search vocabularies, "context", is realized as a vector
of vocabulary pointers. The maximum number of vocabularies in the set
is defined by:
#define CONTEXTSIZE 64
An error will occur it the set is exhausted. This limit is not checked
by the kernel.
1.3 Lookup cache (File: kernel.c)
The vocabulary entry lookup function in the kernel is supported by a
simple cache. A hash function (see below) is used to map a string into
the cache and there, if possible, find the entry. The size of the cache
is given by:
#define CACHESIZE 256
#define hash(s) ((s[0] + (s[1] << 4)) & (CACHESIZE - 1))
The hash function is tailored for the current cache size and thus
special care must be taken when altering these definitions.
1.4 Internal structures (File: kernel.c)
The "pad" and the "tib" may be changed by altering:
#define PADSIZE 84
#define TIBSIZE 256
1.5 Word alignment (File: kernel.h)
Alignment of threaded code and data structures are performed by the
macro:
#define align(p) p = (PTR32) ((INT32) ((PTR8) p + 3) & -4)
This macro currently aligns to word (long) boundaries and is used by
"colon" and "create".
1.6 Typing system (File: kernel.h)
The kernel is written in its own typing system. The typing system may
be extended to allow other data types etc. All data types in the kernel
are written with uppercase words.
#define VOID void
typedef char* PTR8;
typedef short* PTR16;
typedef long* PTR32;
typedef VOID (*SUBR)();
#define NIL 0
typedef long BOOL;
#define TRUE ((BOOL) -1)
#define FALSE ((BOOL) 0)
typedef unsigned NUM;
typedef unsigned char NUM8;
typedef unsigned short NUM16;
typedef unsigned long NUM32;
typedef int INT;
typedef char INT8;
typedef short INT16;
typedef long INT32;
typedef float FLOAT32;
typedef double FLOAT64;
typedef char CHAR;
typedef char* CSTR;
typedef char* PSTR;
typedef union {
BOOL BOOL;
NUM32 NUM32;
INT32 INT32;
FLOAT32 FLOAT32;
CSTR CSTR;
PTR8 PTR8;
PTR16 PTR16;
PTR32 PTR32;
SUBR SUBR;
QUEUE QUEUE;
TASK TASK;
ENTRY ENTRY;
CODE_ENTRY CODE_ENTRY;
VOCABULARY_ENTRY VOCABULARY_ENTRY;
} UNIV, *PTR;
1.7 Initialization of the kernel (File: kernel.c)
The initialization function for the kernel requires five parameters.
The two first allows the application such as forth.c to extend the
basic forth vocabulary by giving the first and last entry in the
application vocabulary. The three following parameters specify the
size of the foreground task, the forth interpreter. See the file
forth.c for an example.
2. IO MANAGEMENT
2.1 File and path name size (File: io.c)
The maximum length of a file or path name is defined as:
#define FILENAMESIZE 128
#define PATHNAMESIZE 128
These lengths are not test for currently. An error may occur if
a file or path name is longer than the given sizes.
2.2 File buffer stack (File: io.c)
The io management package implements a stack of input file buffers to
allow loading of files from within other files etc. The maximum depth
of this stack is defined as:
#define INFSTACKSIZE 32
The depth should be chosen to the maximum number of open files allowed
by the operating system.
2.3 Set of loaded files (File: io.c)
The file loading mechanism automatically looks if the file already
has been opened. The set of opened files is maintained as a vector.
The maximum number of loaded files is:
#define INFILESSIZE 64
The vector contains the fully expanded names of the loaded files.
An error may occur if this limit is exceeded. It is not checked for
currently.
2.4 Set of paths (File: io.c)
The io packages also maintains an ordered collection of paths which
are used to expand file names with when search for the file. The
maximum size of this collection is defined by:
#define PATHSSIZE 32
This collection is automatically appended by the environment variables
$PWD, $HOME, and $TILEPATH when the io package is initiated.
2.5 White space (File: io.h)
The definition of "white" space is defined as:
#define ISSPACE(c) ((c) <= ' ')
This eliminates space and any control characters. Some application
might want to redefine this.
2.6. Directory separator character (File: io.h)
The directory separator character is defined as:
#define DIRSEPCHAR '/'
This makes the code more portable to other machines.
2.6 Non-blocking read operation (File: io.c)
To achieve multi-tasking during input wait the input package function
"io_fillbuf" uses a non-blocking read operation. Some environments
do not support this. This may require re-implementation.
3. ERROR MANAGEMENT
3.1 Signals (File: error.c)
Error handing is realized using two basic mechanisms; first signals from
the execution environment and second, user defined exceptions in the kernel
(forth level code).
The signal message table and the appropriate operations, "error_restart",
or "error_fatal", may have to be changed to give the right performance.
Please see these functions and "error_initiate" where the actual binding
of signals and actions is performed.
4. MEMORY MANAGEMENT
4.1 Memory allocation (File: forth.c)
Currently memory for the dictionary, strings, entries, and task blocks
are allocated using "malloc".
The size of the dictionary is determined when calling the initialization
function, "memory_initiate", in the memory management package. The current
default size is defined as:
#define DICTIONARYSIZE 1024L * 1024L
And may be too large for "small" machines.