tadpole upgrades

This commit is contained in:
Peterino2 2026-12-01 10:39:21 -07:00
parent 9227d0ceaa
commit 299528c5a4
4 changed files with 136 additions and 20 deletions

View File

@ -32,8 +32,6 @@ enum Verbosity
info
warn
err
wutangClan = 0x42061
wutangclank2 = 0x42061
struct SliceMutable
ptr: c_ptr u8

View File

@ -2,10 +2,9 @@
pub const std_options: std.Options = .{
.log_level = .info, // Options: .err, .warn, .info, .debug
.log_scope_levels = &.{
.log_scope_levels = &[_]std.log.ScopeLevel{
.{ .scope = .generateApi, .level = .debug },
.{ .scope = .tad, .level = .debug },
},
} ++ tad.logScopeLevels,
};
const helpText =

View File

@ -82,10 +82,7 @@ fn parseInt(x: []const u8) ?i64 {
const Keyword = enum { @"fn", @"struct", @"enum", module };
const Token = struct {
start: u32,
end: u32,
tokenKind: union(enum(u8)) {
const TokenKind = union(enum(u8)) {
term: TerminalKind,
label: void,
comment: []const u8,
@ -93,13 +90,96 @@ const Token = struct {
keyword: Keyword,
integerValue: struct { i64, IntegerPresentation },
floatValue: f64,
},
};
pub const Token = struct {
start: u32,
end: u32,
tokenKind: TokenKind,
fn slice(self: @This(), contents: []const u8) []const u8 {
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 {
num: 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 {
const log = log_tokenizer;
self.* = .{
.file = file,
.contents = contents,
@ -283,7 +364,7 @@ pub const Module = struct {
var linenum: u32 = 0;
while (toks.next()) |line| {
linenum += 1;
log.debug("(line: {s})", .{line});
log.info("(line: {s})", .{line});
const nl: Line = .{
.offset = @intCast(toks.index - line.len),
.contents = line,
@ -293,7 +374,7 @@ pub const Module = struct {
.num = linenum,
};
for (nl.tokens) |tok| {
log.debug(
log.info(
" (token [{s}]: {s})",
.{
@tagName(tok.tokenKind),
@ -510,6 +591,7 @@ pub const Module = struct {
}
fn parseModule(self: @This(), cursor: *u32) !ModuleDefinition {
const log = log_tokenizer;
const line, const body = try self.setupBodyState(cursor, .module);
var mod: ModuleDefinition = .{ .name = line.tokens[0].slice(line.contents) };
for (body) |l| {
@ -533,6 +615,7 @@ pub const Module = struct {
}
pub fn parseLine(self: *@This(), cursor: *u32) !Definition {
const log = log_main;
const lines = self.lines[cursor.*..];
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" });
}
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 ArrayList = std.ArrayList;

View File

@ -1,10 +1,40 @@
pub fn generateApi(self: *Module, w: *std.Io.Writer) !void {
try w.print("// hello world \n", .{});
for (self.enums.items, 0..) |en, i| {
_ = en;
for (0..self.enums.items) |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 {