Skip to content

Commit

Permalink
chore(zig): zig 0.14.0-dev.1588+2111f4c38
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Sep 19, 2024
1 parent 406bc03 commit 4fea48a
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 75 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
uses: actions/[email protected]
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Configure pcre2
run: cp vendors/pcre2/src/pcre2_chartables.c.dist vendors/pcre2/src/pcre2_chartables.c && cd vendors/pcre2 && ./autogen.sh && ./configure && cd ../..
- name: Setup nightly Zig
uses: mlugg/setup-zig@v1
with:
Expand Down Expand Up @@ -96,6 +98,8 @@ jobs:
uses: actions/[email protected]
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Configure pcre2
run: cp vendors/pcre2/src/pcre2_chartables.c.dist vendors/pcre2/src/pcre2_chartables.c && cd vendors/pcre2 && ./autogen.sh && ./configure && cd ../..
- name: Setup nightly Zig
uses: mlugg/setup-zig@v1
with:
Expand Down
11 changes: 8 additions & 3 deletions 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

_Latest zig version supported: 0.14.0-dev.121+ab4c461b7 (https://github.com/ziglang/zig/issues/20847 prevents us from upgrading further)_
_Latest zig version supported: 0.14.0-dev.1588+2111f4c38_

### Requirements
- 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.
Expand All @@ -42,13 +42,18 @@ _Latest zig version supported: 0.14.0-dev.121+ab4c461b7 (https://github.com/zigl
### Build
1. Clone the project: `git clone https://github.com/buzz-language/buzz <buzz_dir>`
2. Checkout submodules: `git submodule update --init`
3. Run configure for pcre2:
3. Copy `pcre2_chartables`:
```bash
ln -s vendors/pcre2/src/pcre2_chartables.c.dist vendors/pcre2/src/pcre2_chartables.c
```
3. Configure pcre2:
```bash
cd vendors/pcre2
./autogen.sh
./configure
cd ../..
```
4. Have fun: `zig build run -- <myscript.buzz>`
4. Have fun: `zig build run -- <myscript.buzz>` to run a script or `zig build run` to start the REPL

### Install

Expand Down
47 changes: 20 additions & 27 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const std = @import("std");
const builtin = @import("builtin");
const Build = std.Build;

const BuzzDebugOptions = struct {
const DebugOptions = struct {
debug: bool,
stack: bool,
current_instruction: bool,
perf: bool,
stop_on_report: bool,
placeholders: bool,

pub fn step(self: BuzzDebugOptions, options: *Build.Step.Options) void {
pub fn step(self: DebugOptions, options: *Build.Step.Options) void {
options.addOption(@TypeOf(self.debug), "debug", self.debug);
options.addOption(@TypeOf(self.stack), "debug_stack", self.stack);
options.addOption(@TypeOf(self.current_instruction), "debug_current_instruction", self.current_instruction);
Expand All @@ -20,14 +20,14 @@ const BuzzDebugOptions = struct {
}
};

const BuzzJITOptions = struct {
const JITOptions = struct {
on: bool,
always_on: bool,
hotspot_always_on: bool,
debug: bool,
prof_threshold: f128 = 0.05,

pub fn step(self: BuzzJITOptions, options: *Build.Step.Options) void {
pub fn step(self: JITOptions, options: *Build.Step.Options) void {
options.addOption(@TypeOf(self.debug), "jit_debug", self.debug);
options.addOption(@TypeOf(self.always_on), "jit_always_on", self.always_on);
options.addOption(@TypeOf(self.hotspot_always_on), "jit_hotspot_always_on", self.hotspot_always_on);
Expand All @@ -36,7 +36,7 @@ const BuzzJITOptions = struct {
}
};

const BuzzGCOptions = struct {
const GCOptions = struct {
debug: bool,
debug_light: bool,
debug_access: bool,
Expand All @@ -46,7 +46,7 @@ const BuzzGCOptions = struct {
next_full_gc_ratio: usize,
memory_limit: ?usize,

pub fn step(self: BuzzGCOptions, options: *Build.Step.Options) void {
pub fn step(self: GCOptions, options: *Build.Step.Options) void {
options.addOption(@TypeOf(self.debug), "gc_debug", self.debug);
options.addOption(@TypeOf(self.debug_light), "gc_debug_light", self.debug_light);
options.addOption(@TypeOf(self.debug_access), "gc_debug_access", self.debug_access);
Expand All @@ -58,13 +58,13 @@ const BuzzGCOptions = struct {
}
};

const BuzzBuildOptions = struct {
const BuildOptions = struct {
version: std.SemanticVersion,
sha: []const u8,
mimalloc: bool,
debug: BuzzDebugOptions,
gc: BuzzGCOptions,
jit: BuzzJITOptions,
debug: DebugOptions,
gc: GCOptions,
jit: JITOptions,
target: Build.ResolvedTarget,
cycle_limit: ?u128,
recursive_call_limit: ?u32,
Expand Down Expand Up @@ -98,7 +98,7 @@ fn getBuzzPrefix(b: *Build) ![]const u8 {
pub fn build(b: *Build) !void {
// Check minimum zig version
const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse("0.14.0-dev.121+ab4c461b7") catch return;
const min_zig = std.SemanticVersion.parse("0.14.0-dev.1588+2111f4c38") catch return;
if (current_zig.order(min_zig).compare(.lt)) {
@panic(b.fmt("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig }));
}
Expand All @@ -108,9 +108,8 @@ pub fn build(b: *Build) !void {
const is_wasm = target.result.cpu.arch.isWasm();
const install_step = b.getInstallStep();

var build_options = BuzzBuildOptions{
var build_options = BuildOptions{
.target = target,
// Version is latest tag or empty string
.version = std.SemanticVersion{ .major = 0, .minor = 5, .patch = 0 },
// Current commit sha
.sha = std.posix.getenv("GIT_SHA") orelse
Expand Down Expand Up @@ -258,14 +257,6 @@ pub fn build(b: *Build) !void {
var llibs = std.ArrayList([]const u8).init(b.allocator);
defer llibs.deinit();

if (!is_wasm) {
sys_libs.appendSlice(
&[_][]const u8{
"mir",
},
) catch unreachable;
}

includes.appendSlice(&[_][]const u8{
"./vendors/mir",
"./vendors/mimalloc/include",
Expand Down Expand Up @@ -413,7 +404,7 @@ pub fn build(b: *Build) !void {

// Building std libraries
const Lib = struct {
path: ?[]const u8,
path: ?[]const u8 = null,
name: []const u8,
wasm_compatible: bool = true,
};
Expand All @@ -431,8 +422,8 @@ pub fn build(b: *Build) !void {
.{ .name = "http", .path = "src/lib/buzz_http.zig", .wasm_compatible = false },
.{ .name = "ffi", .path = "src/lib/buzz_ffi.zig", .wasm_compatible = false },
.{ .name = "serialize", .path = "src/lib/buzz_serialize.zig" },
.{ .name = "testing", .path = null },
.{ .name = "errors", .path = null },
.{ .name = "testing" },
.{ .name = "errors" },
};

var library_steps = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
Expand Down Expand Up @@ -546,15 +537,15 @@ pub fn build(b: *Build) !void {

pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile {
const copyFiles = b.addWriteFiles();
copyFiles.addCopyFileToSource(
_ = copyFiles.addCopyFile(
b.path("vendors/pcre2/src/config.h.generic"),
"vendors/pcre2/src/config.h",
);
copyFiles.addCopyFileToSource(
_ = copyFiles.addCopyFile(
b.path("vendors/pcre2/src/pcre2.h.generic"),
"vendors/pcre2/src/pcre2.h",
);
copyFiles.addCopyFileToSource(
_ = copyFiles.addCopyFile(
b.path("vendors/pcre2/src/pcre2_chartables.c.dist"),
"vendors/pcre2/src/pcre2_chartables.c",
);
Expand Down Expand Up @@ -726,6 +717,8 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O

lib.addIncludePath(b.path("./vendors/mir"));

lib.linkLibC();

lib.addCSourceFiles(
.{
.files = &.{
Expand Down
2 changes: 1 addition & 1 deletion src/Codegen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub fn identifierConstant(self: *Self, name: []const u8) !u24 {

// Unlocated error, should not be used
fn reportError(self: *Self, error_type: Reporter.Error, message: []const u8) void {
@setCold(true);
@branchHint(.cold);

if (self.reporter.panic_mode) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/FFI.zig
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,8 @@ fn fnProto(self: *Self, tag: Ast.Node.Tag, decl_index: Ast.Node.Index) anyerror!
.generic_types = std.AutoArrayHashMap(*o.ObjString, *o.ObjTypeDef).init(self.gc.allocator),
};

var parameters_zig_types = std.ArrayList(ZigType.Fn.Param).init(self.gc.allocator);
var zig_fn_type = ZigType.Fn{
var parameters_zig_types = std.ArrayList(ZigType.FnType.Param).init(self.gc.allocator);
var zig_fn_type = ZigType.FnType{
.calling_convention = .C,
// How could it be something else?
.alignment = 4,
Expand Down
6 changes: 3 additions & 3 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ pub fn deinit(self: *Self) void {
}

fn reportErrorAtCurrent(self: *Self, error_type: Reporter.Error, message: []const u8) void {
@setCold(true);
@branchHint(.cold);
self.reporter.reportErrorAt(
error_type,
self.ast.tokens.get(self.current_token.?),
Expand All @@ -568,7 +568,7 @@ fn reportErrorAtCurrent(self: *Self, error_type: Reporter.Error, message: []cons
}

pub fn reportError(self: *Self, error_type: Reporter.Error, message: []const u8) void {
@setCold(true);
@branchHint(.cold);
self.reporter.reportErrorAt(
error_type,
self.ast.tokens.get(if (self.current_token.? > 0) self.current_token.? - 1 else 0),
Expand All @@ -577,7 +577,7 @@ pub fn reportError(self: *Self, error_type: Reporter.Error, message: []const u8)
}

fn reportErrorFmt(self: *Self, error_type: Reporter.Error, comptime fmt: []const u8, args: anytype) void {
@setCold(true);
@branchHint(.cold);
self.reporter.reportErrorFmt(
error_type,
self.ast.tokens.get(if (self.current_token.? > 0) self.current_token.? - 1 else 0),
Expand Down
12 changes: 6 additions & 6 deletions src/Scanner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn scanToken(self: *Self) !Token {

const char: u8 = self.advance();
return try switch (char) {
'a'...'z', 'A'...'Z' => self.identifier(),
'a'...'z', 'A'...'Z' => try self.identifier(),
'_' => self.makeToken(
.Identifier,
self.source[self.current.start..self.current.offset],
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn scanToken(self: *Self) !Token {
'&' => self.makeToken(.Ampersand, null, null, null),
'*' => self.makeToken(.Star, null, null, null),
'/' => if (self.match('/'))
self.docblock()
try self.docblock()
else
self.makeToken(.Slash, null, null, null),
'%' => self.makeToken(.Percent, null, null, null),
Expand Down Expand Up @@ -130,11 +130,11 @@ pub fn scanToken(self: *Self) !Token {
null,
null,
),
'"' => self.string(false),
'`' => self.string(true),
'"' => try self.string(false),
'`' => try self.string(true),
'\'' => self.byte(),
'@' => self.atIdentifier(),
'$' => self.pattern(),
'@' => try self.atIdentifier(),
'$' => try self.pattern(),
'\\' => self.makeToken(.AntiSlash, null, null, null),

else => self.makeToken(
Expand Down
2 changes: 1 addition & 1 deletion src/ext/clap
9 changes: 9 additions & 0 deletions src/lib/buzz_io.zig
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ fn handleFileReadWriteError(ctx: *api.NativeCtx, err: anytype) void {
error.SocketNotConnected,
=> ctx.vm.pushErrorEnum("errors.FileSystemError", @errorName(err)),

error.Canceled,
=> ctx.vm.pushErrorEnum("errors.SocketError", @errorName(err)),

error.OperationAborted,
error.BrokenPipe,
error.ConnectionResetByPeer,
Expand Down Expand Up @@ -180,6 +183,9 @@ fn handleFileReadLineError(ctx: *api.NativeCtx, err: anytype) void {
error.SocketNotConnected,
=> ctx.vm.pushErrorEnum("errors.FileSystemError", @errorName(err)),

error.Canceled,
=> ctx.vm.pushErrorEnum("errors.SocketError", @errorName(err)),

error.BrokenPipe,
error.ConnectionResetByPeer,
error.ConnectionTimedOut,
Expand Down Expand Up @@ -244,6 +250,9 @@ fn handleFileReadAllError(ctx: *api.NativeCtx, err: anytype) void {
error.SocketNotConnected,
=> ctx.vm.pushErrorEnum("errors.FileSystemError", @errorName(err)),

error.Canceled,
=> ctx.vm.pushErrorEnum("errors.SocketError", @errorName(err)),

error.OperationAborted,
error.BrokenPipe,
error.ConnectionResetByPeer,
Expand Down
7 changes: 7 additions & 0 deletions src/lib/buzz_os.zig
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ fn handleSpawnError(ctx: *api.NativeCtx, err: anytype) void {
error.ResourceLimitReached,
error.WaitAbandoned,
error.WaitTimeOut,
error.ProcessAlreadyExec,
error.InvalidProcessGroupId,
error.ProcessNotFound,
=> ctx.vm.pushErrorEnum("errors.ExecError", @errorName(err)),

error.OutOfMemory => {
Expand Down Expand Up @@ -249,6 +252,7 @@ fn handleConnectError(ctx: *api.NativeCtx, err: anytype) void {
error.TimeoutTooBig,
error.UnknownHostName,
error.WouldBlock,
error.Canceled,
=> ctx.vm.pushErrorEnum("errors.SocketError", @errorName(err)),

error.BadPathName,
Expand Down Expand Up @@ -461,6 +465,9 @@ fn handleReadLineError(ctx: *api.NativeCtx, err: anytype) void {
error.SocketNotConnected,
=> ctx.vm.pushErrorEnum("errors.FileSystemError", @errorName(err)),

error.Canceled,
=> ctx.vm.pushErrorEnum("errors.SocketError", @errorName(err)),

error.BrokenPipe,
error.ConnectionResetByPeer,
error.ConnectionTimedOut,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/errors.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export enum ExecError {
TooBig,
WaitAbandoned,
WaitTimeOut,
ProcessAlreadyExec,
InvalidProcessGroupId,
ProcessNotFound,
}

export enum SocketError {
Expand All @@ -67,6 +70,7 @@ export enum SocketError {
ConnectionRefused,
ConnectionResetByPeer,
ConnectionTimedOut,
Canceled,
FileDescriptorNotASocket,
HostLacksNetworkAddresses,
Incomplete,
Expand Down
2 changes: 1 addition & 1 deletion src/vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ pub const VM = struct {
}

pub fn panic(self: *Self, msg: []const u8) void {
@setCold(true);
@branchHint(.cold);

self.reportRuntimeErrorWithCurrentStack(msg);

Expand Down
Loading

0 comments on commit 4fea48a

Please sign in to comment.