WARNING: float
is imprecise, and shortly I will be moving everything over to bignum. Large numbers will come out incorrect! (ex. 170 factorial)
gecho is somewhat similar to FORTH. It will probably become less so as it grows.
- compile with
sudo make do-all CC=<compiler of choice> INAME=<what you want gecho to be called> CNAME=<what you want gechoc to be called>
- CC defaults to
cc
and INAME/CNAME default togecho
andgechoc
, respectively
- CC defaults to
OR
sudo make CC=<compiler of choice>
- Just compiles.
make CC=<compiler of choice>
- You can use whatever C compiler you want, defaults to
cc
- You can use whatever C compiler you want, defaults to
sudo make install
.- Moves it to
/usr/bin/
.
- Moves it to
sudo make go CC=<compiler of choice>
- Just makes and cleans up and moves it to
/usr/bin/
for you. Compiler defaults tocc
.
- Just makes and cleans up and moves it to
sudo make do-all CC=<compiler of choice>
- Compiles and installs both interpreter and compiler. Compiler defaults to
cc
.
- Compiles and installs both interpreter and compiler. Compiler defaults to
Think of a stack of books. It starts off empty.
[ ]
However, when you put (or push
) a book (number) onto the stack, it gets added to the top.
[ 12 ]
Keep adding numbers, and it will soon look like this.
[ 12, 4, 8, 3 ]
Note that 3
is at the top of the stack, and 12
is at the bottom.
One can also take off (or pop
) elements from the stack.
[ 12, 4, 8 ]
3.00
The number gets returned as a result of popping it.
Operands can pop numbers from the stack and interact with them. For example,
dels 1 2 +
would clear the stack, push 1
, then push 2
, then pop them both and add them. It will then push the result onto the stack. The stack now looks like this:
[ 3 ]
That's stack theory.
-
SHELL
- just run
gecho
(or./gecho
)
- just run
-
FILE READ
- run
gecho -f <filename>
(or./gecho -f <filename>
)
- run
-
FILE READ THEN SHELL
- run
gecho -sf <filename>
(or./gecho -sf <filename>
)
- run
-
COMPILE GECHO
- run
gechoc <filename>
- run
<compiler of choice> <filename> -o <filename> -lm
- run
<filename>
- run
+
- Pops two elements from the stack, adds them together, and pushes the result.
++
- Pops all the elements from the stack and adds them together; pushes result.
.
- Prints the top element in the stack.
*
- Pops two elements from the stack, multiplies them, and pushes the result.
dels
- Pops all elements from the stack.
show
- Pretty prints the stack.
dup
- Pushes a copy of the top element of the stack.
swap
- Pops two elements from the stack, and pushes back in each other's places.
-
- Pops two elements from the stack, subtracts the upper from the lower, and pushes the result.
jump
- Pops an element from the stack (a) and prints stack[a]
range
- Pops two elements from the stack (a, b) and prints range(b, a); starts at b, increments by one until a, pushes the array onto the stack.
<num>
- Pushes
<num>
to the stack.
- Pushes
**
- Pops all the elements from the stack and multiplies them; pushes result.
!<varnum>
- Pop element from stack; set
variables[<varnum>]
to popped value.
- Pop element from stack; set
&<varnum>
- Push
variables[<varnum>]
to the stack.
- Push
wover
- a = pop(); b = pop(); push(b); push(a); push(b);
- ( a1 a2 -- a1 a2 a1)
drop
||pop
- Pop top element from stack, show value.
top
- Push the index of the top of the stack to the stack.
outascii
- Pop top element of stack and print ASCII character that corresponds to decimal.
print
- Pop all elements of stack and prints ASCII characters that correspond to decimal.
/
- Pop top two elements from stack; divide lower element by upper element.
@<mode>
- Toggles
<mode>
.
- Toggles
mode
- Prints a list of all enabled modes.
modes
- Prints all modes, complete with 'enabled' flag.
tot
- For use with
@tracker
. Prints number of commands so far. Does not count as a command.
- For use with
reset
- Resets the command count. For use with
@tracker
. Does not count as a command.
- Resets the command count. For use with
tan
- Pops one element from the stack (degrees!) computes
tan(x)
- Pops one element from the stack (degrees!) computes
sin
- Pops one element from the stack and computes
sin(x)
- Pops one element from the stack and computes
cos
- Pops one element from the stack and computes
cos(x)
- Pops one element from the stack and computes
pow
- a = pop(); b = pop(); push(b^a);
mod
- a = pop(); b = pop(); push(b%a);
read
- Reads user input. Only really useful with file reading/compiling. Pops one element from the stack and reads that number of numbers, and pushes them to the stack.
<
- b = pop(); a = pop(); push(
a < b
);
- b = pop(); a = pop(); push(
>
a > b
>=
a >= b
<=
a <= b
=
a == b
'<word>
- Push each character of
<word>
onto the stack.
- Push each character of
<>
- Push ' ' to the stack.
and
- Push
a && b
to the stack.
- Push
or
- Push
a || b
to the stack.
- Push
nil
- Does absolutely nothing.
next
- Moves to the next stack (out of 3). Starts at stack 0.
back
- Moves one stack back (out of 3) in a cycle. If it goes past 0, it will cycle to stack 3.
mv
- Moves the top element from the current stack to the next stack. To COPY, use
dup mv
.
- Moves the top element from the current stack to the next stack. To COPY, use
transparent
- Shows the stack after every command.
default
- Regular interpreter settings.
tracker
- After being enabled, counts the commands entered. Can be viewed with
tot
.
- After being enabled, counts the commands entered. Can be viewed with
#t
==#true
1
#f
==#false
0
#pi
- the value
pi
- the value
#e
- the value
e
- the value
#phi
- the value
phi
- the value
-f
- Input file to compile/read. Must come after another flag. (e.g.
-fs
won't work but-sf
will)
- Input file to compile/read. Must come after another flag. (e.g.
-e
- Skip the version and "bye" message. If passing something to gecho, end it with "exit" so it doesn't evaluate endlessly.
-v
- Just print the version information.
-s
- Can enter shell mode after evaluating the file. Also suppresses the version and package name.
-
1 2 3 + .
==5
-
1 2 3 ++ .
==6
-
1 2 3 * .
==6
-
1 2 3 4 dels show
==[ ]
-
1 2 dup show
==[ 1, 2, 2 ]
-
1 2 - .
==-1
-
0 10 range 3 jump
==4
-
1 5 range ** .
==120
- Factorial :)
-
3 4 5 ++ !1
==None
- Doesn't return anything; sets
globals[1]
to the sum of3, 4, 5
- Doesn't return anything; sets
-
0 1 dup wover + dup wover + dup wover + show
==[ 1, 1, 2, 3, 5 ]
- Fibonacci :)
-
1 2 3 4 show drop show
==[1, 2, 3, 4], [1, 2, 3]
-
1 2 3 top .
==2
-
1 2 / .
==0.5
-
@transparent
== shows stack after every command -
45 tan .
==1.00
-
#pi 2 * cos .
==0.99
(truncated, not rounded) -
3 read
== reads 3 numbers and pops them to the stack -
15 5 + 10 dup + = #t = .
==((15+5) == (10+10)) == #t
? -
'Hello, <> 'world! print
==Hello, world!
-
1 2 + show next 3 4 + show back mv + show
=> Adds 1+2 on the first stack, shows it, adds 3+4 on the next stack, shows it, moves the top item on the first stack to the second stack, then adds 7 and 3 together to make 10.