JuliaLang/julia — pull request #1809 by timholy (2012-12-21 18:53:46+00:00)
Title: WIP: make require() load at top level

This is the major piece of work needed to address #1411. Please check, esp. @JeffBezanson. I'm especially worried about the module context in toplevel.c, if the imported file has errors in it. Testing did not result in a segfault, but I doubt the thoroughness of this test.

On both the C side and the julia side this is ugly, but when I tried the more obvious thing in `boot.jl` I either (1) ran into `cconvert not defined` errors (presumably the conversion of a bool to an Int32 is not yet automatizable), (2) didn't figure out a way to generate `0::Int32` in a boot.jl-safe way, or (3) got a weird warning when I said `import Core.include; include(fname::ByteString, inmain::Bool) = ...`. Hence I defined `import_main`. By this point the interface seems kinda dumb (why take a second argument to `import_main`??), but I suspect there's a cleaner solution, so I decided to leave my fingerprints on it.

Also, a more general interface would be `import(fname, mod::Module)`, but I don't know whether that's desirable.