{"id":14966170,"url":"https://github.com/curttilmes/perl6-tcc","last_synced_at":"2025-10-25T16:30:41.246Z","repository":{"id":141572675,"uuid":"95052802","full_name":"CurtTilmes/perl6-tcc","owner":"CurtTilmes","description":"Perl 6 bindings for TCC, the Tiny C Compiler","archived":false,"fork":false,"pushed_at":"2017-06-23T14:18:46.000Z","size":21,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T07:51:27.809Z","etag":null,"topics":["c","perl6"],"latest_commit_sha":null,"homepage":"","language":"Perl6","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CurtTilmes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2017-06-21T22:48:53.000Z","updated_at":"2019-05-14T19:04:20.000Z","dependencies_parsed_at":"2024-07-09T18:45:49.028Z","dependency_job_id":null,"html_url":"https://github.com/CurtTilmes/perl6-tcc","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"17fd731044842810c54c55517033acf7d2dce8ae"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CurtTilmes%2Fperl6-tcc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CurtTilmes%2Fperl6-tcc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CurtTilmes%2Fperl6-tcc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CurtTilmes%2Fperl6-tcc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CurtTilmes","download_url":"https://codeload.github.com/CurtTilmes/perl6-tcc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238174106,"owners_count":19428626,"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":["c","perl6"],"created_at":"2024-09-24T13:35:57.360Z","updated_at":"2025-10-25T16:30:35.931Z","avatar_url":"https://github.com/CurtTilmes.png","language":"Perl6","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Perl 6 bindings for TCC, the Tiny C Compiler\n\n[![Build Status](https://travis-ci.org/CurtTilmes/perl6-tcc.svg)](https://travis-ci.org/CurtTilmes/perl6-tcc)\n\n# Description\n\nTCC provides Perl 6 bindings for [tcc](https://bellard.org/tcc/), the\nTiny C Compiler, an extremely fast C compiler that can compile C code\ndirectly into a memory block that is then callable by Perl.  You can\nalso expose your perl functions to C which can call them, and pass\ndata back and forth.\n\nThe interface between Perl and C makes extensive use of the Perl 6\n[NativeCall](https://docs.perl6.org/language/nativecall) capabilities,\nand is subject to its types and other restrictions.\n\n# Installation\n\nYou have to build [tcc](https://bellard.org/tcc/), the Tiny C Compiler\nby hand since it doesn't install the shared library by default, and\nmost distributions don't include it.\n\n```\ngit clone https://github.com/run4flat/tinycc.git\ncd tinycc\n./configure\nmake libtcc.so   # Have to do this first to compile with PIC for shared\nmake\nsudo make install\nsudo cp libtcc.so /usr/local/lib # or somewhere convenient\n```\n\n# Synopsis\nSee [eg/testit.pl6](eg/testit.pl6)\n\n```perl6\nuse v6;\nuse TCC;\n\n# Make a new Tiny C Compiler\nmy $tcc = TCC.new('-I/usr/local/include -L/usr/local/lib -DDEBUG=0');\n\n# Compile a C program into memory\n$tcc.compile:\n'\n    #include \u003cstdio.h\u003e\n    int add(int a, int b);  /* declare perl functions to quiet warnings */\n    void print_something(char *my_string);\n\n    int x = 7;\n\n    int fib(int n)\n    {\n        if (n \u003c= 2)\n            return 1;\n        else\n            return fib(n-1) + fib(n-2);\n    }\n\n    int foo(int n)\n    {\n        printf(\"Hello World!\\n\");\n        printf(\"fib(%d) = %d\\n\", n, fib(n));\n        printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n\n        print_something(\"this is just a test\");\n\n        if (DEBUG) { print_something(\"debug is on\"); }\n\n        return 0;\n    }\n\n    int set_x(int n)\n    {\n        x = n;\n    }\n';\n\n# These are just perl subs for C to call\nsub add(int32 $a, int32 $b --\u003e int32)\n{\n    return $a + $b;\n}\n\n# This one gets renamed to 'print_something' for C\nsub print-something(Str $my-string)\n{\n    say $my-string;\n}\n\n# Add some perl subs for C to call\n$tcc.add-symbol(\u0026add);\n$tcc.add-symbol(\u0026print-something, name =\u003e 'print_something');\n\n# You just have to do this, so do it.\n$tcc.relocate;\n\n# Bind C functions to perl callable variables, must pass in signature\nmy \u0026fib   := $tcc.bind('fib', :(int32 --\u003e int32));\nmy \u0026foo   := $tcc.bind('foo', :(int32 --\u003e int32));\nmy \u0026set_x := $tcc.bind('set_x', :(int32 --\u003e int32));\n\n# Bind Perl variable to C symbol, pass in type and an optional function\n# to set the variable if you want to go both ways\nmy $x     := $tcc.bind('x', int32, \u0026set_x);\n\n# Once everything is compiled and bound, just work in Perl land like normal:\n\nsay fib(12);\n\nfoo(17);\n\nsay $x;\n\nset_x(12345);\n\nsay $x;\n\n$x = 752;\n\nsay $x;\n```\n\nOutput:\n```\n144\nHello World!\nfib(17) = 1597\nadd(17, 34) = 51\nthis is just a test\n7\n12345\n752\n```\n\n\n# NOTES\n\n* Some assumptions on 64-bit architecture, but everyone has that\n  anyway, right?\n\n* Not really set up for Windows yet -- patches welcome!\n\n* For now you have to manually write a store function if you want\n  two-way variable binding.  Could probably do this automatically.\n\n* The Tiny C Compiler also includes an assembler, so if even C is too\n  slow for you, you can embed x86 assembly language into your critical\n  portions for super speed!\n\n# Acknowledgements\n\nDeveloped after presentation and discussion with David Mertens about\nthe Perl 5 module [C::Blocks](https://metacpan.org/pod/C::Blocks) and\nhow one might approach that in Perl 6.\n\n# SEE ALSO\n\n[Inline](https://github.com/FROGGS/p6-Inline-C)\n\n`Inline::C` uses a slower C compiler, and goes to temp files on disk\nfor compiling and library linking but should generate more optimized\ncode.  It also doesn't seem to have as nice an interface for\ninteracting back and forth with perl.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcurttilmes%2Fperl6-tcc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcurttilmes%2Fperl6-tcc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcurttilmes%2Fperl6-tcc/lists"}