thp-zig/src/main.zig

27 lines
841 B
Zig
Raw Normal View History

2024-11-16 01:00:15 +00:00
const std = @import("std");
2024-11-16 10:46:19 +00:00
const thp_version: []const u8 = "0.0.0";
2024-11-16 01:00:15 +00:00
pub fn main() !void {
2024-11-16 10:46:19 +00:00
try repl();
2024-11-16 01:00:15 +00:00
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
2024-11-16 10:46:19 +00:00
}
2024-11-16 01:00:15 +00:00
2024-11-16 10:46:19 +00:00
fn repl() !void {
2024-11-16 01:00:15 +00:00
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
2024-11-16 10:46:19 +00:00
try stdout.print("The THP REPL, v{s}\n", .{thp_version});
try stdout.print("Enter expressions to evaluate. Enter CTRL-D to exit.\n", .{});
2024-11-16 01:00:15 +00:00
2024-11-16 10:46:19 +00:00
try bw.flush();
2024-11-16 01:00:15 +00:00
}
test "simple test" {
var list = std.ArrayList(i32).init(std.testing.allocator);
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
try list.append(42);
try std.testing.expectEqual(@as(i32, 42), list.pop());
}