Skip to content

Commit

Permalink
zig 0.12.0-dev.3074+ae7f3fc36
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Feb 29, 2024
1 parent 0133fb4 commit 7baaa7a
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 278 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ A small/lightweight statically typed scripting language written in Zig

## How to build and install

_Latest zig version supported: 0.12.0-dev.3074+ae7f3fc36_

### 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.
- Linux or macOS (Windows support [is coming](https://github.com/buzz-language/buzz/issues/74))
Expand Down
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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.12.0-dev.2833+8802ec583") catch return;
const min_zig = std.SemanticVersion.parse("0.12.0-dev.3074+ae7f3fc3") 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 Down
40 changes: 24 additions & 16 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3841,14 +3841,16 @@ fn dot(self: *Self, can_assign: bool, callee: Ast.Node.Index) Error!Ast.Node.Ind
if (try self.match(.LeftParen)) {
// `call` will look to the parent node for the function definition
self.ast.nodes.items(.type_def)[dot_node] = member;
const components = self.ast.nodes.items(.components);
var components = self.ast.nodes.items(.components);
components[dot_node].Dot.member_type_def = member.?;
components[dot_node].Dot.member_kind = .Call;
const dot_call = try self.call(
can_assign,
dot_node,
);
components = self.ast.nodes.items(.components);
components[dot_node].Dot.value_or_call_or_enum = .{
.Call = try self.call(
can_assign,
dot_node,
),
.Call = dot_call,
};

// Node type is the return type of the call
Expand Down Expand Up @@ -3879,14 +3881,16 @@ fn dot(self: *Self, can_assign: bool, callee: Ast.Node.Index) Error!Ast.Node.Ind
if (try self.match(.LeftParen)) {
// `call` will look to the parent node for the function definition
self.ast.nodes.items(.type_def)[dot_node] = member;
const components = self.ast.nodes.items(.components);
var components = self.ast.nodes.items(.components);
components[dot_node].Dot.member_type_def = member.?;
components[dot_node].Dot.member_kind = .Call;
const dot_call = try self.call(
can_assign,
dot_node,
);
components = self.ast.nodes.items(.components);
components[dot_node].Dot.value_or_call_or_enum = .{
.Call = try self.call(
can_assign,
dot_node,
),
.Call = dot_call,
};

// Node type is the return type of the call
Expand Down Expand Up @@ -3917,14 +3921,16 @@ fn dot(self: *Self, can_assign: bool, callee: Ast.Node.Index) Error!Ast.Node.Ind
if (try self.match(.LeftParen)) {
// `call` will look to the parent node for the function definition
self.ast.nodes.items(.type_def)[dot_node] = member;
const components = self.ast.nodes.items(.components);
var components = self.ast.nodes.items(.components);
components[dot_node].Dot.member_kind = .Call;
components[dot_node].Dot.member_type_def = member.?;
const dot_call = try self.call(
can_assign,
dot_node,
);
components = self.ast.nodes.items(.components);
components[dot_node].Dot.value_or_call_or_enum = .{
.Call = try self.call(
can_assign,
dot_node,
),
.Call = dot_call,
};

// Node type is the return type of the call
Expand Down Expand Up @@ -4111,8 +4117,10 @@ fn dot(self: *Self, can_assign: bool, callee: Ast.Node.Index) Error!Ast.Node.Ind
var components = self.ast.nodes.items(.components);
if (can_assign and try self.match(.Equal)) {
components[dot_node].Dot.member_kind = .Value;
const expr = try self.expression(false);
components = self.ast.nodes.items(.components);
components[dot_node].Dot.value_or_call_or_enum = .{
.Value = try self.expression(false),
.Value = expr,
};
self.ast.nodes.items(.type_def)[dot_node] = property_type;
} else if (try self.match(.LeftParen)) { // If it's a method or placeholder we can call it
Expand Down
10 changes: 6 additions & 4 deletions src/lib/buzz_fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const api = @import("buzz_api.zig");

fn handleMakeDirectoryError(ctx: *api.NativeCtx, err: anytype) void {
switch (err) {
error.InvalidWtf8,
error.AccessDenied,
error.BadPathName,
error.DiskQuota,
Expand Down Expand Up @@ -92,6 +93,7 @@ pub export fn delete(ctx: *api.NativeCtx) c_int {

fn handleMoveError(ctx: *api.NativeCtx, err: anytype) void {
switch (err) {
error.InvalidWtf8,
error.AccessDenied,
error.AntivirusInterference,
error.BadPathName,
Expand Down Expand Up @@ -121,6 +123,7 @@ fn handleMoveError(ctx: *api.NativeCtx, err: anytype) void {

fn handleRealpathError(ctx: *api.NativeCtx, err: anytype) void {
switch (err) {
error.InvalidWtf8,
error.AccessDenied,
error.UnrecognizedVolume,
error.AntivirusInterference,
Expand All @@ -129,8 +132,6 @@ fn handleRealpathError(ctx: *api.NativeCtx, err: anytype) void {
error.FileSystem,
error.FileTooBig,
error.InputOutput,
error.InvalidHandle,
error.InvalidUtf8,
error.IsDir,
error.NameTooLong,
error.NoDevice,
Expand Down Expand Up @@ -209,6 +210,7 @@ pub export fn move(ctx: *api.NativeCtx) c_int {

fn handleOpenDirAbsoluteError(ctx: *api.NativeCtx, err: anytype) void {
switch (err) {
error.InvalidWtf8,
error.AccessDenied,
error.AntivirusInterference,
error.BadPathName,
Expand All @@ -217,7 +219,6 @@ fn handleOpenDirAbsoluteError(ctx: *api.NativeCtx, err: anytype) void {
error.FileLocksNotSupported,
error.FileNotFound,
error.FileTooBig,
error.InvalidHandle,
error.InvalidUtf8,
error.IsDir,
error.NameTooLong,
Expand All @@ -241,10 +242,10 @@ fn handleOpenDirAbsoluteError(ctx: *api.NativeCtx, err: anytype) void {

fn handleOpenDirError(ctx: *api.NativeCtx, err: anytype) void {
switch (err) {
error.InvalidWtf8,
error.AccessDenied,
error.BadPathName,
error.DeviceBusy,
error.InvalidHandle,
error.InvalidUtf8,
error.NameTooLong,
error.NoDevice,
Expand All @@ -265,6 +266,7 @@ fn handleDirIterateError(ctx: *api.NativeCtx, err: anytype) void {
switch (err) {
error.AccessDenied,
error.SystemResources,
error.InvalidUtf8,
=> ctx.vm.pushErrorEnum("errors.FileSystemError", @errorName(err)),

error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null),
Expand Down
35 changes: 21 additions & 14 deletions src/lib/buzz_http.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub export fn HttpClientNew(ctx: *api.NativeCtx) c_int {
.allocator = api.VM.allocator,
};

client.loadDefaultProxies() catch @panic("Out of memory");
client.initDefaultProxies(api.VM.allocator) catch @panic("Out of memory");

if (api.ObjUserData.bz_newUserData(ctx.vm, @intFromPtr(client))) |userdata| {
ctx.vm.bz_pushUserData(userdata);
Expand Down Expand Up @@ -44,7 +44,7 @@ pub export fn HttpClientSend(ctx: *api.NativeCtx) c_int {
}

const header_values = ctx.vm.bz_peek(0);
var headers = http.Headers.init(api.VM.allocator);
var headers = std.ArrayList(http.Header).init(api.VM.allocator);
var next_header_key = api.Value.Null;
var next_header_value = api.ObjMap.bz_mapNext(ctx.vm, header_values, &next_header_key);
while (next_header_key.val != api.Value.Null.val) : (next_header_value = api.ObjMap.bz_mapNext(ctx.vm, header_values, &next_header_key)) {
Expand All @@ -57,10 +57,16 @@ pub export fn HttpClientSend(ctx: *api.NativeCtx) c_int {
@panic("Out of memory");
}

headers.append(key.?[0..key_len], value.?[0..value_len]) catch @panic("Could not send request");
headers.append(
.{
.name = key.?[0..key_len],
.value = value.?[0..value_len],
},
) catch @panic("Could not send request");
}

const request = api.VM.allocator.create(http.Client.Request) catch @panic("Out of memory");
const server_header_buffer = api.VM.allocator.alloc(u8, 1024) catch @panic("Out of memory"); // FIXME: what do i do we this??

request.* = client.open(
method,
Expand All @@ -69,8 +75,10 @@ pub export fn HttpClientSend(ctx: *api.NativeCtx) c_int {

return -1;
},
headers,
.{},
.{
.extra_headers = headers.items,
.server_header_buffer = server_header_buffer,
},
) catch |err| {
handleError(ctx, err);

Expand Down Expand Up @@ -190,7 +198,8 @@ pub export fn HttpRequestRead(ctx: *api.NativeCtx) c_int {
headers,
);

for (request.response.headers.list.items) |header| {
var header_it = request.response.iterateHeaders();
while (header_it.next()) |header| {
api.ObjMap.bz_mapSet(
ctx.vm,
headers,
Expand Down Expand Up @@ -220,10 +229,9 @@ fn handleWaitError(ctx: *api.NativeCtx, err: anytype) void {
switch (err) {
error.OutOfMemory => @panic("Out of memory"),

error.RedirectRequiresResend,
error.CertificateBundleLoadFailure,
error.CompressionInitializationFailed,
error.CompressionNotSupported,
error.CompressionUnsupported,
error.ConnectionRefused,
error.ConnectionResetByPeer,
error.ConnectionTimedOut,
Expand All @@ -232,23 +240,22 @@ fn handleWaitError(ctx: *api.NativeCtx, err: anytype) void {
error.HttpChunkInvalid,
error.HttpConnectionHeaderUnsupported,
error.HttpHeaderContinuationsUnsupported,
error.HttpHeadersExceededSizeLimit,
error.HttpHeadersInvalid,
error.HttpRedirectMissingLocation,
error.HttpHeadersOversize,
error.HttpRedirectLocationInvalid,
error.HttpRedirectLocationMissing,
error.HttpTransferEncodingUnsupported,
error.InvalidCharacter,
error.InvalidContentLength,
error.InvalidFormat,
error.InvalidPort,
error.NameServerFailure,
error.NetworkUnreachable,
error.Overflow,
error.RedirectRequiresResend,
error.TemporaryNameServerFailure,
error.TlsAlert,
error.TlsFailure,
error.TlsInitializationFailed,
error.TooManyHttpRedirects,
error.UnexpectedCharacter,
error.UnexpectedConnectFailure,
error.UnexpectedReadFailure,
error.UnexpectedWriteFailure,
Expand Down Expand Up @@ -307,10 +314,10 @@ fn handleResponseError(ctx: *api.NativeCtx, err: anytype) void {
error.UnexpectedReadFailure,
error.EndOfStream,
error.HttpChunkInvalid,
error.HttpHeadersExceededSizeLimit,
error.DecompressionFailure,
error.InvalidTrailers,
error.StreamTooLong,
error.HttpHeadersOversize,
=> ctx.vm.pushErrorEnum("http.HttpError", @errorName(err)),
}
}
5 changes: 1 addition & 4 deletions src/lib/buzz_io.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn handleFileOpenError(ctx: *api.NativeCtx, err: anytype) void {
error.FileBusy,
error.FileLocksNotSupported,
error.FileTooBig,
error.InvalidHandle,
error.InvalidWtf8,
error.InvalidUtf8,
error.IsDir,
error.NameTooLong,
Expand Down Expand Up @@ -125,7 +125,6 @@ fn handleFileReadWriteError(ctx: *api.NativeCtx, err: anytype) void {
error.ConnectionResetByPeer,
error.ConnectionTimedOut,
error.NotOpenForReading,
error.NetNameDeleted,
=> ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)),

error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null),
Expand Down Expand Up @@ -176,7 +175,6 @@ fn handleFileReadLineError(ctx: *api.NativeCtx, err: anytype) void {
error.BrokenPipe,
error.ConnectionResetByPeer,
error.ConnectionTimedOut,
error.NetNameDeleted,
error.NotOpenForReading,
error.OperationAborted,
error.StreamTooLong,
Expand Down Expand Up @@ -242,7 +240,6 @@ fn handleFileReadAllError(ctx: *api.NativeCtx, err: anytype) void {
error.ConnectionResetByPeer,
error.ConnectionTimedOut,
error.NotOpenForReading,
error.NetNameDeleted,
=> ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)),

error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null),
Expand Down
Loading

0 comments on commit 7baaa7a

Please sign in to comment.