Files
mgmt/lang/interpret_test/TestAstFunc3/value-resource-get0.txtar
James Shubin b7d8a769db lang: funcs: core: Add value functions
This adds a new series of "get*" functions which can read values from
the associated "value" resources. The key name of the function must
match the name value of the resource for things to work.

Type unification isn't yet perfect in these scenarios, so you should use
casually and with caution.
2023-12-03 18:24:20 -05:00

46 lines
1.2 KiB
Plaintext

-- main.mcl --
import "value"
value "hello1" {
#any => 42, # can be any type
any => "wow", # can be any type
}
value "hello2" {
any => "whatever", # TODO: remove the temporary placeholder here
#any => "", # XXX: remove any placeholder to see the bug when absent
}
test "test" {
#anotherstr => "", # get it from send/recv
}
Value["hello1"].any -> Value["hello2"].any
Value["hello2"].any -> Test["test"].anotherstr
$ret1 = value.get_str("hello1") # name of value resource
$ret2 = value.get_str("hello2") # name of value resource
test "get1" {
anotherstr => $ret1->value,
onlyshow => ["AnotherStr",], # displays nicer
}
test "get2" {
anotherstr => $ret2->value,
onlyshow => ["AnotherStr",],
}
# XXX: Field entries for test[get1] and test[get2] aren't seen yet :(
-- OUTPUT --
Edge: value[hello1] -> value[hello2] # value[hello1] -> value[hello2]
Edge: value[hello2] -> test[test] # value[hello2] -> test[test]
Field: test[get1].OnlyShow = ["AnotherStr"]
Field: test[get2].OnlyShow = ["AnotherStr"]
Field: test[test].AnotherStr = "wow"
Field: value[hello1].Any = "wow"
Field: value[hello2].Any = "wow"
Vertex: test[get1]
Vertex: test[get2]
Vertex: test[test]
Vertex: value[hello1]
Vertex: value[hello2]