How alissonbrunosa/iracema works
Project type and purpose
• This is a language implementation project (named “Iracema”) written in Go.
• It provides a compiler and bytecode‐based interpreter for a small object‐oriented scripting language.
• Key features: Lexer, Parser, AST, a compiler that emits bytecode, and a virtual machine/ interpreter with built-in types and functions.
File structure
• Top-level
• cmd/iracema: entry point (CLI)
• lexer/: lexical analyzer
• parser/: produces an AST from tokens
• ast/: AST node definitions
• compile/: backend, IR optimization, bytecode emitter, disassembler
• bytecode/: opcode definitions and string representations
• interpreter/: virtual machine, stack frames, bytecode execution
• lang/: standard library, built-in types (objects, methods, utils)
• token/: token types and position tracking
• examples/: sample .ir programs
• c/: unrelated C-language parser/lexer in C (likely experimental or comparison)
README for additional insights
• README shows sample Iracema syntax and operators.
• Confirms this is a full compiler+VM pipeline in Go 1.17+.
a. Main components
• CLI Frontend (cmd/iracema)
• Lexer (lexer package)
• Parser & AST (parser + ast packages)
• Compiler Backend (compile package)
• Bytecode Format (bytecode package)
• Virtual Machine / Interpreter (interpreter package)
• Runtime & Standard Library (lang package)
• Token definitions (token package)
• Example inputs (examples/*.ir)
b. Relationships & data flow
1. User invokes CLI →
2. CLI reads source file & hands it to Lexer →
3. Lexer emits Token stream →
4. Parser consumes tokens → constructs AST nodes →
5. Compiler walks AST → builds basic blocks/IR → emits Bytecode →
6. Interpreter loads bytecode → executes on its VM (Frame, Stack) →
7. Interpreter invokes built-in functions/objects in lang package →
8. Output to stdio (e.g. puts())
c. Architectural patterns & design principles
• Pipeline architecture: front end (lex/parse/AST) → middle end (IR/opt) → back end (bytecode emitter/VM)
• Visitor/pattern matching in AST and compiler (match_helpers_test.go)
• Separation of concerns: each package has a single responsibility
• Test-driven: almost every package has its own *_test.go
d. Key technologies
• Go modules (go.mod)
• Go 1.17+
• Command-line binary (cmd/iracema)
• Optional disassembler tool (compile/disassemble.go)