{"id":15294071,"url":"https://github.com/dqneo/babygo","last_synced_at":"2025-04-06T22:10:19.207Z","repository":{"id":43728593,"uuid":"251019439","full_name":"DQNEO/babygo","owner":"DQNEO","description":"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.","archived":false,"fork":false,"pushed_at":"2024-04-25T13:42:58.000Z","size":5228,"stargazers_count":307,"open_issues_count":22,"forks_count":21,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-30T20:13:03.347Z","etag":null,"topics":["ast","compiler","go","golang","lexer","linux","parser","x86-64"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DQNEO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-29T11:48:07.000Z","updated_at":"2025-03-29T07:29:37.000Z","dependencies_parsed_at":"2024-01-31T04:19:43.875Z","dependency_job_id":"4d2a8d9c-fb63-421f-9381-5f6c614f1157","html_url":"https://github.com/DQNEO/babygo","commit_stats":null,"previous_names":["dqneo/nigo"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DQNEO%2Fbabygo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DQNEO%2Fbabygo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DQNEO%2Fbabygo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DQNEO%2Fbabygo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DQNEO","download_url":"https://codeload.github.com/DQNEO/babygo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","compiler","go","golang","lexer","linux","parser","x86-64"],"created_at":"2024-09-30T16:57:18.041Z","updated_at":"2025-04-06T22:10:19.177Z","avatar_url":"https://github.com/DQNEO.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Babygo, a go compiler made from scratch\n\n![Test](https://github.com/DQNEO/babygo/workflows/Test/badge.svg)\n\nBabygo is a small and simple go compiler. (Smallest and simplest in the world, I believe.)\nIt is made from scratch and can compile itself.\n\n* No dependency to any libraries. Standard libraries and calling of system calls are home made.\n* Lexer, parser and code generator are handwritten.\n* Emit assemble code which results in a single static binary.\n\nIt depends only on `as` as an assembler and `ld` as a linker.\n\n# Design\n\n## Lexer, Parser and AST\nThe design and logic of ast, lexer and parser are borrowed (or should I say \"stolen\")  from `go/ast`, `go/scanner` and `go/parser`.\n\n## Code generator\nThe design of code generator is borrowed from [chibicc](https://github.com/rui314/chibicc) , a C compiler.\n\n## Remaining parts (Semantic analysis, Type management etc.)\nThis is purely my design :)\n\n# Environment\n\nIt supports x86-64 Linux only.\n\nIf you are not using Linux, you can use [a dedicated docker image](https://hub.docker.com/r/dqneo/ubuntu-compiler-go) for this project.\n\n```termiinal\n$ docker pull dqneo/ubuntu-compiler-go\n$ ./docker-run\n```\n\n# Usage\n\n**Currently we are changing CLI design. This section will be updated later**\n\n## Hello world\n\n```terminal\n# Build babygo\n$ go build -o babygo\n\n# Build hello world by babygo\n$ ./babygo build -o hello ./example/hello\n\n# Run hello world\n$ ./hello\nhello world!\n```\n\n## How to do self hosting\n\n```terminal\n# Build babygo (1st generation)\n$ go build -o babygo\n\n# Build babygo (2nd generation) by babygo 1gen\n$ ./babygo build -o babygo2 ./\n\n# Build babygo (3rd generation) by babygo 2gen\n$ ./babygo2 build -o ./babygo3 ./\n\n# Check if babygo2 and babygo3 are identical\n$ diff ./babygo2 ./babygo3\n```\n\n## Test\n\nRun this in the docker container:\n\n```terminal\n$ make test\n```\n\n# Reference\n\n* https://golang.org/ref/spec The Go Programming Language Specification\n* https://golang.org/pkg/go/parser/ go/parser\n* https://sourceware.org/binutils/docs/as/ GNU assembler\n* https://github.com/rui314/chibicc C compiler\n* https://github.com/DQNEO/minigo Go compiler (my previous work)\n\n\n# License\n\nMIT\n\n# Author\n\n[@DQNEO](https://twitter.com/DQNEO)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdqneo%2Fbabygo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdqneo%2Fbabygo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdqneo%2Fbabygo/lists"}