Meow is an esoteric language created for fun purposes and this repo contains bytecode interpreter for meow.
mkdir bin
make
meow input.meow
Every meow instruction is 8-bit, first 3 bit represents operation type, last 5 represents operation itself.
Meow instructions are encoded into two parts firstly #m + #e - 2 gives us info about
type of instruction there are 4 types at total:
- V-Type (Operations to manipulate variables)
- A-Type (Arithmetic operations)
- C-Type (Control flow operations)
- S-Type (Operations that makes syscalls like printf)
We use #o + #w - 2 to get information about second part of instruction.
this part specifies which instruction we want ie:
meowis decoded to00000000which is equilevant ofLOAD_CONSTin bytecode.meoowis decoded to00000001which is equilevant ofLOAD_VARin bytecode.meeowis decoded to00100000which is equilevant ofADDin bytecode.mmeeooowwis decoded to01000101which is equilevant ofJGEin bytecode. it is worthy to remindmeoowandmeowwgenerates same instruction.
You can find more information about instruction encodings at src/lut.c.
Here is an example to find nth fibonacci number in meow.
nyan main:
meow 4
meooww ~~n
meow 0
meow 1
meow 0
meooww ~~a
meooww ~~b
meooww ~~tmp
meoww ~~n
meow 0
mmeeow
mmeeooww base
meow 2
meooww ~~it_count
nyan fib_rec:
meoow ~~a
meoow ~~b
meeow
meooww ~~tmp
meoww ~~b
meooww ~~a
meoow ~~tmp
meooww ~~b
meoow ~~it_count
meow 1
mmeow
meooww ~~it_count
meoow ~~it_count
meoow ~~n
mmeeow
meeeooowwwwww fib_rec
mmeeoow fin
nyan base:
meow 0
meeeeow
meeeeoww
nyan fin:
meoww ~~n
meow ". Fibonacci number is "
meeow
meoww ~~b
meeow
meeeeow