Closed bichanna closed 2 years ago
Probably just import the module via filename, search from the std and installed modules directory to the user script directory, check if it does exist and return an error, define module map/class, get all globals from the module then add the globals to the module map/class. Might be wrong though.
Should I do it in the parser or the interpreter? I tried it in the parser, but it gets nasty (errors thrown, and I don't know how to lead it to the imported file) when there are runtime errors in the source code.
You may do it on runtime.
So, parsing the imported file is done in runtime? I don't know how to do that.
What do you mean? Just call the compiler from inside the VM. How you implement the import system however is more complicated. Do you go down the C route and just copy-paste like header files (in which case there's no runtime support needed but it's a horrible idea) or do you create namespaces like Python does?
Thanks!
Thank you for your amazing book :D
I have currently learned to write my interpreter following the book. But I don't know how to implement a module system like Python. I couldn't find any tutorials on the internet.
I appreciate it if you give me a couple of hints.