Skip to content

Commit 22667b0

Browse files
authored
Merge pull request #1 from travisstaloch/update-0.15.2
Update to 0.15.2
2 parents 9f74c66 + 87fc2ed commit 22667b0

7 files changed

Lines changed: 175 additions & 247 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.zig-cache/
1+
.zig-cache/

build.zig

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,49 @@
11
const std = @import("std");
22

33
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
47
// WASM executable
5-
const target = b.resolveTargetQuery(.{
6-
.cpu_arch = .wasm32,
7-
.os_tag = .freestanding,
8-
});
98
const wasm_exe = b.addExecutable(.{
109
.name = "tinylisp",
11-
.root_source_file = b.path("src/wasm.zig"),
12-
.target = target,
13-
.optimize = .Debug,
10+
.root_module = b.createModule(.{
11+
.root_source_file = b.path("src/wasm.zig"),
12+
.target = b.resolveTargetQuery(.{
13+
.cpu_arch = .wasm32,
14+
.os_tag = .freestanding,
15+
}),
16+
.optimize = optimize,
17+
}),
1418
});
1519
wasm_exe.entry = .disabled;
1620
wasm_exe.rdynamic = true;
1721
b.installArtifact(wasm_exe);
1822

1923
// Local executable
20-
const local_exe = b.addExecutable(.{
24+
const exe = b.addExecutable(.{
2125
.name = "tinylisp",
22-
.root_source_file = b.path("src/main.zig"),
23-
.target = b.standardTargetOptions(.{}),
24-
.optimize = b.standardOptimizeOption(.{}),
26+
.root_module = b.createModule(.{
27+
.root_source_file = b.path("src/main.zig"),
28+
.target = target,
29+
.optimize = optimize,
30+
}),
2531
});
32+
b.installArtifact(exe);
33+
const exe_run = b.addRunArtifact(exe);
34+
exe_run.step.dependOn(&exe.step);
35+
const run_step = b.step("run", "Run the local executable");
36+
run_step.dependOn(&exe_run.step);
2637

27-
const local_exe_install = b.addInstallArtifact(local_exe, .{});
28-
const local_step = b.step("local", "Build the local executable");
29-
local_step.dependOn(&local_exe_install.step);
38+
// expose module for dependees
39+
const mod = b.addModule("tinylisp", .{
40+
.root_source_file = b.path("src/tinylisp.zig"),
41+
.target = target,
42+
.optimize = optimize,
43+
});
3044

31-
const local_exe_run_cmd = b.addRunArtifact(local_exe);
32-
local_exe_run_cmd.step.dependOn(&local_exe_install.step);
33-
const run_step = b.step("run", "Run the local executable");
34-
run_step.dependOn(&local_exe_run_cmd.step);
45+
const tests = b.addTest(.{ .root_module = mod });
46+
const test_step = b.step("test", "Run tests");
47+
const run_tests = b.addRunArtifact(tests);
48+
test_step.dependOn(&run_tests.step);
3549
}

build.zig.zon

Lines changed: 8 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,18 @@
11
.{
2-
// This is the default name used by packages depending on this one. For
3-
// example, when a user runs `zig fetch --save <url>`, this field is used
4-
// as the key in the `dependencies` table. Although the user can choose a
5-
// different name, most users will stick with this provided value.
6-
//
7-
// It is redundant to include "zig" in this name because it is already
8-
// within the Zig package namespace.
92
.name = .tinylisp,
10-
11-
// This is a [Semantic Version](https://semver.org/).
12-
// In a future version of Zig it will be used for package deduplication.
133
.version = "0.0.0",
14-
15-
// Together with name, this represents a globally unique package
16-
// identifier. This field is generated by the Zig toolchain when the
17-
// package is first created, and then *never changes*. This allows
18-
// unambiguous detection of one package being an updated version of
19-
// another.
20-
//
21-
// When forking a Zig project, this id should be regenerated (delete the
22-
// field and run `zig build`) if the upstream project is still maintained.
23-
// Otherwise, the fork is *hostile*, attempting to take control over the
24-
// original project's identity. Thus it is recommended to leave the comment
25-
// on the following line intact, so that it shows up in code reviews that
26-
// modify the field.
274
.fingerprint = 0xf7cb46bc1eba0aec, // Changing this has security and trust implications.
28-
29-
// Tracks the earliest Zig version that the package considers to be a
30-
// supported use case.
31-
.minimum_zig_version = "0.14.0",
32-
33-
// This field is optional.
34-
// Each dependency must either provide a `url` and `hash`, or a `path`.
35-
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
36-
// Once all dependencies are fetched, `zig build` no longer requires
37-
// internet connectivity.
38-
.dependencies = .{
39-
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
40-
//.example = .{
41-
// // When updating this field to a new URL, be sure to delete the corresponding
42-
// // `hash`, otherwise you are communicating that you expect to find the old hash at
43-
// // the new URL. If the contents of a URL change this will result in a hash mismatch
44-
// // which will prevent zig from using it.
45-
// .url = "https://example.com/foo.tar.gz",
46-
//
47-
// // This is computed from the file contents of the directory of files that is
48-
// // obtained after fetching `url` and applying the inclusion rules given by
49-
// // `paths`.
50-
// //
51-
// // This field is the source of truth; packages do not come from a `url`; they
52-
// // come from a `hash`. `url` is just one of many possible mirrors for how to
53-
// // obtain a package matching this `hash`.
54-
// //
55-
// // Uses the [multihash](https://multiformats.io/multihash/) format.
56-
// .hash = "...",
57-
//
58-
// // When this is provided, the package is found in a directory relative to the
59-
// // build root. In this case the package's hash is irrelevant and therefore not
60-
// // computed. This field and `url` are mutually exclusive.
61-
// .path = "foo",
62-
//
63-
// // When this is set to `true`, a package is declared to be lazily
64-
// // fetched. This makes the dependency only get fetched if it is
65-
// // actually used.
66-
// .lazy = false,
67-
//},
68-
},
69-
70-
// Specifies the set of files and directories that are included in this package.
71-
// Only files and directories listed here are included in the `hash` that
72-
// is computed for this package. Only files listed here will remain on disk
73-
// when using the zig package manager. As a rule of thumb, one should list
74-
// files required for compilation plus any license(s).
75-
// Paths are relative to the build root. Use the empty string (`""`) to refer to
76-
// the build root itself.
77-
// A directory listed here means that all files within, recursively, are included.
5+
.minimum_zig_version = "0.15.0",
6+
.dependencies = .{},
787
.paths = .{
798
"build.zig",
809
"build.zig.zon",
8110
"src",
82-
// For example...
83-
//"LICENSE",
84-
//"README.md",
11+
"LICENSE",
12+
"README.md",
13+
"index.html",
14+
"script.js",
15+
"styles.css",
16+
"favicon.ico",
8517
},
8618
}

src/JS.zig

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const std = @import("std");
2+
const Io = std.Io;
23

34
pub const Imports = struct {
45
extern fn jsTerminalWriteBuffer(ptr: [*]const u8, len: usize) void;
@@ -8,20 +9,17 @@ pub const Imports = struct {
89
};
910

1011
pub const Terminal = struct {
11-
pub const Error = error{};
12-
pub const Writer = std.io.GenericWriter(
13-
void,
14-
Error,
15-
writeFn,
16-
);
17-
18-
pub fn writer() Writer {
19-
return Terminal.Writer{ .context = {} };
12+
pub fn writer() Io.Writer {
13+
return .{
14+
.buffer = &.{},
15+
.end = 0,
16+
.vtable = &.{ .drain = writeFn },
17+
};
2018
}
2119

22-
fn writeFn(_: void, bytes: []const u8) Error!usize {
23-
Imports.jsTerminalWriteBuffer(bytes.ptr, bytes.len);
24-
return bytes.len;
20+
fn writeFn(_: *Io.Writer, bytes: []const []const u8, _: usize) Io.Writer.Error!usize {
21+
Imports.jsTerminalWriteBuffer(bytes[0].ptr, bytes[0].len);
22+
return bytes[0].len;
2523
}
2624
};
2725

src/main.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ const std = @import("std");
33
const tinylisp = @import("tinylisp.zig");
44

55
pub fn main() anyerror!void {
6-
const reader = std.io.getStdIn().reader().any();
7-
const writer = std.io.getStdOut().writer().any();
6+
var writer = std.fs.File.stdout().writer(&.{});
87

9-
var lisp = tinylisp.Lisp{};
10-
lisp.init(writer);
11-
try lisp.repl(reader);
8+
var lisp: tinylisp.Lisp = undefined;
9+
var stack: [1024]f64 = undefined;
10+
lisp.initPinned(&writer.interface, &stack);
11+
try lisp.repl(std.fs.File.stdin());
1212
}

0 commit comments

Comments
 (0)