noss

how to gen "run"

s-obj must contain symbol table with the correct references.  

s-obj is generated by gen2.txt.  However, gen2.txt just passes symbol table through.  The symbol table is read from n-obj.

n-obj is generated by nut.txt, the compiler.  The current version dumps everything in the symbol table.

The symbols that must be exported are of type FUN and GVAR only.  

1) change nut.txt to output only the necessary one.
2) change gen2.txt to output the s-code reference.  However the number of symbol does not change.

at nut.txt

dumpsym is responsible to output the symbol table.  relocate the reference to function such that the code segment starts at 2.  It is necessary as nut-compiler is used under "nsim" where both the compiler and the user program to be compiled occupy the same code segment.  Therefore the user program in the code segment will not start at 2.  We would like the object to be relocatable, therefore the user code should start at 2.

When starting the compiler, (sys 9) is used to find out where to user code segment is.  The global variable "Start" stores this location, and it is used to relocate the reference to all function call when output the object.

The following code is added in nut.txt at dumpsym, to output the correct reference.  The data segment is not relocated as it is already started at 0.

      (if (= ty tyFUN)
        (set n (shift (getVal i) Start))
        ; else
        (set n (getVal i)))
      (print n) (space)

at gen2.txt

when read symtab from n-obj, it recognises the type "fun" and outputs the s-address corresponding to the n-address.  Here is the added code to outsym, to output symtab.

    (set ty (atoi tok))
    (tokenise)                    ; ref, reloc
    (if (= ty tyFUN)
      (do
      (set ref (shift (atoi tok) CS))
      (print (assoc ref)))
      ; else
      (prstr tok))
    (space)

how to gen "run"

(run (fn ...))

will generate a call to "run", placing the address pointed to (fn ..) as its argument.

  lit x
  call run
  jmp y
x: ...
  call fn
  end
y: ...

The address of x is the next 3 words.  jmp x skips the code (fn...).  (fn ..) is deferred and "run" will use x as the starting address of the process (fn...). When the process returned, it will be terminated by "end". This is in the function gencall.

; convert arg to index to symtab
; e is arglist
(def gencall (arg e) (idx a)
  (do
  (set idx (searchRef arg))
  (if (= idx Runidx)		; is "run"
    (do
    (outa icLit (+ XP 3))  	; point to code of process
    (outa icCall idx)		; call run
    (set a XP)
    (outa icJmp 0)
    (eval (head e))
    (outs icEnd)
    (patch a (- XP a)))		; jump over
    ; else
    (do				; normal call
    (while e
      (do
      (eval (head e))
      (set e (tail e))))
    (outa icCall idx)))))

15 Aug 2006

