{"id":23959474,"url":"https://github.com/Vexu/toy-lang","last_synced_at":"2025-09-12T17:31:21.277Z","repository":{"id":42573723,"uuid":"235188662","full_name":"Vexu/toy-lang","owner":"Vexu","description":"Toy language for experimentation and fun.","archived":false,"fork":false,"pushed_at":"2025-03-10T23:46:35.000Z","size":1274,"stargazers_count":585,"open_issues_count":6,"forks_count":16,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-08-31T19:36:30.245Z","etag":null,"topics":["compiler","programming-language"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/Vexu.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,"zenodo":null}},"created_at":"2020-01-20T20:04:53.000Z","updated_at":"2025-08-29T08:55:14.000Z","dependencies_parsed_at":"2025-01-04T12:37:31.839Z","dependency_job_id":"0e12fefa-4b7a-4416-a435-ddabeed04394","html_url":"https://github.com/Vexu/toy-lang","commit_stats":{"total_commits":423,"total_committers":7,"mean_commits":60.42857142857143,"dds":"0.023640661938534313","last_synced_commit":"47ceed58b41e57823a10a153b6b20a0a3b2d85a6"},"previous_names":["vexu/toy-lang","vexu/bog"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Vexu/toy-lang","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vexu%2Ftoy-lang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vexu%2Ftoy-lang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vexu%2Ftoy-lang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vexu%2Ftoy-lang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vexu","download_url":"https://codeload.github.com/Vexu/toy-lang/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vexu%2Ftoy-lang/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274847400,"owners_count":25360978,"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","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"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","programming-language"],"created_at":"2025-01-06T18:01:19.866Z","updated_at":"2025-09-12T17:31:21.242Z","avatar_url":"https://github.com/Vexu.png","language":"Zig","funding_links":[],"categories":["Zig"],"sub_categories":[],"readme":"Small, strongly typed, embeddable language. \n## [Examples](examples)\n\n### Hello world\n```julia\nlet {print} = import \"std.io\"\nlet world = \"world\"\nprint(f\"hello {world}!\")\n```\n\n### Async/await\n```julia\nlet {print} = import \"std.io\"\n\nlet foo = fn()\n    print(\"foo started\")\n    let bar_frame = async bar()\n    print(\"in foo\")\n    let bar_res = await bar_frame\n    print(\"foo finished\")\n    return bar_res\n\nlet bar = fn()\n    print(\"bar started\")\n    suspend\n    print(\"bar resumed\")\n    suspend\n    print(\"bar finished\")\n    return 1\n\n\nprint(\"main started\")\nlet foo_frame = async foo()\nprint(\"in main\")\nlet res = await foo_frame\nprint(\"main finished:\", res)\n```\n```sh-session\n$ bog async.bog\nmain started\nfoo started\nbar started\nin foo\nbar resumed\nin main\nbar finished\nfoo finished\nmain finished: 1\n```\n\n### Calculator\n```julia\nlet {input, print} = import \"std.io\"\n\ntry\n    let val1 = input(\"first argument: \") as num\n    let op = input(\"operation: \")\n    let val2 = input(\"second argument: \") as num\n\n    match op\n        \"*\" =\u003e print(val1 * val2)\n        \"+\" =\u003e print(val1 + val2)\n        \"-\" =\u003e print(val1 - val2)\n        \"/\" =\u003e print(val1 / val2)\n        \"**\" =\u003e print(val1 ** val2)\n        _ =\u003e print(f\"unknown op: {op}\")\ncatch\n    print(\"that's not a number\")\n```\n\n### Use command line arguments\n```julia\n# run with `path/to/bog path/here.bog arg1 arg2 \"foo\"`\nlet {print} = import \"std.io\"\nprint(import \"args\")\n```\n\n### Loops\n```julia\nlet mut sum = 0\nfor let c in \"hellö wörld\"\n    match c\n        \"h\" =\u003e sum += 1\n        \"e\" =\u003e sum += 2\n        \"l\" =\u003e sum += 3\n        \"ö\" =\u003e sum += 4\n        \"w\" =\u003e sum += 5\n        \"d\" =\u003e sum += 6\n\nreturn sum # 31\n```\n```julia\nlet getSome = fn(val) if (val != 0) val - 1\n\nlet mut val = 10\nwhile let newVal = getSome(val)\n    val = newVal\nreturn val # 0\n```\n\n### Error handling\n```julia\nlet {input, print} = import \"std.io\"\n\nlet fails_on_1 = fn(arg) if arg == 1 error(69)\nlet fails_on_2 = fn(arg) if arg == 2 error(42)\nlet fails_on_3 = fn(arg) if arg == 3 error(17)\n\nlet foo = fn(arg)\n    try\n        fails_on_1(arg)\n        fails_on_2(arg)\n        fails_on_3(arg)\n    catch let err\n        return err\n\n    return 99\n\nprint(for let i in 0:4 foo(i)) # [99, 69, 42, 17]\nprint(try fails_on_1(input(\"give number: \") as int) catch \"gave 1\")\n```\n\n### Destructuring assignment\n```julia\nlet add = fn ((a,b)) a + b\nlet tuplify = fn (a,b) (a,b)\nreturn add(tuplify(1,2)) # 3\n```\n\n## Embed\n```zig\nconst bog = @import(\"bog\");\n\nvar vm = bog.Vm.init(allocator, .{ .import_files = true });\ndefer vm.deinit();\ntry vm.addStd();\n\nconst res = vm.run(source) catch |e| switch (e) {\n    else =\u003e |err| return err,\n    error.TokenizeError, error.ParseError, error.CompileError =\u003e {\n        try vm.errors.render(source, out_stream);\n        return error.RunningBogFailed;\n    },\n};\n\nconst bog_bool = try res.bogToZig(bool, \u0026vm);\n```\n\n### Calling Bog functions from Zig\n\n```zig\nvar vm = Vm.init(allocator, .{});\ndefer vm.deinit();\n\nconst res = vm.run(source) catch |e| switch (e) {\n    else =\u003e |err| return err,\n    error.TokenizeError, error.ParseError, error.CompileError =\u003e {\n        try vm.errors.render(source, out_stream);\n        return error.RunningBogFailed;\n    },\n};\n\nconst call_res = vm.call(res, \"bogFunction\", .{1, true}) catch |e| switch (e) {\n    else =\u003e |err| return err,\n    error.TokenizeError, error.ParseError, error.CompileError =\u003e {\n        try vm.errors.render(source, out_stream);\n        return error.CallingBogFunctionFailed;\n    },\n};\n\nconst bog_integer = try call_res.bogToZig(i64, \u0026vm);\n```\n\n### Calling Zig functions from Bog\n\n```zig\nconst my_lib = struct {\n    pub fn pow(val: i64) i64 {\n        return val * val;\n    }\n};\n\nvar vm = Vm.init(allocator, .{});\ndefer vm.deinit();\ntry vm.addPackage(\"my_lib\", my_lib);\n\nconst res = vm.run(source) catch |e| switch (e) {\n    else =\u003e |err| return err,\n    error.TokenizeError, error.ParseError, error.CompileError =\u003e {\n        try vm.errors.render(source, out_stream);\n        return error.RunningBogFailed;\n    },\n};\n\nconst bog_integer = try res.bogToZig(i64, \u0026vm);\nstd.debug.assert(bog_integer == 8);\n```\n\n```julia\nlet {pow} = import \"my_lib\"\n\nreturn 2 * pow(2)\n```\n\n## Setup\n* Download master version of Zig from https://ziglang.org/download/\n* Clone this repo\n* Build with `zig build`\n* Run with `./zig-cache/bin/bog`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVexu%2Ftoy-lang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVexu%2Ftoy-lang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVexu%2Ftoy-lang/lists"}