• Stars
    star
    515
  • Rank 84,011 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

minigo🐥is a small Go compiler made from scratch. It can compile itself.

minigo🐥

Go CircleCI

A Go compiler made from scratch.

Notice

This repository is no longer maintained actively.

I made another Go compiler babygo from scratch again, which is much more simple, sophisticated and understandable.

Please look at https://github.com/DQNEO/babygo

Description

minigo🐥 is a small Go compiler made from scratch. It can compile itself.

  • Generates a single static binary executable
  • No dependency on yacc/lex or any external libraries
  • Standard libraries are also made from scratch

It depends only on GNU Assembler and GNU ld.

minigo supports x86-64 Linux only.

Design

I made this almost without reading the original Go compiler.

minigo inherits most of its design from the following:

There are several steps in the compilation process.

[go source] -> byte_stream.go -> [byte stream] -> token.go -> [token stream] -> parser.go -> [AST] -> gen.go -> [assembly code]

How to run

You need Linux, so I would recommend that you use Docker.

$ docker run --rm -it -w /mnt -v `pwd`:/mnt dqneo/ubuntu-build-essential:go bash

After entering the container, you can build and run it.

$ make
$ ./minigo t/hello/hello.go > hello.s
$ as -o hello.o hello.s
$ ld -o hello hello.o
$ ./hello
hello world

How to "self compile"

$ make
$ ./minigo --version
minigo 0.1.0
Copyright (C) 2019 @DQNEO

$ ./minigo *.go > /tmp/minigo2.s
$ as -o /tmp/minigo2.o /tmp/minigo2.s
$ ld -o minigo2 /tmp/minigo2.o
$ ./minigo2 --version
minigo 0.1.0
Copyright (C) 2019 @DQNEO

$ ./minigo2 *.go > /tmp/minigo3.s
$ as -o /tmp/minigo3.o /tmp/minigo3.s
$ ld -o minigo3 /tmp/minigo3.o
$ ./minigo3 --version
minigo 0.1.0
Copyright (C) 2019 @DQNEO

You will see that the contents of 2nd generation compiler and 3rd generation compiler are identical.

$ diff /tmp/minigo2.s /tmp/minigo3.s

Test

$ make test

Debug by gdb

Add --cap-add=SYS_PTRACE --security-opt='seccomp=unconfined' option to docker run. It will allow you to use gdb in the docker image.

docker run --cap-add=SYS_PTRACE --security-opt='seccomp=unconfined' -it --rm -w /mnt -v `pwd`:/mnt --tmpfs=/tmp/tmpfs:rw,size=500m,mode=1777 dqneo/ubuntu-build-essential:go bash

The Assembly language

We are currently using GNU assembler in AT&T syntax.

https://sourceware.org/binutils/docs/as/i386_002dDependent.html#i386_002dDependent

AUTHOR

@DQNEO

LICENSE

MIT License

More Repositories

1

babygo

babygo👶 is a small Go compiler made from scratch, which can compile itself. It's going to be the smallest and simplest go compiler in the world.
Go
252
star
2

CppTetris

Tetris made within an hour
C++
108
star
3

gojvm

JVM implementation by Go
Go
96
star
4

HowToWriteACompiler

How to write a compiler from scratch in 30 minutes
Go
83
star
5

8cc.go

C compiler written in Go
C
71
star
6

goas

port of GNU Assembler written in go
Assembly
61
star
7

minigit

Reinvention of git
C
25
star
8

Amazon-S3-Thin

A thin, lightweight, low-level Amazon S3 client
Perl
21
star
9

go-build-bash

"go build" implementation by bash script
Shell
21
star
10

Renshu

練習用です。ご自由にforkしてPull Requestを送ってください。↓ 「Git/Github超入門:猿でもできるPull Request」
14
star
11

dotfiles

my dot files (.gitconfig, .emacs, .zshrc, .screenrc ..)
Emacs Lisp
13
star
12

php-skeleton

a skeleton package for modern PHP (>= 7.1)
PHP
11
star
13

php-HelloWorldEnterpriseEdition

HelloWorld Enterprise Edition
PHP
9
star
14

apple-dictionary-parser

Tools for extracting and parsing data from MacOS's dictionary files
Go
6
star
15

Vagrantfile-php7

Vagrantfiles to build and run php7
Shell
6
star
16

go-samples

sample code of golang
Go
6
star
17

ansible-role-php7

6
star
18

gospec-analyzer

Natural language processing of Go Language Specification
HTML
6
star
19

rsolo

rsolo is a simple shell-script which runs chef-solo on remote hosts.
Shell
6
star
20

gospec

Word Wise Go Spec
Makefile
4
star
21

vagrant-chef-remi-php55

Vagrantfile and chef cookbook to install php5.5 by remi-php55 repository
Ruby
3
star
22

c-ltsview

LTSV viewer by C language
C
3
star
23

MakeTutorial

Tutorial of Gnu Makefile
C
3
star
24

splatoon3-random

Splatoon3 random weapon selector
JavaScript
3
star
25

movabletype2hugo

a convert tool for migration from MovableType to Hugo
Perl
3
star
26

Yukiwikimini-on-Ethnam

Yet another implementation of Yukiwikimini
PHP
2
star
27

Kaomoji

Japanese Kaomoji Collection( ˘ω˘)
2
star
28

CTetris

Tetris in C language
C
2
star
29

php-fluent-simplelogger

yet another php library for Fluentd
PHP
2
star
30

ansible-example

Shell
2
star
31

Amazon-S3-FastUploader

a CPAN module
Perl
2
star
32

php-mini

php micro framework
PHP
1
star
33

xrea_cgi

Perl
1
star
34

cwork

C言語入門
C
1
star
35

ethfony

Ethfony is a marriage of Ethna + Symfony
PHP
1
star
36

S3Signer

A PHP library for AmazonS3 direct uploading
JavaScript
1
star
37

knife-solo-renshu

knife soloの練習プロジェクト
Ruby
1
star
38

docker-perlimagemagick

Makefile
1
star
39

ansible-role-nginx

1
star
40

c-curl

sample code of http client using curl
C
1
star
41

cookbook-zsh

Chef cookbook to install zsh from source
Ruby
1
star
42

mt_post

MTにXMLRPCで投稿するスクリプト集
Perl
1
star
43

oxgame

○✗ Game
JavaScript
1
star
44

mt_writer

はてだラ(はてなダイアリライータ)のMT版
CSS
1
star
45

smarty-delimiter-converter

PHP
1
star
46

perl-yaml-tiny-test

YAML::TinyのOSごとの挙動を確認するテスト
Perl
1
star
47

mydiary

Perl製のシンプルなブログシステム
Perl
1
star
48

Assembly

My Assembly sandbox
Assembly
1
star
49

memo

DQNEO's memo
PHP
1
star
50

cookbook-remi

Installs/Configures yum remi and remi-php56 repository
Ruby
1
star
51

voa-reader

JavaScript
1
star
52

php

PHPの雑多なコード集
PHP
1
star
53

go-webapp-example

Go
1
star
54

yourdotfiles

yourdotfiles gathers all your dotfiles.
Ruby
1
star
55

cookbook-tokyotyrant

A Chef CookBook to install TokyoTyrant and TokyoCabinet
Shell
1
star
56

docker-ubuntu

Makefile
1
star