{"id":24388223,"url":"https://github.com/frewtypebbles/intersect-programming-language","last_synced_at":"2025-04-11T05:41:11.933Z","repository":{"id":205559483,"uuid":"714516320","full_name":"FrewtyPebbles/Intersect-Programming-Language","owner":"FrewtyPebbles","description":"A simple, strict and uncompromising language.","archived":false,"fork":false,"pushed_at":"2024-06-12T21:55:12.000Z","size":551,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T03:41:35.466Z","etag":null,"topics":["compiler","language","llvm","programming-language"],"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/FrewtyPebbles.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}},"created_at":"2023-11-05T04:31:06.000Z","updated_at":"2024-06-12T21:55:15.000Z","dependencies_parsed_at":"2024-01-03T05:24:53.388Z","dependency_job_id":"3f17cd75-4c62-4f93-b2ed-ae356d7a2ed9","html_url":"https://github.com/FrewtyPebbles/Intersect-Programming-Language","commit_stats":null,"previous_names":["frewtypebbles/python-llvm-compiler","frewtypebbles/tarantula-programming-language","frewtypebbles/intersect-programming-language"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrewtyPebbles%2FIntersect-Programming-Language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrewtyPebbles%2FIntersect-Programming-Language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrewtyPebbles%2FIntersect-Programming-Language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrewtyPebbles%2FIntersect-Programming-Language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FrewtyPebbles","download_url":"https://codeload.github.com/FrewtyPebbles/Intersect-Programming-Language/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351044,"owners_count":21089268,"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","programming-language"],"created_at":"2025-01-19T13:56:42.856Z","updated_at":"2025-04-11T05:41:11.910Z","avatar_url":"https://github.com/FrewtyPebbles.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Intersect**\n\nA functional yet unfinished compiled language that is **explicit and versatile**.\n\n***IMPORTANT***\n\u003e This project has been discontinued.  I had started this project as an experiment to see if I could make a compiler from (mostly) complete scratch in python.  Turns out python is a much nicer compiler development language than I initially thought it would be.  While I did not complete all of my overambitious plans for the compiler, what was completed is mostly functional. All integration tests are passing, except for the hash map test.  I believe this test started failing with the introduction of virtual functions.  By the time I had finished getting virtual functions functional I was so burnt out on my overly ambitious scope that I slowly abandoned the project (I have since learned from my overly ambitious approach to these kinds of projects and have produced much more complete software and libraries since then).  Feel free to clone and try out the compiler,  I cant promise there wont be any bugs, but from my testing it should work for simple-ish test applications.  This project was a great learning experience in both project and scope management.\n\n## How it works\n\n**Intersect** compiles utilizing the *LLVMLite* python module by *Numba*.  It utilizes a complex concrete syntax tree to handle it's compile time mechanisms such as it's garbage collector, minimal function/struct emmitter and mangler, automatic typing, and much more.\n\n## Language Conventions and Features\n\n### Comments\n\n**Intersect** uses cPython style comments:\n\n```py\n# This is a comment.\n```\n\nFor multiline comments use:\n\n```py\n#:\n    This is a multiline/closed comment.\n:#\n```\n\n### Keywords\n\nIn **Intersect**, keywords are explicitly named.  Ex:\n\n```rust\nstruct StructName\u003cTemplateType\u003e {\n\n    attribute:TemplateType;\n\n    operator == (self:$StructName\u003cTemplateType\u003e, other:$StructName\u003cTemplateType\u003e) {\n        return self.attribute == self.attribute;\n    }\n}\n```\n\n### Robust Compile Time Errors\n\nSource Code:\n\n```rust\nstruct MyStruct {\n    data:i32;\n    theta:i32;\n    func meta(self:$MyStruct, arg:i32) {\n        return;\n    }\n}\nfunc main() ~\u003e i32{\n    let my_struct:MyStruct;\n    let my_attr = my_struct.beta;\n    return 0;\n}\n```\n\nOutput:\n\n![alt text](readme_files/FuzzyFindCompileTimeError.png)\n\nCompile time error feedback provides you with a detailed annotated view of the error in your source code.\n\n### Operator Macros (Work in progress)\n\nOperator macros let you implement extra operators with explicit names for classes.  This allows for a more declarative syntax.\n\n```rust\nmacro operator binary equals;\n\nstruct StructName\u003cTemplateType\u003e {\n\n    data:TemplateType;\n\n    operator equals (self:$StructName\u003cTemplateType\u003e, other:$StructName\u003cTemplateType\u003e) ~\u003e bool {\n        return self.data == self.data;\n    }\n}\n\nfunc main() {\n    let s1:StructName\u003ci32\u003e;\n    let s2:StructName\u003ci32\u003e;\n    s1.data = 1;\n    s2.data = 1;\n\n    libc_printf(\"equal operator result %i\\n\":$c8, s1 equals s2);\n    return;\n}\n```\n\n### Automatic Memory Management (Work in progress)\n\n**Intersect**'s automatic memory allocation is confined to scope.  `manage` prefixes a *type* as a managed heap allocated type.  `allocate` then returns an instance of something equivalent to this struct:\n\n```rust\nmacro operator unary clone;\n\nstruct HeapMemory\u003cType\u003e{\n    data:$Type;\n    has_data:bool;\n\n    operator delete (self:$HeapMemory\u003cType\u003e) {\n        if self.points_to_memory {\n            free?\u003cType\u003e(self.data);\n        }\n        return;\n    }\n\n    operator clone (self:$HeapMemory\u003cType\u003e) ~\u003e $HeapMemory\u003cType\u003e {\n        # clone self.data\n        return #: Clone of self.data :#;\n    }\n\n    operator = (self:$HeapMemory\u003cType\u003e, rhs:$HeapMemory\u003cType\u003e) ~\u003e $HeapMemory\u003cType\u003e {\n        if self.points_to_memory {\n            free?\u003cType\u003e(self.data);\n        }\n        # point to new heap memory\n        return \u0026self;\n    }\n}\n```\n\nWhen heap memory is returned from a function, it passes ownership to its caller:\n\n```rust\nfunc ret_heap_memory() ~\u003e manage $i32 {\n    return allocate 1; #allocate creates an instance of a heap wrapper which frees all elements on destruction.\n}\n\nfunc main() {\n    let item:manage $i32;\n    item = ret_heap_memory();\n    # Here!!!\n    return 0;\n}\n```\n\nThis means that the `HeapMemory_instance.has_data` is set to `true`.\n\n## Updates\n\n### First Ever Intersect Program Compiled!\n\nThe first ever **Intersect** program was compiled today on `Saturday, November 18, 2023 at 8:20 P.M.`.  It doesnt do much, but it is *something!*\n\n```rust\n# test.pop\n\nstruct Vector\u003cItemType\u003e {\n    data:[ItemType x 5];\n}\n\nexport func test(num: i32) {\n    let my_vec:Vector\u003ci32\u003e;\n    \n    return;\n}\n```\n\nHeres the *LLVM-IR* generated by compiling this program.\n\n```llvm\n; ModuleID = \"./test.pop\"\ntarget triple = \"unknown-unknown-unknown\"\ntarget datalayout = \"\"\n\n%\"Vector_struct_tmp_MMAANNGGLLEE_i32\" = type {[5 x i32]}\ndeclare i32 @\"printf\"(i8* %\".1\", ...)\n\ndeclare i8* @\"malloc\"(i64 %\".1\")\n\ndeclare i8* @\"realloc\"(i8* %\".1\", i64 %\".2\")\n\ndeclare void @\"free\"(i8* %\".1\")\n\n@\"null\" = global i8 0\ndefine void @\"test\"(i32 %\"num\")\n{\nentry:\n  %\"my_vec\" = alloca %\"Vector_struct_tmp_MMAANNGGLLEE_i32\"\n  ; OP::define(stack) START\n  ; OP::define(stack) END\n  ; OP::return START\n  ret void\n  ; OP::return END\n}\n```\n\n## TODO\n\n### Refactor member function namespace/name mangling to all be within the module class.\n\nOr figure out a way to make current solution work.\n\n### Implement Algorithm for Building Order Of Operations Trees:\n\nSee description of algorithm in file:\n\n`llvmcompiler/tree_builder/build_tree/operations_parser.py`\n\n### Implement Struct Operators (Not started yet):\n\n - Operator functions will be prefixed with the `OPERATOR` keyword rather than `func`\n\n - Destructor operator to decide how to handle memory when out of scope\n\n    All heap allocated values are collected by default.\n\n```rust\nstruct StructName {\n    OPERATOR destructor(self) {\n        delete self.heap_allocated_attribute;\n    }\n}\n```\n\n### Major Rework of Garbage Collector And How Heap is Allocated (Work In Progress):\n\n```py\n{\n    let test_md_array: [$[i32]] persist = [\n        heap [0,1,2],\n        heap [0,1,2],\n        heap [0,1,2],\n        heap [0,1,2],\n        heap [0,1,2]\n    ];\n\n\n    # test_md_array's heap allocated members are freed here at the end of its scope if persist is not used.\n    # all heap values become null\n}\n```\n\nThe heap keyword should prefix values instead of variables.  This means that the garbage collector will need to free those values once the memory goes out of scope.\n\n### Implement Float Types For Operators (Not started yet)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrewtypebbles%2Fintersect-programming-language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrewtypebbles%2Fintersect-programming-language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrewtypebbles%2Fintersect-programming-language/lists"}