Compare commits
No commits in common. "9c97efc6f5ba05066ec134ad47604c33e47ef8d6" and "299528c5a4f8d3f2f99868d9a608980e17d3f712" have entirely different histories.
9c97efc6f5
...
299528c5a4
|
|
@ -29,7 +29,7 @@ pub fn build(b: *std.Build) void {
|
||||||
}),
|
}),
|
||||||
.name = "parser",
|
.name = "parser",
|
||||||
});
|
});
|
||||||
parser.root_module.addImport("p2", p2.module("p2"));
|
|
||||||
const parse_interface_core = b.addRunArtifact(parser);
|
const parse_interface_core = b.addRunArtifact(parser);
|
||||||
parse_interface_core.addFileArg2(b.path("src/core/api.tad"), .{ .prefix = "--input-file=" });
|
parse_interface_core.addFileArg2(b.path("src/core/api.tad"), .{ .prefix = "--input-file=" });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ pub const ConcurrentQueueUnmanagedAdvanced = concurrent_queue.ConcurrentQueueUnm
|
||||||
|
|
||||||
pub const paged_vector = @import("structures/paged-vector.zig");
|
pub const paged_vector = @import("structures/paged-vector.zig");
|
||||||
pub const PagedVector = paged_vector.PagedVector;
|
pub const PagedVector = paged_vector.PagedVector;
|
||||||
pub const PagedVectorUnmanaged = paged_vector.PagedVectorUnmanaged;
|
|
||||||
|
|
||||||
pub const tag_pool = @import("structures/tag-pool.zig");
|
pub const tag_pool = @import("structures/tag-pool.zig");
|
||||||
pub const RawTag = tag_pool.RawTag;
|
pub const RawTag = tag_pool.RawTag;
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,6 @@
|
||||||
#
|
#
|
||||||
# functiondef := "fn" label "->" [([pointertype] builtin) | "void"] [field+]
|
# functiondef := "fn" label "->" [([pointertype] builtin) | "void"] [field+]
|
||||||
#
|
#
|
||||||
# new addition december 1st;
|
|
||||||
# `alias` keyword
|
|
||||||
# `fnptr` keyword
|
|
||||||
|
|
||||||
module core
|
module core
|
||||||
@import platform # platform isn't real it can't hurt you
|
@import platform # platform isn't real it can't hurt you
|
||||||
|
|
@ -40,24 +37,12 @@ struct SliceMutable
|
||||||
ptr: c_ptr u8
|
ptr: c_ptr u8
|
||||||
len: usize
|
len: usize
|
||||||
|
|
||||||
|
|
||||||
struct Slice
|
struct Slice
|
||||||
ptr: const c_ptr
|
ptr: const_c_ptr u8
|
||||||
len: usize
|
len: usize
|
||||||
|
|
||||||
struct Vec2
|
fn get_engine -> c_ptr opaque
|
||||||
x: u32
|
fn get_tag_registry -> c_ptr opaque
|
||||||
y: u32
|
|
||||||
|
|
||||||
alias Size = Vec2
|
|
||||||
alias Point = Vec2
|
|
||||||
|
|
||||||
struct Rect
|
|
||||||
pos: Point
|
|
||||||
size: Size
|
|
||||||
|
|
||||||
fn get_engine -> c_ptr
|
|
||||||
fn get_tag_registry -> c_ptr # new rule: all c_ptr are ?*anyopaque
|
|
||||||
fn start -> void
|
fn start -> void
|
||||||
fn shutdown -> void
|
fn shutdown -> void
|
||||||
|
|
||||||
|
|
@ -70,15 +55,6 @@ fn log_puts -> void
|
||||||
verbosity: Verbosity
|
verbosity: Verbosity
|
||||||
string: Slice
|
string: Slice
|
||||||
|
|
||||||
# define a function type
|
|
||||||
fnptr on_log -> void
|
|
||||||
verbosity: Verbosity
|
|
||||||
slice: Slice
|
|
||||||
|
|
||||||
struct callback
|
|
||||||
func: fnptr onlog # gets called every time a log is called
|
|
||||||
|
|
||||||
|
|
||||||
# todo: constants ...
|
# todo: constants ...
|
||||||
#
|
#
|
||||||
# This will need a 3rd pass of the parser... preferrably maybe with a bit of a parser generator
|
# This will need a 3rd pass of the parser... preferrably maybe with a bit of a parser generator
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ pub fn main(init: std.process.Init) !void {
|
||||||
if (AP.cliArgParse(a, "input-file", "input .tad file to parse")) |arg| {
|
if (AP.cliArgParse(a, "input-file", "input .tad file to parse")) |arg| {
|
||||||
log.info("parsing input file: {s}", .{arg});
|
log.info("parsing input file: {s}", .{arg});
|
||||||
|
|
||||||
try tad.compileAll(.{
|
try tad.compile(.{
|
||||||
.io = init.io,
|
.io = init.io,
|
||||||
.allocator = init.arena.allocator(),
|
.allocator = init.arena.allocator(),
|
||||||
.path = arg,
|
.path = arg,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ fn normalizeContents(buffer: []u8) []u8 {
|
||||||
}
|
}
|
||||||
if (mem.eql(u8, buffer[cursor .. cursor + 2], "\r\n")) {
|
if (mem.eql(u8, buffer[cursor .. cursor + 2], "\r\n")) {
|
||||||
buffer[wcursor] = '\n';
|
buffer[wcursor] = '\n';
|
||||||
cursor += 1;
|
cursor += 2;
|
||||||
wcursor += 1;
|
wcursor += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -29,33 +29,11 @@ const FunctionDefinition = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
args: std.ArrayList(Field) = .empty,
|
args: std.ArrayList(Field) = .empty,
|
||||||
returnType: TypeRef,
|
returnType: TypeRef,
|
||||||
isInstance: bool, // if true this function definition is a function pointer type
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const PointerType = struct {
|
const TypeRef = struct {
|
||||||
alignment: u8,
|
|
||||||
size: u32,
|
|
||||||
isConst: bool,
|
|
||||||
target: TypeId,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const TypeId = u32;
|
|
||||||
|
|
||||||
pub const ResolvedType = struct {
|
|
||||||
kind: union(enum(u8)) {
|
|
||||||
@"struct": u32,
|
|
||||||
@"enum": u32,
|
|
||||||
@"fn": u32,
|
|
||||||
fnptr: u32,
|
|
||||||
builtin: BuiltinType,
|
|
||||||
pointer: PointerType,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const TypeRef = struct {
|
|
||||||
lineRef: u32,
|
lineRef: u32,
|
||||||
tokens: []Token,
|
tokens: []Token,
|
||||||
resolved: ?TypeId = null,
|
|
||||||
|
|
||||||
pub fn format(self: @This(), writer: *std.Io.Writer) !void {
|
pub fn format(self: @This(), writer: *std.Io.Writer) !void {
|
||||||
try writer.print("(type line:{d}", .{self.lineRef});
|
try writer.print("(type line:{d}", .{self.lineRef});
|
||||||
|
|
@ -102,7 +80,7 @@ fn parseInt(x: []const u8) ?i64 {
|
||||||
return std.fmt.parseInt(i64, x, 0) catch null;
|
return std.fmt.parseInt(i64, x, 0) catch null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Keyword = enum { @"fn", @"struct", @"enum", module, fnptr, alias, c_ptr, @"const" };
|
const Keyword = enum { @"fn", @"struct", @"enum", module };
|
||||||
|
|
||||||
const TokenKind = union(enum(u8)) {
|
const TokenKind = union(enum(u8)) {
|
||||||
term: TerminalKind,
|
term: TerminalKind,
|
||||||
|
|
@ -222,11 +200,9 @@ const directives = @typeInfo(Directive).@"enum".field_names;
|
||||||
|
|
||||||
pub const Module = struct {
|
pub const Module = struct {
|
||||||
enums: ArrayList(EnumDefnition) = .empty,
|
enums: ArrayList(EnumDefnition) = .empty,
|
||||||
aliases: ArrayList(AliasDefinition) = .empty,
|
|
||||||
structs: ArrayList(StructDefinition) = .empty,
|
structs: ArrayList(StructDefinition) = .empty,
|
||||||
functions: ArrayList(FunctionDefinition) = .empty,
|
functions: ArrayList(FunctionDefinition) = .empty,
|
||||||
module: ?ModuleDefinition = null,
|
module: ?ModuleDefinition = null,
|
||||||
typeRefs: ArrayList(TypeRef) = .empty,
|
|
||||||
|
|
||||||
gpa: std.mem.Allocator,
|
gpa: std.mem.Allocator,
|
||||||
lines: []Line,
|
lines: []Line,
|
||||||
|
|
@ -412,11 +388,6 @@ pub const Module = struct {
|
||||||
self.lines = try lines.toOwnedSlice(gpa);
|
self.lines = try lines.toOwnedSlice(gpa);
|
||||||
}
|
}
|
||||||
|
|
||||||
const AliasDefinition = struct {
|
|
||||||
name: []const u8,
|
|
||||||
target: TypeRef,
|
|
||||||
};
|
|
||||||
|
|
||||||
const ModuleDefinition = struct {
|
const ModuleDefinition = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
imports: std.ArrayList([]const u8) = .empty,
|
imports: std.ArrayList([]const u8) = .empty,
|
||||||
|
|
@ -428,13 +399,9 @@ pub const Module = struct {
|
||||||
@"fn": FunctionDefinition,
|
@"fn": FunctionDefinition,
|
||||||
@"struct": StructDefinition,
|
@"struct": StructDefinition,
|
||||||
@"enum": EnumDefnition,
|
@"enum": EnumDefnition,
|
||||||
alias: AliasDefinition,
|
|
||||||
|
|
||||||
pub fn format(self: @This(), writer: *std.Io.Writer) !void {
|
pub fn format(self: @This(), writer: *std.Io.Writer) !void {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.alias => |alias| {
|
|
||||||
try writer.print("(alias {s} {f})", .{ alias.name, alias.target });
|
|
||||||
},
|
|
||||||
.module => |mod| {
|
.module => |mod| {
|
||||||
try writer.print("(module", .{});
|
try writer.print("(module", .{});
|
||||||
for (mod.imports.items) |i| {
|
for (mod.imports.items) |i| {
|
||||||
|
|
@ -498,24 +465,17 @@ pub const Module = struct {
|
||||||
.fields = .empty,
|
.fields = .empty,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (body, 1..) |l, i| {
|
for (body) |l| {
|
||||||
if (l.tokens.len == 0) continue;
|
|
||||||
switch (l.tokens[0].tokenKind) {
|
switch (l.tokens[0].tokenKind) {
|
||||||
.directive => return error.UnexpectedDirective, // can easily add directives support here
|
.directive => return error.UnexpectedDirective, // can easily add directives support here
|
||||||
.label => {
|
.label => {
|
||||||
try expectTerminal(l.tokens[1], .colon);
|
try expectTerminal(l.tokens[1], .colon);
|
||||||
|
|
||||||
const endsInComment = l.tokens[l.tokens.len - 1].tokenKind == .comment;
|
|
||||||
|
|
||||||
try s.fields.append(self.gpa, .{
|
try s.fields.append(self.gpa, .{
|
||||||
.docstring = null,
|
.docstring = null,
|
||||||
.name = l.tokens[0].slice(l.contents),
|
.name = l.tokens[0].slice(l.contents),
|
||||||
.typeReference = .{
|
.typeReference = .{ .lineRef = lineRef, .tokens = l.tokens[2..] },
|
||||||
.lineRef = lineRef + @as(u32, @intCast(i)),
|
|
||||||
.tokens = l.tokens[2..if (endsInComment) l.tokens.len - 1 else l.tokens.len],
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
log_tokenizer.warn("{d} {f}", .{ i, s.fields.last().?.typeReference });
|
|
||||||
},
|
},
|
||||||
.comment => {},
|
.comment => {},
|
||||||
else => return error.UnexpectedStatement,
|
else => return error.UnexpectedStatement,
|
||||||
|
|
@ -540,7 +500,6 @@ pub const Module = struct {
|
||||||
var nextValue: i64 = 0;
|
var nextValue: i64 = 0;
|
||||||
|
|
||||||
for (body) |l| {
|
for (body) |l| {
|
||||||
if (l.tokens.len == 0) continue;
|
|
||||||
switch (l.tokens[0].tokenKind) {
|
switch (l.tokens[0].tokenKind) {
|
||||||
.directive => |dir| {
|
.directive => |dir| {
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
|
|
@ -584,7 +543,7 @@ pub const Module = struct {
|
||||||
|
|
||||||
fn parseFunction(self: @This(), cursor: *u32) !FunctionDefinition {
|
fn parseFunction(self: @This(), cursor: *u32) !FunctionDefinition {
|
||||||
const lineRef = cursor.*;
|
const lineRef = cursor.*;
|
||||||
const line, const body, const isInstance = try self.setupFunctionBodyState(cursor);
|
const line, const body = try self.setupBodyState(cursor, .@"fn");
|
||||||
if (line.tokens.len < 4) return error.MalformedFunctionDefinition;
|
if (line.tokens.len < 4) return error.MalformedFunctionDefinition;
|
||||||
if (line.tokens[1].tokenKind != .label) return error.ExpectedLabel;
|
if (line.tokens[1].tokenKind != .label) return error.ExpectedLabel;
|
||||||
try expectTerminal(line.tokens[2], .arrow);
|
try expectTerminal(line.tokens[2], .arrow);
|
||||||
|
|
@ -592,25 +551,18 @@ pub const Module = struct {
|
||||||
var func: FunctionDefinition = .{
|
var func: FunctionDefinition = .{
|
||||||
.name = line.tokens[1].slice(line.contents),
|
.name = line.tokens[1].slice(line.contents),
|
||||||
.returnType = .{ .lineRef = lineRef, .tokens = line.tokens[3..] },
|
.returnType = .{ .lineRef = lineRef, .tokens = line.tokens[3..] },
|
||||||
.isInstance = isInstance,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (body) |l| {
|
for (body) |l| {
|
||||||
if (l.tokens.len == 0) continue;
|
|
||||||
switch (l.tokens[0].tokenKind) {
|
switch (l.tokens[0].tokenKind) {
|
||||||
.directive => return error.UnexpectedDirective, // can easily add directives support here
|
.directive => return error.UnexpectedDirective, // can easily add directives support here
|
||||||
.label => {
|
.label => {
|
||||||
try expectTerminal(l.tokens[1], .colon);
|
try expectTerminal(l.tokens[1], .colon);
|
||||||
|
|
||||||
const endsInComment = l.tokens[l.tokens.len - 1].tokenKind == .comment;
|
|
||||||
|
|
||||||
try func.args.append(self.gpa, .{
|
try func.args.append(self.gpa, .{
|
||||||
.docstring = null,
|
.docstring = null,
|
||||||
.name = l.tokens[0].slice(l.contents),
|
.name = l.tokens[0].slice(l.contents),
|
||||||
.typeReference = .{
|
.typeReference = .{ .lineRef = lineRef, .tokens = l.tokens[2..] },
|
||||||
.lineRef = lineRef,
|
|
||||||
.tokens = l.tokens[2..if (endsInComment) l.tokens.len - 1 else l.tokens.len],
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
.comment => {},
|
.comment => {},
|
||||||
|
|
@ -621,27 +573,6 @@ pub const Module = struct {
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setupFunctionBodyState(self: @This(), cursor: *u32) !struct { Line, []Line, bool } {
|
|
||||||
const lines = self.lines[cursor.*..];
|
|
||||||
if (lines[0].tokens[0].tokenKind != .keyword) {
|
|
||||||
return error.ExpectedKeyword;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isInstance: bool = false;
|
|
||||||
|
|
||||||
// zig fmt: off
|
|
||||||
if(lines[0].tokens[0].tokenKind.keyword == .@"fn")
|
|
||||||
{
|
|
||||||
if(lines[0].tokens[0].tokenKind.keyword == .fnptr)
|
|
||||||
isInstance = true;
|
|
||||||
}
|
|
||||||
// zig fmt: on
|
|
||||||
const indent = lines[0].indent + 1;
|
|
||||||
const body = readBody(lines[1..], indent);
|
|
||||||
cursor.* += @as(u32, @intCast(body.len));
|
|
||||||
return .{ lines[0], body, isInstance };
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setupBodyState(self: @This(), cursor: *u32, keyword: Keyword) !struct { Line, []Line } {
|
fn setupBodyState(self: @This(), cursor: *u32, keyword: Keyword) !struct { Line, []Line } {
|
||||||
const lines = self.lines[cursor.*..];
|
const lines = self.lines[cursor.*..];
|
||||||
try expectKeyword(lines[0].tokens[0], keyword);
|
try expectKeyword(lines[0].tokens[0], keyword);
|
||||||
|
|
@ -659,30 +590,11 @@ pub const Module = struct {
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parseAlias(self: @This(), cursor: *u32) !AliasDefinition {
|
|
||||||
const lineRef = cursor.*;
|
|
||||||
const line = self.lines[cursor.*];
|
|
||||||
try expectKeyword(line.tokens[0], .alias);
|
|
||||||
if (line.tokens[1].tokenKind != .label) return error.ExpectedLabel;
|
|
||||||
if (line.tokens[2].tokenKind != .term or line.tokens[2].tokenKind.term != .equals) return error.ExpectedToken;
|
|
||||||
|
|
||||||
const endsInComment = line.tokens[line.tokens.len - 1].tokenKind == .comment;
|
|
||||||
|
|
||||||
return .{
|
|
||||||
.name = line.tokens[1].slice(line.contents),
|
|
||||||
.target = .{
|
|
||||||
.lineRef = lineRef,
|
|
||||||
.tokens = line.tokens[2..if (endsInComment) line.tokens.len - 1 else line.tokens.len],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parseModule(self: @This(), cursor: *u32) !ModuleDefinition {
|
fn parseModule(self: @This(), cursor: *u32) !ModuleDefinition {
|
||||||
const log = log_tokenizer;
|
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| {
|
||||||
if (l.tokens.len == 0) continue;
|
|
||||||
switch (l.tokens[0].tokenKind) {
|
switch (l.tokens[0].tokenKind) {
|
||||||
.directive => |d| {
|
.directive => |d| {
|
||||||
switch (d) {
|
switch (d) {
|
||||||
|
|
@ -714,18 +626,10 @@ pub const Module = struct {
|
||||||
},
|
},
|
||||||
.keyword => |kw| {
|
.keyword => |kw| {
|
||||||
switch (kw) {
|
switch (kw) {
|
||||||
.alias => {
|
|
||||||
newdef = .{ .alias = try self.parseAlias(cursor) };
|
|
||||||
try self.aliases.append(self.gpa, newdef.alias);
|
|
||||||
},
|
|
||||||
.@"enum" => {
|
.@"enum" => {
|
||||||
newdef = .{ .@"enum" = try self.parseEnum(cursor) };
|
newdef = .{ .@"enum" = try self.parseEnum(cursor) };
|
||||||
try self.enums.append(self.gpa, newdef.@"enum");
|
try self.enums.append(self.gpa, newdef.@"enum");
|
||||||
},
|
},
|
||||||
.fnptr => {
|
|
||||||
newdef = .{ .@"fn" = try self.parseFunction(cursor) };
|
|
||||||
try self.functions.append(self.gpa, newdef.@"fn");
|
|
||||||
},
|
|
||||||
.@"fn" => {
|
.@"fn" => {
|
||||||
newdef = .{ .@"fn" = try self.parseFunction(cursor) };
|
newdef = .{ .@"fn" = try self.parseFunction(cursor) };
|
||||||
try self.functions.append(self.gpa, newdef.@"fn");
|
try self.functions.append(self.gpa, newdef.@"fn");
|
||||||
|
|
@ -738,9 +642,6 @@ pub const Module = struct {
|
||||||
newdef = .{ .module = try self.parseModule(cursor) };
|
newdef = .{ .module = try self.parseModule(cursor) };
|
||||||
self.module = newdef.module;
|
self.module = newdef.module;
|
||||||
},
|
},
|
||||||
.@"const", .c_ptr => {
|
|
||||||
return error.UnexpectedKeyword;
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
else => return error.UnexpectedToken,
|
else => return error.UnexpectedToken,
|
||||||
|
|
@ -763,26 +664,6 @@ pub const Module = struct {
|
||||||
output: []const u8,
|
output: []const u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn resolveTypeRef(self: *@This(), typeref: TypeRef) !void {
|
|
||||||
const line = self.lines[typeref.lineRef];
|
|
||||||
|
|
||||||
for (typeref.tokens) |tok| {
|
|
||||||
const x = tok.slice(line.contents);
|
|
||||||
log_main.warn(" ({s})", .{x});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// link all references together
|
|
||||||
pub fn resolve(self: *@This()) !void {
|
|
||||||
// walk over structs, then function fields in that order
|
|
||||||
for (self.structs.items) |st| {
|
|
||||||
log_main.warn("(struct {s})", .{st.name});
|
|
||||||
for (st.fields.items) |field| {
|
|
||||||
try self.resolveTypeRef(field.typeReference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fmt(self: *@This(), comptime f: []const u8, a: anytype) ?[]const u8 {
|
fn fmt(self: *@This(), comptime f: []const u8, a: anytype) ?[]const u8 {
|
||||||
return self.gpa.print(f, a) catch return null;
|
return self.gpa.print(f, a) catch return null;
|
||||||
}
|
}
|
||||||
|
|
@ -809,7 +690,7 @@ pub const TadModuleOptions = struct {
|
||||||
path: []const u8,
|
path: []const u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn compileAll(opts: TadModuleOptions) !void {
|
pub fn compile(opts: TadModuleOptions) !void {
|
||||||
const rawf = try std.Io.Dir.cwd().readFileAlloc(opts.io, opts.path, opts.allocator, .unlimited);
|
const rawf = try std.Io.Dir.cwd().readFileAlloc(opts.io, opts.path, opts.allocator, .unlimited);
|
||||||
const normalized = normalizeContents(rawf);
|
const normalized = normalizeContents(rawf);
|
||||||
|
|
||||||
|
|
@ -819,21 +700,19 @@ pub fn compileAll(opts: TadModuleOptions) !void {
|
||||||
var mod: Module = undefined;
|
var mod: Module = undefined;
|
||||||
try mod.lex(arena.allocator(), opts.path, normalized);
|
try mod.lex(arena.allocator(), opts.path, normalized);
|
||||||
try mod.parse();
|
try mod.parse();
|
||||||
try mod.resolve(); // resolve all typeRefs
|
|
||||||
|
|
||||||
// parse submodules here...
|
|
||||||
|
|
||||||
// generate
|
// generate
|
||||||
|
|
||||||
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_tokenizer = std.log.scoped(.tad_tok);
|
const log_tokenizer = std.log.scoped(.tad_tok);
|
||||||
const log_main = std.log.scoped(.tad);
|
const log_main = std.log.scoped(.tad);
|
||||||
|
|
||||||
pub const logScopeLevels: []const std.log.ScopeLevel = &[_]std.log.ScopeLevel{
|
pub const logScopeLevels: []const std.log.ScopeLevel = &.{
|
||||||
.{ .scope = .tad, .level = .debug },
|
.{ .scope = .tad, .level = .warn },
|
||||||
.{ .scope = .tad_tok, .level = .debug },
|
.{ .scope = .tad_tok, .level = .warn },
|
||||||
} ++ zig_generator.logScopeLevels;
|
};
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const ArrayList = std.ArrayList;
|
const ArrayList = std.ArrayList;
|
||||||
|
|
@ -841,6 +720,4 @@ const mem = std.mem;
|
||||||
const WriteBuffer = @import("../common/WriteBuffer.zig");
|
const WriteBuffer = @import("../common/WriteBuffer.zig");
|
||||||
const fmt = std.fmt;
|
const fmt = std.fmt;
|
||||||
|
|
||||||
const p2 = @import("p2");
|
|
||||||
|
|
||||||
const zig_generator = @import("zig-generator.zig");
|
const zig_generator = @import("zig-generator.zig");
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,39 @@
|
||||||
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 (0..self.enums.items.len) |i| {
|
for (0..self.enums.items) |i| {
|
||||||
try generateEnum(self, w, i);
|
try generateEnum(self, w, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (0..self.structs.items.len) |i| {
|
for (0..self.structs.items) |i|
|
||||||
|
{
|
||||||
try generateStruct(self, w, i);
|
try generateStruct(self, w, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// writes into the buffer, allocates
|
fn pointerTypeLookup(x: []const u8) []const u8
|
||||||
fn pointerTypeLookup(typedef: []tad.TypeRef, module: *const Module, gpa: mem.Allocator) ![]const u8 {
|
{
|
||||||
_ = module;
|
if()
|
||||||
for (typedef) |tok| {
|
{
|
||||||
switch (tok.tokenKind) {
|
|
||||||
.label => {},
|
|
||||||
else => return error.InvalidTokenType,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var writer: std.Io.Writer.Allocating = .init(gpa);
|
|
||||||
const w = &writer.writer;
|
|
||||||
_ = w;
|
|
||||||
|
|
||||||
return try writer.toOwnedSlice();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generateStruct(self: *Module, w: *std.Io.Writer, structIndex: usize) !void {
|
fn generateStruct(self: *Module, w: *std.Io.Writer, structIndex: usize) !void
|
||||||
|
{
|
||||||
const st = self.structs.items[structIndex];
|
const st = self.structs.items[structIndex];
|
||||||
|
|
||||||
try w.print("pub const {s} = extern struct {{\n", .{st.name});
|
try w.print("pub const {s} = extern struct {{\n", .{});
|
||||||
|
switch()
|
||||||
|
|
||||||
for (st.fields.items) |field| {
|
{
|
||||||
try w.print(" {s}: {s}\n", .{ field.name, "void, // unimplemented" });
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(st.fields.items) |field|
|
||||||
|
{
|
||||||
|
try w.print(" {s}: {s}\n", .{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,12 +108,4 @@ fn generateEnum(self: *Module, w: *std.Io.Writer, index: usize) !void {
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const tad = @import("tad.zig");
|
const tad = @import("tad.zig");
|
||||||
const Token = tad.Token;
|
|
||||||
const mem = std.mem;
|
|
||||||
const Module = tad.Module;
|
const Module = tad.Module;
|
||||||
|
|
||||||
pub const logScopeLevels: []const std.log.ScopeLevel = &.{
|
|
||||||
.{ .scope = .tad_zig_generator, .level = .debug },
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const log = std.log.scoped(.tad_zig_generator);
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,6 @@ Chapter 1: core tech
|
||||||
- simple repl - done
|
- simple repl - done
|
||||||
- Hot Reloading
|
- Hot Reloading
|
||||||
- module loading via cli infrastructure - done
|
- module loading via cli infrastructure - done
|
||||||
- Tad compiler
|
|
||||||
- Compiler store migration
|
|
||||||
- move node store from tad files into the global store
|
|
||||||
|
|
||||||
- API generation
|
- API generation
|
||||||
- generating the handbomb from the parser - done
|
- generating the handbomb from the parser - done
|
||||||
- API generation
|
- API generation
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue