Skip to content
/ lamp Public

Minecraft CarpetMod standalone turing-complete vanilla command-block array-based CPU generator

Notifications You must be signed in to change notification settings

kvbc/lamp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Lamp

Minecraft CarpetMod standalone turing-complete vanilla command-block array-based CPU generator

The generator is written in scarpet using CarpetMod
Assembly is written in JSON so maybe one day, with enough instructions, it would be possible to transpile LUA's bytecode to it. Which would be the ultimate goal of this project

The assembly language is array-based and it provides

  • basic stack manipulation instructions (push and pop instructions)
  • primitive usage of "variables" (get and set instructions)
  • basic arithmetics (add and sub instructions)
  • conditional jumps
  • subroutines


The ALU (Arithmetic Logic Unit) in action

Sections

Synopsis

The first 10 fibonacci numbers - Video Showcase

jmp main
lbl loop
  pop //get 0
  add
  get 0 //10
  push 1
  sub
  set 0
  pop
  pop
  jnz loop
lbl main
  push 10
  push 1
  push 1
  push 69 //dummy for 1st pop in :loop
  jmp loop

Instruction Set

  • number[0-9]+
  • char'.'
  • name[_a-zA-Z][_a-zA-Z0-9]*
  • value — Either number, char or name (constant)
  • idxvalue, 0-based index from the bottom of the stack
  • [...] - optional argument, if not present, taken from the stack
  • A - top value on the stack
  • B - second-top value on the stack

Memory manipulation

Instruction Description
push value Push value onto the top of the stack
pop Discard the top element of the stack
📝 No other instruction can pop a value off the stack
get [idx] Push element at idx onto the top of the stack
set [idx] [value] Set element at idx to value

Control flow

Instruction Description
lbl name Define a new label of ID name
call name Call the subroutine at label name
ret Return from the current subroutine
jmp name Jump to label name
je name Jump to label name if A == B
jne name Jump to label name if A != B
jg name Jump to label name if A > B
jge name Jump to label name if A >= B
jl name Jump to label name if A < B
jle name Jump to label name if A <= B
jz name Jump to label name if A == 0
jnz name Jump to label name if A != 0

Arithmetic

Instruction Description
add Push A + B
sub Push A - B

TO-DO

  • Clean up the scarpet code
  • Clean up this readme
  • Actually handle char cuz I don't think it's working
  • Make conditional jumps pop off their As and Bs
  • Create a const instruction for setting constants
  • Create an idx instruction that pushes the top index
  • Create mul and div instructions for multiplication and division
  • Perhaps create a del instruction that would remove an element at a specified index
  • Perhaps create a put instruction that would place a specified block at the given x y z coordinates (good luck with that)

About

Minecraft CarpetMod standalone turing-complete vanilla command-block array-based CPU generator

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages