Add example of execution limits using fuel consumption (#2869)

* Add example of execution limits using fuel consumption

* run rustfmt

* Use a more naive WAT implementation

* Catch error and return cleanly

* Add a C example to demonstrate fuel consumption

* Add error handling for add_fuel
This commit is contained in:
Ryan Brewster
2021-05-04 08:39:01 -07:00
committed by GitHub
parent 8811246a9f
commit 2145855954
3 changed files with 178 additions and 0 deletions

13
examples/fuel.wat Normal file
View File

@@ -0,0 +1,13 @@
(module
(func $fibonacci (param $n i32) (result i32)
(if
(i32.lt_s (local.get $n) (i32.const 2))
(return (local.get $n))
)
(i32.add
(call $fibonacci (i32.sub (local.get $n) (i32.const 1)))
(call $fibonacci (i32.sub (local.get $n) (i32.const 2)))
)
)
(export "fibonacci" (func $fibonacci))
)