Use multiple return values where possible

This commit is contained in:
gingerBill
2025-06-20 09:17:02 +01:00
parent c3e9b16d5a
commit 9a328e1c97
+67 -39
View File
@@ -18,59 +18,77 @@ import "core:mem"
@(default_calling_convention="c", link_prefix="kbts_", require_results) @(default_calling_convention="c", link_prefix="kbts_", require_results)
foreign lib { foreign lib {
FontIsValid :: proc(Font: ^font) -> b32 --- FontIsValid :: proc(Font: ^font) -> b32 ---
ReadFontHeader :: proc(Font: ^font, Data: rawptr, Size: un) -> un --- SizeOfShapeState :: proc(Font: ^font) -> un ---
ReadFontData :: proc(Font: ^font, Scratch: rawptr, ScratchSize: un) -> un ---
PostReadFontInitialize :: proc(Font: ^font, Memory: rawptr, MemorySize: un) -> b32 ---
SizeOfShapeState :: proc(Font: ^font) -> un ---
PlaceShapeState :: proc(Address: rawptr, Size: un) -> ^shape_state --- ResetShapeState :: proc(State: ^shape_state) ---
ResetShapeState :: proc(State: ^shape_state) ---
ShapeConfig :: proc(Font: ^font, Script: script, Language: language) -> shape_config --- ShapeConfig :: proc(Font: ^font, Script: script, Language: language) -> shape_config ---
ShaperIsComplex :: proc(Shaper: shaper) -> b32 --- ShaperIsComplex :: proc(Shaper: shaper) -> b32 ---
ScriptIsComplex :: proc(Script: script) -> b32 --- ScriptIsComplex :: proc(Script: script) -> b32 ---
Shape :: proc(State: ^shape_state, Config: ^shape_config, Shape :: proc(State: ^shape_state, Config: ^shape_config,
MainDirection, RunDirection: direction, MainDirection, RunDirection: direction,
Glyphs: [^]glyph, GlyphCount: ^u32, GlyphCapacity: u32) -> c.int --- Glyphs: [^]glyph, GlyphCount: ^u32, GlyphCapacity: u32) -> c.int ---
Cursor :: proc(Direction: direction) -> cursor --- Cursor :: proc(Direction: direction) -> cursor ---
PositionGlyph :: proc(Cursor: ^cursor, Glyph: ^glyph, X, Y: ^i32) --- BeginBreak :: proc(State: ^break_state, MainDirection: direction, JapaneseLineBreakStyle: japanese_line_break_style) ---
BeginBreak :: proc(State: ^break_state, MainDirection: direction, JapaneseLineBreakStyle: japanese_line_break_style) --- BreakStateIsValid :: proc(State: ^break_state) -> b32 ---
BreakStateIsValid :: proc(State: ^break_state) -> c.int --- BreakAddCodepoint :: proc(State: ^break_state, Codepoint: rune, PositionIncrement: u32, EndOfText: c.int) ---
BreakAddCodepoint :: proc(State: ^break_state, Codepoint: rune, PositionIncrement: u32, EndOfText: c.int) --- BreakFlush :: proc(State: ^break_state) ---
BreakFlush :: proc(State: ^break_state) --- Break :: proc(State: ^break_state, Break: ^break_type) -> b32 ---
Break :: proc(State: ^break_state, Break: ^break_type) -> c.int --- CodepointToGlyph :: proc(Font: ^font, Codepoint: rune) -> glyph ---
DecodeUtf8 :: proc(Utf8: [^]byte, Length: uint) -> decode --- InferScript :: proc(Direction: ^direction, Script: ^script, GlyphScript: script) ---
CodepointToGlyph :: proc(Font: ^font, Codepoint: rune) -> glyph ---
InferScript :: proc(Direction: ^direction, Script: ^script, GlyphScript: script) ---
} }
@(require_results) @(require_results)
PlaceShapeStateFromSlice :: proc "c" (Memory: []byte) -> ^shape_state { PlaceShapeState :: proc "c" (Memory: []byte) -> ^shape_state {
return PlaceShapeState(raw_data(Memory), un(len(Memory))) @(default_calling_convention="c", require_results)
foreign lib {
kbts_PlaceShapeState :: proc(Address: rawptr, Size: un) -> ^shape_state ---
}
return kbts_PlaceShapeState(raw_data(Memory), un(len(Memory)))
} }
@(require_results) @(require_results)
DecodeUtf8String :: proc "c" (String: string) -> (Codepoint: rune, SourceCharactersConsumed: u32, Valid: b32) { DecodeUtf8 :: proc "contextless" (String: string) -> (Codepoint: rune, SourceCharactersConsumed: u32, Valid: b32) {
Decode := DecodeUtf8(raw_data(String), len(String)) @(default_calling_convention="c", require_results)
Codepoint, SourceCharactersConsumed, Valid = Decode.Codepoint, Decode.SourceCharactersConsumed, Decode.Valid foreign lib {
return kbts_DecodeUtf8 :: proc(Utf8: [^]byte, Length: uint) -> decode ---
}
Decode := kbts_DecodeUtf8(raw_data(String), len(String))
return Decode.Codepoint, Decode.SourceCharactersConsumed, Decode.Valid
} }
@(require_results) @(require_results)
ReadFontHeaderFromSlice :: proc "c" (Font: ^font, Data: []byte) -> un { ReadFontHeader :: proc "c" (Font: ^font, Data: []byte) -> un {
return ReadFontHeader(Font, raw_data(Data), un(len(Data))) @(default_calling_convention="c", require_results)
foreign lib {
kbts_ReadFontHeader :: proc(Font: ^font, Data: rawptr, Size: un) -> un ---
}
return kbts_ReadFontHeader(Font, raw_data(Data), un(len(Data)))
} }
@(require_results) @(require_results)
ReadFontDataFromSlice :: proc "c" (Font: ^font, Scratch: []byte) -> un { ReadFontData :: proc "c" (Font: ^font, Scratch: []byte) -> un {
return ReadFontData(Font, raw_data(Scratch), un(len(Scratch))) @(default_calling_convention="c", require_results)
foreign lib {
kbts_ReadFontData :: proc(Font: ^font, Scratch: rawptr, ScratchSize: un) -> un ---
}
return kbts_ReadFontData(Font, raw_data(Scratch), un(len(Scratch)))
} }
@(require_results) @(require_results)
PostReadFontInitializeFromSlice :: proc "c" (Font: ^font, Memory: []byte) -> b32 { PostReadFontInitialize :: proc "c" (Font: ^font, Memory: []byte) -> b32 {
return PostReadFontInitialize(Font, raw_data(Memory), un(len(Memory))) @(default_calling_convention="c", require_results)
foreign lib {
kbts_PostReadFontInitialize :: proc(Font: ^font, Memory: rawptr, MemorySize: un) -> b32 ---
}
return kbts_PostReadFontInitialize(Font, raw_data(Memory), un(len(Memory)))
} }
@(require_results) @(require_results)
@@ -81,9 +99,9 @@ FontFromMemory :: proc(Data: []byte, allocator: mem.Allocator) -> (Result: font,
} }
copy(ClonedData, Data) copy(ClonedData, Data)
ScratchSize := ReadFontHeaderFromSlice(&Result, ClonedData) ScratchSize := ReadFontHeader(&Result, ClonedData)
Scratch := mem.make_aligned([]byte, ScratchSize, 16, allocator) or_return Scratch := mem.make_aligned([]byte, ScratchSize, 16, allocator) or_return
MemorySize := ReadFontDataFromSlice(&Result, Scratch) MemorySize := ReadFontData(&Result, Scratch)
Memory := Scratch Memory := Scratch
if MemorySize > ScratchSize { if MemorySize > ScratchSize {
@@ -94,7 +112,7 @@ FontFromMemory :: proc(Data: []byte, allocator: mem.Allocator) -> (Result: font,
delete(Memory, allocator) delete(Memory, allocator)
} }
_ = PostReadFontInitializeFromSlice(&Result, Memory) _ = PostReadFontInitialize(&Result, Memory)
return return
} }
@@ -108,9 +126,19 @@ FreeFont :: proc(Font: ^font, allocator: mem.Allocator) {
CreateShapeState :: proc(Font: ^font, allocator: mem.Allocator) -> (Result: ^shape_state, Err: mem.Allocator_Error) { CreateShapeState :: proc(Font: ^font, allocator: mem.Allocator) -> (Result: ^shape_state, Err: mem.Allocator_Error) {
Size := SizeOfShapeState(Font) Size := SizeOfShapeState(Font)
Memory := mem.make_aligned([]byte, Size, 16, allocator) or_return Memory := mem.make_aligned([]byte, Size, 16, allocator) or_return
Result = PlaceShapeStateFromSlice(Memory) Result = PlaceShapeState(Memory)
return return
} }
FreeShapeState :: proc(State: ^shape_state, allocator: mem.Allocator) { FreeShapeState :: proc(State: ^shape_state, allocator: mem.Allocator) {
free(State, allocator) free(State, allocator)
} }
@(require_results)
PositionGlyph :: proc(Cursor: ^cursor, Glyph: ^glyph) -> (X, Y: i32) {
@(default_calling_convention="c", require_results)
foreign lib {
kbts_PositionGlyph :: proc(Cursor: ^cursor, Glyph: ^glyph, X, Y: ^i32) ---
}
kbts_PositionGlyph(Cursor, Glyph, &X, &Y)
return
}