Skip to content

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

🌋 LavaScript 🌋

A toy programming language and compiler built on top of the Hack Computer

LavaScript translates .ls files into Hack assembly, assembles them into binary, and runs them on a custom CPU emulator that operates on top of the Hack ALU.

Inspired by the legendary Nand2Tetris course, extended with ✨ new features ✨ such as assignments, conditions, loops, character printing, and even a quirky Maybe random condition.

✨ Features

  • 📝 Variables with automatic memory allocation
  • ➕ Arithmetic operators: +, -, *, /
  • 🔀 Logical operators: &, |
  • 🔎 Comparisons: ==, !=, >, <, >=, <=
  • 🔁 Control flow:
    • while loops (supports True, False, and Maybe for random branching)
    • if conditionals
    • for (init; condition; increment) loops
  • 🖨️ Printing:
    • print(x) → print number
    • printc('A') or printc(x) → print ASCII character
  • 🔡 Character literals automatically converted to ASCII codes
  • ⚙️ Compiler → Hack assembly
  • 🛠️ Assembler → machine code
  • 💻 CPU emulator executes the machine code with extended print opcodes:
    • 01 → print number (decimal)
    • 10 → print ASCII character
    • 11 → no print (default, backward compatible)

🚀 Getting Started

Clone the repository, then run:

./melt examples/example.ls
to compile and execute a LavaScript program.

Development

  • Add new syntax → parser.py
  • Implement new operations → compiler.py
  • Update opcode translation → assembler.py
  • Extend CPU behavior → cpu.py

Roadmap

Functions and subroutines

Strings and arrays

Additional operators (like % and logical not)

File I/O

License This project is just for learning and fun. Do whatever you want.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages