Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 15 additions & 91 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,16 @@ on:
branches: [main]

jobs:
# test-windows:
# runs-on: windows-latest
# steps:
# - name: Checkout project
# uses: actions/checkout@v3.0.0
# - name: Checkout submodules
# run: git submodule update --init --recursive
# - name: Setup nightly Zig
# uses: mlugg/setup-zig@v2
# with:
# version: 0.15.1
# - name: Build test ffi lib
# run: zig build-lib -dynamic tests/utils/foreign.zig && mv foreign.* tests/utils/

# - name: Build
# run: zig build && ls ./zig-out/lib/buzz

# - name: Run behavior tests Debug
# run: zig build test-behavior
# - name: Cleanup
# run: rm -rf zig-out zig-cache
# - name: Run behavior tests Debug with JIT always on
# run: zig build -Djit_always_on test && zig build -Djit_always_on test-behavior
# - name: Cleanup
# run: rm -rf zig-out zig-cache

# - name: Run behavior tests ReleaseSafe
# run: zig build -Doptimize=ReleaseSafe test && zig build -Doptimize=ReleaseSafe test-behavior
# - name: Cleanup
# run: rm -rf zig-out zig-cache
# - name: Run behavior tests ReleaseSafe with JIT always on
# run: zig build -Doptimize=ReleaseSafe -Djit_always_on test && zig build -Doptimize=ReleaseSafe -Djit_always_on test-behavior
# - name: Cleanup
# run: rm -rf zig-out zig-cache

# - name: Run behavior tests ReleaseFast
# run: zig build -Doptimize=ReleaseFast test && zig build -Doptimize=ReleaseFast test-behavior
# - name: Cleanup
# run: rm -rf zig-out zig-cache
# - name: Run behavior tests ReleaseFast with JIT always on
# run: zig build -Doptimize=ReleaseFast -Djit_always_on test && zig build -Doptimize=ReleaseFast -Djit_always_on test-behavior
# - name: Cleanup
# run: rm -rf zig-out zig-cache
test-macos:
runs-on: macos-latest
tests:
runs-on: ${{ matrix.operating-system }}

strategy:
fail-fast: false
matrix:
zig-version:
- "master"
operating-system: [ ubuntu-latest, macos-latest ]

steps:
- name: Install homebrew
run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Expand All @@ -60,50 +25,7 @@ jobs:
- name: Setup nightly Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
- name: Build test ffi lib
run: zig build-lib -dynamic tests/utils/foreign.zig && mv libforeign.* tests/utils/

- name: Run behavior tests Debug
run: zig build test && zig build test-behavior
- name: Cleanup
run: rm -rf zig-out zig-cache

- name: Run behavior tests Debug with JIT always on
run: zig build -Djit_always_on test && zig build -Djit_always_on test-behavior
- name: Cleanup
run: rm -rf zig-out zig-cache

- name: Run behavior tests ReleaseSafe
run: zig build -Doptimize=ReleaseSafe test && zig build -Doptimize=ReleaseSafe test-behavior
- name: Cleanup
run: rm -rf zig-out zig-cache

- name: Run behavior tests ReleaseSafe with JIT always on
run: zig build -Doptimize=ReleaseSafe -Djit_always_on test && zig build -Doptimize=ReleaseSafe -Djit_always_on test-behavior
- name: Cleanup
run: rm -rf zig-out zig-cache

- name: Run behavior tests ReleaseFast
run: zig build -Doptimize=ReleaseFast test && zig build -Doptimize=ReleaseFast test-behavior
- name: Cleanup
run: rm -rf zig-out zig-cache

- name: Run behavior tests ReleaseFast with JIT always on
run: zig build -Doptimize=ReleaseFast -Djit_always_on test && zig build -Doptimize=ReleaseFast -Djit_always_on test-behavior
- name: Cleanup
run: rm -rf zig-out zig-cache
test-linux:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v3.0.0
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Setup nightly Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: ${{ matrix.zig-version }}
- name: Build test ffi lib
run: zig build-lib -dynamic tests/utils/foreign.zig && mv libforeign.* tests/utils/

