Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (54 sloc) 1.34 KB
inline C <<end
#include <string.h>
#include "str.h"
#include "bytes.h"
#include "index.h"
static datum
find_builtin_module(datum name)
{
lxc_module mod, *modp = lxc_modules;
if (symbolp(name)) name = (datum) name[1]; /* symbol->str */
while ((mod = *modp++)) {
const char *mname = mod->name;
if (str_cmp_charstar(name, strlen(mname), mname) == 0) {
return mod->instrs;
}
}
return nil;
}
end
def *modules* '()
def loader: obj:
(run name):
def ent (*modules*.assq name)
if ent: return ent.cdr
def new-module (make-placeholder.)
*modules* = (cons (cons name new-module) *modules*)
become new-module (load-module name) 1
. new-module
(run-file path):
(read-file path).run
def (load-module name):
(make-module name).run
def (make-module name):
def x (find-builtin name)
if x: return x
read-file (find-file name)
def (find-file name):
name = ("lib/"./ (name.str ./ ".lxc"))
name.encode
def find-builtin: obj:
inline C (run name) <<end
return find_builtin_module(n_name);
end
def read-file: obj:
inline C (run path) <<end
char name[datum_size(n_path) + 1];
copy_bytes_contents0(name, n_path, datum_size(n_path) + 1);
return read_module_file(name);
end
def (make-placeholder.) (obj.)
def module: sobj:
asm (run.):
jr proc
. loader