tadpole upgrades
This commit is contained in:
parent
9227d0ceaa
commit
299528c5a4
|
|
@ -32,8 +32,6 @@ enum Verbosity
|
||||||
info
|
info
|
||||||
warn
|
warn
|
||||||
err
|
err
|
||||||
wutangClan = 0x42061
|
|
||||||
wutangclank2 = 0x42061
|
|
||||||
|
|
||||||
struct SliceMutable
|
struct SliceMutable
|
||||||
ptr: c_ptr u8
|
ptr: c_ptr u8
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
pub const std_options: std.Options = .{
|
pub const std_options: std.Options = .{
|
||||||
.log_level = .info, // Options: .err, .warn, .info, .debug
|
.log_level = .info, // Options: .err, .warn, .info, .debug
|
||||||
.log_scope_levels = &.{
|
.log_scope_levels = &[_]std.log.ScopeLevel{
|
||||||
.{ .scope = .generateApi, .level = .debug },
|
.{ .scope = .generateApi, .level = .debug },
|
||||||
.{ .scope = .tad, .level = .debug },
|
} ++ tad.logScopeLevels,
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const helpText =
|
const helpText =
|
||||||
|
|
|
||||||
|
|
@ -82,10 +82,7 @@ fn parseInt(x: []const u8) ?i64 {
|
||||||
|
|
||||||
const Keyword = enum { @"fn", @"struct", @"enum", module };
|
const Keyword = enum { @"fn", @"struct", @"enum", module };
|
||||||
|
|
||||||
const Token = struct {
|
const TokenKind = union(enum(u8)) {
|
||||||
start: u32,
|
|
||||||
end: u32,
|
|
||||||
tokenKind: union(enum(u8)) {
|
|
||||||
term: TerminalKind,
|
term: TerminalKind,
|
||||||
label: void,
|
label: void,
|
||||||
comment: []const u8,
|
comment: []const u8,
|
||||||
|
|
@ -93,13 +90,96 @@ const Token = struct {
|
||||||
keyword: Keyword,
|
keyword: Keyword,
|
||||||
integerValue: struct { i64, IntegerPresentation },
|
integerValue: struct { i64, IntegerPresentation },
|
||||||
floatValue: f64,
|
floatValue: f64,
|
||||||
},
|
};
|
||||||
|
|
||||||
|
pub const Token = struct {
|
||||||
|
start: u32,
|
||||||
|
end: u32,
|
||||||
|
tokenKind: TokenKind,
|
||||||
|
|
||||||
fn slice(self: @This(), contents: []const u8) []const u8 {
|
fn slice(self: @This(), contents: []const u8) []const u8 {
|
||||||
return contents[self.start..self.end];
|
return contents[self.start..self.end];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const TokenMatcher = struct {
|
||||||
|
search: TokenKind,
|
||||||
|
query: []const Query,
|
||||||
|
|
||||||
|
const Search = struct {
|
||||||
|
tok: TokenKind,
|
||||||
|
query: Query,
|
||||||
|
|
||||||
|
pub fn match(self: @This(), tok: TokenKind) bool {
|
||||||
|
if (self.query == .anything) return true; // anything means it'll match any token
|
||||||
|
if (self.tok != tok) return false; // token kind doesn't match
|
||||||
|
|
||||||
|
switch (self.tok) {
|
||||||
|
.comment => |x| {
|
||||||
|
return mem.eql(u8, x, tok.comment);
|
||||||
|
},
|
||||||
|
.directive => |x| {
|
||||||
|
return x == tok.directive;
|
||||||
|
},
|
||||||
|
.floatValue => |x| {
|
||||||
|
return std.math.approxEqAbs(f64, x, tok.floatValue, std.math.floatEps(f64));
|
||||||
|
},
|
||||||
|
.floatRange => |r| {
|
||||||
|
switch (r[3]) {
|
||||||
|
.inclusive_inclusive => {
|
||||||
|
return (tok.floatValue > r[0] and tok.floatValue < r[1]);
|
||||||
|
},
|
||||||
|
.inclusive_exclusive => {
|
||||||
|
return (tok.floatValue > r[0] and tok.floatValue < r[1]);
|
||||||
|
},
|
||||||
|
.exclusive_inclusive => {
|
||||||
|
return (tok.floatValue > r[0] and tok.floatValue < r[1]);
|
||||||
|
},
|
||||||
|
.exclusive_exclusive => {
|
||||||
|
return (tok.floatValue > r[0] and tok.floatValue < r[1]);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const Query = union {
|
||||||
|
integer: i64,
|
||||||
|
integerRange: struct { i64, i64 },
|
||||||
|
floatRange: struct { f64, f64, RangeMode },
|
||||||
|
floatTolerance: struct { f64, f64 }, // low, then high. in that order
|
||||||
|
strings: []const []const u8,
|
||||||
|
anything: void,
|
||||||
|
|
||||||
|
pub const RangeMode = enum {
|
||||||
|
inclusive_inclusive,
|
||||||
|
inclusive_exclusive,
|
||||||
|
exclusive_exclusive,
|
||||||
|
exclusive_inclusive,
|
||||||
|
|
||||||
|
pub const default: @This() = .inclusive_exclusive;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// returns list of tokens
|
||||||
|
pub fn matchTokenList(self: @This(), tokens: []const Token, gpa: mem.Allocator) ![]u32 {
|
||||||
|
if (self.search.len != self.query.len) return error.MismatchedQueryLength;
|
||||||
|
|
||||||
|
var rv: std.ArrayList(u32) = .empty;
|
||||||
|
|
||||||
|
var i: usize = 0;
|
||||||
|
while (i < tokens.len) : (i += 1) {
|
||||||
|
const q = self.query[i];
|
||||||
|
const t = self.search[i];
|
||||||
|
_ = q;
|
||||||
|
_ = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
return try rv.toOwnedSlice(gpa);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
pub const Line = struct {
|
pub const Line = struct {
|
||||||
num: u32,
|
num: u32,
|
||||||
offset: u32,
|
offset: u32,
|
||||||
|
|
@ -269,6 +349,7 @@ pub const Module = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lex(self: *@This(), gpa: std.mem.Allocator, file: []const u8, contents: []const u8) !void {
|
pub fn lex(self: *@This(), gpa: std.mem.Allocator, file: []const u8, contents: []const u8) !void {
|
||||||
|
const log = log_tokenizer;
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.file = file,
|
.file = file,
|
||||||
.contents = contents,
|
.contents = contents,
|
||||||
|
|
@ -283,7 +364,7 @@ pub const Module = struct {
|
||||||
var linenum: u32 = 0;
|
var linenum: u32 = 0;
|
||||||
while (toks.next()) |line| {
|
while (toks.next()) |line| {
|
||||||
linenum += 1;
|
linenum += 1;
|
||||||
log.debug("(line: {s})", .{line});
|
log.info("(line: {s})", .{line});
|
||||||
const nl: Line = .{
|
const nl: Line = .{
|
||||||
.offset = @intCast(toks.index - line.len),
|
.offset = @intCast(toks.index - line.len),
|
||||||
.contents = line,
|
.contents = line,
|
||||||
|
|
@ -293,7 +374,7 @@ pub const Module = struct {
|
||||||
.num = linenum,
|
.num = linenum,
|
||||||
};
|
};
|
||||||
for (nl.tokens) |tok| {
|
for (nl.tokens) |tok| {
|
||||||
log.debug(
|
log.info(
|
||||||
" (token [{s}]: {s})",
|
" (token [{s}]: {s})",
|
||||||
.{
|
.{
|
||||||
@tagName(tok.tokenKind),
|
@tagName(tok.tokenKind),
|
||||||
|
|
@ -510,6 +591,7 @@ pub const Module = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parseModule(self: @This(), cursor: *u32) !ModuleDefinition {
|
fn parseModule(self: @This(), cursor: *u32) !ModuleDefinition {
|
||||||
|
const log = log_tokenizer;
|
||||||
const line, const body = try self.setupBodyState(cursor, .module);
|
const line, const body = try self.setupBodyState(cursor, .module);
|
||||||
var mod: ModuleDefinition = .{ .name = line.tokens[0].slice(line.contents) };
|
var mod: ModuleDefinition = .{ .name = line.tokens[0].slice(line.contents) };
|
||||||
for (body) |l| {
|
for (body) |l| {
|
||||||
|
|
@ -533,6 +615,7 @@ pub const Module = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parseLine(self: *@This(), cursor: *u32) !Definition {
|
pub fn parseLine(self: *@This(), cursor: *u32) !Definition {
|
||||||
|
const log = log_main;
|
||||||
const lines = self.lines[cursor.*..];
|
const lines = self.lines[cursor.*..];
|
||||||
const line = lines[0];
|
const line = lines[0];
|
||||||
|
|
||||||
|
|
@ -623,7 +706,13 @@ pub fn compile(opts: TadModuleOptions) !void {
|
||||||
try mod.generateZigApi(.{ .io = opts.io, .output = "./zig-out/api/core.zig" });
|
try mod.generateZigApi(.{ .io = opts.io, .output = "./zig-out/api/core.zig" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const log = std.log.scoped(.tad);
|
const log_tokenizer = std.log.scoped(.tad_tok);
|
||||||
|
const log_main = std.log.scoped(.tad);
|
||||||
|
|
||||||
|
pub const logScopeLevels: []const std.log.ScopeLevel = &.{
|
||||||
|
.{ .scope = .tad, .level = .warn },
|
||||||
|
.{ .scope = .tad_tok, .level = .warn },
|
||||||
|
};
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const ArrayList = std.ArrayList;
|
const ArrayList = std.ArrayList;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,40 @@
|
||||||
pub fn generateApi(self: *Module, w: *std.Io.Writer) !void {
|
pub fn generateApi(self: *Module, w: *std.Io.Writer) !void {
|
||||||
try w.print("// hello world \n", .{});
|
try w.print("// hello world \n", .{});
|
||||||
|
|
||||||
for (self.enums.items, 0..) |en, i| {
|
for (0..self.enums.items) |i| {
|
||||||
_ = en;
|
|
||||||
try generateEnum(self, w, i);
|
try generateEnum(self, w, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (0..self.structs.items) |i|
|
||||||
|
{
|
||||||
|
try generateStruct(self, w, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pointerTypeLookup(x: []const u8) []const u8
|
||||||
|
{
|
||||||
|
if()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generateStruct(self: *Module, w: *std.Io.Writer, structIndex: usize) !void
|
||||||
|
{
|
||||||
|
const st = self.structs.items[structIndex];
|
||||||
|
|
||||||
|
try w.print("pub const {s} = extern struct {{\n", .{});
|
||||||
|
switch()
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(st.fields.items) |field|
|
||||||
|
{
|
||||||
|
try w.print(" {s}: {s}\n", .{});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generateEnum(self: *Module, w: *std.Io.Writer, index: usize) !void {
|
fn generateEnum(self: *Module, w: *std.Io.Writer, index: usize) !void {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue