add support for closure calls
Compiling languages with closures often requires passing an extra environment parameter to the called function. One solution is to use a convention, and reserve, say, the first argument for that purpose. However, that makes binding to C a little less smooth. Alternatively, QBE now provides a way to remain fully ABI compatible with C by having a "hidden" environment argument (marked with the keyword 'env'). Calling a function expecting an environment from C will make the contents of the environment undefined, but the normal arguments will be passed without alteration. Conversely, calling a C function like it is a closure by passing it an environemnt will work smoothly.
This commit is contained in:
parent
249af91ff9
commit
a9d81338b1
4 changed files with 68 additions and 28 deletions
4
all.h
4
all.h
|
@ -264,8 +264,12 @@ enum Op {
|
|||
/* function instructions */
|
||||
Opar = NPubOp,
|
||||
Oparc,
|
||||
Opare,
|
||||
#define ispar(o) (Opar <= o && o <= Opare)
|
||||
Oarg,
|
||||
Oargc,
|
||||
Oarge,
|
||||
#define isarg(o) (Oarg <= o && o <= Oarge)
|
||||
Ocall,
|
||||
Ovacall,
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue