mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 19:17:47 +00:00
Defer for trivial cases
This commit is contained in:
@@ -48,6 +48,7 @@ func main() {
|
||||
println("Stringer.String():", s.String())
|
||||
|
||||
runFunc(hello, 5) // must be indirect to avoid obvious inlining
|
||||
testDefer()
|
||||
|
||||
// test library functions
|
||||
println("lower to upper char:", 'h', "->", unicode.ToUpper('h'))
|
||||
@@ -57,6 +58,18 @@ func runFunc(f func(int), arg int) {
|
||||
f(arg)
|
||||
}
|
||||
|
||||
func testDefer() {
|
||||
i := 1
|
||||
defer deferred("...run as defer", i)
|
||||
i += 1
|
||||
defer deferred("...run as defer", i)
|
||||
println("deferring...")
|
||||
}
|
||||
|
||||
func deferred(msg string, i int) {
|
||||
println(msg, i)
|
||||
}
|
||||
|
||||
func readMap(m map[string]int, key string) {
|
||||
println("map length:", len(m))
|
||||
println("map read:", key, "=", m[key])
|
||||
|
||||
Reference in New Issue
Block a user