All Projects → DQNEO → Minigo

DQNEO / Minigo

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

Programming Languages

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

Projects that are alternatives of or similar to Minigo

Cub
The Cub Programming Language
Stars: ✭ 198 (-56.58%)
Mutual labels:  compiler, lexer, parser
Snapdragon
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Stars: ✭ 180 (-60.53%)
Mutual labels:  compiler, lexer, parser
Tiny Compiler
A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example
Stars: ✭ 425 (-6.8%)
Mutual labels:  compiler, lexer, parser
Exprtk
C++ Mathematical Expression Parsing And Evaluation Library
Stars: ✭ 301 (-33.99%)
Mutual labels:  compiler, lexer, parser
Lioness
The Lioness Programming Language
Stars: ✭ 155 (-66.01%)
Mutual labels:  compiler, lexer, parser
Charly Vm
Fibers, Closures, C-Module System | NaN-boxing, bytecode-VM written in C++
Stars: ✭ 66 (-85.53%)
Mutual labels:  compiler, lexer, parser
Xdpw
XD Pascal: A small embeddable self-hosting Pascal compiler for Windows. Supports Go-style methods and interfaces
Stars: ✭ 199 (-56.36%)
Mutual labels:  compiler, parser
Saltwater
A C compiler written in Rust, with a focus on good error messages.
Stars: ✭ 219 (-51.97%)
Mutual labels:  compiler, parser
Re Flex
The regex-centric, fast lexical analyzer generator for C++ with full Unicode support. Faster than Flex. Accepts Flex specifications. Generates reusable source code that is easy to understand. Introduces indent/dedent anchors, lazy quantifiers, functions for lex/syntax error reporting, and more. Seamlessly integrates with Bison and other parsers.
Stars: ✭ 274 (-39.91%)
Mutual labels:  compiler, lexer
Swc
swc is a super-fast compiler written in rust; producing widely-supported javascript from modern standards and typescript.
Stars: ✭ 18,627 (+3984.87%)
Mutual labels:  compiler, parser
Pyverilog
Python-based Hardware Design Processing Toolkit for Verilog HDL
Stars: ✭ 267 (-41.45%)
Mutual labels:  compiler, parser
Tinyrb
A tiny subset of Ruby with a Lua'esc VM
Stars: ✭ 452 (-0.88%)
Mutual labels:  compiler, parser
Craftinginterpreters
Repository for the book "Crafting Interpreters"
Stars: ✭ 4,298 (+842.54%)
Mutual labels:  compiler, parser
Syntax Parser
Light and fast 🚀parser! With zero dependents. - Sql Parser Demo added!
Stars: ✭ 317 (-30.48%)
Mutual labels:  lexer, parser
Ratel Core
High performance JavaScript to JavaScript compiler with a Rust core
Stars: ✭ 367 (-19.52%)
Mutual labels:  compiler, parser
Forge
A lightweight, elegant scripting language with built-in Rust-FFI.
Stars: ✭ 153 (-66.45%)
Mutual labels:  compiler, parser
Verible
Verible is a suite of SystemVerilog developer tools, including a parser, style-linter, and formatter.
Stars: ✭ 384 (-15.79%)
Mutual labels:  lexer, parser
Prance
Resolving Swagger/OpenAPI 2.0 and 3.0 Parser
Stars: ✭ 133 (-70.83%)
Mutual labels:  compiler, parser
Glsl
GLSL parser for Rust
Stars: ✭ 145 (-68.2%)
Mutual labels:  compiler, parser
Kgt
BNF wrangling and railroad diagrams
Stars: ✭ 312 (-31.58%)
Mutual labels:  compiler, parser

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

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