Compare commits
2 commits
c46229154c
...
3b8943731e
Author | SHA1 | Date | |
---|---|---|---|
3b8943731e | |||
53d41b31e7 |
2 changed files with 51 additions and 2 deletions
11
examples/hello.ry
Normal file
11
examples/hello.ry
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import std;
|
||||||
|
|
||||||
|
fn add(a: i32, b: i32) i32 {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// type is void by default
|
||||||
|
fn main() {
|
||||||
|
std.fmt.print("piss\n");
|
||||||
|
// std.fmt.print("2 + 2 = %d\n", add(1, 2));
|
||||||
|
}
|
42
src/main.zig
42
src/main.zig
|
@ -1,5 +1,43 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn main() anyerror!void {
|
pub const Result = enum {
|
||||||
std.debug.warn("All your base are belong to us.\n");
|
Ok,
|
||||||
|
TokenizeError,
|
||||||
|
ParseError,
|
||||||
|
CompileError,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn run(allocator: *std.mem.Allocator, slice: []const u8) Result {
|
||||||
|
return Result.Ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() anyerror!void {
|
||||||
|
const allocator = std.heap.direct_allocator;
|
||||||
|
var args_it = std.process.args();
|
||||||
|
_ = args_it.skip();
|
||||||
|
|
||||||
|
const filepath = try (args_it.next(allocator) orelse @panic("expected file path"));
|
||||||
|
|
||||||
|
var file = try std.fs.File.openRead(filepath);
|
||||||
|
defer file.close();
|
||||||
|
|
||||||
|
const total_bytes = try file.getEndPos();
|
||||||
|
|
||||||
|
var slice = try allocator.alloc(u8, total_bytes);
|
||||||
|
defer allocator.free(slice);
|
||||||
|
|
||||||
|
_ = try file.read(slice);
|
||||||
|
|
||||||
|
//switch (try run(allocator, slice)) {
|
||||||
|
switch (run(allocator, slice)) {
|
||||||
|
.Ok => {},
|
||||||
|
|
||||||
|
.TokenizeError,
|
||||||
|
.ParseError,
|
||||||
|
.CompileError,
|
||||||
|
=> |res| {
|
||||||
|
std.debug.warn("error: {}\n", res);
|
||||||
|
std.os.exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue