From 299528c5a4f8d3f2f99868d9a608980e17d3f712 Mon Sep 17 00:00:00 2001 From: Peterino2 Date: Tue, 1 Dec 2026 10:39:21 -0700 Subject: [PATCH] tadpole upgrades --- engine/src/core/api.tad | 2 - engine/tools/generate-api.zig | 5 +- engine/tools/tad/tad.zig | 115 +++++++++++++++++++++++++---- engine/tools/tad/zig-generator.zig | 34 ++++++++- 4 files changed, 136 insertions(+), 20 deletions(-) diff --git a/engine/src/core/api.tad b/engine/src/core/api.tad index c7f7707..cefbe5e 100644 --- a/engine/src/core/api.tad +++ b/engine/src/core/api.tad @@ -32,8 +32,6 @@ enum Verbosity info warn err - wutangClan = 0x42061 - wutangclank2 = 0x42061 struct SliceMutable ptr: c_ptr u8 diff --git a/engine/tools/generate-api.zig b/engine/tools/generate-api.zig index 3118106..48fd449 100644 --- a/engine/tools/generate-api.zig +++ b/engine/tools/generate-api.zig @@ -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 = diff --git a/engine/tools/tad/tad.zig b/engine/tools/tad/tad.zig index 6d50e0f..3e60260 100644 --- a/engine/tools/tad/tad.zig +++ b/engine/tools/tad/tad.zig @@ -82,24 +82,104 @@ fn parseInt(x: []const u8) ?i64 { const Keyword = enum { @"fn", @"struct", @"enum", module }; -const Token = struct { +const TokenKind = union(enum(u8)) { + term: TerminalKind, + label: void, + comment: []const u8, + directive: Directive, + keyword: Keyword, + integerValue: struct { i64, IntegerPresentation }, + floatValue: f64, +}; + +pub const Token = struct { start: u32, end: u32, - tokenKind: union(enum(u8)) { - term: TerminalKind, - label: void, - comment: []const u8, - directive: Directive, - keyword: Keyword, - integerValue: struct { i64, IntegerPresentation }, - floatValue: f64, - }, + 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; diff --git a/engine/tools/tad/zig-generator.zig b/engine/tools/tad/zig-generator.zig index 013d66c..5616e5d 100644 --- a/engine/tools/tad/zig-generator.zig +++ b/engine/tools/tad/zig-generator.zig @@ -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 {