Skip to content

Commit

Permalink
init scripty interrupt support, add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoff-it committed Jul 21, 2024
1 parent c138d20 commit 5dbf49c
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 159 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI
on: push
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Change if you need git info

- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: 0.13.0

- name: Test
run: zig build test

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ General Options:

### Diagnostics

<img src=".github/vscode.png" width="70%">
![](.github/vscode.png)

This language server is stricter than the HTML spec whenever it would prevent potential human errors from being reported.

Expand All @@ -43,7 +43,7 @@ This will still be reported as an error by SuperHTML because otherwise the follo
```

### Autoformatting
<img src=".github/vscode-autoformat.gif" width="70%">
![](.github/vscode-autoformat.gif")

The autoformatter has two main ways of interacting with it in order to request for horizontal / vertical alignment.

Expand Down
8 changes: 5 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ pub fn build(b: *std.Build) !void {
wasm.dependOn(&target_output.step);

const afl_fuzz_name = b.fmt("superfuzz-afl{s}", .{target.result.exeFileExt()});
const afl_fuzz = b.addObject(.{
const afl_fuzz = b.addStaticLibrary(.{
.name = afl_fuzz_name,
.root_source_file = b.path("src/fuzz/afl.zig"),
// .target = b.resolveTargetQuery(.{ .cpu_model = .baseline }),
// .target = b.resolveTargetQuery(.{ .ofmt = .c }),
.target = target,
.optimize = .Debug,
.single_threaded = true,
Expand All @@ -158,14 +158,16 @@ pub fn build(b: *std.Build) !void {
&.{},
) catch "afl-clang-fast";

const fuzz = b.step("fuzz", "Generate an executable for AFL++ (persistent mode)");
const fuzz = b.step("fuzz", "Generate an executable for AFL++ (persistent mode) plus extra tooling");
const run_afl_clang_fast = b.addSystemCommand(&.{
afl_clang_fast_path,
"-o",
});

const prog_exe = run_afl_clang_fast.addOutputFileArg(afl_fuzz_name);
run_afl_clang_fast.addFileArg(b.path("src/fuzz/afl.c"));
// run_afl_clang_fast.addFileArg(afl_fuzz.getEmittedBin());
// run_afl_clang_fast.addArg("-I/Users/kristoff/zig/0.13.0/files/lib/");
run_afl_clang_fast.addFileArg(afl_fuzz.getEmittedLlvmBc());
fuzz.dependOn(&b.addInstallBinFile(prog_exe, afl_fuzz_name).step);

Expand Down
39 changes: 21 additions & 18 deletions src/Ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Error = struct {
loop_no_value,
block_cannot_be_inlined,
block_missing_id,
duplicate_id_value,
already_branching,
id_under_loop,
extend_without_template_attr,
Expand Down Expand Up @@ -518,8 +519,10 @@ pub fn init(

try p.nodes.append(gpa, .{ .kind = .root, .elem_idx = 0, .depth = 0 });

var cur = p.html.cursor(0);
var seen_ids: std.StringHashMapUnmanaged(Span) = .{};
defer seen_ids.deinit(gpa);

var cur = p.html.cursor(0);
var node_idx: u32 = 0;
var low_mark: u32 = 1;
var seen_non_comment_elems = false;
Expand Down Expand Up @@ -556,6 +559,7 @@ pub fn init(
html_node_idx,
depth,
seen_non_comment_elems,
&seen_ids,
) orelse continue;
const new_node_idx: u32 = @intCast(p.nodes.items.len - 1);

Expand Down Expand Up @@ -700,7 +704,7 @@ const Parser = struct {
elem_idx: u32,
depth: u32,
seen_non_comment_elems: bool,
// id_map: std.StringHashMapUnmanaged(Span),
seen_ids: *std.StringHashMapUnmanaged(Span),
) !?*Node {
const elem = p.html.nodes[elem_idx];

Expand Down Expand Up @@ -979,22 +983,14 @@ const Parser = struct {
}
} else {
// we can only statically analyze non-scripted ids
const gop = try seen_ids.getOrPut(gpa, maybe_code);

// TODO: implement this in a way that can account for branching

// const id_str = value.unquote(self.html);
// const gop = id_map.getOrPut(gpa, id_str) catch oom();
// if (gop.found_existing) {
// return errors.report(
// template_name,
// template_path,
// attr.node,
// self.html,
// "DUPLICATE ID",
// \\TODO: explain
// ,
// );
// }
if (gop.found_existing) {
try p.errors.append(gpa, .{
.kind = .duplicate_id_value,
.main_location = value.span,
});
}
}

tmp_result.id_template_parentid = attr;
Expand Down Expand Up @@ -1668,10 +1664,17 @@ const Parser = struct {
}

// nodes under a loop can't have ids
log.debug("before", .{});
if (node.kind.hasId()) {
log.debug("here", .{});
var maybe_parent = p.parent(node);
while (maybe_parent) |par| : (maybe_parent = p.parent(par)) switch (par.kind.branching()) {
else => continue,
else => {
log.debug("testing '{s}'", .{
par.elem(p.html).open.slice(p.src),
});
continue;
},
.loop, .inloop => {
try p.errors.append(gpa, .{
.kind = .id_under_loop,
Expand Down
2 changes: 1 addition & 1 deletion src/fuzz/afl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export fn zig_fuzz_test_astgen(buf: [*]u8, len: isize) void {
const gpa = gpa_impl.allocator();
const astgen_src = buf[0..@intCast(len)];

const clamp: u32 = @min(2, astgen_src.len);
const clamp: u32 = @min(20, astgen_src.len);
const src = astgen.build(gpa, astgen_src[0..clamp]) catch unreachable;
defer gpa.free(src);

Expand Down
3 changes: 2 additions & 1 deletion src/html/Tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ pub const Attr = struct {

pub fn span(attr: Attr) Span {
if (attr.value) |v| {
const quote: u32 = if (v.quote == .none) 0 else 1;
return .{
.start = attr.name.start,
.end = v.span.end,
.end = v.span.end + quote,
};
}

Expand Down
29 changes: 26 additions & 3 deletions src/root.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
const interpreter = @import("interpreter.zig");
const vm = @import("vm.zig");
const std = @import("std");
pub const html = @import("html.zig");
pub const Ast = @import("Ast.zig");
pub const SuperVM = interpreter.SuperVM;
pub const Exception = interpreter.Exception;
pub const VM = vm.VM;
pub const Exception = vm.Exception;

pub const utils = struct {
pub const ResourceDescriptor = union(enum) { @"if": u32, loop: u32 };
pub fn loopUpFunction(comptime Value: type) fn (
Value.IterElement,
std.mem.Allocator,
[]const Value,
*ResourceDescriptor,
) error{ OutOfMemory, WantResource }!Value {
return struct {
pub fn up(
v: Value.IterElement,
_: std.mem.Allocator,
args: []const Value,
ext: *ResourceDescriptor,
) error{ OutOfMemory, WantResource }!Value {
if (args.len != 0) return .{ .err = "'up' wants 0 arguments" };
ext.* = .{ .loop = v._up_idx };
return error.WantResource;
}
}.up;
}
};

pub const Language = enum {
html,
Expand Down
Loading

0 comments on commit 5dbf49c

Please sign in to comment.