Som v1.5  readme


1  This version includes macro. 
Macro definition
Macro expansion

2  Eliminate  "callt"  but generating a proper tail-call.
(see example in hanoi.lst , there is not "callt")

tail-call

A recursive tail-call will be converted into passing parameters and then instead of a recursive call, use "jump" to the beginning of function reusing the old activation record. The following example shows how a tail-call is converted.

[from hanoi.txt]

to mov n from t2 | other =
  if n == 1
    num[from] = num[from] - 1
    num[t2] = num[t2] + 1
    print from printc 58 print t2 nl
  else  
    other = 6 - from - t2
    mov n-1 from other
    mov 1 from t2
    mov n-1 other t2

in S-code:
     ...

     68 Lit 1        // 1
     69 Get 3        // from
     70 Get 2        // t2
     71 Call mov
     72 Get 4        // n - 1
     73 Lit 1
     74 Sub
     75 Get 1        // other
     76 Get 2        // t2
     77 Callt mov
     78 Ret 5

The last "mov" (77 Callt mov) is converted to:

      3 Fun mov
      4 Get 4
       . . .
     45 Lit 1
     46 Get 3
     47 Get 2
     48 Call mov
     49 Get 4
     50 Lit 1
     51 Sub      // n - 1
     52 Get 1    // other
     53 Get 2    // t2
     54 Put 2    // -> t2
     55 Put 3    // -> other
     56 Put 4    // -> n
     57 Jmp 4    // goto begin
     58 Ret 5

26 June 2005

last update 21 Feb 2024