A subset of Go language compiler implemented in TypeScript/Deno that generates LLVM IR.
- Package declaration (
package main
) - Basic program structure
- String literals
- Print statement (
print("hello")
) - Integer literals
- Boolean literals
- Variables
- Basic arithmetic operations
- Functions
- Control structures
- String type (basic support)
- Integer type
- Boolean type
- Type checking
- Type inference
- Basic syntax error reporting
- Source location tracking
- Multiple error reporting
- Error recovery
- Lexical analysis
- Syntax analysis
- Semantic analysis
- LLVM IR generation
- Native code compilation
- Deno 2.1.0 or later
- LLVM toolchain (llc, clang)
- Install Deno using asdf:
asdf plugin add deno
asdf install deno 2.1.0
- Install LLVM toolchain:
# For macOS
brew install llvm
# For Ubuntu/Debian
apt-get install llvm clang
# For Fedora
dnf install llvm clang
The compilation process has two stages:
- Use
pgo build
to compile your PoorGo source files - The compiler generates an executable file
# Basic compilation
bin/pgo build source.pgo
# Specify output file
bin/pgo build -o program source.pgo
# Show compilation process
bin/pgo build --verbose source.pgo
# Output LLVM IR
bin/pgo build --emit-llvm source.pgo
Usage: pgo build [options] <source-file>
Options:
-o, --output <file> Output file name (default: a.out)
--emit-llvm Output LLVM IR
--verbose Show compilation process
-O<level> Optimization level (0-3)
-h, --help Show this help message
# Run tests
deno task test
# Watch tests
deno task test:watch
# Check types
deno task check
# Format code
deno task fmt
# Lint code
deno task lint
# Generate project summary
python generateprojectsummary.py
The project includes a Python script to generate a comprehensive project summary, useful for documentation and sharing. This summary includes:
- Directory structure
- File contents
- Important code sections
- Tests and examples
To generate the summary:
python generateprojectsummary.py
This will create a summary that can be easily shared with others or used for documentation purposes.
Create a file hello.pgo
:
package main
func main() {
print("hello")
}
Compile and run:
deno task compile # -> `pgo` command is created
bin/pgo build hello.pgo
./a.out # Outputs: hello
poor-go/
├── main.ts # Compiler entry point
├── src/
│ ├── lexer/ # Lexical analysis
│ ├── parser/ # Syntax analysis
│ ├── semantic/ # Semantic analysis
│ ├── codegen/ # LLVM IR generation
│ └── compiler/ # Compilation pipeline
├── examples/ # Example programs
└── README.md
MIT License - see LICENSE for details