Compare commits
2 commits
ea9fa52a38
...
e83052f06d
Author | SHA1 | Date | |
---|---|---|---|
Der Teufel | e83052f06d | ||
Der Teufel | 782e1a2ca3 |
12
README.md
Normal file
12
README.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# topiku
|
||||||
|
topiku is a simple [LISP](https://en.wikipedia.org/wiki/Lisp_(programming_language)) inspired language with [toki pona](https://tokipona.org/) keywords
|
||||||
|
|
||||||
|
## 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.
|
|
@ -11,8 +11,8 @@ pub fn main() anyerror!void {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
var input = prompt.readline("topiku> ") orelse break;
|
var input = prompt.readline("topiku> ") orelse break;
|
||||||
defer std.c.free(&input);
|
defer prompt.free(input);
|
||||||
|
|
||||||
try stdout.print(">>> {s}\n", .{input});
|
try stdout.print(">>> {s}\n", .{input});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,11 @@ const ceditline = @cImport({
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const io = std.io;
|
const io = std.io;
|
||||||
|
|
||||||
pub fn readline(prompt: [*c]const u8) ?[]u8 {
|
const __sighandler = ?fn (c_int) callconv(.C) void;
|
||||||
var line = ceditline.readline(@as([*c]const u8, prompt));
|
extern fn signal(sig: c_int, handler: __sighandler) __sighandler;
|
||||||
|
|
||||||
|
pub fn readline(prompt: []const u8) ?[]u8 {
|
||||||
|
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;
|
||||||
|
@ -14,8 +17,18 @@ pub fn readline(prompt: [*c]const u8) ?[]u8 {
|
||||||
return std.mem.sliceTo(line, 0);
|
return std.mem.sliceTo(line, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn free(slice: []u8) void {
|
||||||
|
std.c.free(slice.ptr);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
ceditline.rl_initialize();
|
ceditline.rl_initialize();
|
||||||
|
_ = signal(std.os.SIG.INT, exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exit(_ : c_int) callconv(.C) void {
|
||||||
|
deinit();
|
||||||
|
std.os.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit() void {
|
pub fn deinit() void {
|
||||||
|
|
Loading…
Reference in a new issue