Compare commits
No commits in common. "main" and "ea9fa52a381e0d57b0c3f50b335bdd71bc1f996d" have entirely different histories.
main
...
ea9fa52a38
15
README.md
15
README.md
|
@ -1,15 +0,0 @@
|
||||||
# topiku
|
|
||||||
topiku is a simple [LISP](https://en.wikipedia.org/wiki/Lisp_(programming_language)) inspired language with [toki pona](https://tokipona.org/) keywords
|
|
||||||
|
|
||||||
### Name
|
|
||||||
The name `topiku` was created as short form of `toki pi kulupu ijo` - language of lists, but it was also retroactively expanded into `toki epiku` - the epic language.
|
|
||||||
|
|
||||||
## Building
|
|
||||||
To build `topiku` interpreter you need a [Zig](https://ziglang.org/) compiler (works with `master`) and [`editline`](https://github.com/troglobit/editline) installed.
|
|
||||||
```sh
|
|
||||||
> git clone https://git.ablecorp.us:443/der-teufel-programming/topiku.git
|
|
||||||
> cd topiku
|
|
||||||
> zig build
|
|
||||||
```
|
|
||||||
The executable is then found as `zig-out/bin/topiku`
|
|
||||||
It is also possible to build and run using `zig build run` command.
|
|
15
src/main.zig
15
src/main.zig
|
@ -3,23 +3,16 @@ const prompt = @import("prompt.zig");
|
||||||
|
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
||||||
|
|
||||||
defer {
|
|
||||||
var notclear = gpa.deinit();
|
|
||||||
if (notclear) {
|
|
||||||
std.log.err("Detected memory leaks!!!", .{});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try stdout.writeAll("topiku - toki pi kulupu ijo - ver. 0.0.1\n");
|
try stdout.writeAll("topiku - toki pi kulupu ijo - ver. 0.0.1\n");
|
||||||
|
|
||||||
prompt.init();
|
prompt.init();
|
||||||
defer prompt.deinit();
|
defer prompt.deinit();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
var input = prompt.readline("topiku> ") orelse break;
|
var input = prompt.readline("topiku> ") orelse break;
|
||||||
defer prompt.free(input);
|
defer std.c.free(&input);
|
||||||
try stdout.print("<{}>: {s}\n", .{ input.num, input.content });
|
|
||||||
|
try stdout.print(">>> {s}\n", .{input});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,41 +5,19 @@ const ceditline = @cImport({
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const io = std.io;
|
const io = std.io;
|
||||||
|
|
||||||
const __sighandler = ?fn (c_int) callconv(.C) void;
|
pub fn readline(prompt: [*c]const u8) ?[]u8 {
|
||||||
extern fn signal(sig: c_int, handler: __sighandler) __sighandler;
|
var line = ceditline.readline(@as([*c]const u8, prompt));
|
||||||
|
|
||||||
var line_num: usize = 0;
|
|
||||||
|
|
||||||
pub const Line = struct {
|
|
||||||
content: []u8,
|
|
||||||
num: usize,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn readline(prompt: []const u8) ?Line {
|
|
||||||
var line = ceditline.readline(@as([*c]const u8, prompt.ptr));
|
|
||||||
if (line == 0) {
|
if (line == 0) {
|
||||||
std.c.free(line);
|
std.c.free(line);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
line_num += 1;
|
return std.mem.sliceTo(line, 0);
|
||||||
return Line{ .content = std.mem.sliceTo(line, 0), .num = line_num };
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn free(line: Line) void {
|
|
||||||
std.c.free(line.content.ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
ceditline.rl_initialize();
|
ceditline.rl_initialize();
|
||||||
_ = signal(std.os.SIG.INT, exit);
|
|
||||||
line_num = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn exit(_: c_int) callconv(.C) void {
|
|
||||||
deinit();
|
|
||||||
std.os.exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit() void {
|
pub fn deinit() void {
|
||||||
ceditline.rl_uninitialize();
|
ceditline.rl_uninitialize();
|
||||||
}
|
}
|
Loading…
Reference in a new issue