Files
mgmt/lang/interpret_test/TestAstFunc1/recursive_module1.graph
James Shubin f53376cea1 lang: Add function values and lambdas
This adds a giant missing piece of the language: proper function values!
It is lovely to now understand why early programming language designers
didn't implement these, but a joy to now reap the benefits of them. In
adding these, many other changes had to be made to get them to "fit"
correctly. This improved the code and fixed a number of bugs.
Unfortunately this touched many areas of the code, and since I was
learning how to do all of this for the first time, I've squashed most of
my work into a single commit. Some more information:

* This adds over 70 new tests to verify the new functionality.

* Functions, global variables, and classes can all be implemented
natively in mcl and built into core packages.

* A new compiler step called "Ordering" was added. It is called by the
SetScope step, and determines statement ordering and shadowing
precedence formally. It helped remove at least one bug and provided the
additional analysis required to properly capture variables when
implementing function generators and closures.

* The type unification code was improved to handle the new cases.

* Light copying of Node's allowed our function graphs to be more optimal
and share common vertices and edges. For example, if two different
closures capture a variable $x, they'll both use the same copy when
running the function, since the compiler can prove if they're identical.

* Some areas still need improvements, but this is ready for mainstream
testing and use!
2019-07-17 00:27:09 -04:00

65 lines
4.6 KiB
Plaintext

Edge: call:_operator(str("+"), int(42), var(third.three)) -> var(h2g2.answer) # var:h2g2.answer
Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name
Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name
Edge: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) -> var(mod1.name) # var:mod1.name
Edge: int(3) -> var(third.three) # var:third.three
Edge: int(42) -> call:_operator(str("+"), int(42), var(third.three)) # a
Edge: str("+") -> call:_operator(str("+"), int(42), var(third.three)) # op
Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # op
Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # op
Edge: str("+") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # op
Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a
Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a
Edge: str("i imported local: %s") -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # format
Edge: str("i imported remote: %s and %s") -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # format
Edge: str("the answer is: %d") -> call:fmt.printf(str("the answer is: %d"), var(answer)) # format
Edge: str("this is module mod1 which contains: ") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # a
Edge: str("this is the nested git module mod1") -> var(mod1.name) # var:mod1.name
Edge: str("this is the nested git module mod1") -> var(mod1.name) # var:mod1.name
Edge: str("this is the nested local module mod1") -> var(mod1.name) # var:mod1.name
Edge: var(answer) -> call:fmt.printf(str("the answer is: %d"), var(answer)) # a
Edge: var(example1.name) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # a
Edge: var(example1.name) -> var(example2.ex1) # var:example2.ex1
Edge: var(example2.ex1) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # b
Edge: var(h2g2.answer) -> var(answer) # var:answer
Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b
Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b
Edge: var(mod1.name) -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # b
Edge: var(mod1.name) -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # a
Edge: var(third.three) -> call:_operator(str("+"), int(42), var(third.three)) # b
Vertex: call:_operator(str("+"), int(42), var(third.three))
Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name))
Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name))
Vertex: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name))
Vertex: call:fmt.printf(str("i imported local: %s"), var(mod1.name))
Vertex: call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1))
Vertex: call:fmt.printf(str("the answer is: %d"), var(answer))
Vertex: int(3)
Vertex: int(42)
Vertex: str("+")
Vertex: str("+")
Vertex: str("+")
Vertex: str("+")
Vertex: str("hello")
Vertex: str("hello2")
Vertex: str("hello3")
Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ")
Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ")
Vertex: str("i imported local: %s")
Vertex: str("i imported remote: %s and %s")
Vertex: str("the answer is: %d")
Vertex: str("this is module mod1 which contains: ")
Vertex: str("this is the nested git module mod1")
Vertex: str("this is the nested git module mod1")
Vertex: str("this is the nested local module mod1")
Vertex: var(answer)
Vertex: var(example1.name)
Vertex: var(example1.name)
Vertex: var(example2.ex1)
Vertex: var(h2g2.answer)
Vertex: var(mod1.name)
Vertex: var(mod1.name)
Vertex: var(mod1.name)
Vertex: var(mod1.name)
Vertex: var(third.three)