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:
6
lang/interpret_test/TestAstFunc2/panic0.txtar
Normal file
6
lang/interpret_test/TestAstFunc2/panic0.txtar
Normal file
@@ -0,0 +1,6 @@
|
||||
-- main.mcl --
|
||||
# This should not panic.
|
||||
panic("")
|
||||
panic("")
|
||||
-- OUTPUT --
|
||||
Vertex: _panic[panic]
|
||||
7
lang/interpret_test/TestAstFunc2/panic1.txtar
Normal file
7
lang/interpret_test/TestAstFunc2/panic1.txtar
Normal file
@@ -0,0 +1,7 @@
|
||||
-- main.mcl --
|
||||
# This should not panic.
|
||||
panic("")
|
||||
test "hello" {}
|
||||
-- OUTPUT --
|
||||
Vertex: _panic[panic]
|
||||
Vertex: test[hello]
|
||||
6
lang/interpret_test/TestAstFunc2/panic2.txtar
Normal file
6
lang/interpret_test/TestAstFunc2/panic2.txtar
Normal file
@@ -0,0 +1,6 @@
|
||||
-- main.mcl --
|
||||
# This should panic!
|
||||
panic("please panic")
|
||||
test "hello" {}
|
||||
-- OUTPUT --
|
||||
# err: errStream: func `panic @ 0x0000000000` stopped before it was loaded
|
||||
Reference in New Issue
Block a user