This adds support for `include as <identifier>` type statements which in addition to pulling in any defined resources, it also makes the contents of the scope of the class available to the scope of the include statement, but prefixed by the identifier specified. This makes passing data between scopes much more powerful, and it also allows classes to return useful classes for subsequent use. This also improves the SetScope procedure and adds to the Ordering stage. It's unclear if the current Ordering stage can handle all code, or if there exist corner-cases which are valid code, but which would produce a wrong or imprecise topological sort. Some extraneous scoping bugs still exist, which expose certain variables that we should not depend on in future code. Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
31 lines
763 B
Plaintext
31 lines
763 B
Plaintext
-- main.mcl --
|
|
class c1 {
|
|
test "t1" {}
|
|
$y = "hello"
|
|
class c0 {
|
|
test "t2" {}
|
|
$x = "goodbye"
|
|
}
|
|
}
|
|
include c1 as i1 # has $y
|
|
include i1.c0 as i0 # has $x ...and $y
|
|
|
|
test $i0.x {} # ok
|
|
test $i1.y {} # ok
|
|
panic($i0.x != "goodbye")
|
|
panic($i1.y != "hello")
|
|
|
|
# the really tricky case
|
|
# XXX: works atm, but not supported for now: could not set scope: variable i0.y not in scope
|
|
# We currently re-export anything in the parent scope as available from our
|
|
# current child scope, which makes this variable visible. Unfortunately, it does
|
|
# not have the correct dependency (edge) present in the Ordering system, so it
|
|
# is flaky depending on luck of the toposort.
|
|
#test $i0.y {}
|
|
|
|
-- OUTPUT --
|
|
Vertex: test[goodbye]
|
|
Vertex: test[hello]
|
|
Vertex: test[t1]
|
|
Vertex: test[t2]
|