Embedded programming language for Zig
1
fork

Configure Feed

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

Rename stdlib to corelib

IamPyu 0e75298c 69a33d2c

+14 -24
+6 -6
src/env.zig
··· 89 89 const slice = try list.toSlice(scope); 90 90 91 91 for (slice) |v| { 92 - _ = try zexa.stdlib.corelib.print(scope, &.{v}); 92 + _ = try zexa.corelib.print(scope, &.{v}); 93 93 } 94 94 95 95 std.debug.print("{any}\n", .{scope.arena.queryCapacity()}); ··· 102 102 const scope = &env.primary_scope; 103 103 104 104 const list = try Value.initList(scope, &.{ 105 - try Value.initNativeFunc(scope, zexa.stdlib.corelib.print), 105 + try Value.initNativeFunc(scope, zexa.corelib.print), 106 106 try Value.initFromAny(scope, 3), 107 107 try Value.initFromAny(scope, 8), 108 108 try Value.initFromAny(scope, 435), ··· 137 137 var current = list; 138 138 while (current.getCdr()) |cdr| : (current = cdr) { 139 139 if (current.getCar()) |car| { 140 - _ = try zexa.stdlib.corelib.print(scope, &.{car}); 140 + _ = try zexa.corelib.print(scope, &.{car}); 141 141 } 142 142 } 143 143 } ··· 149 149 const scope = &env.primary_scope; 150 150 151 151 const list = try Value.initList(scope, &.{ 152 - try Value.initNativeFunc(scope, zexa.stdlib.corelib.format), 152 + try Value.initNativeFunc(scope, zexa.corelib.format), 153 153 try Value.initString(scope, "%{} hello %{} this is the format %{} string!"), 154 154 try Value.initFromAny(scope, 3544), 155 155 try Value.initFromAny(scope, 435), ··· 157 157 }); 158 158 159 159 const v = try scope.evalExpr(list); 160 - _ = try zexa.stdlib.corelib.print(scope, &.{v}); 160 + _ = try zexa.corelib.print(scope, &.{v}); 161 161 162 162 const s = try (try Value.initString(scope, "hey ")).add( 163 163 scope, 164 164 try Value.initString(scope, "cool!"), 165 165 ); 166 - _ = try zexa.stdlib.corelib.print(scope, &.{s}); 166 + _ = try zexa.corelib.print(scope, &.{s}); 167 167 168 168 std.debug.print("{d}\n", .{scope.arena.queryCapacity()}); 169 169 }
+1 -1
src/parser.zig
··· 124 124 125 125 var env = try Environment.init(std.testing.allocator); 126 126 defer env.deinit(); 127 - try zexa.stdlib.loadStd(&env.primary_scope); 127 + try zexa.corelib.loadCoreLibrary(&env.primary_scope); 128 128 129 129 var parser = try Parser.init(std.testing.allocator, &tokenizer, &env); 130 130 try parser.parse();
+3 -3
src/root.zig
··· 1 1 pub const lang = @import("./lang.zig"); 2 2 pub const env = @import("./env.zig"); 3 - pub const stdlib = @import("./stdlib.zig"); 3 + pub const corelib = @import("./corelib.zig"); 4 4 pub const util = @import("./util.zig"); 5 5 6 6 const lexer = @import("./lexer.zig"); ··· 42 42 /// Initialize a Zexa `State` 43 43 pub fn init(allocator: Allocator) !Self { 44 44 var e = try env.Environment.init(allocator); 45 - try stdlib.loadStd(&e.primary_scope); 45 + try corelib.loadCoreLibrary(&e.primary_scope); 46 46 47 47 return .{ 48 48 .allocator = allocator, ··· 95 95 test { 96 96 _ = lang; 97 97 _ = env; 98 - _ = stdlib; 98 + _ = corelib; 99 99 _ = lexer; 100 100 _ = parser; 101 101 }
-10
src/stdlib.zig
··· 1 - const std = @import("std"); 2 - const zexa = @import("./root.zig"); 3 - const Scope = zexa.lang.Scope; 4 - 5 - pub const corelib = @import("./stdlib/core.zig"); 6 - 7 - /// Load the standard library for `scope` 8 - pub fn loadStd(scope: *Scope) !void { 9 - try scope.loadLibrary(corelib.load); 10 - }
+4 -4
src/stdlib/core.zig src/corelib.zig
··· 2 2 3 3 const Io = std.Io; 4 4 5 - const zexa = @import("../root.zig"); 5 + const zexa = @import("./root.zig"); 6 6 const Scope = zexa.lang.Scope; 7 7 const Value = zexa.lang.Value; 8 8 const AST = zexa.lang.AST; 9 9 const RuntimeError = zexa.lang.RuntimeError; 10 10 11 - const util = @import("../util.zig"); 11 + const util = @import("./util.zig"); 12 12 const SliceIterator = util.SliceIterator; 13 13 const StringBuilder = util.StringBuilder; 14 14 15 15 const EXCEPTION_SIZE = 30; 16 16 17 - /// Entry point of the core library 18 - pub fn load(scope: *Scope) RuntimeError!void { 17 + /// Load the standard library for `scope` 18 + pub fn loadCoreLibrary(scope: *Scope) !void { 19 19 try scope.insertRegistry(&.{ 20 20 .{ "#t", try Value.initFromAny(scope, true) }, 21 21 .{ "#f", try Value.initFromAny(scope, false) },