github.com/aykevl/tinygo@v0.5.0/src/runtime/func.go (about) 1 package runtime 2 3 // This file implements some data types that may be useful for some 4 // implementations of func values. 5 6 import ( 7 "unsafe" 8 ) 9 10 // funcValue is the underlying type of func values, depending on which func 11 // value representation was used. 12 type funcValue struct { 13 context unsafe.Pointer // function context, for closures and bound methods 14 id uintptr // ptrtoint of *funcValueWithSignature before lowering, opaque index (non-0) after lowering 15 } 16 17 // funcValueWithSignature is used before the func lowering pass. 18 type funcValueWithSignature struct { 19 funcPtr uintptr // ptrtoint of the actual function pointer 20 signature *uint8 // pointer to identify this signature (the value is undef) 21 } 22 23 // getFuncPtr is a dummy function that may be used if the func lowering pass is 24 // not used. It is generally too slow but may be a useful fallback to debug the 25 // func lowering pass. 26 func getFuncPtr(val funcValue, signature *uint8) uintptr { 27 return (*funcValueWithSignature)(unsafe.Pointer(val.id)).funcPtr 28 }