100 lines
1.7 KiB
Plaintext
100 lines
1.7 KiB
Plaintext
# std contains misc useful procedures and variables
|
|
# that make working in felise easier, but are coded
|
|
# in felise itself, rather than as built-in procs
|
|
# writen in go
|
|
|
|
STRING var! stdout
|
|
"/dev/fd/1" set! stdout
|
|
|
|
STRING var! stderr
|
|
"/dev/fd/2" set! stderr
|
|
|
|
STRING var! stdin
|
|
"/dev/fd/0" set! stdin
|
|
|
|
STRING var! devnull
|
|
"/dev/null" set! devnull
|
|
|
|
proc print
|
|
| Stack: ANY
|
|
Read :
|
|
Push :
|
|
Notes: Prints the value on TOS |
|
|
STRING cast stdout file-write
|
|
.
|
|
|
|
proc println
|
|
| Stack: ANY
|
|
Read :
|
|
Push :
|
|
Notes: Prints the value on TOS + a newline |
|
|
STRING cast "\n" append stdout file-write
|
|
.
|
|
|
|
|
|
proc! ++!
|
|
| Stack:
|
|
Read : SYMBOL(INT)
|
|
Push :
|
|
Notes: Incremens the value stored in the given var |
|
|
procarg TYPE cast INT =
|
|
if
|
|
procarg 1 + set! procarg
|
|
else
|
|
"`++!` expects the given SYMBOL to represent an INT variable" throw
|
|
.
|
|
.
|
|
|
|
proc ++
|
|
| Stack: INT
|
|
Read :
|
|
Push : INT
|
|
Notes: Increments an INT on TOS and places the result back on TOS |
|
|
dup TYPE cast INT =
|
|
if
|
|
1 +
|
|
else
|
|
TYPE cast
|
|
"`++` expects the TOS to represent an INT variable, but found "
|
|
swap append throw
|
|
.
|
|
.
|
|
|
|
proc! --!
|
|
| Stack:
|
|
Read : SYMBOL(INT)
|
|
Push :
|
|
Notes: Incremens the value stored in the given var |
|
|
procarg TYPE cast INT =
|
|
if
|
|
procarg 1 - set! procarg
|
|
else
|
|
"`--!` expects the given SYMBOL to represent an INT variable" throw
|
|
.
|
|
.
|
|
|
|
proc --
|
|
| Stack: INT
|
|
Read :
|
|
Push : INT
|
|
Notes: Decrements an INT on TOS and places the result back on TOS |
|
|
dup TYPE cast INT =
|
|
if
|
|
1 -
|
|
else
|
|
TYPE cast
|
|
"`--` expects the TOS to represent an INT variable, but found "
|
|
swap append throw
|
|
.
|
|
.
|
|
|
|
proc not
|
|
| Stack: ANY
|
|
Read :
|
|
Push : BOOL
|
|
Notes: Treats TOS as a BOOL (regardless of actual type) and inverts the BOOL |
|
|
if false else true .
|
|
.
|
|
|
|
|