how to compile static array

ax = array {10 20 30}

in an immediate line

parser 
  assignment stmt
    exas
      RHS
        tkARRAY
          tkBB
            <action>

action
  a = array 0  // get ads
  alist        // stuff static data into M[newdata]
  tkBE
  doarray a    //  ypush newatom ADS a

what happen when compile assignment stmt?

[ -- %var/%vec]
exas
  execute lval
    if asg (look at tkEQ)
      skip tkEQ
      commit ex0
      doset
    else
      lval already grob iden at LHS
      commit terms
  if backtrack do ex0

// left variable
lval
  if NEW, GVAR, LOCAL then dovar mod else 0

dovar ref
  ypush newatom GNAME/LNAME ref
  
doset
  ypop 2 items
  make (= lhs rhs)

summary

  Static data are stored in M[newdata] and its address is assigned to the global variable denoted its name. The parse tree (= ax ads) will be executed as an immediate line.

  To cross vm to a different one, im line cannot be used as the generated code will be different machine code (for the other vm). To declare static array, its value must be instantiated at compile time, so the object code will have a correct reference. 

  For v5 compiler, the only place where static array occurs is in icode-s.txt  

    op_str = array {mV "nop" 0 ...}

  A solution is to comment it out and not generate a listing (while crossing the compiler). Another solution is to "execute" its parse tree (= ax ads) at compile time without using the vm.

21 Dec 2010



