Please sign in to comment.
llgo: Represent functions as a pair of pointers
This commit changes function representation to be a pair of pointers: (fnptr, context). The first pointer is a raw function pointer; the second pointer is a "context" pointer, which is non-nil for closures. For a plain old function, the function value will be constant, with the second value being const-null. In addition, "receiver" has been removed from LLVMValue, and we overload this pair-of-pointers representation to enable passing bound methods around internally. In this case, the second item in the pair may have some arbitrary non-pointer type (i.e. the type of the method receiver). Closures no longer use trampolines, instead setting the function pair's context value directly. The most complex change is in VisitCallExpr: to avoid generating additional code for plain old functions, it first checks if the context value is const-null, and if so, calls the function pointer as it previously would have. If the context is not const-null, then code is generated to check if it is non-null at runtime, and if so, call the function with an additional argument (the context) prepended to the argument list; otherwise call the function pointer as it previoulst would have. There are some problems remaining with the runtime where functions are assumed to occupy one word, and also in the use of intrinsics (namely llvm.trap).
- Loading branch information
Showing with 231 additions and 139 deletions.
Oops, something went wrong.