3 IMPORT S
:= SYSTEM
, stdlib
:= PosixCstdlib
, stdio
:= PosixCstdio
,
4 time
:= PosixCtime
, wctype
:= PosixCwctype
, sysmman
:= PosixCsys_mman
,
5 dlfcn
:= PosixCdlfcn
, fcntl
:= PosixCfcntl
, types
:= PosixCtypes
,
6 unistd
:= PosixCunistd
, signal
:= PosixCsignal
, setjmp
:= PosixCsetjmp
,
10 (* add signal blocking to avoid race conditions in Try/Trap/TrapHandler *)
11 (* add BeepHook for Beep *)
12 (* implement Call using libffi *)
18 timeResolution
* = 1000; (* ticks per second *)
20 processor
* = 1; (* generic c *)
22 objType
* = "ocf"; (* file types *)
26 (* loader constants *)
40 strictStackSweep
= FALSE
;
41 N
= 128 DIV 16; (* free lists *)
43 (* kernel flags in module desc *)
44 init
= 16; dyn
= 17; dll
= 24; iptrs
= 30;
46 (* meta interface consts *)
47 mConst
= 1; mTyp
= 2; mVar
= 3; mProc
= 4; mField
= 5;
50 Name
* = ARRAY nameLen
OF CHAR;
51 Utf8Name
* = ARRAY nameLen
OF SHORTCHAR
;
54 Module
* = POINTER TO RECORD [untagged
]
56 opts
-: SET; (* 0..15: compiler opts, 16..31: kernel flags *)
57 refcnt
-: INTEGER; (* <0: module invalidated *)
58 compTime
-, loadTime
-: ARRAY 6 OF SHORTINT;
59 ext
-: INTEGER; (* currently not used *)
60 term
-: Command
; (* terminator *)
61 nofimps
-, nofptrs
-: INTEGER;
62 csize
-, dsize
-, rsize
-: INTEGER;
63 code
-, data
-, refs
-: INTEGER;
64 procBase
-, varBase
-: INTEGER; (* meta base addresses *)
65 names
-: POINTER TO ARRAY [untagged
] OF SHORTCHAR
; (* names[0] = 0X *)
66 ptrs
-: POINTER TO ARRAY [untagged
] OF INTEGER;
67 imports
-: POINTER TO ARRAY [untagged
] OF Module
;
68 export
-: Directory
; (* exported objects (name sorted) *)
72 Type
* = POINTER TO RECORD [untagged
]
73 (* record: ptr to method n at offset - 4 * (n+1) *)
74 size
-: INTEGER; (* record: size, array: #elem, dyn array: 0, proc: sigfp *)
76 id
-: INTEGER; (* name idx * 256 + lev * 16 + attr * 4 + form *)
77 base
-: ARRAY 16 OF Type
; (* signature if form = ProcTyp *)
78 fields
-: Directory
; (* new fields (declaration order) *)
79 ptroffs
-: ARRAY any
OF INTEGER (* array of any length *)
82 Object
* = POINTER TO ObjDesc
;
84 ObjDesc
* = RECORD [untagged
]
86 offs
-: INTEGER; (* pvfprint for record types *)
87 id
-: INTEGER; (* name idx * 256 + vis * 16 + mode *)
88 struct
-: Type (* id of basic type or pointer to typedesc/signature *)
91 Directory
* = POINTER TO RECORD [untagged
]
92 num
-: INTEGER; (* number of entries *)
93 obj
-: ARRAY any
OF ObjDesc (* array of any length *)
96 Signature
* = POINTER TO RECORD [untagged
]
97 retStruct
-: Type
; (* id of basic type or pointer to typedesc or 0 *)
98 num
-: INTEGER; (* number of parameters *)
99 par
-: ARRAY any
OF RECORD [untagged
] (* parameters *)
100 id
-: INTEGER; (* name idx * 256 + kind *)
101 struct
-: Type (* id of basic type or pointer to typedesc *)
105 Handler
* = PROCEDURE;
107 Reducer
* = POINTER TO ABSTRACT
RECORD
111 Identifier
* = ABSTRACT
RECORD
116 TrapCleaner
* = POINTER TO ABSTRACT
RECORD
120 TryHandler
* = PROCEDURE (a
, b
, c
: INTEGER);
122 (* meta extension suport *)
124 ItemExt
* = POINTER TO ABSTRACT
RECORD END;
127 obj
*, vis
*, typ
*, adr
*: INTEGER;
134 Hook
* = POINTER TO ABSTRACT
RECORD END;
136 LoaderHook
* = POINTER TO ABSTRACT
RECORD (Hook
)
138 importing
*, imported
*, object
*: ARRAY 256 OF CHAR
141 Block
= POINTER TO RECORD [untagged
]
143 last
: INTEGER; (* arrays: last element *)
144 actual
: INTEGER; (* arrays: used during mark phase *)
145 first
: INTEGER (* arrays: first element *)
148 FreeBlock
= POINTER TO FreeDesc
;
150 FreeDesc
= RECORD [untagged
]
151 tag
: Type
; (* f.tag = ADR(f.size) *)
156 Cluster
= POINTER TO RECORD [untagged
]
157 size
: INTEGER; (* total size *)
159 max
: INTEGER (* exe: reserved size, dll: original address *)
160 (* start of first block *)
163 FList
= POINTER TO RECORD
169 CList
= POINTER TO RECORD
176 PtrType
= RECORD v
: S
.PTR
END; (* used for array of pointer *)
177 Char8Type
= RECORD v
: SHORTCHAR
END;
178 Char16Type
= RECORD v
: CHAR END;
179 Int8Type
= RECORD v
: BYTE END;
180 Int16Type
= RECORD v
: SHORTINT END;
181 Int32Type
= RECORD v
: INTEGER END;
182 Int64Type
= RECORD v
: LONGINT END;
183 BoolType
= RECORD v
: BOOLEAN END;
184 SetType
= RECORD v
: SET END;
185 Real32Type
= RECORD v
: SHORTREAL
END;
186 Real64Type
= RECORD v
: REAL END;
187 ProcType
= RECORD v
: PROCEDURE END;
188 UPtrType
= RECORD v
: INTEGER END;
189 StrPtr
= POINTER TO ARRAY [untagged
] OF SHORTCHAR
;
191 (* SYSTEM.h -> SYSTEM_DLINK *)
192 DLink
= POINTER TO RECORD [untagged
]
196 ArrStrPtr
= POINTER TO ARRAY [untagged
] OF StrPtr
;
198 ADDRESS
* = types
.Pvoid
;
205 err
-, pc
-, sp
-, fp
-, stack
-, val
-: INTEGER;
208 startEnv
: setjmp
.sigjmp_buf
;
209 tryEnv
: setjmp
.jmp_buf
;
210 startDLink
, tryDLink
: DLink
;
214 pagesize
: unistd
.long
;
216 free
: ARRAY N
OF FreeBlock
; (* free list *)
217 sentinelBlock
: FreeDesc
;
219 candidates
: ARRAY 1024 OF INTEGER;
221 allocated
: INTEGER; (* bytes allocated on BlackBox heap *)
222 total
: INTEGER; (* current total size of BlackBox heap *)
223 used
: INTEGER; (* bytes allocated on system heap *)
225 hotFinalizers
: FList
;
228 trapStack
: TrapCleaner
;
229 actual
: Module
; (* valid during module initialization *)
231 trapViewer
, trapChecker
: Handler
;
232 trapped
, guarded
, secondTrap
: BOOLEAN;
233 interrupted
: BOOLEAN;
234 static
, inDll
, terminating
: BOOLEAN;
240 wouldFinalize
: BOOLEAN;
242 watcher
*: PROCEDURE (event
: INTEGER); (* for debugging *)
246 PROCEDURE Erase (adr
, words
: INTEGER);
248 ASSERT(words
>= 0, 20);
257 PROCEDURE (VAR id
: Identifier
) Identified
* (): BOOLEAN, NEW, ABSTRACT
;
258 PROCEDURE (r
: Reducer
) Reduce
* (full
: BOOLEAN), NEW, ABSTRACT
;
259 PROCEDURE (c
: TrapCleaner
) Cleanup
*, NEW, EMPTY
;
261 (* meta extension suport *)
263 PROCEDURE (e
: ItemExt
) Lookup
* (name
: ARRAY OF CHAR; VAR i
: ANYREC
), NEW, ABSTRACT
;
264 PROCEDURE (e
: ItemExt
) Index
* (index
: INTEGER; VAR elem
: ANYREC
), NEW, ABSTRACT
;
265 PROCEDURE (e
: ItemExt
) Deref
* (VAR ref
: ANYREC
), NEW, ABSTRACT
;
267 PROCEDURE (e
: ItemExt
) Valid
* (): BOOLEAN, NEW, ABSTRACT
;
268 PROCEDURE (e
: ItemExt
) Size
* (): INTEGER, NEW, ABSTRACT
;
269 PROCEDURE (e
: ItemExt
) BaseTyp
* (): INTEGER, NEW, ABSTRACT
;
270 PROCEDURE (e
: ItemExt
) Len
* (): INTEGER, NEW, ABSTRACT
;
272 PROCEDURE (e
: ItemExt
) Call
* (OUT ok
: BOOLEAN), NEW, ABSTRACT
;
273 PROCEDURE (e
: ItemExt
) BoolVal
* (): BOOLEAN, NEW, ABSTRACT
;
274 PROCEDURE (e
: ItemExt
) PutBoolVal
* (x
: BOOLEAN), NEW, ABSTRACT
;
275 PROCEDURE (e
: ItemExt
) CharVal
* (): CHAR, NEW, ABSTRACT
;
276 PROCEDURE (e
: ItemExt
) PutCharVal
* (x
: CHAR), NEW, ABSTRACT
;
277 PROCEDURE (e
: ItemExt
) IntVal
* (): INTEGER, NEW, ABSTRACT
;
278 PROCEDURE (e
: ItemExt
) PutIntVal
* (x
: INTEGER), NEW, ABSTRACT
;
279 PROCEDURE (e
: ItemExt
) LongVal
* (): LONGINT, NEW, ABSTRACT
;
280 PROCEDURE (e
: ItemExt
) PutLongVal
* (x
: LONGINT), NEW, ABSTRACT
;
281 PROCEDURE (e
: ItemExt
) RealVal
* (): REAL, NEW, ABSTRACT
;
282 PROCEDURE (e
: ItemExt
) PutRealVal
* (x
: REAL), NEW, ABSTRACT
;
283 PROCEDURE (e
: ItemExt
) SetVal
* (): SET, NEW, ABSTRACT
;
284 PROCEDURE (e
: ItemExt
) PutSetVal
* (x
: SET), NEW, ABSTRACT
;
285 PROCEDURE (e
: ItemExt
) PtrVal
* (): ANYPTR
, NEW, ABSTRACT
;
286 PROCEDURE (e
: ItemExt
) PutPtrVal
* (x
: ANYPTR
), NEW, ABSTRACT
;
287 PROCEDURE (e
: ItemExt
) GetSStringVal
* (OUT x
: ARRAY OF SHORTCHAR
;
288 OUT ok
: BOOLEAN), NEW, ABSTRACT
;
289 PROCEDURE (e
: ItemExt
) PutSStringVal
* (IN x
: ARRAY OF SHORTCHAR
;
290 OUT ok
: BOOLEAN), NEW, ABSTRACT
;
291 PROCEDURE (e
: ItemExt
) GetStringVal
* (OUT x
: ARRAY OF CHAR; OUT ok
: BOOLEAN), NEW, ABSTRACT
;
292 PROCEDURE (e
: ItemExt
) PutStringVal
* (IN x
: ARRAY OF CHAR; OUT ok
: BOOLEAN), NEW, ABSTRACT
;
294 (* -------------------- miscellaneous tools -------------------- *)
296 PROCEDURE IsUpper
* (ch
: CHAR): BOOLEAN;
298 RETURN wctype
.iswupper(ORD(ch
)) # 0
301 PROCEDURE Upper
* (ch
: CHAR): CHAR;
303 RETURN CHR(wctype
.towupper(ORD(ch
)))
306 PROCEDURE IsLower
* (ch
: CHAR): BOOLEAN;
308 RETURN wctype
.iswlower(ORD(ch
)) # 0
311 PROCEDURE Lower
* (ch
: CHAR): CHAR;
313 RETURN CHR(wctype
.towlower(ORD(ch
)))
316 PROCEDURE IsAlpha
* (ch
: CHAR): BOOLEAN;
318 RETURN wctype
.iswalpha(ORD(ch
)) # 0
321 PROCEDURE Utf8ToString
* (IN in
: ARRAY OF SHORTCHAR
; OUT out
: ARRAY OF CHAR; OUT res
: INTEGER);
322 VAR i
, j
, val
, max
: INTEGER; ch
: SHORTCHAR
;
324 PROCEDURE FormatError();
325 BEGIN out
:= in$
; res
:= 2 (*format error*)
329 ch
:= in
[0]; i
:= 1; j
:= 0; max
:= LEN(out
) - 1;
330 WHILE (ch
# 0X
) & (j
< max
) DO
334 val
:= ORD(ch
) - 192;
335 IF val
< 0 THEN FormatError
; RETURN END ;
336 ch
:= in
[i
]; INC(i
); val
:= val
* 64 + ORD(ch
) - 128;
337 IF (ch
< 80X
) OR (ch
>= 0E0X
) THEN FormatError
; RETURN END ;
338 out
[j
] := CHR(val
); INC(j
)
340 val
:= ORD(ch
) - 224;
341 ch
:= in
[i
]; INC(i
); val
:= val
* 64 + ORD(ch
) - 128;
342 IF (ch
< 80X
) OR (ch
>= 0E0X
) THEN FormatError
; RETURN END ;
343 ch
:= in
[i
]; INC(i
); val
:= val
* 64 + ORD(ch
) - 128;
344 IF (ch
< 80X
) OR (ch
>= 0E0X
) THEN FormatError
; RETURN END ;
345 out
[j
] := CHR(val
); INC(j
)
352 IF ch
= 0X
THEN res
:= 0 (*ok*) ELSE res
:= 1 (*truncated*) END
355 PROCEDURE StringToUtf8
* (IN in
: ARRAY OF CHAR; OUT out
: ARRAY OF SHORTCHAR
; OUT res
: INTEGER);
356 VAR i
, j
, val
, max
: INTEGER;
358 i
:= 0; j
:= 0; max
:= LEN(out
) - 3;
359 WHILE (in
[i
] # 0X
) & (j
< max
) DO
360 val
:= ORD(in
[i
]); INC(i
);
362 out
[j
] := SHORT(CHR(val
)); INC(j
)
363 ELSIF val
< 2048 THEN
364 out
[j
] := SHORT(CHR(val
DIV 64 + 192)); INC(j
);
365 out
[j
] := SHORT(CHR(val
MOD 64 + 128)); INC(j
)
367 out
[j
] := SHORT(CHR(val
DIV 4096 + 224)); INC(j
);
368 out
[j
] := SHORT(CHR(val
DIV 64 MOD 64 + 128)); INC(j
);
369 out
[j
] := SHORT(CHR(val
MOD 64 + 128)); INC(j
)
373 IF in
[i
] = 0X
THEN res
:= 0 (*ok*) ELSE res
:= 1 (*truncated*) END
376 PROCEDURE SplitName
* (name
: ARRAY OF CHAR; VAR head
, tail
: ARRAY OF CHAR);
378 VAR i
, j
: INTEGER; ch
, lch
: CHAR;
380 i
:= 0; ch
:= name
[0];
383 head
[i
] := ch
; lch
:= ch
; INC(i
); ch
:= name
[i
]
384 UNTIL (ch
= 0X
) OR (ch
= ".") OR IsUpper(ch
) & ~
IsUpper(lch
);
385 IF ch
= "." THEN i
:= 0; ch
:= name
[0] END;
386 head
[i
] := 0X
; j
:= 0;
387 WHILE ch
# 0X
DO tail
[j
] := ch
; INC(i
); INC(j
); ch
:= name
[i
] END;
389 IF tail
= "" THEN tail
:= head$
; head
:= "" END
390 ELSE head
:= ""; tail
:= ""
394 PROCEDURE MakeFileName
* (VAR name
: ARRAY OF CHAR; type
: ARRAY OF CHAR);
395 VAR i
, j
: INTEGER; ext
: ARRAY 8 OF CHAR; ch
: CHAR;
398 WHILE (name
[i
] # 0X
) & (name
[i
] # ".") DO INC(i
) END;
399 IF name
[i
] = "." THEN
400 IF name
[i
+ 1] = 0X
THEN name
[i
] := 0X
END
402 IF type
= "" THEN ext
:= docType
ELSE ext
:= type$
END;
403 IF i
< LEN(name
) - LEN(ext$
) - 1 THEN
404 name
[i
] := "."; INC(i
); j
:= 0; ch
:= ext
[0];
406 name
[i
] := Lower(ch
); INC(i
); INC(j
); ch
:= ext
[j
]
413 PROCEDURE Time
* (): LONGINT;
414 VAR res
: time
.int
; tp
: time
.struct_timespec
;
416 ASSERT(timeResolution
>= 1);
417 ASSERT(timeResolution
<= 1000000000);
418 res
:= time
.clock_gettime(time
.CLOCK_MONOTONIC
, tp
);
419 ASSERT(res
= 0, 100);
420 RETURN tp
.tv_sec
* LONG(timeResolution
) + tp
.tv_nsec
DIV LONG(1000000000 DIV timeResolution
)
427 PROCEDURE SearchProcVar
* (var
: INTEGER; VAR m
: Module
; VAR adr
: INTEGER);
429 adr
:= var
; m
:= NIL;
432 WHILE (m
# NIL) & ((var
< m
.code
) OR (var
>= m
.code
+ m
.csize
)) DO m
:= m
.next
END;
433 IF m
# NIL THEN DEC(adr
, m
.code
) END
437 (* -------------------- system memory management --------------------- *)
439 PROCEDURE AllocMem (size
: sysmman
.size_t
; VAR max
: sysmman
.size_t
): ADDRESS
;
440 VAR fd
, flags
, res
: fcntl
.int
; ptr
: ADDRESS
;
442 max
:= (size
+ pagesize
- 1) DIV pagesize
* pagesize
;
443 fd
:= fcntl
.open("/dev/zero", fcntl
.O_RDWR
, 0);
445 flags
:= sysmman
.PROT_READ
+ sysmman
.PROT_WRITE
;
446 ptr
:= sysmman
.mmap(0, max
, flags
, sysmman
.MAP_PRIVATE
, fd
, 0);
447 IF ptr
= sysmman
.MAP_FAILED
THEN ptr
:= 0 END;
448 res
:= unistd
.close(fd
);
456 PROCEDURE FreeMem (adr
: ADDRESS
; size
: sysmman
.size_t
);
457 VAR res
: sysmman
.int
;
459 size
:= (size
+ pagesize
- 1) DIV pagesize
* pagesize
;
460 res
:= sysmman
.munmap(adr
, size
);
464 PROCEDURE AllocHeapMem (size
: INTEGER; VAR c
: Cluster
);
465 CONST N
= 65536; (* cluster size for dll *)
466 VAR adr
, allocated
, newsize
: INTEGER;
469 ASSERT(size
> 0, 100); adr
:= 0;
471 adr
:= AllocMem(N
, newsize
);
475 adr
:= AllocMem(size
, newsize
);
478 IF adr
= 0 THEN c
:= NIL
480 c
:= S
.VAL(Cluster
, (adr
+ 15) DIV 16 * 16); c
.max
:= adr
;
481 c
.size
:= allocated
- (S
.VAL(INTEGER, c
) - adr
);
482 INC(used
, c
.size
); INC(total
, c
.size
)
484 ASSERT((adr
= 0) OR (adr
MOD 16 = 0) & (c
.size
>= size
), 101);
485 (* post: (c = NIL) OR (c MOD 16 = 0) & (c.size >= size) *)
488 PROCEDURE FreeHeapMem (c
: Cluster
);
490 DEC(used
, c
.size
); DEC(total
, c
.size
);
491 FreeMem(S
.VAL(ADDRESS
, c
.max
), c
.size
)
494 PROCEDURE HeapFull (size
: INTEGER): BOOLEAN;
499 PROCEDURE AllocModMem
* (descSize
, modSize
: INTEGER; VAR descAdr
, modAdr
: INTEGER);
501 descAdr
:= 0; modAdr
:= 0;
502 descAdr
:= AllocMem(descSize
, descSize
);
504 modAdr
:= AllocMem(modSize
, modSize
);
506 FreeMem(descAdr
, descSize
)
508 INC(used
, descSize
+ modSize
)
513 PROCEDURE DeallocModMem
* (descSize
, modSize
, descAdr
, modAdr
: INTEGER);
515 FreeMem(descAdr
, descSize
);
516 FreeMem(modAdr
, modSize
);
517 DEC(used
, descSize
+ modSize
)
520 PROCEDURE InvalModMem (modSize
, modAdr
: INTEGER);
522 FreeMem(modAdr
, modSize
)
525 PROCEDURE TryRead (from
, to
, c
: INTEGER);
526 VAR i
: INTEGER; x
: BYTE;
529 FOR i
:= from
TO to
DO
533 FOR i
:= to
TO from BY
-1 DO
539 PROCEDURE^ Try
* (h
: TryHandler
; a
, b
, c
: INTEGER);
541 PROCEDURE IsReadable
* (from
, to
: INTEGER): BOOLEAN;
545 Try(TryRead
, from
, to
, 0);
549 (* --------------------- NEW implementation (portable) -------------------- *)
551 PROCEDURE^
NewBlock (size
: INTEGER): Block
;
553 PROCEDURE NewRec
* (typ
: INTEGER): INTEGER; (* implementation of NEW(ptr) *)
554 VAR size
, adr
: INTEGER; b
: Block
; tag
: Type
; l
: FList
;
557 tag
:= S
.VAL(Type
, typ
);
558 b
:= NewBlock(tag
.size
);
561 S
.GET(typ
- 4, size
);
562 IF size
# 0 THEN (* record uses a finalizer *)
563 l
:= S
.VAL(FList
, S
.ADR(b
.last
)); (* anchor new object! *)
564 l
:= S
.VAL(FList
, NewRec(S
.TYP(FList
))); (* NEW(l) *)
565 l
.blk
:= b
; l
.next
:= finalizers
; finalizers
:= l
572 HALT(100) (* COM interface pointers not supported *)
577 PROCEDURE NewArr
* (eltyp
, nofelem
, nofdim
: INTEGER): INTEGER; (* impl. of NEW(ptr, dim0, dim1, ...) *)
578 VAR b
: Block
; size
, headSize
: INTEGER; t
: Type
;
581 |
-1: HALT(100) (* COM interface pointers not supported *)
582 |
0: eltyp
:= S
.ADR(PtrType
)
583 |
1: eltyp
:= S
.ADR(Char8Type
)
584 |
2: eltyp
:= S
.ADR(Int16Type
)
585 |
3: eltyp
:= S
.ADR(Int8Type
)
586 |
4: eltyp
:= S
.ADR(Int32Type
)
587 |
5: eltyp
:= S
.ADR(BoolType
)
588 |
6: eltyp
:= S
.ADR(SetType
)
589 |
7: eltyp
:= S
.ADR(Real32Type
)
590 |
8: eltyp
:= S
.ADR(Real64Type
)
591 |
9: eltyp
:= S
.ADR(Char16Type
)
592 |
10: eltyp
:= S
.ADR(Int64Type
)
593 |
11: eltyp
:= S
.ADR(ProcType
)
594 |
12: HALT(101) (* COM interface pointers not supported *)
596 ASSERT(~
ODD(eltyp
), 102) (* COM interface pointers not supported *)
598 t
:= S
.VAL(Type
, eltyp
);
599 headSize
:= 4 * nofdim
+ 12;
600 size
:= headSize
+ nofelem
* t
.size
;
603 b
.tag
:= S
.VAL(Type
, eltyp
+ 2); (* tag + array mark *)
604 b
.last
:= S
.ADR(b
.last
) + size
- t
.size
; (* pointer to last elem *)
605 b
.first
:= S
.ADR(b
.last
) + headSize
; (* pointer to first elem *)
612 (* -------------------- handler installation (portable) --------------------- *)
614 PROCEDURE ThisFinObj
* (VAR id
: Identifier
): ANYPTR
;
617 ASSERT(id
.typ
# 0, 100);
620 IF S
.VAL(INTEGER, l
.blk
.tag
) = id
.typ
THEN
621 id
.obj
:= S
.VAL(ANYPTR
, S
.ADR(l
.blk
.last
));
622 IF id
.Identified() THEN RETURN id
.obj
END
629 PROCEDURE InstallReducer
* (r
: Reducer
);
631 r
.next
:= reducers
; reducers
:= r
634 PROCEDURE InstallTrapViewer
* (h
: Handler
);
637 END InstallTrapViewer
;
639 PROCEDURE InstallTrapChecker
* (h
: Handler
);
642 END InstallTrapChecker
;
644 PROCEDURE PushTrapCleaner
* (c
: TrapCleaner
);
647 t
:= trapStack
; WHILE (t
# NIL) & (t
# c
) DO t
:= t
.next
END;
649 c
.next
:= trapStack
; trapStack
:= c
652 PROCEDURE PopTrapCleaner
* (c
: TrapCleaner
);
656 WHILE (trapStack
# NIL) & (t
# c
) DO
657 t
:= trapStack
; trapStack
:= trapStack
.next
661 PROCEDURE InstallCleaner
* (p
: Command
);
664 c
:= S
.VAL(CList
, NewRec(S
.TYP(CList
))); (* NEW(c) *)
665 c
.do
:= p
; c
.trapped
:= FALSE
; c
.next
:= cleaners
; cleaners
:= c
668 PROCEDURE RemoveCleaner
* (p
: Command
);
671 c
:= cleaners
; c0
:= NIL;
672 WHILE (c
# NIL) & (c
.do
# p
) DO c0
:= c
; c
:= c
.next
END;
674 IF c0
= NIL THEN cleaners
:= cleaners
.next
ELSE c0
.next
:= c
.next
END
681 c
:= cleaners
; c0
:= NIL;
684 c
.trapped
:= TRUE
; c
.do
; c
.trapped
:= FALSE
; c0
:= c
686 IF c0
= NIL THEN cleaners
:= cleaners
.next
687 ELSE c0
.next
:= c
.next
694 (* -------------------- meta information (portable) --------------------- *)
696 PROCEDURE (h
: LoaderHook
) ThisMod
* (IN name
: ARRAY OF CHAR): Module
, NEW, ABSTRACT
;
698 PROCEDURE SetLoaderHook
*(h
: LoaderHook
);
703 PROCEDURE InitModule (mod
: Module
); (* initialize linked modules *)
706 IF ~
(dyn
IN mod
.opts
) & (mod
.next
# NIL) & ~
(init
IN mod
.next
.opts
) THEN InitModule(mod
.next
) END;
707 IF ~
(init
IN mod
.opts
) THEN
708 body
:= S
.VAL(Command
, mod
.code
);
709 INCL(mod
.opts
, init
);
711 body(); actual
:= NIL
715 PROCEDURE ThisLoadedMod
* (IN name
: ARRAY OF CHAR): Module
; (* loaded modules only *)
716 VAR m
: Module
; res
: INTEGER; n
: Utf8Name
;
718 StringToUtf8(name
, n
, res
); ASSERT(res
= 0);
721 WHILE (m
# NIL) & ((m
.name
# n
) OR (m
.refcnt
< 0)) DO m
:= m
.next
END;
722 IF (m
# NIL) & ~
(init
IN m
.opts
) THEN InitModule(m
) END;
723 IF m
= NIL THEN loadres
:= moduleNotFound
END;
727 PROCEDURE ThisMod
* (IN name
: ARRAY OF CHAR): Module
;
731 RETURN loader
.ThisMod(name
)
733 RETURN ThisLoadedMod(name
)
737 PROCEDURE LoadMod
* (IN name
: ARRAY OF CHAR);
743 PROCEDURE GetLoaderResult
* (OUT res
: INTEGER; OUT importing
, imported
, object
: ARRAY OF CHAR);
747 importing
:= loader
.importing$
;
748 imported
:= loader
.imported$
;
749 object
:= loader
.object$
758 PROCEDURE ThisObject
* (mod
: Module
; IN name
: ARRAY OF CHAR): Object
;
759 VAR l
, r
, m
, res
: INTEGER; p
: StrPtr
; n
: Utf8Name
;
761 StringToUtf8(name
, n
, res
); ASSERT(res
= 0);
762 l
:= 0; r
:= mod
.export
.num
;
763 WHILE l
< r
DO (* binary search *)
765 p
:= S
.VAL(StrPtr
, S
.ADR(mod
.names
[mod
.export
.obj
[m
].id
DIV 256]));
766 IF p^
= n
THEN RETURN S
.VAL(Object
, S
.ADR(mod
.export
.obj
[m
])) END;
767 IF p^
< n
THEN l
:= m
+ 1 ELSE r
:= m
END
772 PROCEDURE ThisDesc
* (mod
: Module
; fprint
: INTEGER): Object
;
775 i
:= 0; n
:= mod
.export
.num
;
776 WHILE (i
< n
) & (mod
.export
.obj
[i
].id
DIV 256 = 0) DO
777 IF mod
.export
.obj
[i
].offs
= fprint
THEN RETURN S
.VAL(Object
, S
.ADR(mod
.export
.obj
[i
])) END;
783 PROCEDURE ThisField
* (rec
: Type
; IN name
: ARRAY OF CHAR): Object
;
784 VAR n
, res
: INTEGER; p
: StrPtr
; obj
: Object
; m
: Module
; nn
: Utf8Name
;
786 StringToUtf8(name
, nn
, res
); ASSERT(res
= 0);
788 obj
:= S
.VAL(Object
, S
.ADR(rec
.fields
.obj
[0])); n
:= rec
.fields
.num
;
790 p
:= S
.VAL(StrPtr
, S
.ADR(m
.names
[obj
.id
DIV 256]));
791 IF p^
= nn
THEN RETURN obj
END;
792 DEC(n
); INC(S
.VAL(INTEGER, obj
), 16)
797 PROCEDURE ThisCommand
* (mod
: Module
; IN name
: ARRAY OF CHAR): Command
;
798 VAR x
: Object
; sig
: Signature
;
800 x
:= ThisObject(mod
, name
);
801 IF (x
# NIL) & (x
.id
MOD 16 = mProc
) THEN
802 sig
:= S
.VAL(Signature
, x
.struct
);
803 IF (sig
.retStruct
= NIL) & (sig
.num
= 0) THEN RETURN S
.VAL(Command
, mod
.procBase
+ x
.offs
) END
808 PROCEDURE ThisType
* (mod
: Module
; IN name
: ARRAY OF CHAR): Type
;
811 x
:= ThisObject(mod
, name
);
812 IF (x
# NIL) & (x
.id
MOD 16 = mTyp
) & (S
.VAL(INTEGER, x
.struct
) DIV 256 # 0) THEN
819 PROCEDURE TypeOf
* (IN rec
: ANYREC
): Type
;
821 RETURN S
.VAL(Type
, S
.TYP(rec
))
824 PROCEDURE LevelOf
* (t
: Type
): SHORTINT;
826 RETURN SHORT(t
.id
DIV 16 MOD 16)
829 PROCEDURE NewObj
* (VAR o
: S
.PTR
; t
: Type
);
832 IF t
.size
= -1 THEN o
:= NIL
834 i
:= 0; WHILE t
.ptroffs
[i
] >= 0 DO INC(i
) END;
835 IF t
.ptroffs
[i
+1] >= 0 THEN INC(S
.VAL(INTEGER, t
)) END; (* with interface pointers *)
836 o
:= S
.VAL(S
.PTR
, NewRec(S
.VAL(INTEGER, t
))) (* generic NEW *)
840 PROCEDURE GetModName
* (mod
: Module
; OUT name
: Name
);
843 Utf8ToString(mod
.name
, name
, res
); ASSERT(res
= 0)
846 PROCEDURE GetObjName
* (mod
: Module
; obj
: Object
; OUT name
: Name
);
847 VAR p
: StrPtr
; res
: INTEGER;
849 p
:= S
.VAL(StrPtr
, S
.ADR(mod
.names
[obj
.id
DIV 256]));
850 Utf8ToString(p^$
, name
, res
); ASSERT(res
= 0)
853 PROCEDURE GetTypeName
* (t
: Type
; OUT name
: Name
);
854 VAR p
: StrPtr
; res
: INTEGER;
856 p
:= S
.VAL(StrPtr
, S
.ADR(t
.mod
.names
[t
.id
DIV 256]));
857 Utf8ToString(p^$
, name
, res
); ASSERT(res
= 0)
860 PROCEDURE RegisterMod
* (mod
: Module
);
861 VAR i
: INTEGER; epoch
: time
.time_t
; tm
: time
.struct_tm
; ptm
: time
.Pstruct_tm
;
863 mod
.next
:= modList
; modList
:= mod
; mod
.refcnt
:= 0; INCL(mod
.opts
, dyn
); i
:= 0;
864 WHILE i
< mod
.nofimps
DO
865 IF mod
.imports
[i
] # NIL THEN INC(mod
.imports
[i
].refcnt
) END;
868 epoch
:= time
.time(NIL);
869 ptm
:= time
.localtime_r(epoch
, tm
);
871 mod
.loadTime
[0] := SHORT(tm
.tm_year
+ 1900);
872 mod
.loadTime
[1] := SHORT(tm
.tm_mon
+ 1);
873 mod
.loadTime
[2] := SHORT(tm
.tm_mday
);
874 mod
.loadTime
[3] := SHORT(tm
.tm_hour
);
875 mod
.loadTime
[4] := SHORT(tm
.tm_min
);
876 mod
.loadTime
[5] := SHORT(tm
.tm_sec
)
878 mod
.loadTime
[0] := 0;
879 mod
.loadTime
[1] := 0;
880 mod
.loadTime
[2] := 0;
881 mod
.loadTime
[3] := 0;
882 mod
.loadTime
[4] := 0;
885 IF ~
(init
IN mod
.opts
) THEN InitModule(mod
) END
890 PROCEDURE UnloadMod
* (mod
: Module
);
891 VAR i
: INTEGER; t
: Command
;
893 IF mod
.refcnt
= 0 THEN
894 t
:= mod
.term
; mod
.term
:= NIL;
895 IF t
# NIL THEN t() END; (* terminate module *)
897 WHILE i
< mod
.nofptrs
DO (* release global pointers *)
898 S
.PUT(mod
.varBase
+ mod
.ptrs
[i
], 0); INC(i
)
900 Collect
; (* call finalizers *)
902 WHILE i
< mod
.nofimps
DO (* release imported modules *)
903 IF mod
.imports
[i
] # NIL THEN DEC(mod
.imports
[i
].refcnt
) END;
907 IF dyn
IN mod
.opts
THEN (* release memory *)
908 InvalModMem(mod
.data
+ mod
.dsize
- mod
.refs
, mod
.refs
)
913 (* -------------------- dynamic procedure call --------------------- *)
922 open array address length .. length
925 PROCEDURE Call
* (adr
: ADDRESS
; sig
: Signature
; IN par
: ARRAY OF INTEGER; n
: INTEGER): LONGINT;
928 mConst
= 1; mTyp
= 2; mVar
= 3; mProc
= 4; mField
= 5;
930 mBool
= 1; mChar8
= 2; mChar16
= 3; mInt8
= 4; mInt16
= 5; mInt32
= 6;
931 mReal32
= 7; mReal64
= 8; mSet
= 9; mInt64
= 10; mAnyRec
= 11; mAnyPtr
= 12; mSysPtr
= 13;
933 mProctyp
= 0; mRecord
= 1; mArray
= 2; mPointer
= 3;
934 (* ??? obj.id DIV 16 MOD 16 *)
935 mInternal
= 1; mReadonly
= 2; mPrivate
= 3; mExported
= 4;
936 (* sig.par[].id MOD 16 *)
937 mValue
= 10; mInPar
= 11; mOutPar
= 12; mVarPar
= 13;
938 mInterface
= 32; mGuid
= 33; mResult
= 34;
939 (* implementation restrictions *)
944 Ptype
= POINTER TO LibFFI
.type
;
945 PPtype
= POINTER TO ARRAY [untagged
] OF Ptype
;
947 status
: LibFFI
.status
;
948 kind
, form
, size
: INTEGER;
949 i
, p
, d
, cn
, ut
, ue
: INTEGER;
952 earg
: ARRAY maxElms
OF Ptype
;
953 targ
: ARRAY maxStrs
OF LibFFI
.type
;
954 farg
: ARRAY maxPars
OF Ptype
;
955 varg
: ARRAY maxPars
OF ADDRESS
;
959 PROCEDURE SetType (IN typ
: LibFFI
.type
);
961 farg
[cn
] := S
.VAL(Ptype
, S
.ADR(typ
));
964 PROCEDURE PushVal (size
: INTEGER);
966 ASSERT(size
IN {1, 2, 4, 8}, 20);
967 ASSERT(littleEndian
); (* !!! swap 64bit value *)
968 varg
[cn
] := S
.ADR(par
[d
]);
969 INC(cn
); INC(d
, MAX(1, size
DIV 4))
972 PROCEDURE Push (IN typ
: LibFFI
.type
);
974 SetType(typ
); PushVal(typ
.size
)
978 p
:= 0; cn
:= 0; d
:= 0; ut
:= 0; ue
:= 0;
980 typ
:= sig
.par
[p
].struct
;
981 kind
:= sig
.par
[p
].id
MOD 16;
982 IF S
.VAL(ADDRESS
, typ
) DIV 256 = 0 THEN (* basic types *)
983 form
:= S
.VAL(ADDRESS
, typ
) MOD 256;
984 IF kind
= mValue
THEN
986 | mBool
, mChar8
: Push(LibFFI
.type_uint8
)
987 | mChar16
: Push(LibFFI
.type_uint16
)
988 | mInt8
: Push(LibFFI
.type_sint8
)
989 | mInt16
: Push(LibFFI
.type_sint16
)
990 | mInt32
: Push(LibFFI
.type_sint32
)
991 | mReal32
: Push(LibFFI
.type_float
)
992 | mReal64
: Push(LibFFI
.type_double
)
993 | mSet
: Push(LibFFI
.type_uint32
)
994 | mInt64
: Push(LibFFI
.type_sint64
)
995 | mAnyPtr
, mSysPtr
: Push(LibFFI
.type_pointer
)
996 ELSE HALT(100) (* unsupported type *)
998 ELSIF kind
IN {mInPar
..mVarPar
} THEN
1000 | mBool
..mInt64
, mAnyPtr
, mSysPtr
: Push(LibFFI
.type_pointer
)
1001 | mAnyRec
: Push(LibFFI
.type_pointer
); Push(LibFFI
.type_pointer
) (* address + tag *)
1002 ELSE HALT(101) (* unsupported type *)
1005 HALT(102) (* unsupported parameter kind *)
1008 CASE typ
.id
MOD 4 OF
1009 | mProctyp
, mPointer
:
1010 Push(LibFFI
.type_pointer
)
1012 IF kind
= mValue
THEN
1014 targ
[ut
].alignment
:= 0;
1015 targ
[ut
].type
:= LibFFI
.TYPE_STRUCT
;
1016 targ
[ut
].elements
:= S
.VAL(PPtype
, S
.ADR(earg
[ue
]));
1017 SetType(targ
[ut
]); INC(ut
);
1018 size
:= MIN(1, typ
.size
);
1019 (* !!! better to pass original layout *)
1021 earg
[ue
] := S
.VAL(Ptype
, S
.ADR(LibFFI
.type_uint64
));
1022 INC(ue
); DEC(size
, 8)
1025 earg
[ue
] := S
.VAL(Ptype
, S
.ADR(LibFFI
.type_uint32
));
1026 INC(ue
); DEC(size
, 4)
1029 earg
[ue
] := S
.VAL(Ptype
, S
.ADR(LibFFI
.type_uint16
));
1030 INC(ue
); DEC(size
, 2)
1033 earg
[ue
] := S
.VAL(Ptype
, S
.ADR(LibFFI
.type_uint32
));
1038 PushVal(LibFFI
.type_pointer
.size
);
1039 INC(d
) (* skip tag *)
1040 ELSIF kind
IN {mInPar
..mVarPar
} THEN
1041 Push(LibFFI
.type_pointer
); (* address *)
1042 Push(LibFFI
.type_pointer
); (* tag *)
1043 ELSE HALT(103) (* unsupported parameter kind *)
1046 Push(LibFFI
.type_pointer
);
1047 ASSERT(kind
IN {mValue
..mVarPar
}, 104); (* unsupported parameter kind *)
1048 (* array copying generated by CPfront, so we can just pass address *)
1049 IF typ
.size
= 0 THEN (* open array *)
1050 FOR i
:= 0 TO typ
.id
DIV 16 - 1 DO
1051 Push(LibFFI
.type_sint32
) (* dim size *)
1059 typ
:= sig
.retStruct
;
1060 IF typ
= NIL THEN fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_void
))
1061 ELSIF S
.VAL(ADDRESS
, typ
) DIV 256 = 0 THEN
1062 form
:= S
.VAL(ADDRESS
, typ
) MOD 256;
1064 | mBool
, mChar8
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_uint8
))
1065 | mChar16
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_uint16
))
1066 | mInt8
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_sint8
))
1067 | mInt16
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_sint16
))
1068 | mInt32
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_sint32
))
1069 | mReal32
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_float
))
1070 | mReal64
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_double
))
1071 | mSet
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_uint32
))
1072 | mInt64
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_sint64
))
1073 | mAnyPtr
, mSysPtr
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_pointer
))
1074 ELSE HALT(106) (* unsupported type *)
1077 CASE typ
.id
MOD 4 OF
1078 | mProctyp
, mPointer
: fret
:= S
.VAL(Ptype
, S
.ADR(LibFFI
.type_pointer
))
1079 ELSE HALT(107) (* unsupported type *)
1082 status
:= LibFFI
.prep_cif(cif
, LibFFI
.DEFAULT_ABI
, cn
, fret
, farg
);
1083 ASSERT(status
= LibFFI
.OK
, 108);
1085 IF littleEndian
THEN LibFFI
.call(cif
, adr
, S
.ADR(vret
), S
.ADR(varg
))
1086 ELSE LibFFI
.call(cif
, adr
, S
.ADR(vret
) + (8 - fret
.size
), S
.ADR(varg
))
1091 (* -------------------- reference information (portable) --------------------- *)
1093 PROCEDURE RefCh (VAR ref
: INTEGER; OUT ch
: SHORTCHAR
);
1095 S
.GET(ref
, ch
); INC(ref
)
1098 PROCEDURE RefNum (VAR ref
: INTEGER; OUT x
: INTEGER);
1099 VAR s
, n
: INTEGER; ch
: SHORTCHAR
;
1101 s
:= 0; n
:= 0; RefCh(ref
, ch
);
1102 WHILE ORD(ch
) >= 128 DO INC(n
, ASH(ORD(ch
) - 128, s
) ); INC(s
, 7); RefCh(ref
, ch
) END;
1103 x
:= n
+ ASH(ORD(ch
) MOD 64 - ORD(ch
) DIV 64 * 64, s
)
1106 PROCEDURE RefName (VAR ref
: INTEGER; OUT n
: Utf8Name
);
1107 VAR i
: INTEGER; ch
: SHORTCHAR
;
1109 i
:= 0; RefCh(ref
, ch
);
1110 WHILE ch
# 0X
DO n
[i
] := ch
; INC(i
); RefCh(ref
, ch
) END;
1114 PROCEDURE GetRefProc
* (VAR ref
: INTEGER; OUT adr
: INTEGER; OUT name
: Utf8Name
);
1118 WHILE ch
>= 0FDX
DO (* skip variables *)
1119 INC(ref
); RefCh(ref
, ch
);
1120 IF ch
= 10X
THEN INC(ref
, 4) END;
1121 RefNum(ref
, adr
); RefName(ref
, name
); S
.GET(ref
, ch
)
1123 WHILE (ch
> 0X
) & (ch
< 0FCX
) DO (* skip source refs *)
1124 INC(ref
); RefNum(ref
, adr
); S
.GET(ref
, ch
)
1126 IF ch
= 0FCX
THEN INC(ref
); RefNum(ref
, adr
); RefName(ref
, name
)
1131 PROCEDURE GetRefVar
* (VAR ref
: INTEGER; OUT mode
, form
: SHORTCHAR
; OUT desc
: Type
; OUT adr
: INTEGER; OUT name
: Utf8Name
);
1133 S
.GET(ref
, mode
); desc
:= NIL;
1134 IF mode
>= 0FDX
THEN
1135 mode
:= SHORT(CHR(ORD(mode
) - 0FCH
));
1136 INC(ref
); RefCh(ref
, form
);
1138 S
.GET(ref
, desc
); INC(ref
, 4); form
:= SHORT(CHR(16 + desc
.id
MOD 4))
1140 RefNum(ref
, adr
); RefName(ref
, name
)
1142 mode
:= 0X
; form
:= 0X
; adr
:= 0
1146 PROCEDURE SourcePos
* (mod
: Module
; codePos
: INTEGER): INTEGER;
1147 VAR ref
, pos
, ad
, d
: INTEGER; ch
: SHORTCHAR
; name
: Utf8Name
;
1149 IF mod
# NIL THEN (* mf, 12.02.04 *)
1150 ref
:= mod
.refs
; pos
:= 0; ad
:= 0; S
.GET(ref
, ch
);
1152 WHILE (ch
> 0X
) & (ch
< 0FCX
) DO (* srcref: {dAdr,dPos} *)
1153 INC(ad
, ORD(ch
)); INC(ref
); RefNum(ref
, d
);
1154 IF ad
> codePos
THEN RETURN pos
END;
1155 INC(pos
, d
); S
.GET(ref
, ch
)
1157 IF ch
= 0FCX
THEN (* proc: 0FCX,Adr,Name *)
1158 INC(ref
); RefNum(ref
, d
); RefName(ref
, name
); S
.GET(ref
, ch
);
1159 IF (d
> codePos
) & (pos
> 0) THEN RETURN pos
END
1161 WHILE ch
>= 0FDX
DO (* skip variables: Mode, Form, adr, Name *)
1162 INC(ref
); RefCh(ref
, ch
);
1163 IF ch
= 10X
THEN INC(ref
, 4) END;
1164 RefNum(ref
, d
); RefName(ref
, name
); S
.GET(ref
, ch
)
1171 PROCEDURE LoadDll
* (IN name
: ARRAY OF CHAR; VAR ok
: BOOLEAN);
1172 VAR h
: ADDRESS
; file
: Utf8Name
; res
: INTEGER;
1174 StringToUtf8(name
, file
, res
);
1176 h
:= dlfcn
.dlopen(file
, dlfcn
.RTLD_LAZY
+ dlfcn
.RTLD_GLOBAL
);
1183 PROCEDURE ThisDllObj
* (mode
, fprint
: INTEGER; IN dll
, name
: ARRAY OF CHAR): INTEGER;
1184 VAR h
, p
: ADDRESS
; file
, sym
: Utf8Name
; res
: INTEGER; err
: dlfcn
.int
;
1186 StringToUtf8(dll
, file
, res
);
1188 h
:= dlfcn
.dlopen(file
, dlfcn
.RTLD_LAZY
+ dlfcn
.RTLD_GLOBAL
);
1190 StringToUtf8(name
, sym
, res
);
1192 p
:= dlfcn
.dlsym(h
, sym
)
1196 err
:= dlfcn
.dlclose(h
);
1197 ASSERT(err
= 0, 100)
1207 (* -------------------- garbage collector (portable) --------------------- *)
1209 PROCEDURE Mark (this
: Block
);
1210 VAR father
, son
: Block
; tag
: Type
; flag
, offset
, actual
: INTEGER;
1212 IF ~
ODD(S
.VAL(INTEGER, this
.tag
)) THEN
1215 INC(S
.VAL(INTEGER, this
.tag
));
1216 flag
:= S
.VAL(INTEGER, this
.tag
) MOD 4;
1217 tag
:= S
.VAL(Type
, S
.VAL(INTEGER, this
.tag
) - flag
);
1218 IF flag
>= 2 THEN actual
:= this
.first
; this
.actual
:= actual
1219 ELSE actual
:= S
.ADR(this
.last
)
1222 offset
:= tag
.ptroffs
[0];
1224 INC(S
.VAL(INTEGER, tag
), offset
+ 4); (* restore tag *)
1225 IF (flag
>= 2) & (actual
< this
.last
) & (offset
< -4) THEN (* next array element *)
1226 INC(actual
, tag
.size
); this
.actual
:= actual
1228 this
.tag
:= S
.VAL(Type
, S
.VAL(INTEGER, tag
) + flag
);
1229 IF father
= NIL THEN RETURN END;
1230 son
:= this
; this
:= father
;
1231 flag
:= S
.VAL(INTEGER, this
.tag
) MOD 4;
1232 tag
:= S
.VAL(Type
, S
.VAL(INTEGER, this
.tag
) - flag
);
1233 offset
:= tag
.ptroffs
[0];
1234 IF flag
>= 2 THEN actual
:= this
.actual
ELSE actual
:= S
.ADR(this
.last
) END;
1235 S
.GET(actual
+ offset
, father
); S
.PUT(actual
+ offset
, S
.ADR(son
.last
));
1236 INC(S
.VAL(INTEGER, tag
), 4)
1239 S
.GET(actual
+ offset
, son
);
1241 DEC(S
.VAL(INTEGER, son
), 4);
1242 IF ~
ODD(S
.VAL(INTEGER, son
.tag
)) THEN (* down *)
1243 this
.tag
:= S
.VAL(Type
, S
.VAL(INTEGER, tag
) + flag
);
1244 S
.PUT(actual
+ offset
, father
); father
:= this
; this
:= son
;
1248 INC(S
.VAL(INTEGER, tag
), 4)
1255 PROCEDURE MarkGlobals
;
1256 VAR m
: Module
; i
, p
: INTEGER;
1260 IF m
.refcnt
>= 0 THEN
1262 WHILE i
< m
.nofptrs
DO
1263 S
.GET(m
.varBase
+ m
.ptrs
[i
], p
); INC(i
);
1264 IF p
# 0 THEN Mark(S
.VAL(Block
, p
- 4)) END
1271 PROCEDURE Next (b
: Block
): Block
; (* next block in same cluster *)
1274 S
.GET(S
.VAL(INTEGER, b
.tag
) DIV 4 * 4, size
);
1275 IF ODD(S
.VAL(INTEGER, b
.tag
) DIV 2) THEN INC(size
, b
.last
- S
.ADR(b
.last
)) END;
1276 RETURN S
.VAL(Block
, S
.VAL(INTEGER, b
) + (size
+ 19) DIV 16 * 16)
1279 PROCEDURE CheckCandidates
;
1280 (* pre: nofcand > 0 *)
1281 VAR i
, j
, h
, p
, end
: INTEGER; c
: Cluster
; blk
, next
: Block
;
1283 (* sort candidates (shellsort) *)
1284 h
:= 1; REPEAT h
:= h
*3 + 1 UNTIL h
> nofcand
;
1285 REPEAT h
:= h
DIV 3; i
:= h
;
1286 WHILE i
< nofcand
DO p
:= candidates
[i
]; j
:= i
;
1287 WHILE (j
>= h
) & (candidates
[j
-h
] > p
) DO
1288 candidates
[j
] := candidates
[j
-h
]; j
:= j
-h
1290 candidates
[j
] := p
; INC(i
)
1296 blk
:= S
.VAL(Block
, S
.VAL(INTEGER, c
) + 12);
1297 end
:= S
.VAL(INTEGER, blk
) + (c
.size
- 12) DIV 16 * 16;
1298 WHILE candidates
[i
] < S
.VAL(INTEGER, blk
) DO
1300 IF i
= nofcand
THEN RETURN END
1302 WHILE S
.VAL(INTEGER, blk
) < end
DO
1304 IF candidates
[i
] < S
.VAL(INTEGER, next
) THEN
1305 IF (S
.VAL(INTEGER, blk
.tag
) # S
.ADR(blk
.last
)) (* not a free block *)
1306 & (~strictStackSweep
OR (candidates
[i
] = S
.ADR(blk
.last
))) THEN
1311 IF i
= nofcand
THEN RETURN END
1312 UNTIL candidates
[i
] >= S
.VAL(INTEGER, next
)
1314 IF (S
.VAL(INTEGER, blk
.tag
) MOD 4 = 0) & (S
.VAL(INTEGER, blk
.tag
) # S
.ADR(blk
.last
))
1315 & (blk
.tag
.base
[0] = NIL) & (blk
.actual
> 0) THEN (* referenced interface record *)
1322 END CheckCandidates
;
1324 PROCEDURE MarkLocals
;
1325 VAR sp
, p
, min
, max
: INTEGER; c
: Cluster
;
1327 sp
:= S
.ADR(sp
); nofcand
:= 0; c
:= root
;
1328 WHILE c
.next
# NIL DO c
:= c
.next
END;
1329 min
:= S
.VAL(INTEGER, root
); max
:= S
.VAL(INTEGER, c
) + c
.size
;
1330 WHILE sp
< baseStack
DO
1332 IF (p
> min
) & (p
< max
) & (~strictStackSweep
OR (p
MOD 16 = 0)) THEN
1333 candidates
[nofcand
] := p
; INC(nofcand
);
1334 IF nofcand
= LEN(candidates
) - 1 THEN CheckCandidates
; nofcand
:= 0 END
1338 candidates
[nofcand
] := max
; INC(nofcand
); (* ensure complete scan for interface mark*)
1339 IF nofcand
> 0 THEN CheckCandidates
END
1342 PROCEDURE MarkFinObj
;
1345 wouldFinalize
:= FALSE
;
1348 IF ~
ODD(S
.VAL(INTEGER, f
.blk
.tag
)) THEN wouldFinalize
:= TRUE
END;
1353 WHILE f
# NIL DO IF ~
ODD(S
.VAL(INTEGER, f
.blk
.tag
)) THEN wouldFinalize
:= TRUE
END;
1359 PROCEDURE CheckFinalizers
;
1360 VAR f
, g
, h
, k
: FList
;
1362 f
:= finalizers
; g
:= NIL;
1363 IF hotFinalizers
= NIL THEN k
:= NIL
1366 WHILE k
.next
# NIL DO k
:= k
.next
END
1369 h
:= f
; f
:= f
.next
;
1370 IF ~
ODD(S
.VAL(INTEGER, h
.blk
.tag
)) THEN
1371 IF g
= NIL THEN finalizers
:= f
ELSE g
.next
:= f
END;
1372 IF k
= NIL THEN hotFinalizers
:= h
ELSE k
.next
:= h
END;
1373 k
:= h
; h
.next
:= NIL
1378 WHILE h
# NIL DO Mark(h
.blk
); h
:= h
.next
END
1379 END CheckFinalizers
;
1381 PROCEDURE ExecFinalizer (a
, b
, c
: INTEGER);
1382 VAR f
: FList
; fin
: PROCEDURE(this
: ANYPTR
);
1384 f
:= S
.VAL(FList
, a
);
1385 S
.GET(S
.VAL(INTEGER, f
.blk
.tag
) - 4, fin
); (* method 0 *)
1386 IF (fin
# NIL) & (f
.blk
.tag
.mod
.refcnt
>= 0) THEN fin(S
.VAL(ANYPTR
, S
.ADR(f
.blk
.last
))) END;
1389 PROCEDURE^ Try
* (h
: TryHandler
; a
, b
, c
: INTEGER); (* COMPILER DEPENDENT *)
1391 PROCEDURE CallFinalizers
;
1394 WHILE hotFinalizers
# NIL DO
1395 f
:= hotFinalizers
; hotFinalizers
:= hotFinalizers
.next
;
1396 Try(ExecFinalizer
, S
.VAL(INTEGER, f
), 0, 0)
1398 wouldFinalize
:= FALSE
1401 PROCEDURE Insert (blk
: FreeBlock
; size
: INTEGER); (* insert block in free list *)
1404 blk
.size
:= size
- 4; blk
.tag
:= S
.VAL(Type
, S
.ADR(blk
.size
));
1405 i
:= MIN(N
- 1, (blk
.size
DIV 16));
1406 blk
.next
:= free
[i
]; free
[i
] := blk
1409 PROCEDURE Sweep (dealloc
: BOOLEAN);
1410 VAR cluster
, last
, c
: Cluster
; blk
, next
: Block
; fblk
, b
, t
: FreeBlock
; end
, i
: INTEGER;
1412 cluster
:= root
; last
:= NIL; allocated
:= 0;
1414 REPEAT DEC(i
); free
[i
] := sentinel
UNTIL i
= 0;
1415 WHILE cluster
# NIL DO
1416 blk
:= S
.VAL(Block
, S
.VAL(INTEGER, cluster
) + 12);
1417 end
:= S
.VAL(INTEGER, blk
) + (cluster
.size
- 12) DIV 16 * 16;
1419 WHILE S
.VAL(INTEGER, blk
) < end
DO
1421 IF ODD(S
.VAL(INTEGER, blk
.tag
)) THEN
1423 Insert(fblk
, S
.VAL(INTEGER, blk
) - S
.VAL(INTEGER, fblk
));
1426 DEC(S
.VAL(INTEGER, blk
.tag
)); (* unmark *)
1427 INC(allocated
, S
.VAL(INTEGER, next
) - S
.VAL(INTEGER, blk
))
1428 ELSIF fblk
= NIL THEN
1429 fblk
:= S
.VAL(FreeBlock
, blk
)
1433 IF dealloc
& (S
.VAL(INTEGER, fblk
) = S
.VAL(INTEGER, cluster
) + 12) THEN (* deallocate cluster *)
1434 c
:= cluster
; cluster
:= cluster
.next
;
1435 IF last
= NIL THEN root
:= cluster
ELSE last
.next
:= cluster
END;
1438 IF fblk
# NIL THEN Insert(fblk
, end
- S
.VAL(INTEGER, fblk
)) END;
1439 last
:= cluster
; cluster
:= cluster
.next
1442 (* reverse free list *)
1446 b
:= free
[i
]; fblk
:= sentinel
;
1447 WHILE b
# sentinel
DO t
:= b
; b
:= t
.next
; t
.next
:= fblk
; fblk
:= t
END;
1455 CallFinalizers
; (* trap cleanup *)
1464 PROCEDURE FastCollect
*;
1474 PROCEDURE WouldFinalize
* (): BOOLEAN;
1476 RETURN wouldFinalize
1479 (* --------------------- memory allocation (portable) -------------------- *)
1481 PROCEDURE OldBlock (size
: INTEGER): FreeBlock
; (* size MOD 16 = 0 *)
1482 VAR b
, l
: FreeBlock
; s
, i
: INTEGER;
1485 i
:= MIN(N
- 1, s
DIV 16);
1486 WHILE (i
# N
- 1) & (free
[i
] = sentinel
) DO INC(i
) END;
1487 b
:= free
[i
]; l
:= NIL;
1488 WHILE b
.size
< s
DO l
:= b
; b
:= b
.next
END;
1489 IF b
# sentinel
THEN
1490 IF l
= NIL THEN free
[i
] := b
.next
ELSE l
.next
:= b
.next
END
1496 PROCEDURE LastBlock (limit
: INTEGER): FreeBlock
; (* size MOD 16 = 0 *)
1497 VAR b
, l
: FreeBlock
; s
, i
: INTEGER;
1502 b
:= free
[i
]; l
:= NIL;
1503 WHILE (b
# sentinel
) & (S
.VAL(INTEGER, b
) + b
.size
# s
) DO l
:= b
; b
:= b
.next
END;
1504 IF b
# sentinel
THEN
1505 IF l
= NIL THEN free
[i
] := b
.next
ELSE l
.next
:= b
.next
END
1509 UNTIL (b
# NIL) OR (i
= N
);
1513 PROCEDURE NewBlock (size
: INTEGER): Block
;
1514 VAR tsize
, a
, s
: INTEGER; b
: FreeBlock
; new
, c
: Cluster
; r
: Reducer
;
1516 ASSERT(size
>= 0, 20);
1517 IF size
> MAX(INTEGER) - 19 THEN RETURN NIL END;
1518 tsize
:= (size
+ 19) DIV 16 * 16;
1519 b
:= OldBlock(tsize
); (* 1) search for free block *)
1521 FastCollect
; b
:= OldBlock(tsize
); (* 2) collect *)
1523 Collect
; b
:= OldBlock(tsize
); (* 2a) fully collect *)
1526 AllocHeapMem(tsize
+ 12, new
); (* 3) allocate new cluster *)
1528 IF (root
= NIL) OR (S
.VAL(INTEGER, new
) < S
.VAL(INTEGER, root
)) THEN
1529 new
.next
:= root
; root
:= new
1532 WHILE (c
.next
# NIL) & (S
.VAL(INTEGER, new
) > S
.VAL(INTEGER, c
.next
)) DO c
:= c
.next
END;
1533 new
.next
:= c
.next
; c
.next
:= new
1535 b
:= S
.VAL(FreeBlock
, S
.VAL(INTEGER, new
) + 12);
1536 b
.size
:= (new
.size
- 12) DIV 16 * 16 - 4
1538 RETURN NIL (* 4) give up *)
1543 a
:= b
.size
+ 4 - tsize
;
1544 IF a
> 0 THEN Insert(S
.VAL(FreeBlock
, S
.VAL(INTEGER, b
) + tsize
), a
) END;
1545 IF size
> 0 THEN Erase(S
.ADR(b
.size
), (size
+ 3) DIV 4) END;
1546 INC(allocated
, tsize
);
1547 RETURN S
.VAL(Block
, b
)
1550 PROCEDURE Allocated
* (): INTEGER;
1555 PROCEDURE Used
* (): INTEGER;
1560 PROCEDURE Root
* (): INTEGER;
1562 RETURN S
.VAL(INTEGER, root
)
1565 (* -------------------- Trap Handling --------------------- *)
1567 PROCEDURE [code
] GetDLink (): DLink
"(Kernel_DLink)SYSTEM_dlink";
1568 PROCEDURE [code
] SetDLink (dl
: DLink
) "SYSTEM_dlink = (SYSTEM_DLINK*)dl";
1570 PROCEDURE Start
* (code
: Command
);
1571 VAR res
: setjmp
.int
; dl
: DLink
;
1574 baseStack
:= S
.ADR(code
); (* XXX: expected that target uses one stack *)
1575 startDLink
:= GetDLink();
1576 res
:= setjmp
.sigsetjmp(startEnv
, 1);
1580 PROCEDURE Quit
* (exitCode
: INTEGER);
1581 VAR m
: Module
; term
: Command
; t
: BOOLEAN;
1583 trapViewer
:= NIL; trapChecker
:= NIL; restart
:= NIL;
1584 t
:= terminating
; terminating
:= TRUE
; m
:= modList
;
1585 WHILE m
# NIL DO (* call terminators *)
1586 IF ~static
OR ~t
THEN
1587 term
:= m
.term
; m
.term
:= NIL;
1588 IF term
# NIL THEN term() END
1593 hotFinalizers
:= finalizers
; finalizers
:= NIL;
1595 stdlib
.exit(exitCode
)
1598 PROCEDURE FatalError
* (id
: INTEGER; str
: ARRAY OF CHAR);
1599 VAR res
: stdio
.int
; title
: ARRAY 16 OF CHAR; text
: ARRAY 256 OF SHORTCHAR
;
1601 title
:= "Error xy";
1602 title
[6] := CHR(id
DIV 10 + ORD("0"));
1603 title
[7] := CHR(id
MOD 10 + ORD("0"));
1604 res
:= unistd
.write(2, S
.ADR(title
), 8);
1608 PROCEDURE DefaultTrapViewer
;
1609 VAR out
: ARRAY 256 OF SHORTCHAR
; c
, len
: INTEGER; res
: unistd
.int
; dl
: DLink
;
1611 PROCEDURE WriteString (IN s
: ARRAY OF SHORTCHAR
);
1615 WHILE (len
< LEN(out
) - 1) & (s
[i
] # 0X
) DO out
[len
] := s
[i
]; INC(i
); INC(len
) END
1618 PROCEDURE WriteHex (x
, n
: INTEGER);
1621 IF len
+ n
< LEN(out
) THEN
1624 y
:= x
MOD 16; x
:= x
DIV 16;
1625 IF y
> 9 THEN y
:= y
+ (ORD("A") - ORD("0") - 10) END;
1626 out
[i
] := SHORT(CHR(y
+ ORD("0"))); DEC(i
)
1634 IF len
< LEN(out
) - 1 THEN out
[len
] := 0AX
; INC(len
) END
1639 WriteString("====== ");
1640 IF err
= 129 THEN WriteString("invalid with")
1641 ELSIF err
= 130 THEN WriteString("invalid case")
1642 ELSIF err
= 131 THEN WriteString("function without return")
1643 ELSIF err
= 132 THEN WriteString("type guard")
1644 ELSIF err
= 133 THEN WriteString("implied type guard")
1645 ELSIF err
= 134 THEN WriteString("value out of range")
1646 ELSIF err
= 135 THEN WriteString("index out of range")
1647 ELSIF err
= 136 THEN WriteString("string too long")
1648 ELSIF err
= 137 THEN WriteString("stack overflow")
1649 ELSIF err
= 138 THEN WriteString("integer overflow")
1650 ELSIF err
= 139 THEN WriteString("division by zero")
1651 ELSIF err
= 140 THEN WriteString("infinite real result")
1652 ELSIF err
= 141 THEN WriteString("real underflow")
1653 ELSIF err
= 142 THEN WriteString("real overflow")
1654 ELSIF err
= 143 THEN WriteString("undefined real result")
1655 ELSIF err
= 144 THEN WriteString("not a number")
1656 ELSIF err
= 200 THEN WriteString("keyboard interrupt")
1657 ELSIF err
= 201 THEN WriteString("NIL dereference")
1658 ELSIF err
= 202 THEN WriteString("illegal instruction: ");
1660 ELSIF err
= 203 THEN WriteString("illegal memory read [ad = ");
1661 WriteHex(val
, 8); WriteString("]")
1662 ELSIF err
= 204 THEN WriteString("illegal memory write [ad = ");
1663 WriteHex(val
, 8); WriteString("]")
1664 ELSIF err
= 205 THEN WriteString("illegal execution [ad = ");
1665 WriteHex(val
, 8); WriteString("]")
1666 ELSIF err
= 257 THEN WriteString("out of memory")
1667 ELSIF err
= 10001H
THEN WriteString("bus error")
1668 ELSIF err
= 10002H
THEN WriteString("address error")
1669 ELSIF err
= 10007H
THEN WriteString("fpu error")
1670 ELSIF err
< 0 THEN WriteString("exception #"); WriteHex(-err
, 2)
1671 ELSE err
:= err
DIV 100 * 256 + err
DIV 10 MOD 10 * 16 + err
MOD 10;
1672 WriteString("trap #"); WriteHex(err
, 3)
1674 WriteString(" ======");
1677 (* skip Kernel.DefaultTrapViewer & Kernel.Trap/Kernel.TrapHandler *)
1679 WHILE (c
> 0) & (dl
# NIL) DO
1685 WHILE (c
> 0) & (dl
# NIL) DO
1686 WriteString("- "); WriteString(dl
.name$
); WriteLn
;
1691 res
:= unistd
.write(2, S
.ADR(out
), len
)
1692 END DefaultTrapViewer
;
1694 PROCEDURE TrapCleanup
;
1697 WHILE trapStack
# NIL DO
1698 t
:= trapStack
; trapStack
:= trapStack
.next
; t
.Cleanup
1700 IF (trapChecker
# NIL) & (err
# 128) THEN trapChecker
END
1703 PROCEDURE SetTrapGuard
* (on
: BOOLEAN);
1708 PROCEDURE Try
* (h
: TryHandler
; a
, b
, c
: INTEGER);
1709 VAR oldIsTry
: BOOLEAN; oldTryEnv
: setjmp
.jmp_buf
; oldTryDLink
: DLink
; res
: setjmp
.int
;
1711 oldIsTry
:= isTry
; oldTryEnv
:= tryEnv
; oldTryDLink
:= tryDLink
;
1712 isTry
:= TRUE
; tryDLink
:= GetDLink();
1713 res
:= setjmp
._setjmp(tryEnv
);
1714 IF res
= 0 THEN h(a
, b
, c
) END;
1715 isTry
:= oldIsTry
; tryEnv
:= oldTryEnv
; tryDLink
:= oldTryDLink
1718 PROCEDURE Trap
* (n
: INTEGER);
1722 IF ~secondTrap
THEN trapped
:= FALSE
; secondTrap
:= TRUE
END
1724 IF n
>= 0 THEN err
:= n
1725 ELSE err
:= -n
+ 128
1727 pc
:= 0; sp
:= 0; fp
:= 0; stack
:= 0; val
:= 0;
1733 setjmp
._longjmp(tryEnv
, 1)
1735 IF (err
= 128) OR (err
= 200) & ~intTrap
THEN (* do nothing *)
1736 ELSIF (trapViewer
# NIL) & (restart
# NIL) & ~trapped
& ~guarded
THEN
1737 trapped
:= TRUE
; trapViewer()
1738 ELSE DefaultTrapViewer
1740 trapped
:= FALSE
; secondTrap
:= FALSE
;
1741 IF restart
# NIL THEN
1742 SetDLink(startDLink
);
1743 setjmp
.siglongjmp(startEnv
, 1)
1748 PROCEDURE [ccall
] TrapHandler (signo
: signal
.int
; IN _info
: signal
.siginfo_t
; context
: ADDRESS
);
1749 TYPE SigInfo
= POINTER [untagged
] TO signal
._siginfo_t
;
1750 VAR res
: signal
.int
; info
: SigInfo
;
1752 info
:= S
.VAL(SigInfo
, S
.ADR(_info
)); (* !!! hack for CPfront *)
1755 IF ~secondTrap
THEN trapped
:= FALSE
; secondTrap
:= TRUE
END
1757 err
:= -signo
; pc
:= 0; sp
:= 0; fp
:= 0; stack
:= 0; val
:= 0;
1761 val
:= info
.si_code
;
1762 CASE info
.si_code
OF
1763 | signal
.FPE_INTDIV
: err
:= 139 (* division by zero *)
1764 | signal
.FPE_INTOVF
: err
:= 138 (* integer overflow *)
1765 | signal
.FPE_FLTDIV
: err
:= 140 (* fpu: division by zero *)
1766 | signal
.FPE_FLTOVF
: err
:= 142 (* fpu: overflow *)
1767 | signal
.FPE_FLTUND
: err
:= 141 (* fpu: underflow *)
1768 (* !!! | signal.FPE_FLTRES: err := ??? (* fpu: *) *)
1769 | signal
.FPE_FLTINV
: err
:= 143 (* val := opcode *) (* fpu: invalid op *)
1770 (* !!! | signal.FPE_FLTSUB: err := ??? (* fpu: *) *)
1774 val
:= info
.si_code
;
1775 err
:= 200 (* keyboard interrupt *)
1777 val
:= info
.si_addr
;
1778 err
:= 203 (* illigal read *)
1780 val
:= info
.si_addr
;
1781 err
:= 10001H (* bus error *)
1784 err
:= 202; (* illigal instruction *)
1785 IF IsReadable(pc
, pc
+ 4) THEN
1787 (* !!! err := halt code *)
1796 setjmp
._longjmp(tryEnv
, 1)
1798 IF (err
= 128) OR (err
= 200) & ~intTrap
THEN (* do nothing *)
1799 ELSIF (trapViewer
# NIL) & (restart
# NIL) & ~trapped
& ~guarded
THEN
1800 trapped
:= TRUE
; trapViewer()
1801 ELSE DefaultTrapViewer
1803 trapped
:= FALSE
; secondTrap
:= FALSE
;
1804 IF restart
# NIL THEN
1805 SetDLink(startDLink
);
1806 setjmp
.siglongjmp(startEnv
, 1)
1811 (* -------------------- Initialization --------------------- *)
1813 PROCEDURE InstallTrap (signo
: signal
.int
);
1814 VAR act
: signal
._struct_sigaction
; (* !!! CPfront hack *) res
: signal
.int
;
1816 act
.sa_handler
:= NIL;
1817 res
:= signal
.sigemptyset(act
.sa_mask
);
1818 act
.sa_flags
:= signal
.SA_NODEFER
+ signal
.SA_SIGINFO
;
1819 act
.sa_sigaction
:= TrapHandler
;
1820 res
:= signal
.sigaction(signo
, S
.VAL(signal
.struct_sigaction
, act
), NIL);
1823 PROCEDURE InstallTrapVectors
;
1825 InstallTrap(signal
.SIGFPE
);
1826 InstallTrap(signal
.SIGINT
);
1827 InstallTrap(signal
.SIGSEGV
);
1828 InstallTrap(signal
.SIGBUS
);
1829 InstallTrap(signal
.SIGILL
)
1830 END InstallTrapVectors
;
1832 PROCEDURE RemoveTrapVectors
;
1833 END RemoveTrapVectors
;
1839 baseStack
:= S
.ADR(i
); (* XXX *)
1840 pagesize
:= unistd
.sysconf(unistd
._SC_PAGESIZE
);
1843 allocated
:= 0; total
:= 0; used
:= 0;
1844 sentinelBlock
.size
:= MAX(INTEGER);
1845 sentinel
:= S
.ADR(sentinelBlock
);
1847 REPEAT DEC(i
); free
[i
] := sentinel
UNTIL i
= 0;
1855 InitModule(modList
);
1856 IF ~inDll
THEN Quit(1) END
1860 PROCEDURE [code
] SYSTEM_argCount (): INTEGER "SYSTEM_argCount";
1861 PROCEDURE [code
] SYSTEM_argVector (): ArrStrPtr
"(Kernel_ArrStrPtr)SYSTEM_argVector";
1862 PROCEDURE [code
] SYSTEM_modlist (): Module
"(Kernel_Module)SYSTEM_modlist";
1865 IF modList
= NIL THEN (* only once *)
1866 argc
:= SYSTEM_argCount();
1867 argv
:= SYSTEM_argVector();
1868 modList
:= SYSTEM_modlist();
1869 static
:= init
IN modList
.opts
;
1870 inDll
:= dll
IN modList
.opts
;
1874 IF ~terminating
THEN
1875 terminating
:= TRUE
;