Types

Tr = Trigger
Si  = Signal
A = Anchor

I = Integer
F = Floating point
C = Character
Sy = Symbol
B = Boolean
P = Pointer
A = Address
Cb = Code-block
Th = Thunk

T = Tuple(Product)

S = Sum-of-Products
Dn = Disjunct number

M = Manager
Li = Lock Index

Is = I-structure
Su = Subscript
Sv = Storable Value

Program graph instructions
-------------------------------------------------------------------------------------
Find out!!!!! Tr => (I + Sy + C + F + B)
 literal 

(I x I) => I
intplus intminus inttimes ;intdivide ;intexpt intmax intmin 
logical-and logical-ior logical-xor 

I => I
intabs
logical-not 

(F x F) => F
floatplus floatminus floattimes ;floatdivide ;floatexpt ;floatintexpt floatmax floatmin 
makefloat (mantissa of 1st and exponent of 2nd)

F => F 
floatabs sqrt exponent mantissa 

F x I => F
scale-float (scale exponent by I)

(B x B) => B
and  or xor
booleq boolne 

B => B
not 

(Sy x Sy) => Sy
symboleq symbolne 

(I x I) => B
inteq intne intle intge intlt intgt 

(C x C) => B
char-less char-greater char-equal char-not-equal char-lesseq char-greatereq 

(F x F) => B
floateq floatne floatle floatge floatlt floatgt 

(P x P) => B
objecteq 

C <=> I
char-to-int int-to-char 

F <=> I
fix floor ceiling round float 

Obsolete:
|.+| |.-| |.*| |./| |.^| |.MAX| |.MIN| 
|.=| |.<>| |.<| |.>| |.<=| |.>=| 
 +  assoc+  -  *  assoc*  /  ^  min max abs
=  <>  <  >  <=  >=  
-----------------------------------------------------------------------------------
Tuples

make-tuple(size:I) 		: (Tr x A) => (T x [Si])
make-functional-tuple(size: I) 	: (I x T x A) => (T x Si)
tuple-fetch(index: I)		:  T => Sv 
tuple-store(index: I) 		:  T x Sv x A => Si

(why optional signals? on monsoon not ttda)
------------------------------------------
Sums of Products - nilary = enumerated, tuple = tagged by disjunct (how are these diff)

make-sum(dn:Dn size: I)		: Tr x An => S x [Si]
make-functional-sum(n: I)	: Sv^n x Tr x An => S x Si
sum-fetch(index: I) 		: S => Sv
sum-store(index: I)		: S x Sv x An => Si
sum-take(index:I)		: S => Sv
sum-put(index: I)		: S x Sv x An => Si
sum-examine(index: I)		: S => Sv x Si (take followed by put)
disjunct-number			: S => Dn
array-p (1 1)		: S => {enumerated or structure}

-------------------------------------------
Conses (Special case for List *0 = Nil | Cons *0 (List *0)

@!:
make-cons 
make-functional-cons
store-hd 
store-tl 
hd 
tl 
---------------------------------------------
I-structures

i-store 	: Is x Su x Sv x An => Si
i-fetch 	: Is x Su => Sv
i-put 		: Is x Su x Sv x An => Si
i-take 		: Is x Sy => Sv
i-overwrite     : Is x Su x Sv x An => Sv x Si
i-examine 	: Is x Su => Sv x Si

@!:
Clearing presence bits:
clear-i-structure 	(1 0 :signal-p t) : Is => Si
i-clear 	 	(2 0 :signal-p t) : Is x Su => Si 

Deallocating structure: Is => Si
free-i-structure 	(1 0 :signal-p t) 
loop-free-i-structure 	(1 0 :signal-p t) 

?? look up args ??)
Allocating Structures: 
make-i-structure 	(1 1 :signal-p *resource-manager-signal-p*)
make-2d-i-structure 	(1 1 :signal-p *resource-manager-signal-p*)
make-3d-i-structure 	(1 1 :signal-p *resource-manager-signal-p*)
make-i-string 		(1 1 :signal-p *resource-manager-signal-p*)
make-i-vector 		(2 1 :signal-p *resource-manager-signal-p*)

Obsolete:

