Embedded programming language for Zig
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

stdlib changes, remove libload

the language should be small for embedding

IamPyu b81bf996 43edb54f

+10 -98
+2 -2
build.zig.zon
··· 3 3 .version = "0.1.0", 4 4 .dependencies = .{ 5 5 .mitochondria = .{ 6 - .url = "git+https://codeberg.org/IamPyu/mitochondria#ca71810849947cbdfc717db0a9de87011f34c19c", 7 - .hash = "mitochondria-0.1.0-RHWHd0ecAADYvF8d3fbTb7-Gga2LErrVmJ9YeQWdfQH9", 6 + .url = "git+https://codeberg.org/IamPyu/mitochondria.git#7b79ffc2df9493e27d9e5c29a53b29ba2c6b3d8a", 7 + .hash = "mitochondria-0.1.0-RHWHd1h4AAAwcZAj91bIc38DOwq8I8hDgo9sybJis8-v", 8 8 }, 9 9 }, 10 10 .minimum_zig_version = "0.15.2",
+3 -12
src/std.zig
··· 3 3 const Scope = zexa.types.Scope; 4 4 const Value = zexa.types.Value; 5 5 6 - pub const corelib = @import("./std/core.zig"); 7 - pub const dylib = @import("./std/libload.zig"); 6 + const corelib = @import("./std/core.zig"); 8 7 9 - pub const StdConfiguration = struct { 10 - load_dylib: bool = true, 11 - load_iolib: bool = true, 12 - }; 8 + pub const StdConfiguration = struct {}; 13 9 14 10 pub fn loadStd(scope: *Scope, config: StdConfiguration) !void { 11 + _ = config; 15 12 try corelib.load(scope); 16 - 17 - if (config.load_dylib) { 18 - try dylib.load(scope); 19 - } 20 - 21 - if (config.load_iolib) {} 22 13 }
-79
src/std/libload.zig
··· 1 - const std = @import("std"); 2 - const DynLib = std.DynLib; 3 - 4 - const zexa = @import("../root.zig"); 5 - const Scope = zexa.types.Scope; 6 - const Value = zexa.types.Value; 7 - const RuntimeError = zexa.types.RuntimeError; 8 - const NativeFunc = zexa.types.NativeFunc; 9 - const NativeMacro = zexa.types.NativeMacro; 10 - 11 - const SliceIterator = @import("mitochondria").SliceIterator; 12 - 13 - pub fn load(scope: *Scope) !void { 14 - try scope.insert("dynlib:load", try Value.initNativeFunc(scope, loadLib)); 15 - try scope.insert("dynlib:close", try Value.initNativeFunc(scope, closeLib)); 16 - } 17 - 18 - pub fn loadLib(scope: *Scope, args: []const *Value) RuntimeError!*Value { 19 - if (args.len != 1) { 20 - return RuntimeError.InvalidArguments; 21 - } 22 - 23 - const lib = args[0]; 24 - 25 - if (lib.getType() != .str) { 26 - return RuntimeError.InvalidArguments; 27 - } 28 - 29 - const dynlib = try scope.allocator.create(DynLib); 30 - dynlib.* = DynLib.open(lib.atom.str) catch return RuntimeError.External; 31 - return Value.initUserData(scope, dynlib); 32 - } 33 - 34 - pub fn closeLib(scope: *Scope, args: []const *Value) RuntimeError!*Value { 35 - if (args.len != 1) 36 - return RuntimeError.InvalidArguments; 37 - 38 - const lib = args[0]; 39 - 40 - if (lib.getType() != .userdata) 41 - return RuntimeError.InvalidArguments; 42 - 43 - const dynlib = @as(*DynLib, @ptrCast(@alignCast(lib.atom.userdata))); 44 - dynlib.close(); 45 - scope.allocator.destroy(dynlib); 46 - 47 - return Value.initNil(scope); 48 - } 49 - 50 - pub fn lookup(scope: *Scope, args: []const *Value) RuntimeError!*Value { 51 - if (args.len != 3) 52 - return RuntimeError.InvalidArguments; 53 - 54 - const lib = args[0]; 55 - 56 - if (lib.getType() != .userdata) 57 - return RuntimeError.InvalidArguments; 58 - const dynlib = @as(*DynLib, lib.atom.userdata); 59 - 60 - const mode = args[1]; 61 - if (mode.getType() != .sym) 62 - return RuntimeError.InvalidArguments; 63 - 64 - const name = args[2]; 65 - if (name.getType() != .str) 66 - return RuntimeError.InvalidArguments; 67 - const namestr = name.atom.str; 68 - 69 - const modestr = mode.atom.sym; 70 - if (std.mem.eql(u8, modestr, "func")) { 71 - if (dynlib.lookup(NativeFunc, namestr)) |func| { 72 - return try Value.initNativeFunc(scope, func); 73 - } 74 - } else { 75 - return RuntimeError.InvalidArguments; 76 - } 77 - 78 - return try Value.initNil(scope); 79 - }
+5
src/test/count.zexa
··· 1 + (define 'count 0) 2 + 3 + (while (not (eql count 5000)) 4 + (print (add count 1)) 5 + (set 'count (add count 1)))
-5
src/test/test2.zexa
··· 1 - (define 'count 5000) 2 - 3 - (while (not (eql count 0)) 4 - (print count) 5 - (set 'count (sub count 1)))
src/test/test3.zexa src/test/hello.zexa