https://github.com/Vexu/bog Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + For + Enterprise + Teams + Startups + Education + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} Vexu / bog Public * Notifications * Fork 5 * Star 326 Small, strongly typed, embeddable language. License MIT license 326 stars 5 forks Star Notifications * Code * Issues 6 * Pull requests 0 * Actions * Security * Insights More * Code * Issues * Pull requests * Actions * Security * Insights Vexu/bog This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 7 branches 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/V] Use Git or checkout with SVN using the web URL. [gh repo clone Vexu/b] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @Vexu Vexu repl: use readUntilDelimiterAlloc for windows ... 3449ea8 Nov 14, 2022 repl: use `readUntilDelimiterAlloc` for windows zig-linenoize doesn't support windows currently. 3449ea8 Git stats * 422 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows run CI on pull requests; fix test step Nov 14, 2022 docs make import take an expression Apr 4, 2022 examples Update to changes in latest master Dec 19, 2021 include use autoIndentingStream in render Dec 8, 2020 lib/linenoize add linenoize src (only essential files) Nov 12, 2022 src repl: use readUntilDelimiterAlloc for windows Nov 14, 2022 tests workaround self-hosted bug Oct 12, 2022 .gitattributes add linenoize src (only essential files) Nov 12, 2022 .gitignore Fix compilation for zig master (#19) Sep 5, 2021 LICENSE add LICENSE and README.md Jan 24, 2020 README.md make import take an expression Apr 4, 2022 build.zig run CI on pull requests; fix test step Nov 14, 2022 View code [ ] Examples Hello world Async/await Calculator Use command line arguments Loops Error handling Destructuring assignment Embed Calling Bog functions from Zig Calling Zig functions from Bog Setup README.md Small, strongly typed, embeddable language. Examples Hello world let {print} = import "std.io" let world = "world" print(f"hello {world}!") Async/await let {print} = import "std.io" let foo = fn() print("foo started") let bar_frame = async bar() print("in foo") let bar_res = await bar_frame print("foo finished") return bar_res let bar = fn() print("bar started") suspend print("bar resumed") suspend print("bar finished") return 1 print("main started") let foo_frame = async foo() print("in main") let res = await foo_frame print("main finished:", res) $ bog async.bog main started foo started bar started in foo bar resumed in main bar finished foo finished main finished: 1 Calculator let {input, print} = import "std.io" try let val1 = input("first argument: ") as num let op = input("operation: ") let val2 = input("second argument: ") as num match op "*" => print(val1 * val2) "+" => print(val1 + val2) "-" => print(val1 - val2) "/" => print(val1 / val2) "**" => print(val1 ** val2) _ => print(f"unknown op: {op}") catch print("that's not a number") Use command line arguments # run with `path/to/bog path/here.bog arg1 arg2 "foo"` let {print} = import "std.io" print(import "args") Loops let mut sum = 0 for let c in "hello world" match c "h" => sum += 1 "e" => sum += 2 "l" => sum += 3 "o" => sum += 4 "w" => sum += 5 "d" => sum += 6 return sum # 31 let getSome = fn(val) if (val != 0) val - 1 let mut val = 10 while let newVal = getSome(val) val = newVal return val # 0 Error handling let {input, print} = import "std.io" let fails_on_1 = fn(arg) if arg == 1 error(69) let fails_on_2 = fn(arg) if arg == 2 error(42) let fails_on_3 = fn(arg) if arg == 3 error(17) let foo = fn(arg) try fails_on_1(arg) fails_on_2(arg) fails_on_3(arg) catch let err return err return 99 print(for let i in 0:4 foo(i)) # [99, 69, 42, 17] print(try fails_on_1(input("give number: ") as int) catch "gave 1") Destructuring assignment let add = fn ((a,b)) a + b let tuplify = fn (a,b) (a,b) return add(tuplify(1,2)) # 3 Embed const bog = @import("bog"); var vm = bog.Vm.init(allocator, .{ .import_files = true }); defer vm.deinit(); try vm.addStd(); const res = vm.run(source) catch |e| switch (e) { else => |err| return err, error.TokenizeError, error.ParseError, error.CompileError, error.RuntimeError => { try vm.errors.render(source, out_stream); return error.RunningBogFailed; }, }; const bog_bool = try res.bogToZig(bool, &vm); Calling Bog functions from Zig var vm = Vm.init(allocator, .{}); defer vm.deinit(); const res = vm.run(source) catch |e| switch (e) { else => |err| return err, error.TokenizeError, error.ParseError, error.CompileError, error.RuntimeError => { try vm.errors.render(source, out_stream); return error.RunningBogFailed; }, }; const call_res = vm.call(res, "bogFunction", .{1, true}) catch |e| switch (e) { else => |err| return err, error.TokenizeError, error.ParseError, error.CompileError, error.RuntimeError => { try vm.errors.render(source, out_stream); return error.CallingBogFunctionFailed; }, }; const bog_integer = try call_res.bogToZig(i64, &vm); Calling Zig functions from Bog const my_lib = struct { pub fn pow(val: i64) i64 { return val * val; } }; var vm = Vm.init(allocator, .{}); defer vm.deinit(); try vm.addPackage("my_lib", my_lib); const res = vm.run(source) catch |e| switch (e) { else => |err| return err, error.TokenizeError, error.ParseError, error.CompileError, error.RuntimeError => { try vm.errors.render(source, out_stream); return error.RunningBogFailed; }, }; const bog_integer = try res.bogToZig(i64, &vm); std.debug.assert(bog_integer == 8); let {pow} = import "my_lib" return 2 * pow(2) Setup * Download master version of Zig from https://ziglang.org/download/ * Clone this repo * Build with zig build * Run with ./zig-cache/bin/bog About Small, strongly typed, embeddable language. Topics programming-language compiler zig Resources Readme License MIT license Stars 326 stars Watchers 11 watching Forks 5 forks Contributors 5 * @Vexu * @data-man * @garrisonhh * @marler8997 * @iddev5 Languages * Zig 99.6% * C 0.4% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.