Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

jspmarc/Vuck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vuck

Apa itu Vuck? (Dalam bahasa Inggris)

  1. 1D, like brainfuck

  2. The stack's elements are of signed int size (4 byte)

  3. The stack's initially empty. Trying to access the stack/do operations on it will cause the interpreter to error.

  4. Pointer can go sideways only

    • l to move to the right
    • h to move to the left

      The stack grows to the right

  5. We can pop and push values to the stack

    • k<number> to push <number> (growing the stack to the right)
    • j to pop (moving the stack pointer down)

      Pushing or popping will reset the stack to the right (top) of the stack

  6. End of program is denoted by :q

  7. Mathematical operation to the top of stack value is done by:

    • + add the first and the second stack value
    • - subtract the first by the second stack value (e.g. first - second)
    • * multiply the first by the second stack value
    • / divide the first by the second stack value (e.g. first / second)
    • % modulo the first with the second stack value (e.g. first % second)
    • Result of the mathematical operation is pushed onto the stack, then the operands of the stack will be popped from the stack
    • If the number of operands in the stack is not enough, the interpreter will error out
    • Doing any mathematical operation will reset the pointer to the "top" of the stack
  8. The program can read a number from the user and then push it to the stack with i

    This will reset the pointer

  9. The program can read an ASCII and then store it as its integer representation from the user and then push it to the stack with I

    This will reset the pointer

  10. The program can output a number as an unsigned integera with p

  11. The program can output a number as its ASCII value with P

    Only the first byte will be taken out of the 4 byte to print as ASCII.

  12. Loops:

    1. Mark the start of a loop with:
      ,
      
    2. The end of loop is:
      F
      
      • The loop will end if the top of the stack is 0
  13. Conditionals:

  14. Mark the start of the conditional with:

    |
    
  15. Mark the end of the conditional with:

    T
    

Rangkuman

Character Usage notes
h move stack pointer left The stack grows to the right (so top == right)
l move stack pointer right
k<number> pushes <number> to the stack Puts the pointer at the top of the stack
j pops the top of the stack Puts the pointer the the top of the stack
:q marks the end of the program HAVE TO HAVE THIS
+ adds the first and second value on the stack The result is put on top of the stack and resets the pointer
- subtract the first value by the second value The result is put on top of the stack and resets the pointer
* multiply the first and second value of the stack The result is put on top of the stack and resets the pointer
/ divide the first value by the second value The result is put on top of the stack and resets the pointer
% mod of the first value by the second value The result is put on top of the stack and resets the pointer
i read a number and push it onto the stack Resets the pointer
I read a character and push it onto the stack Resets the pointer
p prints the number value of the top of the stack Resets the pointer
P prints the ASCII character of the top of the stack Resets the pointer
, the start of a loop block
F the end of a loop block goes back to , if the top of the stack is not 0
| the start of a conditional block skips to T if the top of the stack is not 0
T the end of a conditional block

Pre-requisite

  1. Rust
    • Rustc
    • Cargo

The program was built and tested on Rust v1.55.0-nightly, but it should work on Rust 2018 stable verison as well since experimental features are not used

Running

Debug

  1. cargo run [path/to/.vuck/script]

With gdb

  1. cargo build
  2. rust-gdb ./target/debug/vuck

Production

  1. cargo build --release
  2. ./target/release/vuck [path/to/.vuck/script]

References

https://craftinginterpreters.com/