{"id":41289733,"url":"https://github.com/anissen/cosy","last_synced_at":"2026-01-23T03:28:29.180Z","repository":{"id":37954700,"uuid":"224719431","full_name":"anissen/cosy","owner":"anissen","description":"A simple and pleasant programming language.","archived":false,"fork":false,"pushed_at":"2023-01-14T21:14:24.000Z","size":2460,"stargazers_count":24,"open_issues_count":2,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2023-03-13T04:05:35.389Z","etag":null,"topics":["compiler","interpreter","language","programming-language"],"latest_commit_sha":null,"homepage":"http://andersnissen.com/cosy","language":"Haxe","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/anissen.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}},"created_at":"2019-11-28T19:49:20.000Z","updated_at":"2022-12-12T23:07:39.000Z","dependencies_parsed_at":"2023-02-09T20:30:33.739Z","dependency_job_id":null,"html_url":"https://github.com/anissen/cosy","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/anissen/cosy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anissen%2Fcosy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anissen%2Fcosy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anissen%2Fcosy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anissen%2Fcosy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anissen","download_url":"https://codeload.github.com/anissen/cosy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anissen%2Fcosy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28679145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T01:00:35.747Z","status":"online","status_checked_at":"2026-01-23T02:00:08.296Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","interpreter","language","programming-language"],"created_at":"2026-01-23T03:28:28.571Z","updated_at":"2026-01-23T03:28:29.174Z","avatar_url":"https://github.com/anissen.png","language":"Haxe","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/anissen/cosy\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/anissen/cosy/master/docs/images/cosy-logo.svg\" height=\"30%\" width=\"30%\"\u003e\n  \u003c/a\u003e\n\n  \u003cp align=\"center\"\u003e\n    A simple and pleasant programming language.\n    \u003c!-- \u003cbr /\u003e\n    \u003ca href=\"https://github.com/anissen/cosy\"\u003e\u003cstrong\u003eExplore the docs »\u003c/strong\u003e\u003c/a\u003e\n    \u003cbr /\u003e --\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"http://andersnissen.com/cosy/playground\"\u003eOnline Playground\u003c/a\u003e\n    ·\n    \u003ca href=\"http://andersnissen.com/cosy/api\"\u003eAPI Documentation\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n## Cosy\n\nCosy is a simple and pleasant programming language. Cosy is simple to read and write and has extensive compile-time validating. It has an multi-platform interpreter and can trans-compile to JavaScript.\n\n```js\nprint 'hello world'\n```\n\n## High-level features\n* Familiar syntax.\n* Lambda functions (anonymous functions).\n* Gradural typing.\n* Small and concise.\n  * Cosy is made with fewer than 3200 lines of source code.\n  * Few keywords.\n* Safety.\n  * Variable are immutable by default.\n  * No `null`, `nil` or `undefined`.\n  * No variable shadowing.\n* Compile-time validation.\n  * Unused variables.\n  * Simple dead code detection, i.e. statements following an unconditional `return` in a block.\n  * Type checking.\n* String interpolation.\n* Has built-in code formatter.\n* Simple code optimization.\n* No library dependencies.\n* Web based [playground](http://andersnissen.com/cosy/playground/).\n* Inspired by [V](https://vlang.io/), [Rust](https://www.rust-lang.org/) and [Haxe](https://haxe.org/) among others. Originally based on [Lox](http://www.craftinginterpreters.com/).\n\n## Cosy compiler data flow\n\u003cimg src=\"https://raw.githubusercontent.com/anissen/cosy/master/docs/images/data-flow.png\" width=\"100%\"\u003e\n\n\n## Code examples\n\u003cdetails\u003e\n\u003csummary\u003eCosy basics\u003c/summary\u003e\n\n```js\n// the basics of cosy\n\n// print to output\nprint 'hello world!'\n\n\n// variables and types\nlet a = true     // Boolean\nlet b = 1.2      // Number\nlet c = 'hello'  // String\nlet d = [3, 4]   // Array\n\nstruct Point {   // Struct\n    let x\n    let y\n    let text = 'default value'\n}\n// instantiate struct\nlet point = Point { x = 3, y = 5 }\nprint point\n\n// variables are immutable by default\nlet immutable = 42\n// immutable = 24 // error\n\n// use the `mut` keyword to create a mutable variable\nmut mutable = 42\nmutable = 24 // ok\n\n\n// conditional branching\nif 3 \u003c 5 and 4 == 4 {\n    print 'true'\n} else {\n    print 'false'\n}\n\n\n// loop with counter\nfor i in 0..3 {\n    print 'loop #' + i\n}\n\n// loop without counter\nfor 0..3 {\n    print 'no counter'\n}\n\n// loop with condition\nmut j = 0\nfor j \u003c 3 {\n    print 'conditional loop #i'\n    j = j + 1\n}\n\n// loop over array\nfor i in [5, 6, 7] {\n    print 'array value: ' + i\n}\n\n\n// functions\nfn say(name) {\n    print 'hello ' + name\n}\nsay('world')\n\n// lambda functions\nlet square = fn(value Num) {\n    return value * value\n}\nprint '5 * 5 = ' + square(5)\n\n// functions can return functions\nfn say_with_extra_text(extra_text Str) {\n    return fn(text) {\n        print text + extra_text\n    }\n}\nlet print_courteously = say_with_extra_text(', please!')\nprint_courteously('make me a sandwich')\n\n// functions can tage functions as arguments\nfn do_n_times(f Fn(Num), n Num) {\n    for i in 0..n {\n        f(i)\n    }\n}\ndo_n_times(fn(x Num) { print 'i\\'m called ' + (x + 1) + ' time(s)' }, 3)\n\n// functions act as closures\nfn counter(start, increment) Fn() Num {\n    mut count = start\n    return fn() {\n        count = count + increment\n        return count\n    }\n}\nprint 'counting down...'\nlet count_down = counter(3, -1)\nprint count_down()\nprint count_down()\nprint count_down()\n\n\n// dead code is not allowed\nfn dead_code() {\n    print 'i\\'m always printing this'\n    return true\n    // print 'i\\'m never printing this' // error\n}\ndead_code()\n\n\n// shadowing of variables are not allowed\n{\n    let unique = true\n    {\n        //let unique = 3 // error\n    }\n    print unique\n}\n\n\n// unused variables are not allowed\nlet unused = 42 // error if the line below is removed\nprint unused\n// because of this, we also have to use the variables defined at the top\nif !a print b + c + d + immutable + mutable\n\n// variables can be marked purposely unused with an underscore\nfn some_function(_unused) {\n    print 'the arg is unused, but that\\'s okay'\n}\nsome_function(1234)\n\n\n// that's it for the basics\n// for more examples see:\n// https://github.com/anissen/cosy/tree/master/test/scripts\n```\n\n\u003c/details\u003e\n\n\n## Getting started\n\nTo get a local copy up and running follow these simple steps.\n\n1. Clone the cosy repository\n    ```sh\n    git clone https://github.com/anissen/cosy.git\n    ```\n\n2. Change to the repository directory\n    ```sh\n    cd cosy\n    ```\n\n3. Install [lix](https://github.com/lix-pm/lix.client), a Haxe package manager\n    ```sh\n    npm install lix -g\n    ```\n\n4. Downloading all dependencies\n    ```sh\n    lix download\n    ```\n\n## Usage\n\nUsage: `cosy \u003coptions\u003e (source file)`\n\nOptions:\n```\n--prettyprint    Prints the formatted source.\n--bytecode       Prints the compiled Cosy bytecode.\n--disassembly    Pretty-print Cosy bytecode.\n--javascript     Prints the corresponding JavaScript code.\n--markdown       Prints the code as Markdown documentation.\n--strict         Enable strict enforcing of types.\n--validate-only  Only perform code validation.\n--times          Output time spent in each phase.\n--watch          Watch the file for changes and automatically rerun.\n--no-colors      Disable colors in log output.\n```\n\n\u003c!--\nInformation about using Cosy as stand-alone and integrated into other code as a library\n--\u003e\n\n### Using Haxe interpreter\nRun: `haxe -cp src --run cosy.Cosy`.\n\n### Using JavaScript\nBuild: `haxe scripts/javascript.hxml`.\n\nInclude in your HTML body: `\u003cscript src=\"cosy.js\"\u003e\u003c/script\u003e`.\n\nRun: `window.cosy.Cosy.run(\"print 'hello javascript!'\")`.\n\n### Using Node\nBuild: `haxe scripts/node.hxml`.\n\nRun (as script): `node ./bin/node/cosy.js`.\n\nRun (as library): \n```js\nconst cosy = require(\"./bin/node/cosy.js\").cosy.Cosy;\ncosy.run(\"print 'hello node!'\");\n```\n\n### Using Java\nBuild:\n\n    haxe -cp src -main cosy.Cosy -java bin/java\n\nRun: \n\n    java -jar bin/java/cosy.jar\n\n### Using JVM\nBuild:\n\n    haxe -cp src -main cosy.Cosy --jvm bin/jvm/Cosy.jar\n\nRun:\n\n    java -jar bin/jvm/Cosy.jar\n\n### Using C++\nBuild:\n\n    haxe -main cosy.Cosy -cp src -cpp bin/cpp\n\nRun:\n\n    ./bin/cpp/Cosy\n\n### Using HashLink (bytecode or C)\nBuild to bytecode\n\n    haxe -main cosy.Cosy -cp src -hl bin/hl/Cosy.hl\n\nRun from bytecode\n\n    hl bin/hl/Cosy.hl\n\nBuild to C\n\n    haxe -main cosy.Cosy -cp src -hl bin/hlc/build/Cosy.c\n\nCompile\n\n    gcc -O3 -o bin/hlc/Cosy -std=c11 -I bin/hlc/build bin/hlc/build/Cosy.c -lhl\n\nRun:\n\n    ./bin/hlc/Cosy\n\n\n## Roadmap\n\nCosy is a work-in-progress.\n\nCurrent focus is: :star: _Bytecode code generator and virtual machine_.\n\nSee the [wishlist](https://github.com/anissen/cosy/blob/master/wishlist.md) for a list of proposed features (and known issues).\n\n## License\n\n\u003cdetails\u003e\n\u003csummary\u003eDistributed under the MIT License.\u003c/summary\u003e\n\n```\nMIT License\n\nCopyright (c) 2021 Anders Nissen\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n\u003c/details\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanissen%2Fcosy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanissen%2Fcosy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanissen%2Fcosy/lists"}