{"id":15924807,"url":"https://github.com/harkal/picolang","last_synced_at":"2025-03-24T13:33:19.396Z","repository":{"id":44208305,"uuid":"277758322","full_name":"harkal/picolang","owner":"harkal","description":"A Compiled high level language for the picoVM embeddedable virtual machine","archived":false,"fork":false,"pushed_at":"2022-02-11T01:55:18.000Z","size":184,"stargazers_count":5,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T03:53:10.556Z","etag":null,"topics":["compiler","embedded-systems","languages"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harkal.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}},"created_at":"2020-07-07T08:18:04.000Z","updated_at":"2023-02-03T21:09:39.000Z","dependencies_parsed_at":"2022-08-20T02:00:48.671Z","dependency_job_id":null,"html_url":"https://github.com/harkal/picolang","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/harkal%2Fpicolang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harkal%2Fpicolang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harkal%2Fpicolang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harkal%2Fpicolang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harkal","download_url":"https://codeload.github.com/harkal/picolang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245279959,"owners_count":20589553,"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","embedded-systems","languages"],"created_at":"2024-10-06T21:40:55.317Z","updated_at":"2025-03-24T13:33:19.032Z","avatar_url":"https://github.com/harkal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":" PicoLang - A Compiled high level language for the picoVM embeddedable virtual machine\n=======================================================================================\n\nThis project provides a small high level compiler that targets the embeddedable virtual machine \n(https://github.com/harkal/picovm). \n\nFeatures\n--------\n* Clean and familiar, C like syntax\n* Aims to have everything be an expression \n* Supports integers and floating point arithmetic\n* Compiles to binary code, not interpreted\n* Generics/templates support (take that Golang! :P)\n* Inline assembly support\n\nThe compiler itself is coded in Javascript in order to be easily used by web apps and electron \napps that configure programmable microcontrollers.\n\nHaving said that, the compiler is super-alpha™ code. The bulk of the code was written over a\nweekend as a challenge to myself. For example error reporting is simply not there right now.\nOf course, as I continue to work on it, I will get this updated. \n\nExample\n-------\n\nOk, so what does it look like? Let's look at a classic example:\n\n```C\n//\n// Fibonacci numbers\n//\n\ndef fib(x) {\n    if (x \u003c= 1) {\n        return  x\n    } else {\n        return fib(x-1) + fib(x-2)\n    }\n}\n\nfib(6) \n```\n\nIn this example we define a procedure named `fib` that takes a parameter `x` and returns the `x`-th fibonacci number. Note that we don't provide a data type for `x`. This procedure is a template that PicoLang will use to generate a type specific procedure when the procedure is used. In this example it will be compiled down to machine code as if `x` was of integer type because of the call `fib(6)`.\n\nEven though the above code would compile and run just fine, since in PicoLang everything is an expression we would probably write it in a more picolang-ie form:\n\n```C++\n//\n// Fibonacci numbers\n//\n\ndef fib(x)\n    if x \u003c= 1\n        x\n    else\n        fib(x-1) + fib(x-2)\n    \nfib(6) \n```\n\nSweet!\n\nA more elaborate example\n------------------------\n\nWhat if we want to draw the Mandelbrot set? Let's see the code:\n\n```C++\n\ndef putc(ch) {\n    __asm__ \"LOAD32 [SFP + 4]\"\n    __asm__ \"CALLUSER\"\n}\n\ndef pdensity(d) \n    if d \u003e 32.0\n        putc(32)  // ' '\n    else if d \u003e 16.0 \n        putc(46) // '.'\n    else if d \u003e 8.0 \n        putc(58) // ':'\n    else if d \u003e 4.0 \n        putc(45) // '-'\n    else if d \u003e 2.0\n        putc(61) // '='\n    else if d \u003e 1.0 \n         putc(42) // '*'\n    else if d \u003e 0.5 \n        putc(37) // '%'\n    else\n        putc(64) // '@'\n\ndef mandelconverge(real, imag, iters, creal, cimag) \n    if real*real + imag*imag \u003e 4\n        iters\n    else if iters \u003e 254\n        iters\n    else \n        mandelconverge(real*real - imag*imag + creal, 2*real*imag + cimag, iters+1, creal, cimag)\n\ndef mandelhelp(xmin, xmax, xstep, ymin, ymax, ystep)\n{\n    y = ymin\n    while y \u003c ymax {\n        x = xmin\n        while x \u003c xmax {\n            pdensity(mandelconverge(x, y, 0, x, y))\n            x = x + xstep\n        }\n        putc(10)\n        y = y + ystep\n    }\n}\n\ndef mand(realstart, imagstart, realmag, imagmag)\n    mandelhelp(realstart, realstart+realmag*120, realmag, imagstart, imagstart+imagmag*40, imagmag)\n\nmand(0-2.1, 0-1.3, 0.027, 0.067)\n\n```\n\nWe compile and run the above code in PicoVM and we get this result:\n\n```\n@@@@@@@@@@@@@@@@@@@@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%*********************%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@@@@@@@%%%%%%%%%%%%%%%%%%%*****************************************%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@@@@@%%%%%%%%%%%%%%%*********************************===========*********%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@@@%%%%%%%%%%%%*******************************==========--:--==========*******%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@@%%%%%%%%%%******************************==============--: :-----========********%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@%%%%%%%%******************************=================-----::.:---==========********%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@%%%%%%%*****************************==================-----:...::----===========*********%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@%%%%%*****************************==================----:: .     .::---============*********%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@%%%%****************************================----------..        .------===========*********%%%%%%%%%%%%%%%%\n@@@@@@@@@%%%***************************===============----:-------::::       .::-----------.-====**********%%%%%%%%%%%%%%\n@@@@@@@@%%%*************************===============----: ..: :::                 .  .---:-::--====***********%%%%%%%%%%%%\n@@@@@@@%%************************================-------:.   .                        :    ::--====***********%%%%%%%%%%%\n@@@@@@@%*********************=================-------:.:..                                .:---=====***********%%%%%%%%%%\n@@@@@@%***************=======-----------------------:.                                    . ----=====***********%%%%%%%%%\n@@@@@%*********=============---::------::----------.                                       . . --=====***********%%%%%%%%\n@@@@@%****=================-----::..::::. :.::--:::                                         ::---=====************%%%%%%%\n@@@@@***==================------::.           . :::.                                         ..-=======************%%%%%%\n@@@@%*=================--:----::                 ..                                         .:--=======************%%%%%%\n@@@@*==========-----------: :::.                                                            :--========************%%%%%%\n@@@@===-----::--------::::.                                                               :----=========***********%%%%%%\n@@@@====---------------::::                                                               .----=========***********%%%%%%\n@@@@*===========----------::::::                  .                                         :--========************%%%%%%\n@@@@%*==================------:...               :.                                          :--=======************%%%%%%\n@@@@@***==================------:..  .       . ::::                                         .::--======***********%%%%%%%\n@@@@@%*****================-----::..::::. ::::---:: .                                         ---=====************%%%%%%%\n@@@@@@**********============---::-------:----------: :                                     :.:.--=====***********%%%%%%%%\n@@@@@@%*****************======--------====----------..                                    ::----=====***********%%%%%%%%%\n@@@@@@@%*********************==================-------::::.                                .---=====***********%%%%%%%%%%\n@@@@@@@%%%***********************================-------:.   .                       .:    ..--====***********%%%%%%%%%%%\n@@@@@@@@%%%**************************===============---:: ::.::.  .            . :  :-----: --====**********%%%%%%%%%%%%%\n@@@@@@@@@%%%%***************************==============-------------::.        ::------------=====**********%%%%%%%%%%%%%%\n@@@@@@@@@@%%%%%****************************===============----------..       .:-----===========**********%%%%%%%%%%%%%%%%\n@@@@@@@@@@@%%%%%%*****************************==================---:..:.   ..:.---============*********%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@%%%%%%%******************************==================-----:: ::----===========********%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@%%%%%%%%******************************================-----::.::--=========********%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@@%%%%%%%%%%*******************************=============--::-----=========*******%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@@@@%%%%%%%%%%%%*******************************=========-:-:==========*******%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@@@@@%%%%%%%%%%%%%%%%***********************************=====***********%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@@@@@@@%%%%%%%%%%%%%%%%%%%%%**************************************%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n@@@@@@@@@@@@@@@@@@@@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%**************%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nExecuted 13518344 instructions\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharkal%2Fpicolang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharkal%2Fpicolang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharkal%2Fpicolang/lists"}