Skip to content

Latest commit

Β 

History

History
66 lines (55 loc) Β· 2.28 KB

File metadata and controls

66 lines (55 loc) Β· 2.28 KB

πŸŒ‹ 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
<p>Functions and subroutines</p> <p>Strings and arrays</p> <p>Additional operators (like % and logical not)</p> <p>File I/O</p>
License
This project is just for learning and fun. Do whatever you want.