Differences From
Artifact [56067a22ef]:
41 41 # in turn. the array *gd-api-map* is assembled at
42 42 # compile-time and then used by the init function at
43 43 # runtime to enumerate and install the core modules.
44 44 # when core modules use a primitive, they declare their
45 45 # own *gd-api-map* which maps gensyms to the name of
46 46 # the desired primitive.
47 47 (def *gd-api-map* @{})
48 -(defn- install [name env]
48 +(defn- dict-filter [pred dict]
49 + (def d @{})
50 + (loop [[k v] :pairs dict]
51 + (when (pred k v)
52 + (put d k v)))
53 + d)
54 +(defn- install [name env-raw]
55 + (def env (dict-filter
56 + |(and (table? $1)
57 + (not ($1 :private)))
58 + env-raw))
49 59 (put *gd-api-map* name env)
50 - (when (has-key? env '*gd-api-map*)
51 - (def gdmap (get-in env ['*gd-api-map* :value]))
60 + (when-let [b (get env '*gd-api-ext*)
61 + ok (table? b)]
62 + (def gdmap (get-in env ['*gd-api-ext* :value]))
52 63 (loop [[val key] :pairs gdmap
53 64 :when (safe-to-export? val)]
54 65 (def sym (symbol '-val- (bxor (hash name) (hash val))))
55 66 (put marshal-map val sym)
56 67 (put unmarshal-map sym val))
57 68 (merge-into extern-table gdmap)))
58 69
................................................................................
69 80 # macro implementations can be provided directly in janet
70 81 # and incorporated into the API image without having to
71 82 # implement anything beyond the primitive API in C
72 83
73 84 # this function is exported as part of api.jimage.
74 85 # it will be called from vm.c after initializing
75 86 # the primitive bindings
76 -(defn init []
87 +(defn init [core-env]
77 88 (print "beginning merge")
78 89 (merge-into module/cache *gd-api-map*)
90 + (print "loaded modules, forcing imports")
91 + (merge-into core-env (get *gd-api-map* "core"))
79 92 (print "api loaded"))
80 93
81 94 # this is the build-time entry point, which does
82 95 # the work of assembling the modules and marshalling
83 96 # them out. it is not exported
84 97 (defn main [_ out-path]
85 98 (def env @{})
86 99 (each sym '[init marshal-map unmarshal-map]
87 100 (put env sym ((curenv) sym)))
88 101 (let [blob (marshal env extern-table)]
89 102 (with [fd (file/open out-path :w)]
90 103 (:write fd blob)))
91 104 0)