consideration of call

Should call be a 2-arg intruction?  Originally v5 call is 3-arg. Two additional arguments can be embedded in the call instruction because an instruction format is 96 bits so there is room to fit them.  In 64-bit format, to embed two instructions is tight.  The room to fit an argument into c is small.  Therefore call should be 2-arg and this will simplify the instruction call.

call  arg (d), ads (b)

How to make call more light weight?

a normal call does:
1.  pass parameters to param[.] (in vm)
2.  save reg in frame
3.  param[.] to reg
4.  goto body

or it does the following
1.  create a new frame
2.  save reg in the frame
3.  pass parameters
4.  goto body

when fun arity is 0, step 3 can be omitted. For arity 1, pass one parameter can be done from the caller hence step 3 can be omitted.  Therefore step 3 is necessary when arity > 1. The task can be divided between caller and callee:

caller:   create new frame & save reg
callee:   [pass parameters] body

The lighter weight is achieved when arity 0 or 1, no need to pass parameters.  A new instruction is introduced:

call  arg (d), ads (b)

  get arity and fs  from ads
  create new frame
  save reg (fs)
  if (arity > 0)  r[1] = M[arg]
  goto ads+2 (body of fun)

pass  num (d)

  get sp' from frame
  for i = 2 to num+1
    r[i] = M[sp']
    sp'--
  update sp' in frame

lo

current  |        |
frame    |        |
         |        |
         |  fp''  |
         ----------
         | ...    |
stack    | pv_n   |
         | ...    |
         | pv_2   | <- sp'
         ----------
         | save r |
new      |        |
frame    | pc     |
         | sp'    |
         | fp'    | <- fp <- sp 
         ---------- 

update sp' in new frame to be sp'-arity+1

14 Dec 2010