Start getting module loading working.
Right now, it uses a weird "import_" method on String which should either be replaced or at least hidden behind some syntax. But it does roughly the right thing. Still lots of corner cases to clean up and stuff to fix. In particular: - Need to handle compilation errors in imported modules. - Need to implicitly import all core and IO types into imported module. - Need to handle circular imports. (Just need to give entry module the right name for this to work.)
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
var Module = "module.wren".import_("Module")
|
||||
var Other = "module.wren".import_("Other")
|
||||
|
||||
IO.print(Module) // expect: before
|
||||
|
||||
// Reassigning the variable in the other module does not affect this one's
|
||||
// binding.
|
||||
Other.change
|
||||
IO.print(Module) // expect: before
|
||||
|
||||
// But it does change there.
|
||||
Other.show // expect: after
|
||||
|
||||
// TODO: Cyclic import.
|
||||
@@ -0,0 +1,12 @@
|
||||
// nontest
|
||||
var Module = "before"
|
||||
|
||||
class Other {
|
||||
static change {
|
||||
Module = "after"
|
||||
}
|
||||
|
||||
static show {
|
||||
IO.print(Module)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// nontest
|
||||
var Module1 = "from module one"
|
||||
var Module2 = "from module two"
|
||||
var Module3 = "from module three"
|
||||
var Module4 = "from module four"
|
||||
var Module5 = "from module five"
|
||||
|
||||
IO.print("ran module")
|
||||
@@ -0,0 +1,14 @@
|
||||
var Module1 = "module.wren".import_("Module1")
|
||||
var Module2 = "module.wren".import_("Module2")
|
||||
var Module3 = "module.wren".import_("Module3")
|
||||
var Module4 = "module.wren".import_("Module4")
|
||||
var Module5 = "module.wren".import_("Module5")
|
||||
|
||||
// Only execute module body once:
|
||||
// expect: ran module
|
||||
|
||||
IO.print(Module1) // expect: from module one
|
||||
IO.print(Module2) // expect: from module two
|
||||
IO.print(Module3) // expect: from module three
|
||||
IO.print(Module4) // expect: from module four
|
||||
IO.print(Module5) // expect: from module five
|
||||
@@ -0,0 +1,5 @@
|
||||
// nontest
|
||||
IO.print("a")
|
||||
var Shared = "shared.wren".import_("Shared")
|
||||
var A = "a " + Shared
|
||||
IO.print("a done")
|
||||
@@ -0,0 +1,5 @@
|
||||
// nontest
|
||||
IO.print("b")
|
||||
var Shared = "shared.wren".import_("Shared")
|
||||
var B = "b " + Shared
|
||||
IO.print("b done")
|
||||
@@ -0,0 +1,3 @@
|
||||
// nontest
|
||||
IO.print("shared")
|
||||
var Shared = "shared"
|
||||
@@ -0,0 +1,12 @@
|
||||
var A = "a.wren".import_("A")
|
||||
var B = "b.wren".import_("B")
|
||||
|
||||
// Shared module should only run once:
|
||||
// expect: a
|
||||
// expect: shared
|
||||
// expect: a done
|
||||
// expect: b
|
||||
// expect: b done
|
||||
|
||||
IO.print(A) // expect: a shared
|
||||
IO.print(B) // expect: b shared
|
||||
@@ -0,0 +1,3 @@
|
||||
// nontest
|
||||
var Module = "from module"
|
||||
IO.print("ran module")
|
||||
@@ -0,0 +1,4 @@
|
||||
var Module = "module.wren".import_("Module")
|
||||
// expect: ran module
|
||||
|
||||
IO.print(Module) // expect: from module
|
||||
@@ -0,0 +1 @@
|
||||
var DoesNotExist = "does_not_exist.wren".import_("DoesNotExist") // expect runtime error: Could not find module 'does_not_exist.wren'.
|
||||
@@ -0,0 +1,3 @@
|
||||
// nontest
|
||||
var Module = "from module"
|
||||
IO.print("ran module")
|
||||
@@ -0,0 +1,3 @@
|
||||
// Should execute the module:
|
||||
// expect: ran module
|
||||
var DoesNotExist = "module.wren".import_("DoesNotExist") // expect runtime error: Could not find a variable named 'DoesNotExist' in module 'module.wren'.
|
||||
Reference in New Issue
Block a user