Getting Started
Learn how to install TinyLang, write your first program, and explore the development tools.
Installation
Prerequisites
- Node.js 18+ (Node.js 22 recommended)
- npm (comes with Node.js)
Install from Source
# Clone the repository
git clone https://github.com/tinylang/tinylang.git
cd tinylang
# Install dependencies
npm install
# Build the project
npm run build
# Run a program
node dist/cli/index.js run examples/01-hello.tiny
Global Installation (Optional)
# Link globally for the `tinylang` command
npm link
# Now you can use tinylang directly
tinylang run examples/01-hello.tiny
If you do not install globally, replace tinylang with node dist/cli/index.js in all examples below.
Your First Program
Create a file called hello.tiny:
// hello.tiny
print("Hello, World!")
let name = "TinyLang"
print("Welcome to " + name + "!")
Run it:
tinylang run hello.tiny
Output:
Hello, World!
Welcome to TinyLang!
Project Scaffolding
Use tinylang init to create a new project with all the standard files:
tinylang init my-project
cd my-project
This creates:
| File | Purpose |
|---|---|
main.tiny | Entry point for your program |
lib.tiny | Library module with shared functions |
main.test.tiny | Test file for your code |
.tinylang.json | Formatter and linter configuration |
README.md | Project documentation |
Running Programs
Interpreter (Default)
The default execution mode uses a tree-walk interpreter:
tinylang run main.tiny
Compile and Execute
For better performance, compile to bytecode and run on the VM:
# Compile to bytecode
tinylang compile main.tiny
# Execute the compiled bytecode
tinylang exec main.tinyc
View Disassembly
See the generated bytecode instructions:
tinylang compile main.tiny --disassemble
Using the REPL
Start an interactive session to experiment with TinyLang:
tinylang repl
Example REPL session:
TinyLang REPL v1.0.0
Type expressions or statements. Use Ctrl+C to exit.
> let x = 42
> x * 2
84
> fn square(n) { return n * n }
> square(7)
49
> [1, 2, 3].map((x) => x * 2)
[2, 4, 6]
Using the Web IDE
TinyLang includes a full-featured Web IDE (in the playground/ directory) that runs entirely in the browser. It features:
- CodeMirror editor with syntax highlighting
- AST Viewer to inspect the parse tree
- Debugger with step-through execution
- Multiple example programs to load and experiment with
- Bytecode disassembly viewer
To use the Web IDE, simply open playground/index.html in your browser.
Development Workflow
A typical TinyLang development workflow:
# 1. Write code
tinylang init my-app
cd my-app
# 2. Run and iterate
tinylang run main.tiny
# 3. Format your code
tinylang fmt --write main.tiny
# 4. Check for issues
tinylang lint main.tiny
# 5. Run tests
tinylang test
# 6. Check syntax without executing
tinylang check main.tiny
# 7. Debug if needed
tinylang debug main.tiny
# 8. Benchmark performance
tinylang bench main.tiny --compare