Expand Down Expand Up @@ -136,6 +58,7 @@ jobs:
run: zig build -Doptimize=ReleaseFast -Djit_always_on test && zig build -Doptimize=ReleaseFast -Djit_always_on test-behavior
- name: Cleanup
run: rm -rf zig-out zig-cache

wasm-build:
runs-on: ubuntu-latest
steps:
Expand All @@ -146,17 +69,18 @@ jobs:
- name: Setup nightly Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: master
- name: Build for wasm
run: zig build -Dtarget=wasm32-freestanding -freference-trace -Doptimize=ReleaseSmall
- name: Cleanup
run: rm -rf zig-out zig-cache

lint:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3.0.0
- name: Setup nightly Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: master
- run: zig fmt --check src/*.zig src/**/*.zig
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A small/lightweight statically typed scripting language written in Zig
## How to build and install

### Requirements
- Zig 0.15.1
- Zig 0.16.0-dev.732+2f3234c76
- Since this is built with Zig, you should be able to build buzz on a wide variety of architectures even though this has only been tested on x86/M1.
- Linux or macOS (Windows support [is coming](https://github.com/buzz-language/buzz/issues/74))
- libc
Expand Down
9 changes: 8 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn build(b: *Build) !void {

// Check minimum zig version
const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse("0.15.1") catch return;
const min_zig = std.SemanticVersion.parse("0.16.0-dev.732+2f3234c76") catch return;
if (current_zig.order(min_zig).compare(.lt)) {
@panic(b.fmt("Your Zig version v{f} does not meet the minimum build requirement of v{f}", .{ current_zig, min_zig }));
}
Expand Down Expand Up @@ -382,6 +382,11 @@ pub fn build(b: *Build) !void {
},
);

exe_check.root_module.addImport(
"clap",
clap.module("clap"),
);

exe.root_module.sanitize_c = .off;
if (behavior_exe) |bexe| bexe.root_module.sanitize_c = .off;
if (!is_wasm) lsp_exe.?.root_module.sanitize_c = .off;
Expand Down Expand Up @@ -659,6 +664,7 @@ pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin
.{
.target = target,
.optimize = optimize,
.sanitize_c = .off,
},
),
},
Expand Down Expand Up @@ -782,6 +788,7 @@ pub fn buildLinenoise(b: *Build, target: Build.ResolvedTarget, optimize: std.bui
.{
.target = target,
.optimize = optimize,
.sanitize_c = .off,
},
),
},
Expand Down
9 changes: 5 additions & 4 deletions src/Ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -819,13 +819,14 @@ pub const Slice = struct {
.String => string: {
const elements = self.nodes.items(.components)[node].String;

var string = std.ArrayList(u8).empty;
const writer = &string.writer(gc.allocator);
var string = std.Io.Writer.Allocating.init(gc.allocator);
defer string.deinit();

for (elements) |element| {
try (try self.toValue(element, gc)).toString(writer);
try (try self.toValue(element, gc)).toString(&string.writer);
}

break :string (try gc.copyString(try string.toOwnedSlice(gc.allocator))).toValue();
break :string (try gc.copyString(string.written())).toValue();
},
.Subscript => subscript: {
const components = self.nodes.items(.components)[node].Subscript;
Expand Down
12 changes: 7 additions & 5 deletions src/Codegen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub const Error = error{
UnwrappedNull,
OutOfBound,
ReachedMaximumMemoryUsage,
WriteFailed,
} || std.mem.Allocator.Error || std.fmt.BufPrintError;

pub const Frame = struct {
Expand Down Expand Up @@ -1246,10 +1247,11 @@ fn generateCall(self: *Self, node: Ast.Node.Index, breaks: ?*Breaks) Error!?*obj
}

if (missing_arguments.count() > 0) {
var missing = std.ArrayList(u8).empty;
const missing_writer = missing.writer(self.gc.allocator);
var missing = std.Io.Writer.Allocating.init(self.gc.allocator);
defer missing.deinit();

for (missing_arguments.keys(), 0..) |key, i| {
try missing_writer.print(
try missing.writer.print(
"{s}{s}",
.{
key,
Expand All @@ -1260,7 +1262,7 @@ fn generateCall(self: *Self, node: Ast.Node.Index, breaks: ?*Breaks) Error!?*obj
},
);
}
defer missing.deinit(self.gc.allocator);

self.reporter.reportErrorFmt(
.call_arguments,
self.ast.tokens.get(locations[node]),
Expand All @@ -1271,7 +1273,7 @@ fn generateCall(self: *Self, node: Ast.Node.Index, breaks: ?*Breaks) Error!?*obj
"s"
else
"",
missing.items,
missing.written(),
},
);
}
Expand Down
24 changes: 12 additions & 12 deletions src/FFI.zig
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ pub fn parseTypeExpr(self: *Self, ztype: []const u8) !?*Zdef {
return zdef;
}

var full = std.ArrayList(u8).empty;
defer full.deinit(self.gc.allocator);
var full = std.Io.Writer.Allocating.init(self.gc.allocator);
defer full.deinit();

full.writer(self.gc.allocator).print("const zig_type: {s};", .{ztype}) catch @panic("Out of memory");
full.writer.print("const zig_type: {s};", .{ztype}) catch @panic("Out of memory");

const zdef = try self.parse(
null,
0,
full.items,
full.written(),
);

std.debug.assert(zdef == null or zdef.?.len == 1);
Expand Down Expand Up @@ -527,10 +527,10 @@ fn unionContainer(self: *Self, name: []const u8, container: Ast.full.ContainerDe
},
};

var qualified_name = std.ArrayList(u8).empty;
defer qualified_name.deinit(self.gc.allocator);
var qualified_name = std.Io.Writer.Allocating.init(self.gc.allocator);
defer qualified_name.deinit();

try qualified_name.writer(self.gc.allocator).print(
try qualified_name.writer.print(
"{s}.{s}",
.{
self.state.?.script,
Expand All @@ -548,7 +548,7 @@ fn unionContainer(self: *Self, name: []const u8, container: Ast.full.ContainerDe
.location = self.state.?.source,
.name = try self.gc.copyString(name),
// FIXME
.qualified_name = try self.gc.copyString(qualified_name.items),
.qualified_name = try self.gc.copyString(qualified_name.written()),
.zig_type = zig_type,
.buzz_type = buzz_fields,
.fields = get_set_fields,
Expand Down Expand Up @@ -918,16 +918,16 @@ fn fnProto(self: *Self, tag: Ast.Node.Tag, decl_index: Ast.Node.Index) anyerror!
}

fn reportZigError(self: *Self, err: Ast.Error) void {
var message = std.ArrayList(u8).empty;
defer message.deinit(self.gc.allocator);
var message = std.Io.Writer.Allocating.init(self.gc.allocator);
defer message.deinit();

message.writer(self.gc.allocator).print("zdef could not be parsed: {}", .{err.tag}) catch unreachable;
message.writer.print("zdef could not be parsed: {}", .{err.tag}) catch unreachable;

const location = self.state.?.buzz_ast.?.tokens.get(self.state.?.source);
self.reporter.report(
.zdef,
location,
location,
message.items,
message.written(),
);
}
8 changes: 4 additions & 4 deletions src/GC.zig
Original file line number Diff line number Diff line change
Expand Up @@ -944,10 +944,10 @@ pub const Debugger = struct {
var items = std.ArrayList(Reporter.ReportItem).empty;
defer items.deinit(self.allocator);

var message = std.ArrayList(u8).empty;
defer message.deinit(self.allocator);
var message = std.Io.Writer.Allocating.init(self.allocator);
defer message.deinit();

message.writer(self.allocator).print(
message.writer.print(
"Access to already collected {} {*}",
.{
tracked.what,
Expand All @@ -961,7 +961,7 @@ pub const Debugger = struct {
.location = at.?,
.end_location = at.?,
.kind = .@"error",
.message = message.items,
.message = message.written(),
},
) catch unreachable;

Expand Down
Loading
Loading