form-address-i-put 
;i-put (2 0 :signal-p t)
opcode-i-take 
i-read! 
i-write! 
i-store-delay 
i-bulk-clear (1 1)
-------------------------------------------------
Managers

ENTER-MANAGER 	: M x Li => M
EXIT-MANAGER 	: Sv x Tr => Sv 
RELEASE-MANAGER : M x Li x Sv => Si
BEFORE-ENTER 	: M x Si => 
BEFORE-RELEASE  : M x Si =>

@!:
make-manager-signal
raise-manager-signal
---------------------------------------------
Contexts & Closures

apply 		 : C x Sv x An => Sv x Si

Used to implement apply
get-context      : ????
return-context   : ????
new-closure      : ????
closure-ready	 : ????
closure-cbname	 : ????
closure-chain    : ????

-----------------------------------------
Encapsulators (And helping instructions)

def (n-args: I) 			: 
	[:body]				: Sv^n-args x Tr x An => Sv x Si

if (n-in n-out)				: Sv^n-in x B x An => Sv^n-out
	[:then]				: Sv^n-in x An => Sv^n-out
	[:else]				: Sv^n-in x An => Sv^n-out

{loop-max-iter is obsolete?}
loop (n-var n-const constant-mode)	: Sv^n-var x Sv^n-const x (loop-max-iter:I) x (loop-bound:I) => Sv^n
	[:predicate]			: Sv^n-var x Sv^n-const x An => Sv^n-var x B
	[:body]				: Sv^n-var x Sv^n-const x An => Sv^n-var 

{used to feed loop constants after constant propagation}
loop-constant(index:I) 			: Tr => Sv

;;; There are two formats for LOOP instructions.  Ordinarily, loop constants are fed to the
;;; predicate and body through the PREDICATE-CONSTANT and BODY-CONSTANT outputs; this is
;;; indicated by specifying :PORT for the constant mode.  After constant propagation, however,
;;; constants are fed by special LOOP-CONSTANT instructions; this is indicated by a constant
;;; mode of :INSTRUCTION.

constant-def (n-res:I, name)		: 
	[:body]				: Tr x An => Sv^n-res x Si

;;; The CONSTANT-DEF program graph instruction encloses a loop code block.  The
;;; PARAMETER slot of this instruction holds the code block name.


seq (n-inputs, n-outputs: I; gate-p: B)	: Sv^n-in x An x [Tr] => Sv^n-out x Si
	[:body]				: Sv^n-in x An => Sv^n-out x Si

;; The operational semantics of a SEQ instruction are as follows:
;;
;; If the instruction is gated (i.e., gate-p is true)
;;   then the :INPUT's are gated to the :BODY-INPUT's by the :TRIGGER
;; If the instruction is not gated,
;;   then tokens flow from the :INPUT's to the :BODY-INPUT's (with no gating).
;; A token will not appear on the :SIGNAL until a token has appeared on 
;;   all of the :BODY-OUTPUT's and the :BODY-SIGNAL.
;; The :OUTPUT's are just connected from the :BODY-OUTPUT's.
;;
;; The idea of this is that if we string two SEQ instructions together
;; with the :SIGNAL of one connected to the :TRIGGER of the next then
;; the two subgraphs will be completely sequentialized.
;;
;; One could imagine using two instructions, one to deal with the inputs
;; (a big multi-gate) and one to deal with the outputs (a funny kind of
;; signal tree), but this formulation is supposedly easier to work with
;; because we can automatically do signals-and-triggers correctly.
;;

synch		: Sv => Sv 
;;; SYNCH denotes that the input should be gated by the termination of
;;; all other computation in the same encapsulator.

CASE!!!!!

Thunks (See SH Thesis)

delay(n:I)			: A x Sv^n => 
	[:body]			: Sv^n x An => Sv

defthunk (n-arguments)		: 
	[:body]			: Tr x Sv^n x An => Sv x Si

make-thunk (n-arguments)	: Cb x Sv^n x An => Th x Si
store-thunk 			: A x Th x An => Si

(should make all Is ops take Structure & index, flush this)
form-address 			: Is x Su x An => A


