All Projects → DQNEO → Babygo

DQNEO / Babygo

Licence: mit
Go compiler made from scratch, which can compile itself. It's going to be the smallest and simplest go compiler in the world.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Babygo

Wag
WebAssembly compiler implemented in Go
Stars: ✭ 177 (+23.78%)
Mutual labels:  compiler, x86-64
Dora
Dora VM
Stars: ✭ 371 (+159.44%)
Mutual labels:  compiler, x86-64
Minijit
A basic x86-64 JIT compiler written from scratch in stock Python
Stars: ✭ 185 (+29.37%)
Mutual labels:  compiler, x86-64
Crust
C compiler toolchain in Rust. [WIP, early development stage]
Stars: ✭ 150 (+4.9%)
Mutual labels:  compiler, x86-64
Mir
A light-weight JIT compiler based on MIR (Medium Internal Representation)
Stars: ✭ 1,075 (+651.75%)
Mutual labels:  compiler, x86-64
Ppci
A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python
Stars: ✭ 210 (+46.85%)
Mutual labels:  compiler, x86-64
Asmjit
Machine code generation for C++
Stars: ✭ 2,874 (+1909.79%)
Mutual labels:  compiler, x86-64
Mazucc
A minimalist C compiler with x86_64 code generation
Stars: ✭ 437 (+205.59%)
Mutual labels:  compiler, x86-64
Mlml
self-hosted compiler for a subset of OCaml
Stars: ✭ 41 (-71.33%)
Mutual labels:  compiler, x86-64
Dynarmic
An ARM dynamic recompiler.
Stars: ✭ 475 (+232.17%)
Mutual labels:  compiler, x86-64
Pyast64
Compile a subset of the Python AST to x64-64 assembler
Stars: ✭ 93 (-34.97%)
Mutual labels:  compiler, x86-64
Jit Compiler
JIT compiler in Go
Stars: ✭ 70 (-51.05%)
Mutual labels:  compiler, x86-64
Peachpy
x86-64 assembler embedded in Python
Stars: ✭ 1,592 (+1013.29%)
Mutual labels:  compiler, x86-64
Asmtk
Assembler toolkit based on AsmJit
Stars: ✭ 131 (-8.39%)
Mutual labels:  x86-64
Tendra
The TenDRA Project
Stars: ✭ 134 (-6.29%)
Mutual labels:  compiler
Instapack
All-in-one TypeScript and Sass compiler for web applications! 📦 🚀
Stars: ✭ 131 (-8.39%)
Mutual labels:  compiler
Jphp
JPHP - an implementation of PHP on Java VM
Stars: ✭ 1,665 (+1064.34%)
Mutual labels:  compiler
R9cc
Toy C compiler
Stars: ✭ 139 (-2.8%)
Mutual labels:  compiler
Koto
A simple, expressive, embeddable programming language, made with Rust
Stars: ✭ 134 (-6.29%)
Mutual labels:  compiler
Ocaml Protoc
A Protobuf Compiler for OCaml
Stars: ✭ 129 (-9.79%)
Mutual labels:  compiler

Babygo, a go compiler made from scratch

Test

Babygo is a small and simple go compiler. (Smallest and simplest in the world, I believe.) It is made from scratch and can compile itself.

  • No dependency to any libraries. Standard libraries and calling of system calls are home made.
  • Lexer, parser and code generator are hand written.
  • Emit assemble code which resutls in a single static binary.

It depends only on as as an assembler and ld as a linker.

It is composed of only a fiew files.

  • main.go - the main compiler
  • runtime.s - low level of runtime
  • src/ - internal packages
  • lib/ - libraries

Design

Lexer, Parser and AST

The design and logic of ast, lexer and parser are borrowed (or should I say "stolen") from go/ast, go/scanner and go/parser.

Code generator

The design of code generator is borrowed from chibicc , a C compiler.

Remaining parts (Semantic analysis, Type management etc.)

This is purely my design :)

Environment

It supports x86-64 Linux only.

If you are not using Linux, you can use a dedicated docker image for this project.

$ docker pull dqneo/ubuntu-build-essential:go
$ ./docker-run

Usage

Hello world

# Build babygo
$ go build -o babygo *.go

# Compile the hello world program by babygo
$ ./babygo t/hello.go > /tmp/hello.s

# Assemble and link
$ as -o hello.o /tmp/hello.s runtime.s
$ ld -e _rt0_amd64_linux -o hello hello.o

# Run hello world
$ ./hello
hello world!

How to do self hosting

# Build babygo (1st generation)
$ go build -o babygo *.go

# Build babygo by babygo (2nd generation)
$ ./babygo *.go > /tmp/babygo2.s
$ as -o babygo2.o /tmp/babygo2.s runtime.s
$ ld -e _rt0_amd64_linux  -o babygo2 babygo2.o # 2nd generation compiler

# Assert babygo2.s and babygo3.s are exactly same
$ ./babygo2 *.go > /tmp/babygo3.s
$ diff /tmp/babygo2.s /tmp/babygo3.s

Test

$ make test

Reference

License

MIT

Author

@DQNEO

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].