0

I am not clear about was static and stack allocation are? Is static allocation static and stack allocation dynamic? Then where does heap allocation belong?

How is activation record related to this? I thought activation record is a conceptual thing like activation tree, and does not have any physical existence.

What does the following target machine code mean?

static allocation:

ST callee. staticArea , #here + 20
BR callee. codeArea

stack allocation :

LD SP , #stackStart
code for the first procedure
HALT
ADD SP , SP , #caller. recordSize
ST *SP , #here + 16
BR callee. codeArea

BR *O (SP) // return to caller
SUB SP , SP , #caller. recordSize // decrement stack pointer
afsara_ben
  • 542
  • 1
  • 11
  • 30
  • Read a good compiler book such as [the Dragon Book](https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools). Read also about [continuation](https://en.wikipedia.org/wiki/Continuation)s and [CPS](https://en.wikipedia.org/wiki/Continuation-passing_style). [Heap allocation](https://en.wikipedia.org/wiki/Memory_management#DYNAMIC) requires help from the [operating system](http://pages.cs.wisc.edu/~remzi/OSTEP/) (e.g. `malloc` uses sometimes [mmap(2)](http://man7.org/linux/man-pages/man2/mmap.2.html)...) – Basile Starynkevitch Aug 18 '18 at 07:59
  • I am reading the dragon book, but i'm not understanding the concept from reading the passages. :/ – afsara_ben Aug 18 '18 at 08:01
  • Read also about [CPS conversion](http://matt.might.net/articles/cps-conversion/), about [garbage collection](http://gchandbook.org/) – Basile Starynkevitch Aug 18 '18 at 08:04
  • Activation records are also called [call frames](https://en.wikipedia.org/wiki/Call_stack#CALL-FRAME) and they do exist in the call stack – Basile Starynkevitch Aug 18 '18 at 08:05
  • 1
    "Activation frame" generally applies to the stack frame, that's where the local variables of a function are stored. It is created on function entry by adjusting the stack pointer by the size of the local variable storage and destroyed on function exit by restoring the stack pointer. "Static allocation" generally applies to the data section of a program, the place where global variables and local variables that are declared *static* are stored. "Dynamic allocation" generally applies to storage that the program explicitly allocates from the heap. – Hans Passant Aug 18 '18 at 08:16
  • So three distinct kind of places to store variables, it is up to the language compiler to choose one of them to implement the language. There is a forth place that books don't typically talk about but is important for modern languages, thread-local storage. – Hans Passant Aug 18 '18 at 08:20
  • @HansPassant can you provide any link which explains all of this in a step by step, easy way? I'm finding the dragon book and wiki quite difficult – afsara_ben Aug 18 '18 at 08:26
  • 1
    I wouldn't know where to begin linking. In general you need to have a pretty good idea how the OS and the processor works before you can write a compiler. It is an outdated concept anyway, these days you don't write the back-end of the compiler yourself anymore. The code-generator and optimizer, that's where the real work is located. LLVM is an example of one that generates machine code, Java bytecode or .NET IL of ones that use a jitter and garbage collection. You target the intermediate representation of the back-end to implement the compiler, it sets the rules you must live by. – Hans Passant Aug 18 '18 at 08:37
  • 1
    And transpilers are getting common again, translating the language syntax into code of another language. That used to commonly be C, Javascript is a common target today. – Hans Passant Aug 18 '18 at 08:42
  • An alternative to LLVM might be [libgccjit](https://gcc.gnu.org/onlinedocs/jit/) – Basile Starynkevitch Aug 18 '18 at 08:55

0 Answers0