File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -295,12 +295,16 @@ func (c *Compiler) emitRunDefers(frame *Frame) {
295295 forwardParams = append (forwardParams , forwardParam )
296296 }
297297
298- // Add the context parameter. We know it is ignored by the receiving
299- // function, but we have to pass one anyway.
300- forwardParams = append (forwardParams , llvm .Undef (c .i8ptrType ))
301-
302- // Parent coroutine handle.
303- forwardParams = append (forwardParams , llvm .Undef (c .i8ptrType ))
298+ // Plain TinyGo functions add some extra parameters to implement async functionality and function recievers.
299+ // These parameters should not be supplied when calling into an external C/ASM function.
300+ if ! callback .IsExported () {
301+ // Add the context parameter. We know it is ignored by the receiving
302+ // function, but we have to pass one anyway.
303+ forwardParams = append (forwardParams , llvm .Undef (c .i8ptrType ))
304+
305+ // Parent coroutine handle.
306+ forwardParams = append (forwardParams , llvm .Undef (c .i8ptrType ))
307+ }
304308
305309 // Call real function.
306310 c .createCall (callback .LLVMFn , forwardParams , "" )
Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ func hello(n int) {
7272}
7373
7474func testDefer () {
75+ defer exportedDefer ()
76+
7577 i := 1
7678 defer deferred ("...run as defer" , i )
7779 i ++
@@ -98,6 +100,11 @@ func deferred(msg string, i int) {
98100 println (msg , i )
99101}
100102
103+ //go:export __exportedDefer
104+ func exportedDefer () {
105+ println ("...exported defer" )
106+ }
107+
101108func testBound (f func () string ) {
102109 println ("bound method:" , f ())
103110}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ Thing.Print: foo arg: bar
44...run as defer 3
55...run closure deferred: 4
66...run as defer 1
7+ ...exported defer
78loop 3
89loop 2
910loop 1
You can’t perform that action at this time.
0 commit comments