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>
27 lines
673 B
Plaintext
27 lines
673 B
Plaintext
-- main.mcl --
|
|
$x1 = "i am x1" # i am top-level
|
|
$x2 = "i am x2" # i am top-level
|
|
|
|
class c2() {
|
|
$z = "i am y and " + $x1
|
|
|
|
$x1 = "hey" # shadow
|
|
}
|
|
|
|
include c2 as f1
|
|
|
|
test $f1.z {}
|
|
test $f1.x1 {}
|
|
|
|
# the really tricky case
|
|
# XXX: works atm, but not supported for now: could not set scope: variable f1.x2 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 $f1.x2 {}
|
|
|
|
-- OUTPUT --
|
|
Vertex: test[hey]
|
|
Vertex: test[i am y and hey]
|