Checkpoint moving to supporting native (JS in this case) modules.
Chris Pressey
1 year, 5 months ago
163 | 163 | -- |
164 | 164 | local imported_module = self.modules[module_name] |
165 | 165 | if imported_module == nil and self.module_path ~= nil then |
166 | -- | |
167 | -- First, try to load a Lua implementation module. | |
168 | -- | |
169 | debug("module", "loading: " .. module_name) | |
170 | local lua_mod_impl_filename = ( | |
171 | self.module_path .. "lua/" .. module_name .. ".lua" | |
172 | ) | |
173 | local program_text = try_load_file(lua_mod_impl_filename) | |
174 | if program_text ~= nil then | |
175 | local make_module = dofile(lua_mod_impl_filename) | |
176 | self.modules[module_name] = make_module() | |
166 | if self.evaluator ~= nil then | |
167 | -- | |
168 | -- We are evaluating. | |
169 | -- | |
170 | -- First, try to load a Lua implementation module. | |
171 | -- | |
172 | debug("module", "loading: " .. module_name) | |
173 | local lua_mod_impl_filename = ( | |
174 | self.module_path .. "lua/" .. module_name .. ".lua" | |
175 | ) | |
176 | local program_text = try_load_file(lua_mod_impl_filename) | |
177 | if program_text ~= nil then | |
178 | local make_module = dofile(lua_mod_impl_filename) | |
179 | self.modules[module_name] = make_module() | |
180 | else | |
181 | -- | |
182 | -- If that didn't work, load a Decoy implementation module. | |
183 | -- | |
184 | self:process_module_file( | |
185 | self.module_path .. "decoy/" .. module_name .. ".scm" | |
186 | ) | |
187 | end | |
177 | 188 | else |
178 | 189 | -- |
179 | -- If that didn't work, try to load a Decoy implementation module. | |
180 | -- | |
181 | self:process_module_file( | |
182 | self.module_path .. "decoy/" .. module_name .. ".scm" | |
190 | -- We are compiling. | |
191 | -- | |
192 | -- First, try to load a target-language (JS...) implementation module. | |
193 | -- | |
194 | debug("module", "loading: " .. module_name) | |
195 | local js_mod_impl_filename = ( | |
196 | self.module_path .. "js/" .. module_name .. ".mjs" | |
183 | 197 | ) |
198 | local program_text = try_load_file(js_mod_impl_filename) | |
199 | if program_text ~= nil then | |
200 | -- FIXME: we may need to "register module specially". | |
201 | self.modules[module_name] = program_text -- !!! | |
202 | else | |
203 | -- | |
204 | -- If that didn't work, load a Decoy implementation module. | |
205 | -- | |
206 | self:process_module_file( | |
207 | self.module_path .. "decoy/" .. module_name .. ".scm" | |
208 | ) | |
209 | end | |
184 | 210 | end |
185 | 211 | imported_module = self.modules[module_name] |
186 | 212 | elseif self.module_path == nil then |