mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Clarify iterate step and unroll syntax
This commit is contained in:
1 parent
a511e927a1
commit
c511c53b1f
5 files changed
+44
-15
No files matched your search
+3
-2
@@ -515,7 +515,8 @@ func NewIOBind(in_fields []*Node, body []*Node) *IOBind {
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate is "iterate[ID0, ID2]:ID1 (vars), List1 { List2 }":
|
||||
// Iterate is
|
||||
// "iterate:ID1 (step: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
|
||||
@@ -541,7 +542,7 @@ func (n *Iterate) Tail() []*Node { return n.list3 }
|
||||
func (n *Iterate) SetHasBreak() { n.flags |= FlagsHasBreak }
|
||||
func (n *Iterate) SetHasContinue() { n.flags |= FlagsHasContinue }
|
||||
|
||||
func NewIterate(unroll t.ID, step t.ID, label t.ID, variables []*Node, asserts []*Node, body []*Node, tail []*Node) *Iterate {
|
||||
func NewIterate(label t.ID, step t.ID, unroll t.ID, variables []*Node, asserts []*Node, body []*Node, tail []*Node) *Iterate {
|
||||
return &Iterate{
|
||||
kind: KIterate,
|
||||
id0: unroll,
|
||||
|
||||
+35
-11
@@ -735,22 +735,21 @@ func (p *parser) parseIterateNode() (*a.Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if x := p.peek1(); x != t.IDOpenBracket {
|
||||
if x := p.peek1(); x != t.IDOpenParen {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "[", got %q at %s:%d`, got, p.filename, p.line())
|
||||
return nil, fmt.Errorf(`parse: expected "(", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
unroll := p.peek1()
|
||||
if unroll.SmallPowerOf2Value() == 0 {
|
||||
return nil, fmt.Errorf(`parse: expected power-of-2 unroll count in [1..256], got %q at %s:%d`,
|
||||
p.tm.ByID(unroll), p.filename, p.line())
|
||||
if x := p.peek1(); x != t.IDStep {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "step", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDComma {
|
||||
if x := p.peek1(); x != t.IDColon {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line())
|
||||
return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
@@ -761,9 +760,34 @@ func (p *parser) parseIterateNode() (*a.Node, error) {
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDCloseBracket {
|
||||
if x := p.peek1(); x != t.IDComma {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "]", got %q at %s:%d`, got, p.filename, p.line())
|
||||
return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDUnroll {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "unroll", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDColon {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
unroll := p.peek1()
|
||||
if unroll.SmallPowerOf2Value() == 0 {
|
||||
return nil, fmt.Errorf(`parse: expected power-of-2 unroll count in [1..256], got %q at %s:%d`,
|
||||
p.tm.ByID(unroll), p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDCloseParen {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ")", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
@@ -798,7 +822,7 @@ func (p *parser) parseIterateNode() (*a.Node, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return a.NewIterate(unroll, step, label, vars, asserts, body, tail).Node(), nil
|
||||
return a.NewIterate(label, step, unroll, vars, asserts, body, tail).Node(), nil
|
||||
}
|
||||
|
||||
func (p *parser) parseArgNode() (*a.Node, error) {
|
||||
|
||||
@@ -441,6 +441,8 @@ const (
|
||||
IDLowBits = ID(0xCE)
|
||||
IDHighBits = ID(0xCF)
|
||||
IDUnreadU8 = ID(0xD0)
|
||||
IDStep = ID(0xD1)
|
||||
IDUnroll = ID(0xD2)
|
||||
|
||||
IDEmptyStruct = ID(0xF8)
|
||||
IDBool = ID(0xF9)
|
||||
@@ -623,6 +625,8 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDLowBits: "low_bits",
|
||||
IDHighBits: "high_bits",
|
||||
IDUnreadU8: "unread_u8",
|
||||
IDStep: "step",
|
||||
IDUnroll: "unroll",
|
||||
|
||||
IDEmptyStruct: "empty_struct",
|
||||
IDBool: "bool",
|
||||
|
||||
@@ -34,7 +34,7 @@ pub func hasher.update(x slice base.u8)(checksum base.u32) {
|
||||
in.x = in.x[:5552]
|
||||
}
|
||||
|
||||
iterate[8, 1](p ptr base.u8:in.x) {
|
||||
iterate (step:1, unroll:8)(p ptr base.u8:in.x) {
|
||||
s1 ~mod+= deref p as base.u32
|
||||
s2 ~mod+= s1
|
||||
}
|
||||
|
||||
@@ -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[1, 8](p ptr base.u8:in.x) {
|
||||
iterate (step:8, unroll:1)(p ptr base.u8:in.x) {
|
||||
// TODO.
|
||||
} else {
|
||||
s = ieee_table[0][((s & 0xFF) as base.u8) ^ deref p] ^ (s >> 8)
|
||||
|
||||
Reference in new issue
Block a user