buzz-language / buzz

👨‍🚀 buzz, A small/lightweight statically typed scripting language
https://buzz-lang.dev
MIT License
1.22k stars 34 forks source link

Add `pushError`/`pushErrorEnum` helper methods #133

Closed FnControlOption closed 1 year ago

FnControlOption commented 1 year ago

Working on updating to latest Zig and added some helper methods to make it less painful 😅 This led to finding some copy-paste mistakes fixed in the first commit of this PR.

Another possible optimization using @errorName:

switch (err) {
    error.AccessDenied,
    error.InputOutput,
    error.SystemResources,
    error.WouldBlock,
    error.DiskQuota,
    error.FileTooBig,
    error.NoSpaceLeft,
    error.DeviceBusy,
    => |e| ctx.vm.pushErrorEnum("lib.errors.FileSystemError", @errorName(e)),

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

    error.Unexpected => ctx.vm.pushError("lib.errors.UnexpectedError"),
    error.InvalidArgument => ctx.vm.pushError("lib.errors.InvalidArgumentError"),
}
giann commented 1 year ago

Oh didn't know about @errorName. If you want to update the code to latest zig you could start on the mir branch. It's a big wip on the JIT with MIR rather than LLVM. But it'll be easier for me to merge. Thanks for the effort 🙏

giann commented 1 year ago

Merged manually 88778741ed244c34f63b3f115f0f76205a982826