{"id":16871701,"url":"https://github.com/phase/mars","last_synced_at":"2025-04-11T10:42:28.262Z","repository":{"id":43797232,"uuid":"67004836","full_name":"phase/mars","owner":"phase","description":"Minimal programming language with type inference, structures, control flow, and more.","archived":false,"fork":false,"pushed_at":"2019-07-26T21:04:15.000Z","size":502,"stargazers_count":21,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-03T19:52:35.243Z","etag":null,"topics":["compiler","language","llvm"],"latest_commit_sha":null,"homepage":"https://jadon.io/mars/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-31T04:59:48.000Z","updated_at":"2024-12-08T22:40:01.000Z","dependencies_parsed_at":"2022-08-28T10:12:05.748Z","dependency_job_id":null,"html_url":"https://github.com/phase/mars","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phase%2Fmars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phase%2Fmars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phase%2Fmars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phase%2Fmars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phase","download_url":"https://codeload.github.com/phase/mars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239604540,"owners_count":19666994,"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":["compiler","language","llvm"],"created_at":"2024-10-13T15:09:30.734Z","updated_at":"2025-02-19T05:31:51.393Z","avatar_url":"https://github.com/phase.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mars compiler\n\n[![Build Status](https://travis-ci.org/phase/lang-kotlin-antlr-compiler.svg?branch=master)](https://travis-ci.org/phase/lang-kotlin-antlr-compiler)\n\n[![codecov](https://codecov.io/gh/phase/lang-kotlin-antlr-compiler/branch/master/graph/badge.svg)](https://codecov.io/gh/phase/lang-kotlin-antlr-compiler)\n\nThis is a compiler written in Kotlin using an ANTLR parser. The language includes: Global variables, Functions, Classes, Methods, Automatic Memory Management, Type Inference, Calling External Functions, Modules, etc.\n\nHere's some example syntax:\n\n```rust\ngenComplexExpressionsInWhileLoop (a : Int, z : Int, y : Int, x : Int, w : Int)\n    var i = 0,\n    var sum = 0,\n    while i \u003c a\n        var v = 42 + x,\n        let u = 45 + v * 67 + 124 - (w * 4) / 5,\n        v = v * 2 - z,\n        var t = 1,\n        if z \u003c 10\n            t = v * z\n        else\n            t = v - z\n        ;\n        let l = 74 * 3 - v + z * x - w,\n        i = 5 + u * z * v + t * 2 * l\n    ;\n    let r = sum * i,\n    r\n```\n\nThis will be parsed into the AST and printed out as:\n\n```javascript\n; Module: genComplexExpressionsInWhileLoop\n\n; genComplexExpressionsInWhileLoop has 4 statements and a return expression.\nfunction genComplexExpressionsInWhileLoop (a: Int, z: Int, y: Int, x: Int, w: Int) -\u003e Int {\n    ; VariableDeclarationStatement\n    variable i: Int = 0\n    ; VariableDeclarationStatement\n    variable sum: Int = 0\n    ; WhileStatement\n    while (i \u003c a) {\n        ; VariableDeclarationStatement\n        variable v: Int = (42 + x)\n        ; VariableDeclarationStatement\n        constant u: Int = (((45 + (v * 67)) + 124) - ((w * 4) / 5))\n        ; VariableReassignmentStatement\n        v = ((v * 2) - z)\n        ; VariableDeclarationStatement\n        variable t: Int = 1\n        ; IfStatement\n        if (z \u003c 10) {\n            ; VariableReassignmentStatement\n            t = (v * z)\n        }\n        else if (true) {\n            ; VariableReassignmentStatement\n            t = (v - z)\n        }\n        ; VariableDeclarationStatement\n        constant l: Int = ((((74 * 3) - v) + (z * x)) - w)\n        ; VariableReassignmentStatement\n        i = ((5 + ((u * z) * v)) + ((t * 2) * l))\n    }\n    ; VariableDeclarationStatement\n    constant r: Int = (sum * i)\n    return r    \n}\n```\n\n(Notice the type inference: variables and return types are inferred and\nchecked in the TypePass.)\n\nThe LLVM backend will produce something like:\n\n```LLVM\n; ModuleID = 'genComplexExpressionsInWhileLoop'\n\ndefine i32 @genComplexExpressionsInWhileLoop(i32, i32, i32, i32, i32) {\nentry:\n  br label %\"while.c (i \u003c a)\"\n\n\"while.c (i \u003c a)\":                                ; preds = %\"if.o (z \u003c 10)\", %entry\n  %i.0 = phi i32 [ 0, %entry ], [ %\"((5 + ((u * z) * v)) + ((t * 2) * l))\", %\"if.o (z \u003c 10)\" ]\n  %\"(i \u003c a)\" = icmp slt i32 %i.0, %0\n  br i1 %\"(i \u003c a)\", label %\"while.b (i \u003c a)\", label %\"while.o (i \u003c a)\"\n\n\"while.b (i \u003c a)\":                                ; preds = %\"while.c (i \u003c a)\"\n  %v = alloca i32, align 4\n  %\"(42 + x)\" = add i32 %3, 42\n  store i32 %\"(42 + x)\", i32* %v, align 4\n  %\"(v * 67)\" = mul i32 %\"(42 + x)\", 67\n  %\"((45 + (v * 67)) + 124)\" = add i32 %\"(v * 67)\", 169\n  %\"(w * 4)\" = shl i32 %4, 2\n  %\"((w * 4) / 5)\" = sdiv i32 %\"(w * 4)\", 5\n  %\"(((45 + (v * 67)) + 124) - ((w * 4) / 5))\" = sub i32 %\"((45 + (v * 67)) + 124)\", %\"((w * 4) / 5)\"\n  %\"(v * 2)\" = shl i32 %\"(42 + x)\", 1\n  %\"((v * 2) - z)\" = sub i32 %\"(v * 2)\", %1\n  store i32 %\"((v * 2) - z)\", i32* %v, align 4\n  %t = alloca i32, align 4\n  store i32 1, i32* %t, align 4\n  %\"(z \u003c 10)\" = icmp slt i32 %1, 10\n  br i1 %\"(z \u003c 10)\", label %\"if.t (z \u003c 10)\", label %\"if.t true\"\n\n\"while.o (i \u003c a)\":                                ; preds = %\"while.c (i \u003c a)\"\n  ret i32 0\n\n\"if.t (z \u003c 10)\":                                  ; preds = %\"while.b (i \u003c a)\"\n  %\"(v * z)\" = mul i32 %\"((v * 2) - z)\", %1\n  store i32 %\"(v * z)\", i32* %t, align 4\n  br label %\"if.o (z \u003c 10)\"\n\n\"if.o (z \u003c 10)\":                                  ; preds = %\"if.t true\", %\"if.t (z \u003c 10)\"\n  %t8 = phi i32 [ %\"(v - z)\", %\"if.t true\" ], [ %\"(v * z)\", %\"if.t (z \u003c 10)\" ]\n  %\"((74 * 3) - v)\" = sub i32 222, %\"((v * 2) - z)\"\n  %\"(z * x)\" = mul i32 %1, %3\n  %\"(((74 * 3) - v) + (z * x))\" = add i32 %\"((74 * 3) - v)\", %\"(z * x)\"\n  %\"((((74 * 3) - v) + (z * x)) - w)\" = sub i32 %\"(((74 * 3) - v) + (z * x))\", %4\n  %\"(u * z)\" = mul i32 %\"(((45 + (v * 67)) + 124) - ((w * 4) / 5))\", %1\n  %\"((u * z) * v)\" = mul i32 %\"(u * z)\", %\"((v * 2) - z)\"\n  %\"(5 + ((u * z) * v))\" = add i32 %\"((u * z) * v)\", 5\n  %\"(t * 2)\" = shl i32 %t8, 1\n  %\"((t * 2) * l)\" = mul i32 %\"(t * 2)\", %\"((((74 * 3) - v) + (z * x)) - w)\"\n  %\"((5 + ((u * z) * v)) + ((t * 2) * l))\" = add i32 %\"(5 + ((u * z) * v))\", %\"((t * 2) * l)\"\n  br label %\"while.c (i \u003c a)\"\n\n\"if.t true\":                                      ; preds = %\"while.b (i \u003c a)\"\n  %\"(v - z)\" = sub i32 %\"((v * 2) - z)\", %1\n  store i32 %\"(v - z)\", i32* %t, align 4\n  br label %\"if.o (z \u003c 10)\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphase%2Fmars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphase%2Fmars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphase%2Fmars/lists"}