You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
STABLE is an extremely minimalistic "Forth-like" (but not Forth) language by Sandor Schneider.
Originally in C, I have ported it to Typescript to explore what can be done with the one of the world's smallest viable programming languages.
STABLE stands for STAck Bytecode Language & Engine and the original implementation is only about 233 lines of formatted C code and much shorter if all the whitespace is removed.
selected register contains an address. Fetch value from there
!
( value --)
selected register contains an address. Store value there.
-
( -- )
immediately after register, increment content by 1
*
( -- )
immediately after register, decrement content by 1
Functions
opcode
stack effects
description
{X
( -- )
start function definition for function X (A..Z)
}
( -- )
end of function definition
X
( -- )
call function X (A..Z)
I/O
opcode
stack effects
description
.
(value -- )
display value as decimal number on stdout
,
(value -- )
send value to terminal, 27 is ESC, 10 is newline, etc.
^
( -- key)
read key from terminal, don't wait for newline.
"
( -- )
read string until next '"' put it on stdout
0..9
( -- value)
scan decimal number until non digit. to push two values on stack separate those by space (4711 3333). to enter negative numbers call _ (negate) after the number
0..9.0
( -- value)
to enter float numbers digits must contain one '.' (only available if float module is active, see 0`)
Conditionals
opcode
stack effects
description
<
(a b -- f)
true (-1) if b is < a, false (0) otherwise
>
(a b -- f)
true (-1) if b is > a, false (0) otherwise
=
(a b -- f)
true (-1) if a is equal to b, false (0) otherwise
(
(f -- )
if f is true, execute content until ), if false skip code until ')'
[
(f -- f)
begin while loop only if f is true. keep flag on stack if f is false, skip code until ']'
]
(f --)
repeat the loop if f is true. If f is false continue with code after ']'