mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Utilize union #shared_nil in more places
This commit is contained in:
@@ -8,6 +8,7 @@ import "core:intrinsics"
|
|||||||
|
|
||||||
// Extra errors returns by scanning procedures
|
// Extra errors returns by scanning procedures
|
||||||
Scanner_Extra_Error :: enum i32 {
|
Scanner_Extra_Error :: enum i32 {
|
||||||
|
None,
|
||||||
Negative_Advance,
|
Negative_Advance,
|
||||||
Advanced_Too_Far,
|
Advanced_Too_Far,
|
||||||
Bad_Read_Count,
|
Bad_Read_Count,
|
||||||
@@ -15,7 +16,7 @@ Scanner_Extra_Error :: enum i32 {
|
|||||||
Too_Short,
|
Too_Short,
|
||||||
}
|
}
|
||||||
|
|
||||||
Scanner_Error :: union {
|
Scanner_Error :: union #shared_nil {
|
||||||
io.Error,
|
io.Error,
|
||||||
Scanner_Extra_Error,
|
Scanner_Extra_Error,
|
||||||
}
|
}
|
||||||
@@ -68,7 +69,7 @@ scanner_destroy :: proc(s: ^Scanner) {
|
|||||||
// Returns the first non-EOF error that was encounted by the scanner
|
// Returns the first non-EOF error that was encounted by the scanner
|
||||||
scanner_error :: proc(s: ^Scanner) -> Scanner_Error {
|
scanner_error :: proc(s: ^Scanner) -> Scanner_Error {
|
||||||
switch s._err {
|
switch s._err {
|
||||||
case .EOF, .None:
|
case .EOF, nil:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return s._err
|
return s._err
|
||||||
@@ -93,10 +94,6 @@ scanner_text :: proc(s: ^Scanner) -> string {
|
|||||||
// scanner_scan advances the scanner
|
// scanner_scan advances the scanner
|
||||||
scanner_scan :: proc(s: ^Scanner) -> bool {
|
scanner_scan :: proc(s: ^Scanner) -> bool {
|
||||||
set_err :: proc(s: ^Scanner, err: Scanner_Error) {
|
set_err :: proc(s: ^Scanner, err: Scanner_Error) {
|
||||||
err := err
|
|
||||||
if err == .None {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
switch s._err {
|
switch s._err {
|
||||||
case nil, .EOF:
|
case nil, .EOF:
|
||||||
s._err = err
|
s._err = err
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ Options :: struct {
|
|||||||
level: u8,
|
level: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
Error :: compress.Error
|
Error :: compress.Error
|
||||||
General_Error :: compress.General_Error
|
General_Error :: compress.General_Error
|
||||||
ZLIB_Error :: compress.ZLIB_Error
|
ZLIB_Error :: compress.ZLIB_Error
|
||||||
Deflate_Error :: compress.Deflate_Error
|
Deflate_Error :: compress.Deflate_Error
|
||||||
|
|||||||
@@ -8,17 +8,18 @@ import "core:strings"
|
|||||||
import "core:io"
|
import "core:io"
|
||||||
|
|
||||||
Marshal_Data_Error :: enum {
|
Marshal_Data_Error :: enum {
|
||||||
|
None,
|
||||||
Unsupported_Type,
|
Unsupported_Type,
|
||||||
}
|
}
|
||||||
|
|
||||||
Marshal_Error :: union {
|
Marshal_Error :: union #shared_nil {
|
||||||
Marshal_Data_Error,
|
Marshal_Data_Error,
|
||||||
io.Error,
|
io.Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
marshal :: proc(v: any, allocator := context.allocator) -> (data: []byte, err: Marshal_Error) {
|
marshal :: proc(v: any, allocator := context.allocator) -> (data: []byte, err: Marshal_Error) {
|
||||||
b := strings.make_builder(allocator)
|
b := strings.make_builder(allocator)
|
||||||
defer if err != .None {
|
defer if err != nil {
|
||||||
strings.destroy_builder(&b)
|
strings.destroy_builder(&b)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ marshal :: proc(v: any, allocator := context.allocator) -> (data: []byte, err: M
|
|||||||
if len(b.buf) != 0 {
|
if len(b.buf) != 0 {
|
||||||
data = b.buf[:]
|
data = b.buf[:]
|
||||||
}
|
}
|
||||||
return data, .None
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
marshal_to_builder :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
|
marshal_to_builder :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
|
||||||
|
|||||||
Reference in New Issue
Block a user