|
|
# Function Calls
|
|
|
|
|
|
|
|
|
Source files: [rts/Apply.h](/ghc/ghc/tree/master/ghc/rts/Apply.h), [rts/Apply.cmm](/trac/ghc/browser/ghc/rts/Apply.cmm)
|
|
|
Source files: [rts/Apply.h](https://gitlab.haskell.org/ghc/ghc/tree/master/ghc/rts/Apply.h), [rts/Apply.cmm](/trac/ghc/browser/ghc/rts/Apply.cmm)
|
|
|
|
|
|
|
|
|
Dealing with calls is by far the most complicated bit of the execution model, and hence of the code generator. GHC uses an *eval/apply* strategy for compiling function calls; all the details of the design are in the paper [Making a fast curry: push/enter vs. eval/apply for higher-order languages](http://simonmar.github.io/bib/papers/evalapplyjfp06.pdf).
|
... | ... | @@ -42,7 +42,7 @@ When compiling a call, there are several cases to consider, which are treated se |
|
|
## Generic apply
|
|
|
|
|
|
|
|
|
Files: [utils/genapply](/ghc/ghc/tree/master/ghc/utils/genapply)
|
|
|
Files: [utils/genapply](https://gitlab.haskell.org/ghc/ghc/tree/master/ghc/utils/genapply)
|
|
|
|
|
|
|
|
|
When compiling a call that has an unknown function, we must generate code to
|
... | ... | @@ -55,7 +55,7 @@ When compiling a call that has an unknown function, we must generate code to |
|
|
- Too many arguments: save the excess arguments, and tail call the function as for a saturated cal.
|
|
|
|
|
|
|
|
|
All of this takes quite a lot of code, so we pre-generate a whole bunch of generic-apply code sequencues, one for each combination of arguments. This code is generated by the tool [utils/genapply](/ghc/ghc/tree/master/ghc/utils/genapply), and the generated code appears in `rts/AutoApply.cmm`.
|
|
|
All of this takes quite a lot of code, so we pre-generate a whole bunch of generic-apply code sequencues, one for each combination of arguments. This code is generated by the tool [utils/genapply](https://gitlab.haskell.org/ghc/ghc/tree/master/ghc/utils/genapply), and the generated code appears in `rts/AutoApply.cmm`.
|
|
|
|
|
|
|
|
|
For example, if we find a call to an unknown function applied to two (boxed) `Int` arguments, load the function and its two arguments as for the standard entry convention and jump to `stg_ap_pp_fast`. This latter code is in `rts/AutoApply.cmm`, generated by the `genapply` tool. The "`pp`" part is the bit that says the code is specialised for two pointer arguments.
|
... | ... | |