Fraglets Instruction Set, 2007-09-24 ------------------------------------ We present the fraglet instruction set in six sections: 1 core instructions 2 communication and timing 3 logic and arithmetic operations 4 reserved keywords 5 various extensions 6 deprecated 1) Core instructions -------------------------------------------- dup [dup t a tail] --> [t a a tail] duplicate a single symbol exch [exch t a b tail] --> [t b a tail] swap two tags fork [fork a b tail] --> [a tail], [b tail] copy fraglet and prepend different header symbols match [match a tail1], [a tail2] --> [tail1 tail2] two fraglets react, their tails are concatenated matchp [matchp a tail1], [a tail2] --> [matchp a tail1], [tail1 tail2] "catalytic match", i.e. the 'matchp' rule persists nop [nop tail] --> [tail] does nothing (except consuming the instruction tag) nul [nul tail] --> [] destroy a fraglet pop2 [pop2 h t a b tail] --> [h a], [t b tail] pops head element 'a' out of a list 'a b tail'; the result has header tags 'h' and 't', respectively. split [split seq1 * seq2] --> [seq1], [seq2] break a fraglet into two at the first occurence of * 2) Communication and Timing ------------------------------------- broadcast [broadcast seg tail] --> n[tail] all neighbors 'n' attached to 'seg' receceive [tail] delay [delay n tail] --> [tail] (after waiting 'n' time units) remove a fraglet from the pool for some time send [send seg dest tail] --> dest[tail] send [tail] to node 'dest' attached to segment 'seg' [send stdout tail] --> [] [send stderr tail] --> [] as a side effect, the 'tail' is printed to stdout/err 3) Logic and Arithmetic operations ------------------------------ abs [abs tag n tail] --> [tag (|n|) tail] absolute value div [div tag n1 n2 tail] --> [tag (n1/n2) tail] division - fraglet is discarded if 2nd param is 0 empty [empty yes no tail] --> if |tail|==0: [yes] else: [no tail] test for empty tail eq [eq yes no n m tail] --> if n==m: [yes n m tail] else: [no n m tail] length [length t1 tail] --> [t1 |tail| tail] length of fraglet lt [lt yes no n m tail] --> if n [tag (n1 % n2) tail] mult [mult tag n1 n2 tail] --> [tag (n1 * n2) tail] pow [pow tag n1 n2 tail] --> [tag (n1 ^ n2) tail] sub [sub tag n1 n2 tail] --> [tag (n1 - n2) tail] sum [sum tag n1 n2 tail] --> [tag (n1 + n2) tail] 4) Reserved keywords (excluding instructions) ------------------- * separation symbol (for split) stdout special channel for send (for printing to stdout) stderr special channel for send (for printing to stderr) stdin reserved for future use ([receive stdin] to be implemented) out reserved for internal experiments _ (local trigger) reserved for internal experiments __ (double underscore) reserved for internal experiments 5) Various extensions (experimental) ---------------------------- anycast [anycast seg tail] --> n[tail] 'tail' is copied to at most one neighbour copy [copy tail] --> [tail]2 pop [pop h a b c] --> [h b c] # to do: rename this to 'tail' # then create corresponding 'head' printsym [printsym sym tail] --> [tail] prints 'sym' to stdout (for debugging) wait wait 10 cycles; equivalent to [delay 10 ...] [wait a b c] --> ... (after 10 cycles) ... -> [a b c] # to do: wait should be deprecated in favour of the more generic # [delay N ...] splitat splits at the first occurrence of symbol h, which is the symbol following the splitat tag. [splitat | a b c | x y z] --> [a b c], [x y z] newnode dynamic node creation (hierarchically) m[newnode ch n tail] --> a n ch, n[tail] node n is created as a child of node m. the root node is the empty node "": [newnode ch n tail] --> a n ch, n[tail] n is created as a child of the root node (this the default action when creating static nodes via the "attach" 'a node ch' command) inject inject fraglet in child node n1[inject n2 tail] --> n2[tail] (if n2 is a child of n1) expel expel fraglet out of node, to parent n2[expel tail] --> n1[tail] (where n1 is the parent of n2) newname creates a new symbol by concatenating two given symbols [newname tag s1 s2 tail] --> [tag s1s2 tail] 6) Deprecated instructions and keywords ------------------------- diff was abs(n1-n2) because integer numbers didn't have sign. now numbers have sign, so the old 'diff' is superseeded by 'sub' and 'abs' # eof