Hi all,
Here is my most recent 16 instruction set for concatenative hardware.
Any comments would be greatly appreciated.
/*
* Released into the public domain by Christopher Diggins
* Contact me if you have special licensing requirements
*
http://www.cdiggins.com */
enum
{
/* Push a literal value from the instruction stream */
LIT = 0, /* -> a */
/* Add top two values on the stack */
ADD = 1, /* a b -> (a + b) */
/* Shift second value on the stack left or right */
SHIFT = 2, /* a b -> b < 32 ? (a >> b) : (a << (b - 32)) */
/* Perform exclusive or of top two values */
XOR = 3, /* a b -> (a ^ b) */
/* Perfrom bitwise and of top two values */
AND = 4, /* a b -> (a & b) */
/* Dynamic function/list construction */
/* Note: lists and functions are identical from a programmer's perspective,
a list is the result of a function that consumes nothing. Think of it
as a new stack yielded by executing the function, except that it is
lazy (evaluated at last minute) */
PAPPLY = 5, /* a [X] -> [a X] */
COMPOSE = 6, /* [X] [Y] -> [X Y] */
/* Branching and calling */
APPLYIF = 7, /* bool [X] -> X or NOOP */
/* Reference creation and manipulation, used for playing with heap */
MAKEREF = 8, /* a -> &a */
GETREF = 9, /* &a -> a */
SETREF = 10, /* &a b -> &(*a = b) */
/* Stack manipulation operations */
FLIP = 11, /* a X b n:int -> b X a ; sizeof(X) == n */
GETN = 12, /* a X n:int -> (a X, a) ; sizeof(X) == n */
SETN = 13, /* (a X n:int, b) -> b X ; sizeof(X) == n */
/* Applies a function to a list */
APPPLYTO = 14, /* [->X] [X->Y] => [Y] */
/* Make a suggestion ( I was thinking of COUNT, but I
am not so sure ) */
UNUSED = 15
}
opcodes;
/*
Some examples of derived opcodes:
SWAP = 0 FLIPN
DUP = 0 GETN
POPD = 0 SETN
POP = SWAP POPD
QUOTE = [] CONS
APPLY = TRUE SWAP APPLYIF
CONS = SWAP QUOTE PAPPLY
UNCONS = APPLY SWAP
DIP = SWAP QUOTE COMPOSE APPLY
*/
Christopher Diggins
http://www.cat-language.com