[ Instructions not defined in program-graph-instructions

call-substitution.lisp

;;; We need a directcall instruction (which is very similar to the
;;; fastcall-apply instruction used for loops).  Note that this is not
;;; "apply-like"!  That term only applies (pardon pun) to instructions with
;;; the same topology and general meaning as APPLY.

(define-program-graph-instruction :direct-apply (n-arguments)
  (:inputs :cb-name 1
	   :argument n-arguments
	   :anchor 1)
  (:outputs :output 1
	    :signal 1)
  (:properties :gmg-function 'gmg-direct-apply-instruction
	       :gmon-function 'gmon-direct-apply-instruction
	       :gcfg-function 'gcfg-direct-apply-instruction
	       :side-effecting-p t))

;;; We also need to define the apply-unsatisfied instruction, which
;;; is used when the arity of the function is definitely not yet
;;; satisfied.  Note that it causes no side effects.

(define-program-graph-instruction :apply-unsatisfied ()
  (:inputs :procedure 1
	   :argument 1
	   :anchor 1)
  (:outputs :output 1
	    :signal 1)
  (:properties :gmg-function 'gmg-apply-unsatisfied-instruction
	       :gmon-function 'gmon-apply-unsatisfied-instruction
	       :gcfg-function 'gcfg-apply-unsatisfied-instruction
	       :apply-like-p t))


code-blocks.lisp

;;; The FASTCALL-APPLY program graph instruction invokes a loop code block.
(define-program-graph-instruction :fastcall-apply (n-arguments n-results)
  (:inputs :cb-name 1
	   :argument n-arguments
	   :anchor 1)
  (:outputs :result n-results
	    :signal 1)
  (:properties :side-effecting-p t
	       :gmg-function 'gmg-fastcall-apply-instruction
	       :gmon-function 'gmon-fastcall-apply-instruction
	       :gcfg-function 'gcfg-fastcall-apply-instruction
	       ))


;;; The FASTCALL-DEF program graph instruction encloses a loop code block.  The PARAMETER slot
;;; of this instruction holds the code block name.
(define-program-graph-instruction :fastcall-def (n-arguments n-results)
  (:constructor-name make-fastcall-def-instruction-internal)
  (:inputs :result n-results
	   :signal 1)
  (:outputs :argument n-arguments
	    :trigger 1
	    :anchor 1)
  (:blocks :body (:result :signal) (:argument :trigger :anchor))
  (:properties :gmg-function 'gmg-fastcall-def-instruction
	       :gmon-function 'gmon-fastcall-def-instruction
	       :gcfg-function 'gcfg-fastcall-def-instruction
	       :gcfgri-function 'gcfgri-fastcall-def-instruction
	       ))

(defun make-fastcall-def-instruction (cb-name n-arguments n-results)
  (let ((fastcall-def-instruction 
	  (make-fastcall-def-instruction-internal n-arguments n-results)))
    (setf (instruction-parameter fastcall-def-instruction) cb-name)
    fastcall-def-instruction))

@!:
id-io.lisp
(define-@!opcode-instruction file-operation (2 1 :signal-p nil)
  (:properties :gmg-function 'gmg-binary-instruction
	       :gmon-function 'gmon-binary-instruction
	       :side-effecting-p t
	       :strict-p t
 	       ))


-------------------------------------------

Miscellaneous

signal-tree (n: I) 	: Tr^n => Si		(trigger in, signal out)

@!:
gate(2,1)		: Sv x Tr => Sv

record-create 		: I x An => R
make-string(s: S)	: Tr x An => S x Si

---------------------------
Obsolete :

identity 	: ?? => ??
r-shift-32 (1 1)	

Tag manipulation

@!:
adjust-offset-change-tag
change-tag 
adjust-offset 

set-ip 
set-ip-port-l 
set-ip-port-r 

Accumulators (now use put and take)

@!:
accumulator-slot-initialize (2 1)
make-cobj (2 1)
make-count-acd (2 1)
make-boolean-acd (2 1)
initialize-cobj-counter (2 1)
change-accum-function (2 1)
form-accumulator-address(2 1)
get-acd-isd (1 1)
get-acd-cobj (1 1)
address-accumulate 
decrement-cobj-count(2 1)
lock-and-read-accum-slot (1 1)
get-accum-function (1 1)
write-and-unlock-accum-slot 
accum-lower-bound (1 1)
accum-upper-bound (1 1)
