-; Things are organized so that files can be compiled with Hobbit for
-; experimentation. Thus we need one file that loads all the other files.
-; This is that file, though it would make sense to move the code in this
-; file to another.
-
-; If a routine to initialize compiled-in code is defined, run it.
-(if (defined? 'cgen-init-c) (cgen-init-c))
-
-; If this is set to #f, the file is always loaded.
-; Don't override any current setting, e.g. from dev.scm.
-(if (not (defined? 'CHECK-LOADED?))
- (define CHECK-LOADED? #t))
-
-; Unlink file if we're reloaded (say in an interactive session).
-; Dynamic loading is enabled by setting LIBCPU.SO to the pathname of the .so.
-(if (and (defined? 'libcpu.so) (dynamic-object? libcpu.so))
- (dynamic-unlink libcpu.so))
-(define libcpu.so #f)
-(if (and (defined? 'LIBCPU.SO)
- (file-exists? LIBCPU.SO))
- (set! libcpu.so (dynamic-link LIBCPU.SO))
-)
-
-; List of loaded files.
-
-(if (not (defined? '/loaded-file-list))
- (define /loaded-file-list '()))
-
-; Return non-zero if FILE was loaded last time through.
-
-(define (/loaded-file? file)
- (->bool (memq (string->symbol file) /loaded-file-list))
-)
-
-; Record FILE as compiled in.
-
-(define (/loaded-file-record! file)
- (let ((file (string->symbol file)))
- (if (not (memq file /loaded-file-list))
- (set! /loaded-file-list (cons file /loaded-file-list))))
-)
-
-; Load FILE if SYM is not compiled in.
-
-(define (maybe-load file init-func sym)
- ; Return non-#f if FUNC is present in DYNOBJ.
- (define (dynamic-func? func dynobj)
- (catch #t
- (lambda () (dynamic-func func dynobj))
- (lambda args #f))
- )
-
- (let ((init-func (string-append "init_" (if init-func init-func file))))
- (cond ((and libcpu.so
- (dynamic-func? init-func libcpu.so))
- (dynamic-call init-func libcpu.so)
- (display (string-append "Skipping " file ", dynamically loaded.\n")))
- ((or (not CHECK-LOADED?)
- (not (defined? sym))
- (/loaded-file? file))
- (/loaded-file-record! file)
- (load file))
- (else
- (display (string-append "Skipping " file ", already loaded.\n")))))
-)