Skip to content

Commit

Permalink
chore: zig 0.14.0-dev.2162+3054486d1
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Nov 4, 2024
1 parent 19bb942 commit f93fd78
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 58 deletions.
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

_Latest zig version supported: 0.14.0-dev.1588+2111f4c38_
_Latest zig version supported: 0.14.0-dev.2162+3054486d1_

### 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 Down
32 changes: 16 additions & 16 deletions src/FFI.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ const Self = @This();

const basic_types = std.StaticStringMap(o.ObjTypeDef).initComptime(
.{
.{ "u8", .{ .def_type = .Integer } },
.{ "i8", .{ .def_type = .Integer } },
.{ "u16", .{ .def_type = .Integer } },
.{ "i16", .{ .def_type = .Integer } },
.{ "i32", .{ .def_type = .Integer } },
.{ "u8", o.ObjTypeDef{ .def_type = .Integer } },
.{ "i8", o.ObjTypeDef{ .def_type = .Integer } },
.{ "u16", o.ObjTypeDef{ .def_type = .Integer } },
.{ "i16", o.ObjTypeDef{ .def_type = .Integer } },
.{ "i32", o.ObjTypeDef{ .def_type = .Integer } },

// Could it be > 32bits one some systems?
.{ "c_int", .{ .def_type = .Integer } },
.{ "c_int", o.ObjTypeDef{ .def_type = .Integer } },

.{ "c_uint", .{ .def_type = .Double } },
.{ "u32", .{ .def_type = .Double } },
.{ "i64", .{ .def_type = .Double } },
.{ "f32", .{ .def_type = .Double } },
.{ "f64", .{ .def_type = .Double } },
.{ "c_uint", o.ObjTypeDef{ .def_type = .Double } },
.{ "u32", o.ObjTypeDef{ .def_type = .Double } },
.{ "i64", o.ObjTypeDef{ .def_type = .Double } },
.{ "f32", o.ObjTypeDef{ .def_type = .Double } },
.{ "f64", o.ObjTypeDef{ .def_type = .Double } },

.{ "u64", .{ .def_type = .UserData } },
.{ "usize", .{ .def_type = .UserData } },
.{ "u64", o.ObjTypeDef{ .def_type = .UserData } },
.{ "usize", o.ObjTypeDef{ .def_type = .UserData } },

.{ "bool", .{ .def_type = .Bool } },
.{ "bool", o.ObjTypeDef{ .def_type = .Bool } },

.{ "void", .{ .def_type = .Void } },
.{ "anyopaque", .{ .def_type = .Void } },
.{ "void", o.ObjTypeDef{ .def_type = .Void } },
.{ "anyopaque", o.ObjTypeDef{ .def_type = .Void } },
},
);

Expand Down
42 changes: 23 additions & 19 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1479,25 +1479,7 @@ fn statement(self: *Self, hanging: bool, loop_scope: ?LoopScope) !?Ast.Node.Inde
std.debug.assert(!hanging);
return try self.outStatement();
} else if (try self.match(.Throw)) {
const start_location = self.current_token.? - 1;
// For now we don't care about the type. Later if we have `Error` type of data, we'll type check this
const error_value = try self.expression(false);

try self.consume(.Semicolon, "Expected `;` after statement.");

return try self.ast.appendNode(
.{
.tag = .Throw,
.location = start_location,
.end_location = self.current_token.? - 1,
.components = .{
.Throw = .{
.expression = error_value,
.unconditional = self.current.?.scope_depth == 1,
},
},
},
);
return try self.throw();
}
}

Expand Down Expand Up @@ -8647,6 +8629,28 @@ fn outStatement(self: *Self) Error!Ast.Node.Index {
);
}

fn throw(self: *Self) Error!Ast.Node.Index {
const start_location = self.current_token.? - 1;
// For now we don't care about the type. Later if we have `Error` type of data, we'll type check this
const error_value = try self.expression(false);

try self.consume(.Semicolon, "Expected `;` after statement.");

return try self.ast.appendNode(
.{
.tag = .Throw,
.location = start_location,
.end_location = self.current_token.? - 1,
.components = .{
.Throw = .{
.expression = error_value,
.unconditional = self.current.?.scope_depth == 1,
},
},
},
);
}

