Giter Site home page Giter Site logo

quan8 / minigo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dqneo/minigo

0.0 1.0 0.0 2.2 MB

A small Go compiler written from scratch. It can compile itself. The goal is to be the most easy-to-understand Go compiler.

License: MIT License

Go 94.04% Makefile 0.56% Shell 1.44% C 0.89% Assembly 3.07%

minigo's Introduction

Minigo

CircleCI

A Go compiler from scratch.

Description

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

  • No dependency on yacc/lex
  • No dependency on external libraries
  • Standard libraries are also made from scratch.

It depends only on gcc as an assembler and linker, and on libc as a runtime.

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 followings.

There are several steps in the compilation proccess.

[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 > a.s
$ gcc -g -no-pie a.s
$ ./a.out
hello world

How to "self compile"

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

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

$ ./minigo2 *.go > /tmp/minigo3.s
$ gcc -no-pie -o minigo3 /tmp/minigo3.s
$ ./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

AUTHOR

@DQNEO

LICENSE

MIT License

minigo's People

Contributors

dqneo avatar wayneashleyberry avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.