{"id":17040863,"url":"https://github.com/m4gnv5/pointerscript","last_synced_at":"2025-04-12T14:33:03.783Z","repository":{"id":80537425,"uuid":"52201132","full_name":"M4GNV5/PointerScript","owner":"M4GNV5","description":"Scripting language with pointers and native library access.","archived":false,"fork":false,"pushed_at":"2024-08-29T12:34:19.000Z","size":3402,"stargazers_count":29,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T09:05:03.555Z","etag":null,"topics":["ffi","language","native","native-libraries","pointer","programming-language","scripting","scripting-language"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"eupl-1.2","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/M4GNV5.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-21T10:21:18.000Z","updated_at":"2024-09-25T12:45:01.000Z","dependencies_parsed_at":"2023-03-12T11:23:15.809Z","dependency_job_id":"edd1d2f6-705f-4652-ad75-894c3ee1543f","html_url":"https://github.com/M4GNV5/PointerScript","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/M4GNV5%2FPointerScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4GNV5%2FPointerScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4GNV5%2FPointerScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4GNV5%2FPointerScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/M4GNV5","download_url":"https://codeload.github.com/M4GNV5/PointerScript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248581292,"owners_count":21128145,"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":["ffi","language","native","native-libraries","pointer","programming-language","scripting","scripting-language"],"created_at":"2024-10-14T09:10:45.134Z","updated_at":"2025-04-12T14:33:03.764Z","avatar_url":"https://github.com/M4GNV5.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PointerScript\n\nScripting language with pointers and native library access. PointerScript\nfeels like C but has awesome features like operator overloading, dynamic typing and\neven though you have direct low level access your code is more safe thanks to boundary\nchecks. Additionally finding errors is less painful as you get a full backtrace when a\nruntime error occurs or you receive e.g. a segmentation fault.\n\n## Language\n\n### Documentation\nMost of PointerScript is similar to Javascript and/or C. For a full Documentation see [LanguageDoc.md](LanguageDoc.md)\n\n### Standard Library\nPointerScript has no standard-library. You can use all C libraries using the built-in ffi ([Import statement](LanguageDoc.md#importstatement)).\nThere are a couple of easy-to-use libraries (sockets, regexp, http, json, lists, maps etc.)\nin [this repository](https://github.com/M4GNV5/PtrsStuff)\n\n### Testing\nYou can run tests for the interpreter by executing the `runTests.sh` script in the repository.\n\n### Introduction\nThe following is a small code sample, annotated with comments to explain what is happening.\n```javascript\n//using the import statement you can import any function from the C standard library\nimport puts, qsort;\n\n//this defines an array of 4 signed 32-bit integers.\n//Using var nums: var[4]; we could create an array of dynamically typed variables instead.\nvar nums: i32[4] = [1337, 666, 3112, 42];\n\n//here we use the standard C function qsort to sort the array\n//the last argument to qsort is a function pointer, here we use a lambda expression\nqsort(nums, sizeof nums, sizeof i32, (a: i32*, b: i32*) -\u003e *a - *b);\n\n//using the foreach loop on arrays is similar to a for loop from 0 to sizeof nums\nforeach(i, val in nums)\n{\n\t// the language as built-in string formatting\n\tputs(\"nums[$i] = $val\");\n}\n```\n\n## JIT Compilation\nThere are three main steps involved when running PointerScript code:\n- parsing the source code (handeled by the built-in recusive descent parser)\n- predicting types of expressions\n- converting the code to GNU [libjit](https://www.gnu.org/software/libjit/) IR\n- converting the IR to machine code (handled by [my fork of libjit](https://github.com/M4GNV5/libjit/tree/ptrs-graphalloc))\n\nThe following shows the process of these steps inspecting the lambda function from the above\ncode example.\n\n### Predicting types\nUsing the `--dump-predictions` flag to view predictions made by PointerScript:\n```\n(a: i32*, b: i32*) -\u003e *a - *b\n                      ││ │ │└─\u003e meta: i32[1] ast: identifier\n                      ││ │ └──\u003e meta: int ast: prefix_dereference\n                      ││ └────\u003e type: int ast: op_sub\n                      │└──────\u003e meta: i32[1] ast: identifier\n                      └───────\u003e meta: int ast: prefix_dereference\n```\n\n### libjit IR\nUsing the `--dump-jit` flag to dump libjit IR of the lambda expresssion:\n```\nfunction (lambda expression)([l1 : parent_frame], l2 : ptr, l3 : long, l4 : ulong, l5 : long, l6 : ulong) : struct\u003c16\u003e\n[...]\n\ti18 = load_relative_int(l3, 0)\n\tl19 = expand_int(i18)\n\ti22 = load_relative_int(l5, 0)\n\tl23 = expand_int(i22)\n\tl26 = l19 - l23\n\treturn_struct_from_regs(l26, 1)\n[...]\nend\n```\n\n### x64 machine code\nUsing the `--dump-asm` flag to dump assembly of the lambda expresssion:\n```asm\nfunction (lambda expression)(ptr, long, ulong, long, ulong) : struct\u003c16\u003e\n    7fb7e050a260:\t8b 12                \tmov    (%rdx),%edx\n    7fb7e050a262:\t48 63 c2             \tmovslq %edx,%rax\n    7fb7e050a265:\t45 8b 00             \tmov    (%r8),%r8d\n    7fb7e050a268:\t4d 63 c0             \tmovslq %r8d,%r8\n    7fb7e050a26b:\t49 2b c0             \tsub    %r8,%rax\n    7fb7e050a26e:\tba 01 00 00 00       \tmov    $0x1,%edx\n    7fb7e050a273:\tc3                   \tretq\n```\n\n### More example code\nThere are examples including the usage of Types, Structs, Arrays, Threading and many more in\nthe [examples](examples/) directory of this repository. The most interresting ones are listed here:\n\n- [pi](examples/pi.ptrs) and [circle](examples/circle.ptrs) Basic mathematic expressions and loops\n- [fork](examples/fork.ptrs) Using posix functions for creating child processes\n- [array](examples/array.ptrs) and [bubblesort](examples/bubblesort.ptrs) Basic array usage\n- [struct](examples/struct.ptrs) Basic struct usage\n- [threads](examples/threads.ptrs) Using libpthread\n- [gtk](examples/gtk.ptrs) Using GTK for creating a window with a clickable button.\n- [window](examples/window.ptrs) Using libSDL for creating X windows. (Example orginally by [@Webfreak001](https://github.com/WebFreak001))\n\n## Installing\nPointerscript uses [libjit](https://www.gnu.org/software/libjit/) which is included in the repository as a submodule.\n```bash\n#Install dependencies (this might differ if you are not using debian)\n# everything below apart from git and build-essential is required by libjit\nsudo apt install git build-essential bison flex autoconf automake libtool texinfo\n\n#Recursively clone the repository\ngit clone --recursive https://github.com/M4GNV5/PointerScript\n\n#Compile...\ncd PointerScript\nmake -j4 #-j specifies the number of tasks to run in parallel\n\n#Done! PointerScript is at ./bin/ptrs\nbin/ptrs --help\n```\n\n## License\n[EUPL v1.2](LICENSE.txt)\n\n\u003e Copyright (C) 2020 Jakob Löw (jakob@löw.com)\n\u003e\n\u003e Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European\n\u003e Commission - subsequent versions of the EUPL (the \"Licence\"); You may not use this work\n\u003e except in compliance with the Licence.\n\u003e\n\u003e You may obtain a copy of the Licence at:\n\u003e http://ec.europa.eu/idabc/eupl.html\n\u003e\n\u003e Unless required by applicable law or agreed to in writing, software distributed under\n\u003e the Licence is distributed on an \"AS IS\" basis, WITHOUT WARRANTIES OR CONDITIONS OF\n\u003e ANY KIND, either express or implied. See the Licence for the specific language\n\u003e governing permissions and limitations under the Licence.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4gnv5%2Fpointerscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm4gnv5%2Fpointerscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4gnv5%2Fpointerscript/lists"}