fn namespaceStatement(self: *Self) Error!Ast.Node.Index {
const start_location = self.current_token.? - 1;

Expand Down
26 changes: 16 additions & 10 deletions src/lib/buzz_fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,22 @@ pub export fn move(ctx: *api.NativeCtx) c_int {
return -1;
};
} else {
const source_absolute = if (source_is_absolute) source_slice else std.fs.cwd().realpathAlloc(api.VM.allocator, source_slice) catch |err| {
handleRealpathError(ctx, err);

return -1;
};
const destination_absolute = if (destination_is_absolute) destination_slice else std.fs.cwd().realpathAlloc(api.VM.allocator, destination_slice) catch |err| {
handleRealpathError(ctx, err);

return -1;
};
const source_absolute = if (source_is_absolute)
source_slice
else
std.fs.cwd().realpathAlloc(api.VM.allocator, source_slice) catch |err| {
handleRealpathError(ctx, err);

return -1;
};
const destination_absolute = if (destination_is_absolute)
destination_slice
else
std.fs.cwd().realpathAlloc(api.VM.allocator, destination_slice) catch |err| {
handleRealpathError(ctx, err);

return -1;
};
defer {
if (source_is_absolute) {
api.VM.allocator.free(source_absolute);
Expand Down
17 changes: 17 additions & 0 deletions src/lib/buzz_io.zig
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ fn handleFileReadWriteError(ctx: *api.NativeCtx, err: anytype) void {
error.ConnectionResetByPeer,
error.ConnectionTimedOut,
error.NotOpenForReading,
error.LockViolation,
=> ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)),

error.ProcessNotFound,
=> ctx.vm.pushErrorEnum("errors.ExecError", @errorName(err)),

error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null),
error.OutOfMemory => {
ctx.vm.bz_panic("Out of memory", "Out of memory".len);
Expand Down Expand Up @@ -192,8 +196,12 @@ fn handleFileReadLineError(ctx: *api.NativeCtx, err: anytype) void {
error.NotOpenForReading,
error.OperationAborted,
error.StreamTooLong,
error.LockViolation,
=> ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)),

error.ProcessNotFound,
=> ctx.vm.pushErrorEnum("errors.ExecError", @errorName(err)),

error.OutOfMemory => {
ctx.vm.bz_panic("Out of memory", "Out of memory".len);
unreachable;
Expand Down Expand Up @@ -258,8 +266,12 @@ fn handleFileReadAllError(ctx: *api.NativeCtx, err: anytype) void {
error.ConnectionResetByPeer,
error.ConnectionTimedOut,
error.NotOpenForReading,
error.LockViolation,
=> ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)),

error.ProcessNotFound,
=> ctx.vm.pushErrorEnum("errors.ExecError", @errorName(err)),

error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null),
}
}
Expand Down Expand Up @@ -333,15 +345,20 @@ pub export fn FileWrite(ctx: *api.NativeCtx) c_int {
error.SystemResources,
error.WouldBlock,
=> ctx.vm.pushErrorEnum("errors.FileSystemError", @errorName(err)),

error.BrokenPipe,
error.ConnectionResetByPeer,
error.LockViolation,
error.NotOpenForWriting,
error.OperationAborted,
=> ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)),

error.InputOutput => ctx.vm.pushErrorEnum("errors.SocketError", "InputOutput"),
error.InvalidArgument => ctx.vm.pushError("errors.InvalidArgumentError", null),
error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null),

error.ProcessNotFound,
=> ctx.vm.pushErrorEnum("errors.ExecError", @errorName(err)),
}

return -1;
Expand Down
8 changes: 8 additions & 0 deletions src/lib/buzz_os.zig
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,14 @@ fn handleConnectError(ctx: *api.NativeCtx, err: anytype) void {
error.BrokenPipe,
error.NotOpenForReading,
error.OperationAborted,
error.LockViolation,
=> ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)),

error.OutOfMemory => {
ctx.vm.bz_panic("Out of memory", "Out of memory".len);
unreachable;
},
error.ProcessNotFound => ctx.vm.pushErrorEnum("errors.ExecError", @errorName(err)),
error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null),
error.Overflow => ctx.vm.pushError("errors.OverflowError", null),
}
Expand Down Expand Up @@ -474,8 +476,12 @@ fn handleReadLineError(ctx: *api.NativeCtx, err: anytype) void {
error.NotOpenForReading,
error.OperationAborted,
error.StreamTooLong,
error.LockViolation,
=> ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)),

error.ProcessNotFound,
=> ctx.vm.pushErrorEnum("errors.ExecError", @errorName(err)),

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

error.OutOfMemory => {
Expand Down Expand Up @@ -607,6 +613,8 @@ pub export fn SocketWrite(ctx: *api.NativeCtx) c_int {
=> ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)),
error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null),
error.InvalidArgument => ctx.vm.pushError("errors.InvalidArgumentError", null),
error.ProcessNotFound,
=> ctx.vm.pushErrorEnum("errors.ExecError", @errorName(err)),
}

return -1;
Expand Down
14 changes: 2 additions & 12 deletions src/lib/buzz_std.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ pub export fn toInt(ctx: *api.NativeCtx) c_int {
const value = ctx.vm.bz_peek(0);

ctx.vm.bz_push(
api.Value.fromInteger(
if (value.isFloat())
@intFromFloat(value.double())
else
value.integer(),
),
api.Value.fromInteger(@intFromFloat(value.double())),
);

return 1;
Expand All @@ -75,12 +70,7 @@ pub export fn toDouble(ctx: *api.NativeCtx) c_int {
const value = ctx.vm.bz_peek(0);

ctx.vm.bz_push(
api.Value.fromFloat(
if (value.isInteger())
@floatFromInt(value.integer())
else
value.double(),
),
api.Value.fromFloat(@floatFromInt(value.integer())),
);

return 1;
Expand Down

0 comments on commit f93fd78

Please sign in to comment.