Runtime Structure of Stack-based Languages (C3)

 

C3

New Features

C3 Example - Factorial

 

Mutual Recursion

Effect of Introducing Recursion

 

 

Semantics of a Routine call specified by SIMPLESEM

Routine call This code is in the caller
set 1, D[1] +1 allocate space on the stack for the return value (assume one cell needed)

this step adds one to the value of  FREE
set D[1], ip + 4 set the value of the return pointer in the callee's activation record. The 4 is added to ip because 4 more instructions are needed to complete the call.

this step stores the return pointer in the cell at offset 0 of the callee's activation record, though technically it has not been allocated yet. We store it at the cell pointed to by FREE.

set D[1]+1, D[0] set the dynamic link of the callee's activation record to point to the caller's activation record

this step stores the value, CURRENT, in the cell at offset 1 of the callee's activation record, technically not allocated yet

set 0, D[1] Set CURRENT to reflect the address of the currently executing activation record.

this step stores the value FREE in address 0 of D

set 1, D[1] + AR Allocates space for the currently executing activation record by setting the value of FREE. AR is the size of the callee's activation record.
jump start_addr start_addr is an address in C storage where the first instruction of the callee's code is stored
   
Return from Routine  This code is in the callee
set 1, D[0] set FREE ( deallocates current activation record by setting value of FREE to CURRENT
set 0, D[D0]+1] set CURRENT ( D[0]+1 represents cell where dynamic link to caller's base address is stored)
jump D[D[1]] jump to stored_return_pointer (D[1] represents the address of the memory cell at offset 0 of the callee's activation record; which contains the return_pointer)

 

 

 

Example - Code for C3 Program in Figure 2.17

 

 

D-Store Snapshots

Assumptions