{"id":15101415,"url":"https://github.com/mfroeh/flux","last_synced_at":"2026-02-15T19:07:19.332Z","repository":{"id":252198748,"uuid":"799501060","full_name":"mfroeh/flux","owner":"mfroeh","description":"An imperative, statically typed toy programming language with classes, type inference and some other fun features.","archived":false,"fork":false,"pushed_at":"2024-09-30T12:02:03.000Z","size":1161,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T18:15:21.545Z","etag":null,"topics":["antlr","cpp","llvm","nix"],"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/mfroeh.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":"2024-05-12T10:45:49.000Z","updated_at":"2024-09-30T12:02:07.000Z","dependencies_parsed_at":"2024-08-08T09:29:37.772Z","dependency_job_id":"5781b7cd-13a2-43b9-9cfc-cee5fd237821","html_url":"https://github.com/mfroeh/flux","commit_stats":null,"previous_names":["mfroeh/flux"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfroeh%2Fflux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfroeh%2Fflux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfroeh%2Fflux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfroeh%2Fflux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfroeh","download_url":"https://codeload.github.com/mfroeh/flux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245858879,"owners_count":20684057,"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":["antlr","cpp","llvm","nix"],"created_at":"2024-09-25T18:22:23.797Z","updated_at":"2026-02-15T19:07:14.311Z","avatar_url":"https://github.com/mfroeh.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"logo.png\" alt=\"Flux logo\" height=\"200\"\u003e\n\u003c/p\u003e\n\n# flux\n\nAn imperative, statically typed toy programming language with classes, type inference and some other fun features.\n\n## How to use\nTry it out with nix:\n1. Clone and enter dev shell: `git clone git@github.com:mfroeh/flux \u0026\u0026 cd flux \u0026\u0026 nix develop`\n2. Build flux compiler and compile object file `nix run . -- examples/classes.fl`\n3. Link object file using clang and produce binary `clang a.out -o out`\n4. Run `./out`\n\nWhenever developing\n* Enter devshell: `nix develop`\n\nOne time dev setup\n1. Build compiler: `mkdir build \u0026\u0026 cd build \u0026\u0026 cmake .. \u0026\u0026 ninja -j 8`\n2. Make work with clangd: `cd .. \u0026\u0026 ln -s build/compile_commands.json .`\n\nMake package and run\n* Build and run package: `nix build \u0026\u0026 result/bin/flux` or `nix run`\n\n## Features\n* [Classes](examples/classes.fl)\n```\nclass Point { \n    x: i64; \n    y: i64; \n}\n\nclass Rectangle { \n    topleft: Point;\n    bottomright: Point; \n\n    height(): i64 =\u003e this-\u003ebottomright.y - this-\u003etopleft.y;\n\n    width() =\u003e this-\u003ebottomright.x - this-\u003etopleft.x;\n\n    area() =\u003e this-\u003eheight() * this-\u003ewidth();\n\n    contains(p: Point*): bool {\n        ret p-\u003ex \u003e= this-\u003etopleft.x \u0026\u0026 p-\u003ex \u003c= this-\u003ebottomright.x \u0026\u0026\n            p-\u003ey \u003e= this-\u003etopleft.y \u0026\u0026 p-\u003ey \u003c= this-\u003ebottomright.y;\n    }\n}\n\nmain(): i64 {\n    let p1 = Point { x: 0, y: 0 };\n    let p2: Point;\n    print \"p2: %d %d \" p1.x, p2.x;\n\n    p2.x = 10;\n    p2.y = 10;\n\n    let r = Rectangle { topleft: p1, bottomright: p2 };\n\n    let height = r.height();\n    let width = r.width();\n    let area = r.area();\n\n    let p = Point { x: 5, y: 5 };\n    let contains = r.contains(\u0026p);\n\n    print \"height: %d, width: %d, area: %d, contains: %d\" height, width, area, contains;\n    ret 0;\n}\n```\n\n* [Multi-dimensional arrays](examples/arrs.fl)\n```\nmain(): i64 {\n    let board: i64[8, 8, 8];\n    board[1, 2, 3] = 44;\n    print \"%d \" board[1, 2, 3];\n\n    // remaining elements are default initialized\n    let arr: f64[8] = [2.5, 2.6];\n    print \"%.2f \" arr[3];\n    ret 0;\n}\n```\n\n* [Pointers](examples/pointers.fl)\n```\nsum(arr: i64[4]*): i64 {\n    let sum = 0;\n    for (let i = 0; i in [0, 4); i += 1;) -\u003e sum += *arr[i];\n    ret sum;\n}\n\nsquares(arr: i64*[4]*): i64*[4]* {\n    for (let i = 0; i \u003c 4; i += 1;) {\n        let ptr = *arr[i];\n        *ptr *= *ptr;\n    }\n    ret arr;\n}\n\nmain(): i64 {\n    let arr = [1, 2, 3, 4];\n    let arrPtrs: i64*[4] = [\u0026(arr[0]), \u0026(arr[1]), \u0026(arr[2]), \u0026(arr[3])];\n    let ptrptr = \u0026(arrPtrs[2]);\n    print \"%d \" sum(\u0026arr);\n    print \"%d==%d==%d \" *squares(\u0026arrPtrs)[2], arr[2], **ptrptr;\n    ret 0;\n}\n```\n\n* [Variable and function shadowing](examples/shadowing.fl)\n```\nadd(a: i64, b: i64) =\u003e a + b;\n\nmain(): i64 {\n    let a = 3.1415;\n    print \"a: %f \" a;\n    let a = true;\n    print \"a: %d \" a;\n    let a = \"hello\";\n    print \"a: %s \" a;\n\n    print \"add(1, 2): %d \" add(1, 2);\n    add(a: i64, b: i64): f64 =\u003e a * b;\n    print \"add(1, 2): %f \" add(1, 2);\n    ret 0;\n}\n```\n\n* [Type inferrence](examples/infer.fl)\n```\nadd(a: i64, b: i64) =\u003e a + b;\n\nmain(): i64 {\n    let res = add(1, 2);\n    print \"%d \" res;\n    ret 0;\n}\n```\n\n* Expressions [expression](grammar/FluxParser.g4)\n\n* Builtin types [types](grammar/FluxParser.g4)\n\n* Includes\n\n```\n// file: math.fl\nclass Point {\n    x: i64;\n    y: i64;\n}\n\nadd(a: i64, b: i64) =\u003e a + b;\n```\n\n```\n// file: main.fl\nincl ./math.fl;\n\nmain(): i64 {\n    let p = Point { x: 1, y: 2 };\n    print \"add(p.x, p.y): %d \" add(p.x, p.y);\n    ret 0;\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfroeh%2Fflux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfroeh%2Fflux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfroeh%2Fflux/lists"}