Change func out-type from struct to bare type

This commit is contained in:
Nigel Tao committed 2018-07-29 10:02:06 +10:00
1 parent af7b15bc17
commit 9919d78245
19 files changed
+236 -239

No files matched your search

+20 -26
View File
@@ -88,15 +88,12 @@ func (g *gen) writeFuncSignature(b *buffer, n *a.Func, cpp uint32) error {
// TODO: write n's return values. // TODO: write n's return values.
if n.Suspendible() { if n.Suspendible() {
b.writes("wuffs_base__status ") b.writes("wuffs_base__status ")
} else if outFields := n.Out().Fields(); len(outFields) == 0 { } else if out := n.Out(); out == nil {
// TODO: wuffs_base__empty_struct.
b.writes("void ") b.writes("void ")
} else if len(outFields) == 1 { // TODO: does writeCTypeName generate the right C if out is an array?
// TODO: does this generate the right C if the XType is an array? } else if err := g.writeCTypeName(b, out, "", ""); err != nil {
if err := g.writeCTypeName(b, outFields[0].AsField().XType(), "", ""); err != nil { return err
return err
}
} else {
return fmt.Errorf("TODO: multiple return values")
} }
if cpp != cppInsideStruct { if cpp != cppInsideStruct {
@@ -203,22 +200,19 @@ func (g *gen) gatherFuncImpl(_ *buffer, n *a.Func) error {
return nil return nil
} }
func (g *gen) writeOutFieldsZeroValue(b *buffer, outFields []*a.Node) error { func (g *gen) writeOutParamZeroValue(b *buffer, typ *a.TypeExpr) error {
switch len(outFields) { if typ == nil {
case 0: // No-op. It's "return;" and not "return foo;".
// No-op. //
case 1: // TODO: "return ((wuffs_base__empty_struct){})".
if typ := outFields[0].AsField().XType(); typ.IsNumType() { } else if typ.IsNumType() {
b.writes("0") b.writes("0")
} else { } else {
b.writes("((") b.writes("((")
if err := g.writeCTypeName(b, typ, "", ""); err != nil { if err := g.writeCTypeName(b, typ, "", ""); err != nil {
return err return err
}
b.writes("){})")
} }
default: b.writes("){})")
return fmt.Errorf("TODO: handle structured return types")
} }
return nil return nil
} }
@@ -226,12 +220,12 @@ func (g *gen) writeOutFieldsZeroValue(b *buffer, outFields []*a.Node) error {
func (g *gen) writeFuncImplHeader(b *buffer) error { func (g *gen) writeFuncImplHeader(b *buffer) error {
// Check the previous status and the "self" arg. // Check the previous status and the "self" arg.
if g.currFunk.public && !g.currFunk.astFunc.Receiver().IsZero() { if g.currFunk.public && !g.currFunk.astFunc.Receiver().IsZero() {
outFields := g.currFunk.astFunc.Out().Fields() out := g.currFunk.astFunc.Out()
b.writes("if (!self) { return ") b.writes("if (!self) { return ")
if g.currFunk.suspendible { if g.currFunk.suspendible {
b.writes("WUFFS_BASE__ERROR_BAD_RECEIVER") b.writes("WUFFS_BASE__ERROR_BAD_RECEIVER")
} else if err := g.writeOutFieldsZeroValue(b, outFields); err != nil { } else if err := g.writeOutParamZeroValue(b, out); err != nil {
return err return err
} }
b.writes(";}") b.writes(";}")
@@ -242,7 +236,7 @@ func (g *gen) writeFuncImplHeader(b *buffer) error {
b.writes("if (self->private_impl.status < 0) { return ") b.writes("if (self->private_impl.status < 0) { return ")
if g.currFunk.suspendible { if g.currFunk.suspendible {
b.writes("self->private_impl.status") b.writes("self->private_impl.status")
} else if err := g.writeOutFieldsZeroValue(b, outFields); err != nil { } else if err := g.writeOutParamZeroValue(b, out); err != nil {
return err return err
} }
b.writes(";}\n") b.writes(";}\n")
+1 -1
View File
@@ -358,7 +358,7 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
} }
b.writes("return ") b.writes("return ")
if len(g.currFunk.astFunc.Out().Fields()) == 0 { if g.currFunk.astFunc.Out() == nil {
if retExpr != nil { if retExpr != nil {
return fmt.Errorf("return expression %q incompatible with empty return type", retExpr.Str(g.tm)) return fmt.Errorf("return expression %q incompatible with empty return type", retExpr.Str(g.tm))
} }
+11 -12
View File
@@ -296,21 +296,20 @@ func (h *genHelper) genWuffs(dirname string, qualifiedFilenames []string) error
} }
// TODO: look at n.Asserts(). // TODO: look at n.Asserts().
fmt.Fprintf(out, "pub func %s.%s%s(", n.Receiver().Str(&h.tm), n.FuncName().Str(&h.tm), effect) fmt.Fprintf(out, "pub func %s.%s%s(", n.Receiver().Str(&h.tm), n.FuncName().Str(&h.tm), effect)
for i, param := range [2]*a.Struct{n.In(), n.Out()} { for i, field := range n.In().Fields() {
field := field.AsField()
if i > 0 { if i > 0 {
fmt.Fprintf(out, ")(") fmt.Fprintf(out, ", ")
}
for j, field := range param.Fields() {
field := field.AsField()
if j > 0 {
fmt.Fprintf(out, ", ")
}
// TODO: what happens if the XType is from another
// package?
fmt.Fprintf(out, "%s %s", field.Name().Str(&h.tm), field.XType().Str(&h.tm))
} }
// TODO: what happens if the XType is from another package?
// Similarly for the out-param.
fmt.Fprintf(out, "%s %s", field.Name().Str(&h.tm), field.XType().Str(&h.tm))
} }
fmt.Fprintf(out, ") { }\n") fmt.Fprintf(out, ") ")
if o := n.Out(); o != nil {
fmt.Fprintf(out, "%s", o.Str(&h.tm))
}
fmt.Fprintf(out, " { }\n")
case a.KStatus: case a.KStatus:
n := n.AsStatus() n := n.AsStatus()
+1
View File
@@ -10,6 +10,7 @@
- Added an `io_bind` keyword. - Added an `io_bind` keyword.
- Added a `use` keyword. - Added a `use` keyword.
- Added a `yield` keyword. - Added a `yield` keyword.
- Changed func out-type from struct to bare type.
- Added `std/adler32`, `std/crc32` and `std/gzip`. - Added `std/adler32`, `std/crc32` and `std/gzip`.
- Spun `std/lzw` out of `std/gif`. - Spun `std/lzw` out of `std/gif`.
- Spun `std/zlib` out of `std/flate`. - Spun `std/zlib` out of `std/flate`.
+2 -2
View File
@@ -818,11 +818,11 @@ func (n *Func) QQID() t.QQID { return t.QQID{n.id1, n.id2, n.id0} }
func (n *Func) Receiver() t.QID { return t.QID{n.id1, n.id2} } func (n *Func) Receiver() t.QID { return t.QID{n.id1, n.id2} }
func (n *Func) FuncName() t.ID { return n.id0 } func (n *Func) FuncName() t.ID { return n.id0 }
func (n *Func) In() *Struct { return n.lhs.AsStruct() } func (n *Func) In() *Struct { return n.lhs.AsStruct() }
func (n *Func) Out() *Struct { return n.rhs.AsStruct() } func (n *Func) Out() *TypeExpr { return n.rhs.AsTypeExpr() }
func (n *Func) Asserts() []*Node { return n.list1 } func (n *Func) Asserts() []*Node { return n.list1 }
func (n *Func) Body() []*Node { return n.list2 } func (n *Func) Body() []*Node { return n.list2 }
func NewFunc(flags Flags, filename string, line uint32, receiverName t.ID, funcName t.ID, in *Struct, out *Struct, asserts []*Node, body []*Node) *Func { func NewFunc(flags Flags, filename string, line uint32, receiverName t.ID, funcName t.ID, in *Struct, out *TypeExpr, asserts []*Node, body []*Node) *Func {
return &Func{ return &Func{
kind: KFunc, kind: KFunc,
flags: flags, flags: flags,
+116 -116
View File
@@ -99,55 +99,55 @@ var Types = []string{
} }
var Funcs = []string{ var Funcs = []string{
"u8.high_bits(n u32[..8])(ret u8)", "u8.high_bits(n u32[..8]) u8",
"u8.low_bits(n u32[..8])(ret u8)", "u8.low_bits(n u32[..8]) u8",
"u8.max(x u8)(ret u8)", "u8.max(x u8) u8",
"u8.min(x u8)(ret u8)", "u8.min(x u8) u8",
"u16.high_bits(n u32[..16])(ret u16)", "u16.high_bits(n u32[..16]) u16",
"u16.low_bits(n u32[..16])(ret u16)", "u16.low_bits(n u32[..16]) u16",
"u16.max(x u16)(ret u16)", "u16.max(x u16) u16",
"u16.min(x u16)(ret u16)", "u16.min(x u16) u16",
"u32.high_bits(n u32[..32])(ret u32)", "u32.high_bits(n u32[..32]) u32",
"u32.low_bits(n u32[..32])(ret u32)", "u32.low_bits(n u32[..32]) u32",
"u32.max(x u32)(ret u32)", "u32.max(x u32) u32",
"u32.min(x u32)(ret u32)", "u32.min(x u32) u32",
"u64.high_bits(n u32[..64])(ret u64)", "u64.high_bits(n u32[..64]) u64",
"u64.low_bits(n u32[..64])(ret u64)", "u64.low_bits(n u32[..64]) u64",
"u64.max(x u64)(ret u64)", "u64.max(x u64) u64",
"u64.min(x u64)(ret u64)", "u64.min(x u64) u64",
// ---- utility // ---- utility
"utility.make_range_ii_u32(min_incl u32, max_incl u32)(ret range_ii_u32)", "utility.make_range_ii_u32(min_incl u32, max_incl u32) range_ii_u32",
"utility.make_range_ie_u32(min_incl u32, max_excl u32)(ret range_ie_u32)", "utility.make_range_ie_u32(min_incl u32, max_excl u32) range_ie_u32",
"utility.make_range_ii_u64(min_incl u64, max_incl u64)(ret range_ii_u64)", "utility.make_range_ii_u64(min_incl u64, max_incl u64) range_ii_u64",
"utility.make_range_ie_u64(min_incl u64, max_excl u64)(ret range_ie_u64)", "utility.make_range_ie_u64(min_incl u64, max_excl u64) range_ie_u64",
"utility.make_rect_ii_u32(min_incl_x u32, min_incl_y u32, max_incl_x u32, max_incl_y u32)(ret rect_ii_u32)", "utility.make_rect_ii_u32(min_incl_x u32, min_incl_y u32, max_incl_x u32, max_incl_y u32) rect_ii_u32",
"utility.make_rect_ie_u32(min_incl_x u32, min_incl_y u32, max_excl_x u32, max_excl_y u32)(ret rect_ie_u32)", "utility.make_rect_ie_u32(min_incl_x u32, min_incl_y u32, max_excl_x u32, max_excl_y u32) rect_ie_u32",
// ---- io_reader // ---- io_reader
"io_reader.can_undo_byte()(ret bool)", "io_reader.can_undo_byte() bool",
"io_reader.undo_byte!()()", "io_reader.undo_byte!()",
"io_reader.read_u8?()(ret u8)", "io_reader.read_u8?() u8",
"io_reader.read_u16be?()(ret u16)", "io_reader.read_u16be?() u16",
"io_reader.read_u16le?()(ret u16)", "io_reader.read_u16le?() u16",
"io_reader.read_u24be?()(ret u32[..0xFFFFFF])", "io_reader.read_u24be?() u32[..0xFFFFFF]",
"io_reader.read_u24le?()(ret u32[..0xFFFFFF])", "io_reader.read_u24le?() u32[..0xFFFFFF]",
"io_reader.read_u32be?()(ret u32)", "io_reader.read_u32be?() u32",
"io_reader.read_u32le?()(ret u32)", "io_reader.read_u32le?() u32",
"io_reader.read_u40be?()(ret u64[..0xFFFFFFFFFF])", "io_reader.read_u40be?() u64[..0xFFFFFFFFFF]",
"io_reader.read_u40le?()(ret u64[..0xFFFFFFFFFF])", "io_reader.read_u40le?() u64[..0xFFFFFFFFFF]",
"io_reader.read_u48be?()(ret u64[..0xFFFFFFFFFFFF])", "io_reader.read_u48be?() u64[..0xFFFFFFFFFFFF]",
"io_reader.read_u48le?()(ret u64[..0xFFFFFFFFFFFF])", "io_reader.read_u48le?() u64[..0xFFFFFFFFFFFF]",
"io_reader.read_u56be?()(ret u64[..0xFFFFFFFFFFFFFF])", "io_reader.read_u56be?() u64[..0xFFFFFFFFFFFFFF]",
"io_reader.read_u56le?()(ret u64[..0xFFFFFFFFFFFFFF])", "io_reader.read_u56le?() u64[..0xFFFFFFFFFFFFFF]",
"io_reader.read_u64be?()(ret u64)", "io_reader.read_u64be?() u64",
"io_reader.read_u64le?()(ret u64)", "io_reader.read_u64le?() u64",
// TODO: these should have an explicit pre-condition "available() >= N". // TODO: these should have an explicit pre-condition "available() >= N".
// For now, that's implicitly checked (i.e. hard coded). // For now, that's implicitly checked (i.e. hard coded).
@@ -155,114 +155,114 @@ var Funcs = []string{
// The io_reader has peek_etc methods and skip_fast, not read_etc_fast, // The io_reader has peek_etc methods and skip_fast, not read_etc_fast,
// because we sometimes advance the pointer by less than what's read. See // because we sometimes advance the pointer by less than what's read. See
// https://fgiesen.wordpress.com/2018/02/20/reading-bits-in-far-too-many-ways-part-2/ // https://fgiesen.wordpress.com/2018/02/20/reading-bits-in-far-too-many-ways-part-2/
"io_reader.peek_u8()(ret u8)", "io_reader.peek_u8() u8",
"io_reader.peek_u16be()(ret u16)", "io_reader.peek_u16be() u16",
"io_reader.peek_u16le()(ret u16)", "io_reader.peek_u16le() u16",
"io_reader.peek_u24be()(ret u32[..0xFFFFFF])", "io_reader.peek_u24be() u32[..0xFFFFFF]",
"io_reader.peek_u24le()(ret u32[..0xFFFFFF])", "io_reader.peek_u24le() u32[..0xFFFFFF]",
"io_reader.peek_u32be()(ret u32)", "io_reader.peek_u32be() u32",
"io_reader.peek_u32le()(ret u32)", "io_reader.peek_u32le() u32",
"io_reader.peek_u40be()(ret u64[..0xFFFFFFFFFF])", "io_reader.peek_u40be() u64[..0xFFFFFFFFFF]",
"io_reader.peek_u40le()(ret u64[..0xFFFFFFFFFF])", "io_reader.peek_u40le() u64[..0xFFFFFFFFFF]",
"io_reader.peek_u48be()(ret u64[..0xFFFFFFFFFFFF])", "io_reader.peek_u48be() u64[..0xFFFFFFFFFFFF]",
"io_reader.peek_u48le()(ret u64[..0xFFFFFFFFFFFF])", "io_reader.peek_u48le() u64[..0xFFFFFFFFFFFF]",
"io_reader.peek_u56be()(ret u64[..0xFFFFFFFFFFFFFF])", "io_reader.peek_u56be() u64[..0xFFFFFFFFFFFFFF]",
"io_reader.peek_u56le()(ret u64[..0xFFFFFFFFFFFFFF])", "io_reader.peek_u56le() u64[..0xFFFFFFFFFFFFFF]",
"io_reader.peek_u64be()(ret u64)", "io_reader.peek_u64be() u64",
"io_reader.peek_u64le()(ret u64)", "io_reader.peek_u64le() u64",
"io_reader.available()(ret u64)", "io_reader.available() u64",
"io_reader.set!(s slice u8, closed bool)()", "io_reader.set!(s slice u8, closed bool)",
"io_reader.set_limit!(l u64)()", "io_reader.set_limit!(l u64)",
"io_reader.set_mark!()()", "io_reader.set_mark!()",
"io_reader.since_mark()(ret slice u8)", "io_reader.since_mark() slice u8",
"io_reader.skip?(n u32)()", "io_reader.skip?(n u32)",
// TODO: this should have explicit pre-conditions "actual <= worst_case" // TODO: this should have explicit pre-conditions "actual <= worst_case"
// and "worst_case <= available()". As an implementation restriction, we // and "worst_case <= available()". As an implementation restriction, we
// also require that worst_case has a constant value. For now, that's all // also require that worst_case has a constant value. For now, that's all
// implicitly checked (i.e. hard coded). // implicitly checked (i.e. hard coded).
"io_reader.skip_fast!(actual u32, worst_case u32)()", "io_reader.skip_fast!(actual u32, worst_case u32)",
// ---- io_writer // ---- io_writer
"io_writer.write_u8?(x u8)()", "io_writer.write_u8?(x u8)",
"io_writer.write_u16be?(x u16)()", "io_writer.write_u16be?(x u16)",
"io_writer.write_u16le?(x u16)()", "io_writer.write_u16le?(x u16)",
"io_writer.write_u24be?(x u32[..0xFFFFFF])()", "io_writer.write_u24be?(x u32[..0xFFFFFF])",
"io_writer.write_u24le?(x u32[..0xFFFFFF])()", "io_writer.write_u24le?(x u32[..0xFFFFFF])",
"io_writer.write_u32be?(x u32)()", "io_writer.write_u32be?(x u32)",
"io_writer.write_u32le?(x u32)()", "io_writer.write_u32le?(x u32)",
"io_writer.write_u40be?(x u64[..0xFFFFFFFFFF])()", "io_writer.write_u40be?(x u64[..0xFFFFFFFFFF])",
"io_writer.write_u40le?(x u64[..0xFFFFFFFFFF])()", "io_writer.write_u40le?(x u64[..0xFFFFFFFFFF])",
"io_writer.write_u48be?(x u64[..0xFFFFFFFFFFFF])()", "io_writer.write_u48be?(x u64[..0xFFFFFFFFFFFF])",
"io_writer.write_u48le?(x u64[..0xFFFFFFFFFFFF])()", "io_writer.write_u48le?(x u64[..0xFFFFFFFFFFFF])",
"io_writer.write_u56be?(x u64[..0xFFFFFFFFFFFFFF])()", "io_writer.write_u56be?(x u64[..0xFFFFFFFFFFFFFF])",
"io_writer.write_u56le?(x u64[..0xFFFFFFFFFFFFFF])()", "io_writer.write_u56le?(x u64[..0xFFFFFFFFFFFFFF])",
"io_writer.write_u64be?(x u64)()", "io_writer.write_u64be?(x u64)",
"io_writer.write_u64le?(x u64)()", "io_writer.write_u64le?(x u64)",
// TODO: these should have an explicit pre-condition "available() >= N". // TODO: these should have an explicit pre-condition "available() >= N".
// For now, that's implicitly checked (i.e. hard coded). // For now, that's implicitly checked (i.e. hard coded).
// //
// The io_writer has write_fast_etc methods, not poke_etc and skip_fast, // The io_writer has write_fast_etc methods, not poke_etc and skip_fast,
// because skip_fast could leave uninitialized bytes in the io_buffer. // because skip_fast could leave uninitialized bytes in the io_buffer.
"io_writer.write_fast_u8!(x u8)()", "io_writer.write_fast_u8!(x u8)",
"io_writer.write_fast_u16be!(x u16)()", "io_writer.write_fast_u16be!(x u16)",
"io_writer.write_fast_u16le!(x u16)()", "io_writer.write_fast_u16le!(x u16)",
"io_writer.write_fast_u24be!(x u32[..0xFFFFFF])()", "io_writer.write_fast_u24be!(x u32[..0xFFFFFF])",
"io_writer.write_fast_u24le!(x u32[..0xFFFFFF])()", "io_writer.write_fast_u24le!(x u32[..0xFFFFFF])",
"io_writer.write_fast_u32be!(x u32)()", "io_writer.write_fast_u32be!(x u32)",
"io_writer.write_fast_u32le!(x u32)()", "io_writer.write_fast_u32le!(x u32)",
"io_writer.write_fast_u40be!(x u64[..0xFFFFFFFFFF])()", "io_writer.write_fast_u40be!(x u64[..0xFFFFFFFFFF])",
"io_writer.write_fast_u40le!(x u64[..0xFFFFFFFFFF])()", "io_writer.write_fast_u40le!(x u64[..0xFFFFFFFFFF])",
"io_writer.write_fast_u48be!(x u64[..0xFFFFFFFFFFFF])()", "io_writer.write_fast_u48be!(x u64[..0xFFFFFFFFFFFF])",
"io_writer.write_fast_u48le!(x u64[..0xFFFFFFFFFFFF])()", "io_writer.write_fast_u48le!(x u64[..0xFFFFFFFFFFFF])",
"io_writer.write_fast_u56be!(x u64[..0xFFFFFFFFFFFFFF])()", "io_writer.write_fast_u56be!(x u64[..0xFFFFFFFFFFFFFF])",
"io_writer.write_fast_u56le!(x u64[..0xFFFFFFFFFFFFFF])()", "io_writer.write_fast_u56le!(x u64[..0xFFFFFFFFFFFFFF])",
"io_writer.write_fast_u64be!(x u64)()", "io_writer.write_fast_u64be!(x u64)",
"io_writer.write_fast_u64le!(x u64)()", "io_writer.write_fast_u64le!(x u64)",
"io_writer.available()(ret u64)", "io_writer.available() u64",
"io_writer.set!(s slice u8)()", "io_writer.set!(s slice u8)",
"io_writer.set_limit!(l u64)()", "io_writer.set_limit!(l u64)",
"io_writer.set_mark!()()", "io_writer.set_mark!()",
"io_writer.since_mark()(ret slice u8)", "io_writer.since_mark() slice u8",
"io_writer.copy_from_slice!(s slice u8)(ret u64)", "io_writer.copy_from_slice!(s slice u8) u64",
"io_writer.copy_n_from_history!(n u32, distance u32)(ret u32)", "io_writer.copy_n_from_history!(n u32, distance u32) u32",
"io_writer.copy_n_from_reader!(n u32, r io_reader)(ret u32)", "io_writer.copy_n_from_reader!(n u32, r io_reader) u32",
"io_writer.copy_n_from_slice!(n u32, s slice u8)(ret u32)", "io_writer.copy_n_from_slice!(n u32, s slice u8) u32",
// TODO: this should have explicit pre-conditions: // TODO: this should have explicit pre-conditions:
// - n <= this.available() // - n <= this.available()
// - distance > 0 // - distance > 0
// - distance <= this.since_mark().length() // - distance <= this.since_mark().length()
// For now, that's all implicitly checked (i.e. hard coded). // For now, that's all implicitly checked (i.e. hard coded).
"io_writer.copy_n_from_history_fast!(n u32, distance u32)(ret u32)", "io_writer.copy_n_from_history_fast!(n u32, distance u32) u32",
// ---- status // ---- status
"status.is_error()(ret bool)", "status.is_error() bool",
"status.is_ok()(ret bool)", "status.is_ok() bool",
"status.is_suspension()(ret bool)", "status.is_suspension() bool",
// ---- frame_config // ---- frame_config
// Duration's upper bound is the maximum possible i64 value. // Duration's upper bound is the maximum possible i64 value.
"frame_config.update!(bounds rect_ie_u32, duration u64[..0x7FFFFFFFFFFFFFFF], " + "frame_config.update!(bounds rect_ie_u32, duration u64[..0x7FFFFFFFFFFFFFFF], " +
"blend bool, disposal u8, palette_changed bool)()", "blend bool, disposal u8, palette_changed bool)",
// ---- image_config // ---- image_config
"image_config.initialize!(pixfmt u32, pixsub u32, width u32, height u32, " + "image_config.initialize!(pixfmt u32, pixsub u32, width u32, height u32, " +
"num_loops u32, first_frame_is_opaque bool)()", "num_loops u32, first_frame_is_opaque bool)",
// ---- pixel_buffer // ---- pixel_buffer
"pixel_buffer.plane(p u32[..3])(ret table u8)", "pixel_buffer.plane(p u32[..3]) table u8",
"pixel_buffer.set_palette!(palette slice u8)()", "pixel_buffer.set_palette!(palette slice u8)",
} }
// The "T1" and "T2" types here are placeholders for generic "slice T" or // The "T1" and "T2" types here are placeholders for generic "slice T" or
@@ -279,16 +279,16 @@ const (
var SliceFuncs = []string{ var SliceFuncs = []string{
// TODO: should copy_from_slice be a ! method? // TODO: should copy_from_slice be a ! method?
"T1.copy_from_slice(s T1)(ret u64)", "T1.copy_from_slice(s T1) u64",
"T1.length()(ret u64)", "T1.length() u64",
"T1.prefix(up_to u64)(ret T1)", "T1.prefix(up_to u64) T1",
"T1.suffix(up_to u64)(ret T1)", "T1.suffix(up_to u64) T1",
} }
var TableFuncs = []string{ var TableFuncs = []string{
"T2.height()(ret u64)", "T2.height() u64",
"T2.stride()(ret u64)", "T2.stride() u64",
"T2.width()(ret u64)", "T2.width() u64",
"T2.row(y u32)(ret T1)", "T2.row(y u32) T1",
} }
+33 -19
View File
@@ -419,8 +419,7 @@ func (c *Checker) checkStructDecl(node *a.Node) error {
// A struct declaration implies a reset method. // A struct declaration implies a reset method.
in := a.NewStruct(0, n.Filename(), n.Line(), t.IDIn, nil) in := a.NewStruct(0, n.Filename(), n.Line(), t.IDIn, nil)
out := a.NewStruct(0, n.Filename(), n.Line(), t.IDOut, nil) f := a.NewFunc(0, n.Filename(), n.Line(), qid[1], t.IDReset, in, nil, nil, nil)
f := a.NewFunc(0, n.Filename(), n.Line(), qid[1], t.IDReset, in, out, nil, nil)
if qid[0] != 0 { if qid[0] != 0 {
f.AsNode().AsRaw().SetPackage(c.tm, qid[0]) f.AsNode().AsRaw().SetPackage(c.tm, qid[0])
} }
@@ -461,11 +460,8 @@ func (c *Checker) checkFields(fields []*a.Node, banPtrTypes bool, checkDefaultZe
if _, ok := fieldNames[f.Name()]; ok { if _, ok := fieldNames[f.Name()]; ok {
return fmt.Errorf("check: duplicate field %q", f.Name().Str(c.tm)) return fmt.Errorf("check: duplicate field %q", f.Name().Str(c.tm))
} }
if err := q.tcheckTypeExpr(f.XType(), 0); err != nil { if err := checkTypeExpr(q, f.XType()); err != nil {
return fmt.Errorf("%v in field %q", err, f.Name().Str(c.tm)) return fmt.Errorf("%v for field %q", err, f.Name().Str(c.tm))
}
if _, err := q.bcheckTypeExpr(f.XType()); err != nil {
return fmt.Errorf("%v in field %q", err, f.Name().Str(c.tm))
} }
if banPtrTypes && f.XType().HasPointers() { if banPtrTypes && f.XType().HasPointers() {
return fmt.Errorf("check: pointer-containing type %q not allowed for field %q", return fmt.Errorf("check: pointer-containing type %q not allowed for field %q",
@@ -487,6 +483,16 @@ func (c *Checker) checkFields(fields []*a.Node, banPtrTypes bool, checkDefaultZe
return nil return nil
} }
func checkTypeExpr(q *checker, n *a.TypeExpr) error {
if err := q.tcheckTypeExpr(n, 0); err != nil {
return err
}
if _, err := q.bcheckTypeExpr(n); err != nil {
return err
}
return nil
}
func (c *Checker) checkFuncSignature(node *a.Node) error { func (c *Checker) checkFuncSignature(node *a.Node) error {
n := node.AsFunc() n := node.AsFunc()
if err := c.checkFields(n.In().Fields(), false, false); err != nil { if err := c.checkFields(n.In().Fields(), false, false); err != nil {
@@ -497,17 +503,23 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
} }
} }
setPlaceholderMBoundsMType(n.In().AsNode()) setPlaceholderMBoundsMType(n.In().AsNode())
if err := c.checkFields(n.Out().Fields(), false, true); err != nil { if out := n.Out(); out != nil {
return &Error{ // TODO: does checking a TypeExpr need a q?
Err: fmt.Errorf("%v in out-params for func %s", err, n.QQID().Str(c.tm)), q := &checker{
Filename: n.Filename(), c: c,
Line: n.Line(), tm: c.tm,
}
if err := checkTypeExpr(q, out); err != nil {
return &Error{
Err: fmt.Errorf("%v in out-param for func %s", err, n.QQID().Str(c.tm)),
Filename: n.Filename(),
Line: n.Line(),
}
} }
} }
setPlaceholderMBoundsMType(n.Out().AsNode())
setPlaceholderMBoundsMType(n.AsNode()) setPlaceholderMBoundsMType(n.AsNode())
// TODO: check somewhere that, if n.Out() is non-empty (or we are // TODO: check somewhere that, if n.Out() is non-nil (or we are
// suspendible), that we end with a return statement? Or is that an // suspendible), that we end with a return statement? Or is that an
// implicit "return out"? // implicit "return out"?
@@ -535,13 +547,15 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
inTyp.AsNode().SetMBounds(a.Bounds{zero, zero}) inTyp.AsNode().SetMBounds(a.Bounds{zero, zero})
inTyp.AsNode().SetMType(typeExprTypeExpr) inTyp.AsNode().SetMType(typeExprTypeExpr)
oQID := n.Out().QID() outTyp := n.Out()
outTyp := a.NewTypeExpr(0, oQID[0], oQID[1], nil, nil, nil) if outTyp == nil {
outTyp.AsNode().SetMBounds(a.Bounds{zero, zero}) outTyp = typeExprEmptyStruct
outTyp.AsNode().SetMType(typeExprTypeExpr) }
localVars := typeMap{ localVars := typeMap{
t.IDIn: inTyp, t.IDIn: inTyp,
// TODO: drop the implicit "out" variable (and exprOut in this
// package)?
t.IDOut: outTyp, t.IDOut: outTyp,
} }
if qqid[1] != 0 { if qqid[1] != 0 {
+2 -2
View File
@@ -125,7 +125,7 @@ func (c *Checker) parseBuiltInFuncs(ss []string, generic bool) (map[t.QQID]*a.Fu
const filename = "builtin.wuffs" const filename = "builtin.wuffs"
tokens, _, err := t.Tokenize(c.tm, filename, buf) tokens, _, err := t.Tokenize(c.tm, filename, buf)
if err != nil { if err != nil {
return nil, fmt.Errorf("check: could not tokenize built-in funcs: %v", err) return nil, fmt.Errorf("check: parsing %q: could not tokenize built-in funcs: %v", s, err)
} }
if generic { if generic {
for i := range tokens { for i := range tokens {
@@ -138,7 +138,7 @@ func (c *Checker) parseBuiltInFuncs(ss []string, generic bool) (map[t.QQID]*a.Fu
} }
file, err := parse.Parse(c.tm, filename, tokens, &opts) file, err := parse.Parse(c.tm, filename, tokens, &opts)
if err != nil { if err != nil {
return nil, fmt.Errorf("check: could not parse built-in funcs: %v", err) return nil, fmt.Errorf("check: parsing %q: could not parse built-in funcs: %v", s, err)
} }
tlds := file.TopLevelDecls() tlds := file.TopLevelDecls()
+10 -23
View File
@@ -581,23 +581,15 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
if n.Operator() == t.IDTry { if n.Operator() == t.IDTry {
n.SetMType(typeExprStatus) n.SetMType(typeExprStatus)
} else { } else {
outFields := f.Out().Fields() oTyp := f.Out()
switch len(outFields) { if oTyp == nil {
default:
// TODO: figure out how to translate f.Out(), which is an
// *ast.Struct, to an *ast.TypeExpr we can pass to n.SetMType.
return fmt.Errorf("TODO: translate an *ast.Struct to an *ast.TypeExpr")
case 0:
n.SetMType(typeExprEmptyStruct) n.SetMType(typeExprEmptyStruct)
case 1: } else if genericType1 != nil && oTyp.Eq(typeExprGeneric1) {
oTyp := outFields[0].AsField().XType() n.SetMType(genericType1)
if genericType1 != nil && oTyp.Eq(typeExprGeneric1) { } else if genericType2 != nil && oTyp.Eq(typeExprGeneric2) {
n.SetMType(genericType1) n.SetMType(genericType2)
} else if genericType2 != nil && oTyp.Eq(typeExprGeneric2) { } else {
n.SetMType(genericType2) n.SetMType(oTyp)
} else {
n.SetMType(oTyp)
}
} }
} }
return nil return nil
@@ -640,13 +632,8 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
} }
s := (*a.Struct)(nil) s := (*a.Struct)(nil)
if q.astFunc != nil && lQID[0] == 0 { if q.astFunc != nil && lQID[0] == 0 && lQID[1] == t.IDIn {
switch lQID[1] { s = q.astFunc.In()
case t.IDIn:
s = q.astFunc.In()
case t.IDOut:
s = q.astFunc.Out()
}
} }
if s == nil { if s == nil {
s = q.c.structs[lQID] s = q.c.structs[lQID]
+7 -5
View File
@@ -198,9 +198,12 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
outFields, err := p.parseList(t.IDCloseParen, (*parser).parseFieldNode) outTyp := (*a.TypeExpr)(nil)
if err != nil { if p.peek1() != t.IDOpenCurly {
return nil, err outTyp, err = p.parseTypeExpr()
if err != nil {
return nil, err
}
} }
asserts := []*a.Node(nil) asserts := []*a.Node(nil)
if p.peek1() == t.IDComma { if p.peek1() == t.IDComma {
@@ -223,8 +226,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
} }
p.src = p.src[1:] p.src = p.src[1:]
in := a.NewStruct(0, p.filename, line, t.IDIn, inFields) in := a.NewStruct(0, p.filename, line, t.IDIn, inFields)
out := a.NewStruct(0, p.filename, line, t.IDOut, outFields) return a.NewFunc(flags, p.filename, line, id0, id1, in, outTyp, asserts, body).AsNode(), nil
return a.NewFunc(flags, p.filename, line, id0, id1, in, out, asserts, body).AsNode(), nil
case t.IDError, t.IDSuspension: case t.IDError, t.IDSuspension:
keyword := p.src[0].ID keyword := p.src[0].ID
+1 -1
View File
@@ -20,7 +20,7 @@ pub struct hasher?(
started base.bool, started base.bool,
) )
pub func hasher.update!(x slice base.u8)(checksum base.u32) { pub func hasher.update!(x slice base.u8) base.u32 {
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in // The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
// RFC 1950. // RFC 1950.
+1 -1
View File
@@ -22,7 +22,7 @@ pub struct ieee_hasher?(
// TODO: should it be ? instead of ! because it's public, and might need a way // TODO: should it be ? instead of ! because it's public, and might need a way
// to signal "initializer not called"? Should the return type, in the generated // to signal "initializer not called"? Should the return type, in the generated
// C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"? // C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"?
pub func ieee_hasher.update!(x slice base.u8)(checksum base.u32) { pub func ieee_hasher.update!(x slice base.u8) base.u32 {
var s base.u32 = 0xFFFFFFFF ^ this.state var s base.u32 = 0xFFFFFFFF ^ this.state
iterate (p slice base.u8 =: in.x)(length:8, unroll:8) { iterate (p slice base.u8 =: in.x)(length:8, unroll:8) {
+6 -6
View File
@@ -122,7 +122,7 @@ pub struct decoder?(
end_of_block base.bool, end_of_block base.bool,
) )
pub func decoder.decode?(dst base.io_writer, src base.io_reader)() { pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
while true { while true {
in.dst.set_mark!() in.dst.set_mark!()
var z base.status = try this.decode_blocks?(dst:in.dst, src:in.src) var z base.status = try this.decode_blocks?(dst:in.dst, src:in.src)
@@ -174,7 +174,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader)() {
} }
} }
pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader)() { pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader) {
var final base.u32 var final base.u32
while final == 0 { while final == 0 {
while this.n_bits < 3, while this.n_bits < 3,
@@ -214,7 +214,7 @@ pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader)() {
// decode_uncompressed decodes an uncompresed block as per the RFC section // decode_uncompressed decodes an uncompresed block as per the RFC section
// 3.2.4. // 3.2.4.
pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader)() { pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader) {
// TODO: make this "if" into a function invariant? // TODO: make this "if" into a function invariant?
// //
// Ditto for decode_huffman_slow and decode_huffman_fast. // Ditto for decode_huffman_slow and decode_huffman_fast.
@@ -245,7 +245,7 @@ pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader)()
} }
// init_fixed_huffman initializes this.huffs as per the RFC section 3.2.6. // init_fixed_huffman initializes this.huffs as per the RFC section 3.2.6.
pri func decoder.init_fixed_huffman?()() { pri func decoder.init_fixed_huffman?() {
var i base.u32 var i base.u32
while i < 144 { while i < 144 {
this.code_lengths[i] = 8 this.code_lengths[i] = 8
@@ -272,7 +272,7 @@ pri func decoder.init_fixed_huffman?()() {
} }
// init_dynamic_huffman initializes this.huffs as per the RFC section 3.2.7. // init_dynamic_huffman initializes this.huffs as per the RFC section 3.2.7.
pri func decoder.init_dynamic_huffman?(src base.io_reader)() { pri func decoder.init_dynamic_huffman?(src base.io_reader) {
var bits base.u32 = this.bits var bits base.u32 = this.bits
var n_bits base.u32 = this.n_bits var n_bits base.u32 = this.n_bits
while n_bits < 14, while n_bits < 14,
@@ -422,7 +422,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader)() {
// TODO: skip generating WUFFS_COROUTINE_SUSPENSION_POINTs for *callers* of // TODO: skip generating WUFFS_COROUTINE_SUSPENSION_POINTs for *callers* of
// this function, as it can only return errors, not suspensions. // this function, as it can only return errors, not suspensions.
pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_codes1 base.u32[..320], base_symbol base.u32)() { pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_codes1 base.u32[..320], base_symbol base.u32) {
// For the clcode example in this package's README.md: // For the clcode example in this package's README.md:
// - n_codes0 = 0 // - n_codes0 = 0
// - n_codes1 = 19 // - n_codes1 = 19
+1 -1
View File
@@ -14,7 +14,7 @@
// TODO: describe how the xxx_fast version differs from the xxx_slow one, the // TODO: describe how the xxx_fast version differs from the xxx_slow one, the
// assumptions that xxx_fast makes, and how that makes it fast. // assumptions that xxx_fast makes, and how that makes it fast.
pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader)() { pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
// When editing this function, consider making the equivalent change to the // When editing this function, consider making the equivalent change to the
// decode_huffman_slow function. Keep the diff between the two // decode_huffman_slow function. Keep the diff between the two
// decode_huffman_*.wuffs files as small as possible, while retaining both // decode_huffman_*.wuffs files as small as possible, while retaining both
+1 -1
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader)() { pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
// When editing this function, consider making the equivalent change to the // When editing this function, consider making the equivalent change to the
// decode_huffman_fast function. Keep the diff between the two // decode_huffman_fast function. Keep the diff between the two
// decode_huffman_*.wuffs files as small as possible, while retaining both // decode_huffman_*.wuffs files as small as possible, while retaining both
+17 -17
View File
@@ -122,7 +122,7 @@ pub struct decoder?(
lzw lzw.decoder, lzw lzw.decoder,
) )
pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_reader)() { pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_reader) {
if this.call_sequence >= 1 { if this.call_sequence >= 1 {
return error "invalid call sequence" return error "invalid call sequence"
} }
@@ -156,19 +156,19 @@ pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_re
this.call_sequence = 1 this.call_sequence = 1
} }
pub func decoder.num_decoded_frame_configs()(ret base.u64) { pub func decoder.num_decoded_frame_configs() base.u64 {
return this.num_decoded_frame_configs_value return this.num_decoded_frame_configs_value
} }
pub func decoder.num_decoded_frames()(ret base.u64) { pub func decoder.num_decoded_frames() base.u64 {
return this.num_decoded_frames_value return this.num_decoded_frames_value
} }
pub func decoder.work_buffer_size()(ret base.range_ii_u64) { pub func decoder.work_buffer_size() base.range_ii_u64 {
return this.util.make_range_ii_u64(min_incl:0, max_incl:0) return this.util.make_range_ii_u64(min_incl:0, max_incl:0)
} }
pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_reader)() { pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_reader) {
if not this.end_of_data { if not this.end_of_data {
if this.call_sequence == 0 { if this.call_sequence == 0 {
this.decode_image_config?(dst:nullptr, src:in.src) this.decode_image_config?(dst:nullptr, src:in.src)
@@ -215,7 +215,7 @@ pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_re
this.call_sequence = 2 this.call_sequence = 2
} }
pri func decoder.skip_frame?(src base.io_reader)() { pri func decoder.skip_frame?(src base.io_reader) {
var lw base.u8 = in.src.read_u8?() var lw base.u8 = in.src.read_u8?()
this.skip_blocks?(src:in.src) this.skip_blocks?(src:in.src)
@@ -232,7 +232,7 @@ pri func decoder.skip_frame?(src base.io_reader)() {
} }
// TODO: honor pixbuf_origin_x and pixbuf_origin_y args. // TODO: honor pixbuf_origin_x and pixbuf_origin_y args.
pub func decoder.decode_frame?(dst ptr base.pixel_buffer, pixbuf_origin_x base.u32, pixbuf_origin_y base.u32, src base.io_reader, work_buffer slice base.u8)() { pub func decoder.decode_frame?(dst ptr base.pixel_buffer, pixbuf_origin_x base.u32, pixbuf_origin_y base.u32, src base.io_reader, work_buffer slice base.u8) {
if this.call_sequence != 2 { if this.call_sequence != 2 {
this.decode_frame_config?(dst:nullptr, src:in.src) this.decode_frame_config?(dst:nullptr, src:in.src)
} }
@@ -251,7 +251,7 @@ pub func decoder.decode_frame?(dst ptr base.pixel_buffer, pixbuf_origin_x base.u
this.call_sequence = 3 this.call_sequence = 3
} }
pri func decoder.decode_up_to_id_part1?(src base.io_reader)() { pri func decoder.decode_up_to_id_part1?(src base.io_reader) {
while true { while true {
var block_type base.u8 = in.src.read_u8?() var block_type base.u8 = in.src.read_u8?()
if block_type == 0x21 { // The spec calls 0x21 the "Extension Introducer". if block_type == 0x21 { // The spec calls 0x21 the "Extension Introducer".
@@ -271,7 +271,7 @@ pri func decoder.decode_up_to_id_part1?(src base.io_reader)() {
// decode_header reads either "GIF87a" or "GIF89a". // decode_header reads either "GIF87a" or "GIF89a".
// //
// See the spec section 17 "Header" on page 7. // See the spec section 17 "Header" on page 7.
pri func decoder.decode_header?(src base.io_reader)() { pri func decoder.decode_header?(src base.io_reader) {
var c array[6] base.u8 var c array[6] base.u8
var i base.u32 var i base.u32
while i < 6 { while i < 6 {
@@ -287,7 +287,7 @@ pri func decoder.decode_header?(src base.io_reader)() {
// decode_lsd reads the Logical Screen Descriptor. // decode_lsd reads the Logical Screen Descriptor.
// //
// See the spec section 18 "Logical Screen Descriptor" on page 8. // See the spec section 18 "Logical Screen Descriptor" on page 8.
pri func decoder.decode_lsd?(src base.io_reader)() { pri func decoder.decode_lsd?(src base.io_reader) {
this.width = in.src.read_u16le?() as base.u32 this.width = in.src.read_u16le?() as base.u32
this.height = in.src.read_u16le?() as base.u32 this.height = in.src.read_u16le?() as base.u32
var flags base.u8 = in.src.read_u8?() var flags base.u8 = in.src.read_u8?()
@@ -329,7 +329,7 @@ pri func decoder.decode_lsd?(src base.io_reader)() {
// - section 24 "Comment Extension" on page 17. // - section 24 "Comment Extension" on page 17.
// - section 25 "Plain Text Extension" on page 18. // - section 25 "Plain Text Extension" on page 18.
// - section 26 "Application Extension" on page 21. // - section 26 "Application Extension" on page 21.
pri func decoder.decode_extension?(src base.io_reader)() { pri func decoder.decode_extension?(src base.io_reader) {
var label base.u8 = in.src.read_u8?() var label base.u8 = in.src.read_u8?()
if label == 0xF9 { // The spec calls 0xF9 the "Graphic Control Label". if label == 0xF9 { // The spec calls 0xF9 the "Graphic Control Label".
this.decode_gc?(src:in.src) this.decode_gc?(src:in.src)
@@ -343,7 +343,7 @@ pri func decoder.decode_extension?(src base.io_reader)() {
this.skip_blocks?(src:in.src) this.skip_blocks?(src:in.src)
} }
pri func decoder.skip_blocks?(src base.io_reader)() { pri func decoder.skip_blocks?(src base.io_reader) {
while true { while true {
var block_size base.u8 = in.src.read_u8?() var block_size base.u8 = in.src.read_u8?()
if block_size == 0 { if block_size == 0 {
@@ -364,7 +364,7 @@ pri const netscape2dot0 array[11] base.u8 = $(
) )
// decode_ae reads an Application Extension. // decode_ae reads an Application Extension.
pri func decoder.decode_ae?(src base.io_reader)() { pri func decoder.decode_ae?(src base.io_reader) {
// This "while true" always executes exactly once, as it ends with a // This "while true" always executes exactly once, as it ends with a
// "break", but using "break"s throughout simplifies the control flow. // "break", but using "break"s throughout simplifies the control flow.
while true { while true {
@@ -430,7 +430,7 @@ pri func decoder.decode_ae?(src base.io_reader)() {
} }
// decode_gc reads a Graphic Control. // decode_gc reads a Graphic Control.
pri func decoder.decode_gc?(src base.io_reader)() { pri func decoder.decode_gc?(src base.io_reader) {
if this.seen_graphic_control { if this.seen_graphic_control {
return error "bad graphic control" return error "bad graphic control"
} }
@@ -479,7 +479,7 @@ pri func decoder.decode_gc?(src base.io_reader)() {
// The code is split into two parts (part0 and part1) because determining the // The code is split into two parts (part0 and part1) because determining the
// overall image's width and height also requires decoding the first frame's // overall image's width and height also requires decoding the first frame's
// bounds (but doesn't require decoding the first frame's pixels). // bounds (but doesn't require decoding the first frame's pixels).
pri func decoder.decode_id_part0?(src base.io_reader)() { pri func decoder.decode_id_part0?(src base.io_reader) {
this.frame_rect_x0 = in.src.read_u16le?() as base.u32 this.frame_rect_x0 = in.src.read_u16le?() as base.u32
this.frame_rect_y0 = in.src.read_u16le?() as base.u32 this.frame_rect_y0 = in.src.read_u16le?() as base.u32
this.frame_rect_x1 = this.frame_rect_x0 ~mod+ (in.src.read_u16le?() as base.u32) this.frame_rect_x1 = this.frame_rect_x0 ~mod+ (in.src.read_u16le?() as base.u32)
@@ -534,7 +534,7 @@ pri func decoder.decode_id_part0?(src base.io_reader)() {
} }
} }
pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)() { pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader) {
if this.gc_has_transparent_index { if this.gc_has_transparent_index {
if not this.use_local_palette { if not this.use_local_palette {
this.palettes[1][:].copy_from_slice(s:this.palettes[0][:]) this.palettes[1][:].copy_from_slice(s:this.palettes[0][:])
@@ -622,7 +622,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
// TODO: check for "not enough pixel data". // TODO: check for "not enough pixel data".
} }
pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer)() { pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer) {
// TODO: don't assume a packed pixel format. // TODO: don't assume a packed pixel format.
var dst slice base.u8 var dst slice base.u8
var src slice base.u8 var src slice base.u8
+2 -2
View File
@@ -28,11 +28,11 @@ pub struct decoder?(
ignore_checksum base.bool, ignore_checksum base.bool,
) )
pub func decoder.set_ignore_checksum!(ic base.bool)() { pub func decoder.set_ignore_checksum!(ic base.bool) {
this.ignore_checksum = in.ic this.ignore_checksum = in.ic
} }
pub func decoder.decode?(dst base.io_writer, src base.io_reader)() { pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
// Read the header. // Read the header.
var c base.u8 = in.src.read_u8?() var c base.u8 = in.src.read_u8?()
if c != 0x1F { if c != 0x1F {
+2 -2
View File
@@ -24,11 +24,11 @@ pub struct decoder?(
prefixes array[4096] base.u16[..4095], prefixes array[4096] base.u16[..4095],
) )
pub func decoder.set_literal_width!(lw base.u32[2..8])() { pub func decoder.set_literal_width!(lw base.u32[2..8]) {
this.literal_width = in.lw this.literal_width = in.lw
} }
pub func decoder.decode?(dst base.io_writer, src base.io_reader)() { pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
// These variables don't change over the lifetime of this func. // These variables don't change over the lifetime of this func.
var literal_width base.u32[2..8] = 8 var literal_width base.u32[2..8] = 8
if this.literal_width >= 2 { if this.literal_width >= 2 {
+2 -2
View File
@@ -30,11 +30,11 @@ pub struct decoder?(
ignore_checksum base.bool, ignore_checksum base.bool,
) )
pub func decoder.set_ignore_checksum!(ic base.bool)() { pub func decoder.set_ignore_checksum!(ic base.bool) {
this.ignore_checksum = in.ic this.ignore_checksum = in.ic
} }
pub func decoder.decode?(dst base.io_writer, src base.io_reader)() { pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
var x base.u16 = in.src.read_u16be?() var x base.u16 = in.src.read_u16be?()
if ((x >> 8) & 0x0F) != 0x08 { if ((x >> 8) & 0x0F) != 0x08 {
return error "bad compression method" return error "bad compression method"