{"id":15705758,"url":"https://github.com/tetsuo-cpp/glacier","last_synced_at":"2025-03-30T15:44:16.215Z","repository":{"id":154780556,"uuid":"193208376","full_name":"tetsuo-cpp/glacier","owner":"tetsuo-cpp","description":"A compiler and virtual machine for a toy object oriented programming language.","archived":false,"fork":false,"pushed_at":"2024-03-20T15:46:17.000Z","size":280,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-05T17:18:11.090Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/tetsuo-cpp.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":"2019-06-22T08:05:11.000Z","updated_at":"2020-07-06T12:11:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"4861e554-7cc5-45c9-be54-fe52af37241c","html_url":"https://github.com/tetsuo-cpp/glacier","commit_stats":{"total_commits":175,"total_committers":2,"mean_commits":87.5,"dds":0.3771428571428571,"last_synced_commit":"8ce902ba1f1d43475f4381110f6f99a2f0beec93"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tetsuo-cpp%2Fglacier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tetsuo-cpp%2Fglacier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tetsuo-cpp%2Fglacier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tetsuo-cpp%2Fglacier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tetsuo-cpp","download_url":"https://codeload.github.com/tetsuo-cpp/glacier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246342716,"owners_count":20761938,"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":[],"created_at":"2024-10-03T20:19:35.441Z","updated_at":"2025-03-30T15:44:16.187Z","avatar_url":"https://github.com/tetsuo-cpp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Glacier\nThis is a toy statically typed object oriented programming language that I'm working on to consolidate what I've learnt about compilers so far.\n\nThere are two components:\n* A compiler written in Python that parses Glacier source code and emits a custom bytecode format.\n* A stack-based virtual machine written in C that executes this bytecode.\n## Build\nSetup a Python virtual environment for running the Glacier compiler.\n```\n$ bash setup_env.sh\n```\nThe Glacier VM requires dependencies such as the Boehm-Demers-Weiser Garbage Collector so they need to be pulled in as submodules before invoking the CMake build.\n```\n$ git submodule init\n$ cmake . \u0026\u0026 make\n```\n## Usage\n```\n$ source .ve/bin/activate\n$ ./glacierc \u003cglacier_source\u003e -o \u003cbytecode\u003e\n$ ./glaciervm \u003cbytecode\u003e\n```\nRun unit tests.\n```\n$ bash unit_test.sh\n```\nRun system tests.\n```\n$ bash system_test_all.sh\n```\n## Hello World!\n```\nfn main() -\u003e void {\n  print(\"Hello World!\");\n}\n```\n## Features\nThis is not an exhaustive list. The examples under the `system_tests/` directory are the source of truth for what features Glacier supports at any given time.\n### Control flow\nGlacier supports conditionals and loops.\n```\nfn main() -\u003e void {\n  // Print numbers from 0-9.\n  let count = 0;\n  while (count \u003c 10) {\n    if (count == 5) {\n      print(\"five\");\n    } else {\n      print(count);\n    }\n    count = count + 1;\n  }\n}\n```\n### Types and data structures\nGlacier supports a range of built in types.\n* Integer.\n* String.\n* Vector.\n* Hashmap.\n### Static typing\nGlacier is a statically typed language meaning that certain classes of bugs can be caught at compile time.\n```\nfn bar(int num) -\u003e int {\n  ...\n}\n\nfn main() -\u003e void {\n  let foo = \"Hello World!\";\n  bar(foo); // Compilation error. We tried to pass a string into a function taking an int arg.\n}\n```\n### Type inference\nGlacier infers type declarations where possible making code less verbose.\n```\nfn createMap(int num) -\u003e map\u003cint, string\u003e {\n  ...\n}\n\nfn main() -\u003e void {\n  let integerType = 1;\n  let stringType = \"Hello World!\";\n  let mapType = createMap(10);\n}\n```\n### Structs\nGlacier supports bundling related data types together and binding methods to them. These types can be used in conjunction with built in data structures such as `vector` and `map`.\n```\nstruct Doubler {\n  int num;\n  fn double() -\u003e int {\n    this.num = this.num * 2;\n    return this.num;\n  }\n};\n\nfn main() -\u003e void {\n  let doubler = new Doubler(2);\n  print(doubler.num); // 2\n  doubler.double();\n  print(doubler.num); // 4\n  let vectorOfDoublers = [doubler, new Doubler(10)]\u003cDoubler\u003e;\n}\n```\nGlacier also supports default arguments for struct constructors.\n```\nstruct Person {\n  string name = \"Alex\";\n  int age = 24;\n};\n\nfn main() -\u003e void {\n  let person1 = new Person(); // Alex, 24\n  let person2 = new Person(\"Michelle\"); // Michelle, 24\n  let person3 = new Person(\"Michelle\", 26); // Michelle, 26\n}\n```\n### Disassembler\nGlacier also provides a bytecode disassembler to debug the compiler and VM.\n```\n$ ./glacierd system_tests/example_1/example_1.bc\nSTRUCT_DEF (0)\n  type_id: 2\n  member_id_len: 2\n    member_id_0: 1\n    member_id_1: 0\nFUNCTION_JMP (5)\n  function_id: 1\n  offset: 0\nFUNCTION_JMP (8)\n  function_id: 2\n  offset: 10\nFUNCTION_JMP (11)\n  function_id: 0\n  offset: 20\n...\n```\n## Glacier DSL\nThe definitions of what ops exist in the GlacierVM are described by a Python DSL in `glacierdsl`. Running `glacierdsl` will generate:\n* A C header for the VM containing `#define`s for each opcode (`Ops.h`).\n* A Python file for the compiler containing serialisation classes for writing bytecode for each op (`compiler/ops.py`).\n* A Python file for the disassembler containing a function to print an op from bytecode in human readable form (`disassembler/ops.py`).\n## TODO\n* Make object stack resizeable.\n* More sensible bytecode format (at the moment all arguments are 1 byte).\n* More tests around static typing.\n* Reduce technical debt and general hackiness.\n* Improve compiler errors and diagnostics.\n* Add an error handling mechanism.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftetsuo-cpp%2Fglacier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftetsuo-cpp%2Fglacier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftetsuo-cpp%2Fglacier/lists"}