diff --git a/cmd/wuffs-c/internal/cgen/statement.go b/cmd/wuffs-c/internal/cgen/statement.go index 039f781a..8825f843 100644 --- a/cmd/wuffs-c/internal/cgen/statement.go +++ b/cmd/wuffs-c/internal/cgen/statement.go @@ -264,19 +264,19 @@ func (g *gen) writeStatementIterate(b *buffer, n *a.Iterate, depth uint32) error // TODO: look at n.HasContinue() and n.HasBreak(). block := n.Body() - step := n.Step().SmallPowerOf2Value() + length := n.Length().SmallPowerOf2Value() unroll := n.Unroll().SmallPowerOf2Value() - if unroll > 1 || step > 1 { - if err := g.writeIterateRound(b, name, block, 0, depth, step, unroll); err != nil { + if unroll > 1 || length > 1 { + if err := g.writeIterateRound(b, name, block, 0, depth, length, unroll); err != nil { return err } } if unroll > 1 { - if err := g.writeIterateRound(b, name, block, 1, depth, step, 1); err != nil { + if err := g.writeIterateRound(b, name, block, 1, depth, length, 1); err != nil { return err } } - if step > 1 { + if length > 1 { block = n.Tail() if err := g.writeIterateRound(b, name, block, 2, depth, 1, 1); err != nil { return err @@ -416,10 +416,10 @@ func (g *gen) writeStatementWhile(b *buffer, n *a.While, depth uint32) error { return nil } -func (g *gen) writeIterateRound(b *buffer, name string, block []*a.Node, round uint32, depth uint32, step int, unroll int) error { - b.printf("%s%s.len = %d;\n", vPrefix, name, step) +func (g *gen) writeIterateRound(b *buffer, name string, block []*a.Node, round uint32, depth uint32, length int, unroll int) error { + b.printf("%s%s.len = %d;\n", vPrefix, name, length) b.printf("uint8_t* %send%d_%s = %sslice_%s.ptr + (%sslice_%s.len / %d) * %d;\n", - iPrefix, round, name, iPrefix, name, iPrefix, name, step*unroll, step*unroll) + iPrefix, round, name, iPrefix, name, iPrefix, name, length*unroll, length*unroll) b.printf("while (%s%s.ptr < %send%d_%s) {\n", vPrefix, name, iPrefix, round, name) for i := 0; i < unroll; i++ { for _, o := range block { @@ -427,7 +427,7 @@ func (g *gen) writeIterateRound(b *buffer, name string, block []*a.Node, round u return err } } - b.printf("%s%s.ptr += %d;\n", vPrefix, name, step) + b.printf("%s%s.ptr += %d;\n", vPrefix, name, length) } b.writes("}\n") return nil diff --git a/doc/changelog.md b/doc/changelog.md index 6c83512b..8b90c20a 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -15,7 +15,7 @@ - Renamed `~+` to `~mod+`; added `~mod-`, `~sat+` and `~sat-`. - Removed `&^`. - Renamed `[N] T` and `[] T` types to `array[N] T` and `slice T`. -- Renamed `iterate.U` to `iterate (step:S, unroll:U)`. +- Renamed `iterate.U` to `iterate (length:L, unroll:U)`. - Changed iterate variable types from ptr T to slice T. - Renamed `buf1`, `reader1`, etc to `io_buffer`, `io_reader`, etc. - Renamed `u32`, `io_reader`, etc to `base.u32`, `base.io_reader`, etc. diff --git a/lang/ast/ast.go b/lang/ast/ast.go index e7a1fef7..e9cb9445 100644 --- a/lang/ast/ast.go +++ b/lang/ast/ast.go @@ -166,7 +166,7 @@ type Node struct { // Func funcName receiverPkg receiverName Func // IOBind . . . IOBind // If . . . If - // Iterate unroll label step Iterate + // Iterate unroll label length Iterate // Jump keyword label . Jump // PackageID . . lit(pkgID) PackageID // Ret keyword . . Ret @@ -516,12 +516,12 @@ func NewIOBind(in_fields []*Node, body []*Node) *IOBind { } // Iterate is -// "iterate:ID1 (step:ID2, unroll:ID0)(vars), List1 { List2 } else { List3 }": +// "iterate:ID1 (length:ID2, unroll:ID0)(vars), List1 { List2 } else { List3 }": // - FlagsHasBreak is the iterate has an explicit break // - FlagsHasContinue is the iterate has an explicit continue // - ID0: unroll // - ID1: <0|label> -// - ID2: step +// - ID2: length // - List0: variables // - List1: asserts // - List2: body @@ -533,7 +533,7 @@ func (n *Iterate) HasBreak() bool { return n.flags&FlagsHasBreak != 0 } func (n *Iterate) HasContinue() bool { return n.flags&FlagsHasContinue != 0 } func (n *Iterate) Unroll() t.ID { return n.id0 } func (n *Iterate) Label() t.ID { return n.id1 } -func (n *Iterate) Step() t.ID { return n.id2 } +func (n *Iterate) Length() t.ID { return n.id2 } func (n *Iterate) Variables() []*Node { return n.list0 } func (n *Iterate) Asserts() []*Node { return n.list1 } func (n *Iterate) Body() []*Node { return n.list2 } @@ -542,12 +542,12 @@ func (n *Iterate) Tail() []*Node { return n.list3 } func (n *Iterate) SetHasBreak() { n.flags |= FlagsHasBreak } func (n *Iterate) SetHasContinue() { n.flags |= FlagsHasContinue } -func NewIterate(label t.ID, step t.ID, unroll t.ID, variables []*Node, asserts []*Node, body []*Node, tail []*Node) *Iterate { +func NewIterate(label t.ID, length t.ID, unroll t.ID, variables []*Node, asserts []*Node, body []*Node, tail []*Node) *Iterate { return &Iterate{ kind: KIterate, id0: unroll, id1: label, - id2: step, + id2: length, list0: variables, list1: asserts, list2: body, diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 78109c7b..e4243ee8 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -304,7 +304,7 @@ func (q *checker) bcheckStatement(n *a.Node) error { q.facts = q.facts[:0] for _, o := range n.Variables() { v := o.Var() - q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.XType(), n.Step())) + q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.XType(), n.Length())) } for _, o := range n.Body() { if err := q.bcheckStatement(o); err != nil { diff --git a/lang/parse/parse.go b/lang/parse/parse.go index 0e31c619..2741fbff 100644 --- a/lang/parse/parse.go +++ b/lang/parse/parse.go @@ -741,9 +741,9 @@ func (p *parser) parseIterateNode() (*a.Node, error) { } p.src = p.src[1:] - if x := p.peek1(); x != t.IDStep { + if x := p.peek1(); x != t.IDLength { got := p.tm.ByID(x) - return nil, fmt.Errorf(`parse: expected "step", got %q at %s:%d`, got, p.filename, p.line()) + return nil, fmt.Errorf(`parse: expected "length", got %q at %s:%d`, got, p.filename, p.line()) } p.src = p.src[1:] @@ -753,10 +753,10 @@ func (p *parser) parseIterateNode() (*a.Node, error) { } p.src = p.src[1:] - step := p.peek1() - if step.SmallPowerOf2Value() == 0 { - return nil, fmt.Errorf(`parse: expected power-of-2 step count in [1..256], got %q at %s:%d`, - p.tm.ByID(step), p.filename, p.line()) + length := p.peek1() + if length.SmallPowerOf2Value() == 0 { + return nil, fmt.Errorf(`parse: expected power-of-2 length count in [1..256], got %q at %s:%d`, + p.tm.ByID(length), p.filename, p.line()) } p.src = p.src[1:] @@ -805,7 +805,7 @@ func (p *parser) parseIterateNode() (*a.Node, error) { } tail := ([]*a.Node)(nil) - if step == t.ID1 { + if length == t.ID1 { if x := p.peek1(); x == t.IDElse { got := p.tm.ByID(x) return nil, fmt.Errorf(`parse: expected non-"else", got %q at %s:%d`, got, p.filename, p.line()) @@ -822,7 +822,7 @@ func (p *parser) parseIterateNode() (*a.Node, error) { } } - return a.NewIterate(label, step, unroll, vars, asserts, body, tail).Node(), nil + return a.NewIterate(label, length, unroll, vars, asserts, body, tail).Node(), nil } func (p *parser) parseArgNode() (*a.Node, error) { diff --git a/lang/token/list.go b/lang/token/list.go index b27d5220..c2ccb4e4 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -441,8 +441,7 @@ const ( IDLowBits = ID(0xCE) IDHighBits = ID(0xCF) IDUnreadU8 = ID(0xD0) - IDStep = ID(0xD1) - IDUnroll = ID(0xD2) + IDUnroll = ID(0xD1) IDEmptyStruct = ID(0xF8) IDBool = ID(0xF9) @@ -625,7 +624,6 @@ var builtInsByID = [nBuiltInIDs]string{ IDLowBits: "low_bits", IDHighBits: "high_bits", IDUnreadU8: "unread_u8", - IDStep: "step", IDUnroll: "unroll", IDEmptyStruct: "empty_struct", diff --git a/std/adler32/common_adler32.wuffs b/std/adler32/common_adler32.wuffs index f0961404..41417413 100644 --- a/std/adler32/common_adler32.wuffs +++ b/std/adler32/common_adler32.wuffs @@ -34,7 +34,7 @@ pub func hasher.update(x slice base.u8)(checksum base.u32) { in.x = in.x[:5552] } - iterate (step:1, unroll:8)(p slice base.u8:in.x) { + iterate (length:1, unroll:8)(p slice base.u8:in.x) { s1 ~mod+= p[0] as base.u32 s2 ~mod+= s1 } diff --git a/std/crc32/common_crc32.wuffs b/std/crc32/common_crc32.wuffs index 975c1d3b..18ed2bd6 100644 --- a/std/crc32/common_crc32.wuffs +++ b/std/crc32/common_crc32.wuffs @@ -27,7 +27,7 @@ pub struct ieee_hasher?( pub func ieee_hasher.update(x slice base.u8)(checksum base.u32) { var s base.u32 = 0xFFFFFFFF ^ this.state - iterate (step:8, unroll:8)(p slice base.u8:in.x) { + iterate (length:8, unroll:8)(p slice base.u8:in.x) { // TODO: explain the slicing-by-8 algorithm. s ^= ((p[0] as base.u32) << 0) | ((p[1] as base.u32) << 8) |