engine: resources, lang: funcs, parser: Add panic magic
It's valuable to check your runtime values and to shut down the entire engine in case something doesn't match. This patch adds some magic plumbing to support a "panic" mechanism. A new "panic" statement gets transparently converted into a panic function and panic resource. The former errors if the input is not empty. The latter must be present to consume the value, but doesn't actually do anything.
This commit is contained in:
8
examples/lang/panic/main.mcl
Normal file
8
examples/lang/panic/main.mcl
Normal file
@@ -0,0 +1,8 @@
|
||||
class foo() {
|
||||
panic("fail3") # should panic
|
||||
panic("fail4") # should panic
|
||||
|
||||
test "nested-test" {
|
||||
anotherstr => "hello!\n",
|
||||
}
|
||||
}
|
||||
18
examples/lang/panic0.mcl
Normal file
18
examples/lang/panic0.mcl
Normal file
@@ -0,0 +1,18 @@
|
||||
import "panic/" as nested # local, relative module to prove it can nest
|
||||
|
||||
panic("") # should NOT panic
|
||||
panic("") # should NOT panic
|
||||
panic("fail1") # should panic
|
||||
panic("fail2") # should panic
|
||||
|
||||
include nested.foo()
|
||||
|
||||
test "test" {
|
||||
anotherstr => "hello!\n",
|
||||
}
|
||||
|
||||
# this is what we're simulating:
|
||||
#$_panic1 = panic("whatever1") # this is a function
|
||||
#_panic $_panic1 {} # this is a resource
|
||||
#$_panic2 = panic("whatever2")
|
||||
#_panic $_panic2 {}
|
||||
Reference in New Issue
Block a user