Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bgk- committed Jun 20, 2024
1 parent 0db63d2 commit 31da66b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 33 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![](https://github.com/peartreegames/topiary/blob/main/assets/logo_horizontal_outline.png)

Topiary is a narrative scripting tool which uses the Topi language to write interactive stories.
It is designed to be integrated into video games which require a large amount of state and control flow in their narrative.
Topiary is a dialogue scripting tool which uses the Topi language to write interactive stories.
It is designed to be integrated into video games which require a large amount of state and control flow in their dialogue.

Think of Topiary as programming a screenplay for your video game.

Expand All @@ -16,7 +16,7 @@ It is recommended to start there to see how you can use topiary in your projects
To run the CLI:

```sh
zig build //or download from release page
zig build // or download from release page
./zig-out/bin/topi run ./examples/hello.topi
```

Expand Down Expand Up @@ -78,4 +78,4 @@ zig build
```

I'm confident there are many areas of improvement so please feel free to submit pull requests.
This is my first time writing a compiler, and I'm still not sure that I fully understand everything.
This is my first time writing a compiler, and I'm definitely don't understand everything.
15 changes: 15 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const version = getVersion(b) catch |err| {
std.log.err("Could not get version: {}", .{err});
return;
};
const build_options = b.addOptions();
build_options.addOption([]const u8, "version", version);

_ = b.addModule("topi", .{
.root_source_file = b.path("src/topi.zig"),
});
Expand All @@ -23,6 +30,7 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
});
exe.root_module.addOptions("build", build_options);
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
Expand All @@ -44,3 +52,10 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&tests.step);
}

fn getVersion(b: *std.Build) ![]const u8 {
var tree = try std.zig.Ast.parse(b.allocator, @embedFile("build.zig.zon"), .zon);
defer tree.deinit(b.allocator);
const version_str = tree.tokenSlice(tree.nodes.items(.main_token)[2]);
return b.allocator.dupe(u8, version_str[1 .. version_str.len - 1]);
}
5 changes: 3 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Usage:
Commands:
topi version
topi run <file> [start_bough] [--auto|-a] [--lang language_key] [--verbose]
topi test <file> <count> [--verbose]
topi test <file> <count> [--quiet] [--verbose]
topi compile <file> <output_file|--dry|-d> [--loc] [--verbose]
topi loc validate <file> [--verbose]
topi loc export <file> <output_file|--dry|-d> [--verbose]
Expand All @@ -24,7 +24,8 @@ Flags:
--auto, -a: Automatically continue to next line
--lang: Localization language key
--loc: Include localization in compiled bytecode
--dry, -d: Compile only
--dry, -d: Compile only without output file
--quiet: Do not output results
```

While running a topi file you can press `enter` for the next line, and select a choice with `0-9` then `enter`
6 changes: 3 additions & 3 deletions docs/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ disk space and not much memory.

## Run

When running topiary pass in the `--loc language-key` flag
When running topiary pass in the `--lang language-key` flag

eg `topi run ./examples/locale/locale.topi --loc fr`
eg `topi run ./examples/locale/locale.topi --lang fr`


## Tips
Expand Down Expand Up @@ -87,6 +87,6 @@ That way we can have both lines localized appropriately.

This will increase the localized word count,
but with modern software like Translation Memory
and Repitition analysis, it shouldn't be much of a problem.
and Repitition analysis, it hopefully shouldn't be much of a problem.

:::
17 changes: 0 additions & 17 deletions docs/testing.md

This file was deleted.

19 changes: 14 additions & 5 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Errors = @import("compiler-error.zig").CompilerErrors;
const module = @import("module.zig");
const runners = @import("runner.zig");
const Locale = @import("locale.zig").Locale;
const version = @import("build").version;

const Runner = runners.Runner;
const Line = runners.Line;
Expand All @@ -27,7 +28,7 @@ fn usage(comptime msg: []const u8) !void {
try out.print("Commands:\n", .{});
try out.print(" topi version\n", .{});
try out.print(" topi run <file> [start_bough] [--auto|-a] [--lang language_key] [--verbose]\n", .{});
try out.print(" topi test <file> <count> [--verbose]\n", .{});
try out.print(" topi test <file> <count> [--quiet] [--verbose]\n", .{});
try out.print(" topi compile <file> <output_file|--dry|-d> [--loc] [--verbose]\n", .{});
try out.print(" topi loc validate <file> [--verbose]\n", .{});
try out.print(" topi loc export <file> <output_file|--dry|-d> [--verbose]\n", .{});
Expand Down Expand Up @@ -70,7 +71,9 @@ pub fn main() !void {

const is_version = std.mem.eql(u8, cmd, "version");
if (is_version) {
try std.io.getStdErr().writeAll("v0.12.0");
const out = std.io.getStdOut();
try out.writeAll(version);
try out.writeAll("\n");
return;
}

Expand Down Expand Up @@ -185,7 +188,7 @@ pub fn main() !void {
if (is_compile) {
if (is_dry) {
var out = std.io.getStdOut().writer();
try out.writeAll("Success");
try out.writeAll("Success\n");
return;
}
const dir = std.fs.cwd();
Expand All @@ -210,16 +213,18 @@ pub fn main() !void {
};

var i: usize = 0;
const is_quiet = try checkFlag("--quiet");
var visit_counts = std.StringArrayHashMap(u64).init(vm_alloc);
defer visit_counts.deinit();
while (i < auto_count) : (i += 1) {
var auto_runner = AutoTestRunner.init();
var vm = try Vm.init(vm_alloc, bytecode, &auto_runner.runner);
vm.interpret() catch {
vm.err.print(std.io.getStdErr().writer());
continue;
return;
};
defer vm.deinit();
if (is_quiet) continue;
for (vm.globals, 0..) |g, idx| {
if (g == .visit) {
const name = bytecode.global_symbols[idx].name;
Expand All @@ -229,9 +234,13 @@ pub fn main() !void {
// all visits are first so we can break
}
}
const out = std.io.getStdOut().writer();
if (is_quiet) {
try out.writeAll("Success\n");
}
var it = visit_counts.iterator();
while (it.next()) |entry| {
std.debug.print("{s} = {}\n", .{ entry.key_ptr.*, entry.value_ptr.* });
try out.print("{s} = {}\n", .{ entry.key_ptr.*, entry.value_ptr.* });
}
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiler.test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1668,8 +1668,8 @@ test "Serialize" {
defer bytecode.free(allocator);

// this doesn't need to be a file, but it's nice to sometimes not delete it and inspect it
const file = try std.fs.cwd().createFile("tmp.topib", .{ .read = true });
defer std.fs.cwd().deleteFile("tmp.topib") catch {};
const file = try std.fs.cwd().createFile("tmp.topi.byte", .{ .read = true });
defer std.fs.cwd().deleteFile("tmp.topi.byte") catch {};
defer file.close();
try bytecode.serialize(file.writer());

Expand Down

0 comments on commit 31da66b

Please sign in to comment.