SSBPL

From Esolang
Jump to navigation Jump to search

SSBPL(Simple Stack Based Programming Lamguage) is untyped and stack based programming language by user User:EzoLang.

CMD STACK EXPLANATION
[x] (--l) Push pointer to lambda l with code x
+ (n1 n2--n) Push n1+n2
- (n1 n2--n) Push n1-n2
* (n1 n2--n) Push n1*n2
/ (n1 n2--n) Push n1/n2
% (n1 n2--n) Push n1 mod n2
! (l--) Execute lambda at address l
? (n l--) If n is nonzero then execute lambda at address l
# (l1 l2--) Repeat l2 while top of stack after l1 is nonzero
& (n1 n2--n) Push n1&n2
| (n1 n2--n) Push n1|n2
^ (n1 n2--n) Push n1 xor n2
_ (n--n) Push !n1
123 (--n) Push number
'c (--n) Push ascii of c
@ (p--x1..xn) Push data from address of pointer p and free memory at address of p
\ (x1..xn n--p) Pop n levels of stack to address of pointer p and push pointer p
. (n--) Output n as char
, (--n) Push ascii of inputted char
; (n--n) (--n) Store top of stack and after exiting push strored value
= (x1 x2--n) Push x1==x2
< (x1 x2--n) Push x1<x2
> (x1 x2--n) Push x1>x2
: (n--) Pop
$ (n--n n) Push copy of n
~ (n1 n2--n2 n1) Swap positions of two topmost stack items
(x) (--) Comment
a..z (--p) Push pointer to variable a..z
` (n p--) Store and pop 1 level of stack to address of pointer p
" (p--n) Load 1 word of data from address of pointer p

When function exits it returns to address at the top of stack so stack is like return stack in forth. If there is something in stack when lambda is executed then top of stack before lambda execution is popped and pushed to stack after return addresses. Whitespace is used to separate two numbers from each other. &, |, ^ and _ are bitwise operators. =,< and > return true or false with 0 as false and 65535 as true. Everything in stack is 16bit. Variables a..z are global.0

Examples

Fibonacci sequence

0a`1b`1 (Put 0 to a, 1 to b and 1 to top of stack)
[10<;:] (Is number on the top of the stack smaller than 10?)
[a"b"+ (Load a and b and then add them together)
b"a` (Load b and store it to a)
$b` (Duplicate and store to b)
$'0+. (Duplicate, convert to ascii and output)
;:] (Save result for smaller than 10 check, pop it and exit lambda)
# (loop)

Hello, world!

'H.'e.'l$..'o.',.' .'w.'o.'r.'l.'d.'!.