{"id":20639226,"url":"https://github.com/alexdremov/nggc","last_synced_at":"2026-04-21T01:31:58.870Z","repository":{"id":146181943,"uuid":"356848113","full_name":"alexdremov/NGGC","owner":"alexdremov","description":"Compilable to Mach-O Never Gonna Give you up© programming language","archived":false,"fork":false,"pushed_at":"2021-05-18T09:15:11.000Z","size":2772,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-15T01:13:51.032Z","etag":null,"topics":["assembly","ast","educational","language","mach","mach-o","x86-64"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexdremov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-04-11T11:24:35.000Z","updated_at":"2021-05-21T13:09:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"d2354bc6-126d-47e6-af69-97f5f0222a87","html_url":"https://github.com/alexdremov/NGGC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexdremov/NGGC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FNGGC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FNGGC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FNGGC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FNGGC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexdremov","download_url":"https://codeload.github.com/alexdremov/NGGC/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FNGGC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32072953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T21:26:33.338Z","status":"ssl_error","status_checked_at":"2026-04-20T21:26:22.081Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["assembly","ast","educational","language","mach","mach-o","x86-64"],"created_at":"2024-11-16T15:23:03.287Z","updated_at":"2026-04-21T01:31:58.851Z","avatar_url":"https://github.com/alexdremov.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NGGC\nCompilable to Mach-O Never Gonna Give you up© programming language\n\n## Features\n\n- x86_64 compilable\n- Object files in Mach-O format\n- Call external functions\n\n**plans**\n\n- Full System V support -\u003e call any C or C++ function\n\n## Requirment\n\nRequires MachOBuilder to be installed: https://github.com/AlexRoar/MachOBuilder\n\n## Installation\n\n```bash\nmkdir build\ncd build\ncmake .. -DCMAKE_BUILD_TYPE=Release\nmake -j3\nmake install -j3\n```\n\n## Examples\n\n```python\ndef giveYouUp() {\n\tlet x = 0;\n\tlet userData = input;\n\twhile(x \u003c userData) {\n\t    print fact(x);\n\t    x += 1;\n\t}\n}\n\ndef fact(x) {\n    if (x \u003c= 1){ ret 1; }\n    \n    ret fact(x - 1) * x;\n}\n```\n\n## Usage\n\n```bash\nNGGC help\n--input        \u003cinput file\u003e input file to be compiled .ngg format (source)\n-o, --output   \u003coutput file\u003e output file. a.out by default (mach-o executable)\n-h, --help     show this help message\n-c             object file only\n-C             keep object file\n--verbose      output debug information to the console\n--lex          \u003c.lex file\u003e file to dump lexemes\n--lst          \u003c.lst file\u003e file to dump detailed listing\n-g             generate AST graph\n-d             dump AST graph\n```\n\n## Optimization features\n\n### Registers planning\u0026management\n\nWhy use memory when you can use registers only?\n\nThis code does not use memory access at all (apart from requried call convention saves). Planner maps registers to variables and saves values to RAM only when all registers are exhausted.\n\n```python\ndef giveYouUp() {\n\tlet i = 0;\n\tlet res = 0;\n\twhile (i \u003c 100) {\n\t\tres += i * i;\n\t\ti += 1;\n\t}\n\tprint res;\n}\n```\n\n```asm\n0:  55                      push   rbp\n1:  90                      nop\n2:  48 89 e5                mov    rbp,rsp\n5:  48 81 ec 10 00 00 00    sub    rsp,0x10\nc:  b8 00 00 00 00          mov    eax,0x0\n11: 49 89 c3                mov    r11,rax\n14: b8 00 00 00 00          mov    eax,0x0\n19: 48 89 c1                mov    rcx,rax\n1c: 4c 89 d8                mov    rax,r11\n1f: 49 89 c2                mov    r10,rax\n22: b8 64 00 00 00          mov    eax,0x64\n27: 49 89 c1                mov    r9,rax\n2a: 48 31 c0                xor    rax,rax\n2d: 4d 39 ca                cmp    r10,r9\n30: 7d 05                   jge    0x37\n32: b8 01 00 00 00          mov    eax,0x1\n37: 48 85 c0                test   rax,rax\n3a: 0f 84 23 00 00 00       je     0x63\n40: 4c 89 d8                mov    rax,r11\n43: 49 89 c2                mov    r10,rax\n46: 4c 89 d8                mov    rax,r11\n49: 49 0f af c2             imul   rax,r10\n4d: 49 89 c2                mov    r10,rax\n50: 4c 01 d1                add    rcx,r10\n53: b8 01 00 00 00          mov    eax,0x1\n58: 49 89 c2                mov    r10,rax\n5b: 4d 01 d3                add    r11,r10\n5e: e9 b9 ff ff ff          jmp    0x1c\n63: 48 89 c8                mov    rax,rcx\n66: 48 89 c7                mov    rdi,rax\n69: 48 89 8d f0 ff ff ff    mov    QWORD PTR [rbp-0x10],rcx\n70: 4c 89 9d f8 ff ff ff    mov    QWORD PTR [rbp-0x8],r11\n77: e8 00 00 00 00          call   0x7c\n7c: 48 81 c4 10 00 00 00    add    rsp,0x10\n83: 5d                      pop    rbp\n84: 90                      nop\n85: c3                      ret\n```\n\nTo achive that, special register planner was implemented. Its interface:\n- get temporary register =\u003e allocate register for tmp use.\n- get variable =\u003e get register used for variable, or, if it is not loaded yet, select least used at the moment register and load var to it.\n\nIt was essential to correctly work with structures that change program flow. For example, for the code to function correctly, it is neccessary that state of registers in the end of `while` will be tha same as the one at the beginning of condition. The same conception works for `if-else` structure. State at the end of `if` branch must be the same as one in the end of `if` condition. \n\n### In-loop variables usage optimizations\nBefore entering a loop, compiler checks for used variables and force-allocate registers for them. Thus, in-loop memory access is minimal.\n\n## Plans\n- Middle representation – Currently, machine code is generated directly from AST. That poses several issues on redundant code optimisations. Middle representation allows to optimize instructions like\n```asm\nmov    eax,0x0\nmov    r11,rax\n;===============\nmov    r11,0x0\n;=============== or even better\nxor    r11,r11\n```\n- AST-level optimizations – There are possibilities of high level optimizations. For example, constant expressions evaluation, unreachable code removal, and tail calls.\n\n## Structure\n### Main function: \ngiveYouUp() -\u003e main()\n\n### Function definition:\n```python\ndef identifier(a, b, c, ...) {\n  ...\n}\n```\n\nReturn value: ret ... ;\nEvery function returns some value even if it is unspecified.\nAll local variables are mutable.\nAll functions can be accessed from extern object files.\n\n### Operations:\n\\*, -, +, / (int division), \u003c, \u003e, \u003c=, \u003e=, !=, ==,\n\n### Var declaration\nVariables must be declared before their first use.\n```js\nlet name = 123;\nlet something;\n```\n\n### Polymorphysm \nFunctions can have the same name and different number of arguments in the same file.\n```python\ndef poly(a) {\n  print a;\n}\n```\n```python\ndef poly(a, b) {\n  print a * b;\n}\n```\n\n## Additionally \n\nnggcload utility takes dumped AST graph structure and generates source code.\n```bash\nnggcload \u003cdump file name\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdremov%2Fnggc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexdremov%2Fnggc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdremov%2Fnggc/lists"}