Skip to content

A subset of Go language compiler implemented in TypeScript/Deno that generates LLVM IR.

License

Notifications You must be signed in to change notification settings

danimal141/poor-go

Repository files navigation

PoorGo

A subset of Go language compiler implemented in TypeScript/Deno that generates LLVM IR.

Current Implementation Status

Basic Features

  • Package declaration (package main)
  • Basic program structure
  • String literals
  • Print statement (print("hello"))
  • Integer literals
  • Boolean literals
  • Variables
  • Basic arithmetic operations
  • Functions
  • Control structures

Types

  • String type (basic support)
  • Integer type
  • Boolean type
  • Type checking
  • Type inference

Error Handling

  • Basic syntax error reporting
  • Source location tracking
  • Multiple error reporting
  • Error recovery

Compiler Pipeline

  • Lexical analysis
  • Syntax analysis
  • Semantic analysis
  • LLVM IR generation
  • Native code compilation

Requirements

  • Deno 2.1.0 or later
  • LLVM toolchain (llc, clang)

Installation

  1. Install Deno using asdf:
asdf plugin add deno
asdf install deno 2.1.0
  1. Install LLVM toolchain:
# For macOS
brew install llvm

# For Ubuntu/Debian
apt-get install llvm clang

# For Fedora
dnf install llvm clang

Usage

Compiling PoorGo Programs

The compilation process has two stages:

  1. Use pgo build to compile your PoorGo source files
  2. 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

Command-Line Options

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

Development

# 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

Project Summary Generation

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.

Example

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

Project Structure

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

License

MIT License - see LICENSE for details

About

A subset of Go language compiler implemented in TypeScript/Deno that generates LLVM IR.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published