srctree

Gregory Mullen parent 66d751aa 53785a49
upgrade syntax/lang to zig 0.11

src/builtins.zig added: 72, removed: 77, total 0
@@ -74,7 +74,7 @@ pub fn exec(self: Builtins) BuiltinFn {
/// Caller must ensure this builtin exists.
pub fn strExec(str: []const u8) BuiltinFn {
inline for (@typeInfo(Builtins).Enum.fields[0..]) |f| {
if (std.mem.eql(u8, f.name, str)) return exec(@intToEnum(Builtins, f.value));
if (std.mem.eql(u8, f.name, str)) return exec(@enumFromInt(f.value));
}
std.debug.print("strExec panic on {s}\n", .{str});
unreachable;
 
src/builtins/set.zig added: 72, removed: 77, total 0
@@ -24,7 +24,7 @@ pub const Opts = enum(u8) {
 
pub fn find(c: u8) Err!Opts {
inline for (@typeInfo(Opts).Enum.fields) |field| {
if (field.value == c) return @intToEnum(Opts, field.value);
if (field.value == c) return @enumFromInt(field.value);
}
return Err.InvalidToken;
}
 
src/completion.zig added: 72, removed: 77, total 0
@@ -6,6 +6,7 @@ const IterableDir = std.fs.IterableDir;
const tokenizer = @import("tokenizer.zig");
const Token = tokenizer.Token;
const Draw = @import("draw.zig");
const Cord = Draw.Cord;
const log = @import("log");
 
const Self = @This();
@@ -126,7 +127,7 @@ pub const CompSet = struct {
 
pub fn reset(self: *CompSet) void {
self.index = 0;
self.group_index = @enumToInt(Flavors.Original);
self.group_index = @intFromEnum(Flavors.Original);
self.group = &self.groups[self.group_index];
}
 
@@ -156,14 +157,14 @@ pub const CompSet = struct {
}
 
pub fn push(self: *CompSet, o: CompOption) !void {
var group = &self.groups[@enumToInt(o.kind)];
var group = &self.groups[@intFromEnum(o.kind)];
try group.append(o);
}
 
pub fn drawGroup(self: *const CompSet, f: Flavors, d: *Draw.Drawable, w: u32) !void {
var list = ArrayList(Draw.Lexeme).init(self.alloc);
var group = &self.groups[@enumToInt(f)];
var current_group = if (@enumToInt(f) == self.group_index) true else false;
var group = &self.groups[@intFromEnum(f)];
var current_group = if (@intFromEnum(f) == self.group_index) true else false;
 
if (group.items.len == 0) return;
for (group.items, 0..) |itm, i| {
@@ -185,7 +186,7 @@ pub const CompSet = struct {
// Yeah... I know
for (0..flavors_len) |flavor| {
// TOD Draw name
try self.drawGroup(@intToEnum(Flavors, flavor), d, w);
try self.drawGroup(@enumFromInt(flavor), d, w);
}
}
 
@@ -238,9 +239,10 @@ fn completePath(_: *HSH, target: []const u8) !void {
var dir: std.fs.IterableDir = undefined;
if (target[0] == '/') {
if (path.len == 0) {
path = target;
dir = std.fs.openIterableDirAbsolute("/", .{}) catch return;
} else {
dir = std.fs.openIterableDirAbsolute(path, .{}) catch return;
}
dir = std.fs.openIterableDirAbsolute(path, .{}) catch return;
} else {
dir = std.fs.cwd().openIterableDir(path, .{}) catch return;
}
 
src/context.zig added: 72, removed: 77, total 0
@@ -73,10 +73,10 @@ pub fn available(hsh: *const HSH) ![]Contexts {
 
pub fn update(h: *HSH, requested: []const Contexts) !void {
for (requested) |r| {
try a_contexts.items[@enumToInt(r)].update(h);
try a_contexts.items[@intFromEnum(r)].update(h);
}
}
 
pub fn fetch(h: *const HSH, c: Contexts) Error!Lexeme {
return try a_contexts.items[@enumToInt(c)].fetch(h);
return try a_contexts.items[@intFromEnum(c)].fetch(h);
}
 
src/draw.zig added: 72, removed: 77, total 0
@@ -208,7 +208,7 @@ fn drawTrees(buf: *DrawBuf, x: usize, y: usize, tree: []LexTree) Err!void {
}
 
fn countLines(buf: []const u8) u16 {
return @truncate(u16, std.mem.count(u8, buf, "\n"));
return @truncate(std.mem.count(u8, buf, "\n"));
}
 
pub fn drawBefore(d: *Drawable, t: LexTree) !void {
@@ -256,17 +256,17 @@ pub fn render(d: *Drawable) Err!void {
if (d.right.items.len > 0) {
cntx += try d.write("\r\x1B[K");
// Assumes that movement becomes a nop once at term width
cntx += try d.write(d.move(.Absolute, @intCast(u16, d.term_size.x)));
cntx += try d.write(d.move(.Absolute, @intCast(d.term_size.x)));
// printable [...] to give a blank buffer (I hate line wrapping)
const printable = countPrintable(d.right.items);
cntx += try d.write(d.move(.Left, @intCast(u16, printable)));
cntx += try d.write(d.move(.Left, @intCast(printable)));
cntx += try d.write(d.right.items);
}
 
if (cntx == 0) _ = try d.write("\r\x1B[K");
_ = try d.write("\r");
_ = try d.write(d.b.items);
_ = try d.write(d.move(.Left, @truncate(u16, d.cursor)));
_ = try d.write(d.move(.Left, @truncate(d.cursor)));
// TODO save backtrack line count?
d.lines += countLines(d.b.items);
}
 
src/draw/layout.zig added: 72, removed: 77, total 0
@@ -81,7 +81,7 @@ pub fn grid(a: Allocator, items: []const []const u8, w: u32) Error![]LexTree {
 
const cols: u32 = @max(w / largest, 1);
const remainder: u32 = if (items.len % cols > 0) 1 else 0;
const rows: u32 = @truncate(u32, items.len) / cols + remainder;
const rows: u32 = @as(u32, @truncate(items.len)) / cols + remainder;
 
var trees = a.alloc(LexTree, rows) catch return Error.Memory;
var lexes = a.alloc(Lexeme, items.len) catch return Error.Memory;
@@ -124,7 +124,7 @@ pub fn tableLexeme(a: Allocator, items: []Lexeme, w: u32) Error![]LexTree {
cols_w = a.realloc(cols_w, cols) catch return Error.Memory;
@memset(cols_w, 0);
const remainder: u32 = if (items.len % cols > 0) 1 else 0;
rows = @truncate(u32, items.len / cols) + remainder;
rows = @as(u32, @truncate(items.len / cols)) + remainder;
for (0..rows) |row| {
const current = items[row * cols .. @min((row + 1) * cols, items.len)];
if (countLexems(current) > w) {
@@ -213,7 +213,7 @@ test "table" {
try std.testing.expect(rows[0].siblings.len == 4);
 
// I have my good ol' C pointers back... this is so nice :)
a.free(@ptrCast(*[strs12.len]Lexeme, rows[0].siblings));
a.free(@as(*[strs12.len]Lexeme, @ptrCast(rows[0].siblings)));
a.free(rows);
}
 
@@ -235,7 +235,7 @@ test "grid 3*4" {
try std.testing.expect(rows[3].siblings.len == 3);
 
// I have my good ol' C pointers back... this is so nice :)
a.free(@ptrCast(*[strs12.len]Lexeme, rows[0].siblings));
a.free(@as(*[strs12.len]Lexeme, @ptrCast(rows[0].siblings)));
a.free(rows);
}
 
@@ -256,6 +256,6 @@ test "grid 3*4 + 1" {
try std.testing.expect(rows[4].siblings.len == 1);
 
// I have my good ol' C pointers back... this is so nice :)
a.free(@ptrCast(*[strs13.len]Lexeme, rows[0].siblings));
a.free(@as(*[strs13.len]Lexeme, @ptrCast(rows[0].siblings)));
a.free(rows);
}
 
src/exec.zig added: 72, removed: 77, total 0
@@ -252,7 +252,7 @@ fn execBuiltin(h: *HSH, b: *Builtin) Error!u8 {
 
fn execBin(e: Binary) Error!void {
// TODO manage env
const res = std.os.execveZ(e.arg, e.argv, @ptrCast([*:null]?[*:0]u8, std.os.environ));
const res = std.os.execveZ(e.arg, e.argv, @ptrCast(std.os.environ));
switch (res) {
error.FileNotFound => {
// we validate exes internally now this should be impossible
@@ -383,11 +383,7 @@ pub fn child(h: *HSH, argv: [:null]const ?[*:0]const u8) !ERes {
std.os.dup2(pipe[1], std.os.STDOUT_FILENO) catch unreachable;
std.os.close(pipe[0]);
std.os.close(pipe[1]);
std.os.execvpeZ(
argv[0].?,
argv.ptr,
@ptrCast([*:null]?[*:0]u8, std.os.environ),
) catch {
std.os.execvpeZ(argv[0].?, argv.ptr, @ptrCast(std.os.environ)) catch {
unreachable;
};
unreachable;
 
src/fs.zig added: 72, removed: 77, total 0
@@ -129,7 +129,7 @@ pub fn watchCheck(self: *fs) ?[]u8 {
);
return null;
}
var event = @ptrCast(*const std.os.linux.inotify_event, &buf);
var event: *const std.os.linux.inotify_event = @ptrCast(&buf);
log.debug("inotify event {any}\n", .{event});
}
}
 
src/history.zig added: 72, removed: 77, total 0
@@ -69,8 +69,8 @@ fn samesame(any: anytype, line: []const u8) !bool {
 
var stream = any;
const size = line.len + 2;
 
try stream.seekBy(-@intCast(i64, size));
const seekby: isize = -@as(isize, @intCast(size));
try stream.seekBy(seekby);
var buf: [2048]u8 = undefined;
const read = try stream.reader().read(buf[0..size]);
if (read < size) return false;
 
src/hsh.zig added: 72, removed: 77, total 0
@@ -279,7 +279,7 @@ pub const HSH = struct {
//std.debug.print("Unknown child on {} {}\n", .{ sig.info.code, pid });
continue;
};
switch (@intToEnum(SI_CODE, sig.info.code)) {
switch (@as(SI_CODE, @enumFromInt(sig.info.code))) {
SI_CODE.STOPPED => {
if (child.*.status == .Running) {
child.*.termattr = hsh.tty.popTTY() catch unreachable;
@@ -296,7 +296,7 @@ pub const HSH = struct {
};
}
const status = sig.info.fields.common.second.sigchld.status;
child.*.exit_code = @bitCast(u8, @truncate(i8, status));
child.*.exit_code = @intCast(status);
child.*.status = .Ded;
},
SI_CODE.CONTINUED => {
@@ -308,7 +308,7 @@ pub const HSH = struct {
log.err("CHLD CRASH on {}\n", .{pid});
child.*.status = .Crashed;
const status = sig.info.fields.common.second.sigchld.status;
child.*.exit_code = @bitCast(u8, @truncate(i8, status));
child.*.exit_code = @intCast(status);
},
}
},
 
src/keys.zig added: 72, removed: 77, total 0
@@ -82,7 +82,7 @@ pub fn esc(hsh: *HSH) !KeyPress {
else => {
log.debug("\n\nunknown input: escape {s} {}\n", .{ buffer, buffer[0] });
return .{ .ModKey = .{
.key = @intToEnum(Key, buffer[0]),
.key = @enumFromInt(buffer[0]),
.mods = .alt,
} };
},
@@ -148,11 +148,10 @@ fn csi_xterm(buffer: []const u8) KeyPress {
 
const rest = mods.rest();
const mod_bits = (std.fmt.parseInt(u8, rest[0 .. rest.len - 1], 10) catch 1) -% 1;
const mod_keys = @intToEnum(Modifiers, mod_bits);
return KeyPress{
.ModKey = .{
.key = key,
.mods = mod_keys,
.mods = @enumFromInt(mod_bits),
},
};
},
 
src/log.zig added: 72, removed: 77, total 0
@@ -22,7 +22,7 @@ pub fn hshLogFn(
comptime format: []const u8,
args: anytype,
) void {
if (@enumToInt(verbosity) < @enumToInt(level)) return;
if (@intFromEnum(verbosity) < @intFromEnum(level)) return;
const prefix = comptime switch (level) {
.err => "[\x1B[31merr\x1B[39m] ",
.warning => "[\x1B[33mwrn\x1B[39m] ",
 
src/main.zig added: 72, removed: 77, total 0
@@ -104,7 +104,7 @@ fn input(hsh: *HSH, tkn: *Tokenizer, buffer: u8, prev: u8, comp_: *complete.Comp
.alt => {
switch (mk.key) {
else => |k| {
const key: u8 = @enumToInt(k);
const key: u8 = @intFromEnum(k);
switch (key) {
'.' => log.err("<A-.> not yet implemented\n", .{}),
else => {},
@@ -163,7 +163,7 @@ fn input(hsh: *HSH, tkn: *Tokenizer, buffer: u8, prev: u8, comp_: *complete.Comp
}
//for (comp.list.items) |c| std.debug.print("comp {}\n", .{c});
} else {
try comp.drawAll(&hsh.draw, @intCast(u32, hsh.draw.term_size.x));
try comp.drawAll(&hsh.draw, @intCast(hsh.draw.term_size.x));
}
 
target = comp.next();
@@ -254,7 +254,7 @@ fn input(hsh: *HSH, tkn: *Tokenizer, buffer: u8, prev: u8, comp_: *complete.Comp
fn read(fd: std.os.fd_t, buf: []u8) !usize {
const rc = std.os.linux.read(fd, buf.ptr, buf.len);
switch (std.os.linux.getErrno(rc)) {
.SUCCESS => return @intCast(usize, rc),
.SUCCESS => return @intCast(rc),
.INTR => return error.Interupted,
.AGAIN => return error.WouldBlock,
.BADF => return error.NotOpenForReading, // Can be a race condition.
@@ -279,7 +279,7 @@ fn core(hsh: *HSH, tkn: *Tokenizer, comp: *complete.CompSet) !bool {
//try Context.update(hsh, &[_]Context.Contexts{.git});
 
while (true) {
hsh.draw.cursor = @truncate(u32, tkn.cadj());
hsh.draw.cursor = @truncate(tkn.cadj());
hsh.spin();
 
//Draw.clearCtx(&hsh.draw);
 
src/syscalls.zig added: 72, removed: 77, total 0
@@ -23,7 +23,7 @@ comptime {
// pub fn tcgetpgrp(fd: fd_t, pgrp: *pid_t) usize {
// return std.os.linux.syscall3(
// .ioctl,
// @bitCast(usize, @as(isize, fd)),
// @bitCast(fd)),
// std.os.linux.T.IOCGPGRP,
// @ptrToInt(pgrp),
// );
@@ -32,30 +32,28 @@ comptime {
// pub fn tcsetpgrp(fd: fd_t, pgrp: *const pid_t) usize {
// return std.os.linux.syscall3(
// .ioctl,
// @bitCast(usize, @as(isize, fd)),
// @bitCast(fd)),
// std.os.linux.T.IOCSPGRP,
// @ptrToInt(pgrp),
// );
// }
 
pub fn getsid(pid: pid_t) pid_t {
return @bitCast(pid_t, @truncate(
u32,
std.os.linux.syscall1(.getsid, @bitCast(usize, @as(isize, pid))),
));
return @bitCast(
@as(u32, @truncate(
std.os.linux.syscall1(.getsid, @bitCast(@as(isize, pid))),
)),
);
}
 
pub fn getpgid(pid: pid_t) pid_t {
return @bitCast(pid_t, @truncate(u32, std.os.linux.syscall1(
.getpgid,
@bitCast(usize, @as(isize, pid)),
return @truncate(@as(isize, @bitCast(
std.os.linux.syscall1(.getpgid, @bitCast(@as(isize, pid))),
)));
}
 
pub fn setpgid(pid: pid_t, pgid: pid_t) usize {
return @bitCast(usize, @truncate(usize, std.os.linux.syscall2(
.setpgid,
@bitCast(usize, @as(isize, pid)),
@bitCast(usize, @as(isize, pgid)),
)));
return @bitCast(
std.os.linux.syscall2(.setpgid, @bitCast(@as(isize, pid)), @bitCast(@as(isize, pgid))),
);
}
 
src/tokenizer.zig added: 72, removed: 77, total 0
@@ -585,18 +585,18 @@ pub const Tokenizer = struct {
if (self.raw.items.len == 0 or self.c_idx == 0) return;
 
self.c_idx -|= 1;
var t = self.raw.orderedRemove(@bitCast(usize, self.c_idx));
var t = self.raw.orderedRemove(@bitCast(self.c_idx));
while (std.ascii.isWhitespace(t) and self.c_idx > 0) {
self.c_idx -|= 1;
t = self.raw.orderedRemove(@bitCast(usize, self.c_idx));
t = self.raw.orderedRemove(@bitCast(self.c_idx));
}
while (std.ascii.isAlphanumeric(t) and self.c_idx > 0) {
self.c_idx -|= 1;
t = self.raw.orderedRemove(@bitCast(usize, self.c_idx));
t = self.raw.orderedRemove(@bitCast(self.c_idx));
}
while (std.ascii.isWhitespace(t) and self.c_idx > 0) {
self.c_idx -|= 1;
t = self.raw.orderedRemove(@bitCast(usize, self.c_idx));
t = self.raw.orderedRemove(@bitCast(self.c_idx));
}
if (self.c_idx > 1 and (std.ascii.isWhitespace(t) or std.ascii.isAlphanumeric(t)))
try self.consumec(t);
@@ -629,7 +629,7 @@ pub const Tokenizer = struct {
}
 
pub fn consumec(self: *Tokenizer, c: u8) Error!void {
self.raw.insert(@bitCast(usize, self.c_idx), c) catch return Error.Unknown;
self.raw.insert(self.c_idx, @bitCast(c)) catch return Error.Unknown;
self.c_idx += 1;
}
 
 
src/tty.zig added: 72, removed: 77, total 0
@@ -184,9 +184,9 @@ pub const TTY = struct {
 
pub fn geom(self: *TTY) !Cord {
var size: os.linux.winsize = mem.zeroes(os.linux.winsize);
const err = os.system.ioctl(self.dev, os.linux.T.IOCGWINSZ, @ptrToInt(&size));
const err = os.system.ioctl(self.dev, os.linux.T.IOCGWINSZ, @intFromPtr(&size));
if (os.errno(err) != .SUCCESS) {
return os.unexpectedErrno(@intToEnum(os.system.E, err));
return os.unexpectedErrno(@enumFromInt(err));
}
return .{
.x = size.ws_col,