Git Product home page Git Product logo

lamp's Introduction

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)

lamp's People

Contributors

kvbc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.