mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
Tweak io_bind syntax
This commit is contained in:
1 parent
e992921dce
commit
badbdfc487
7 files changed
+62
-88
No files matched your search
@@ -173,9 +173,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxIOBinds = 100
|
maxIOBinds = 100
|
||||||
maxIOBindInFields = 100
|
maxTemp = 10000
|
||||||
maxTemp = 10000
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type status struct {
|
type status struct {
|
||||||
|
|||||||
@@ -225,12 +225,7 @@ func (g *gen) writeStatementAssign(b *buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
|
func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
|
||||||
inFields := n.InFields()
|
if g.currFunk.ioBinds > maxIOBinds {
|
||||||
if n.Keyword() == t.IDIOLimit {
|
|
||||||
inFields = []*a.Node{n.IO().AsNode()}
|
|
||||||
}
|
|
||||||
|
|
||||||
if g.currFunk.ioBinds > maxIOBinds || len(inFields) > maxIOBindInFields {
|
|
||||||
return fmt.Errorf("too many temporary variables required")
|
return fmt.Errorf("too many temporary variables required")
|
||||||
}
|
}
|
||||||
ioBindNum := g.currFunk.ioBinds
|
ioBindNum := g.currFunk.ioBinds
|
||||||
@@ -240,8 +235,8 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
|
|||||||
// instead of block-scoped (smaller scope) if the coro_susp_point
|
// instead of block-scoped (smaller scope) if the coro_susp_point
|
||||||
// switch can jump past this initialization??
|
// switch can jump past this initialization??
|
||||||
b.writes("{\n")
|
b.writes("{\n")
|
||||||
for i := 0; i < len(inFields); i++ {
|
{
|
||||||
e := inFields[i].AsExpr()
|
e := n.IO()
|
||||||
prefix := vPrefix
|
prefix := vPrefix
|
||||||
if e.Operator() != 0 {
|
if e.Operator() != 0 {
|
||||||
prefix = aPrefix
|
prefix = aPrefix
|
||||||
@@ -278,8 +273,8 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := len(inFields) - 1; i >= 0; i-- {
|
{
|
||||||
e := inFields[i].AsExpr()
|
e := n.IO()
|
||||||
prefix := vPrefix
|
prefix := vPrefix
|
||||||
if e.Operator() != 0 {
|
if e.Operator() != 0 {
|
||||||
prefix = aPrefix
|
prefix = aPrefix
|
||||||
|
|||||||
+9
-13
@@ -482,30 +482,26 @@ func NewField(name t.ID, xType *TypeExpr) *Field {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IOBind is "io_bind (in_fields) { List2 }" or "io_limit (io:LHS, limit:MHS)":
|
// IOBind is "io_bind (io:LHS) { List2 }" or "io_limit (io:LHS, limit:MHS) {
|
||||||
|
// List2 }":
|
||||||
// - ID0: <IDIOBind|IDIOLimit>
|
// - ID0: <IDIOBind|IDIOLimit>
|
||||||
// - LHS: <nil|Expr>
|
// - LHS: <Expr>
|
||||||
// - MHS: <nil|Expr>
|
// - MHS: <nil|Expr>
|
||||||
// - List0: <Expr> in.something fields
|
|
||||||
// - List2: <Statement> body
|
// - List2: <Statement> body
|
||||||
//
|
|
||||||
// TODO: in_fields and "in.something" isn't right.
|
|
||||||
type IOBind Node
|
type IOBind Node
|
||||||
|
|
||||||
func (n *IOBind) AsNode() *Node { return (*Node)(n) }
|
func (n *IOBind) AsNode() *Node { return (*Node)(n) }
|
||||||
func (n *IOBind) Keyword() t.ID { return n.id0 }
|
func (n *IOBind) Keyword() t.ID { return n.id0 }
|
||||||
func (n *IOBind) IO() *Expr { return n.lhs.AsExpr() }
|
func (n *IOBind) IO() *Expr { return n.lhs.AsExpr() }
|
||||||
func (n *IOBind) Limit() *Expr { return n.mhs.AsExpr() }
|
func (n *IOBind) Limit() *Expr { return n.mhs.AsExpr() }
|
||||||
func (n *IOBind) InFields() []*Node { return n.list0 }
|
func (n *IOBind) Body() []*Node { return n.list2 }
|
||||||
func (n *IOBind) Body() []*Node { return n.list2 }
|
|
||||||
|
|
||||||
func NewIOBind(keyword t.ID, io *Expr, limit *Expr, in_fields []*Node, body []*Node) *IOBind {
|
func NewIOBind(keyword t.ID, io *Expr, limit *Expr, body []*Node) *IOBind {
|
||||||
return &IOBind{
|
return &IOBind{
|
||||||
kind: KIOBind,
|
kind: KIOBind,
|
||||||
id0: keyword,
|
id0: keyword,
|
||||||
lhs: io.AsNode(),
|
lhs: io.AsNode(),
|
||||||
mhs: limit.AsNode(),
|
mhs: limit.AsNode(),
|
||||||
list0: in_fields,
|
|
||||||
list2: body,
|
list2: body,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,16 +234,12 @@ func (q *checker) bcheckStatement(n *a.Node) error {
|
|||||||
|
|
||||||
case a.KIOBind:
|
case a.KIOBind:
|
||||||
n := n.AsIOBind()
|
n := n.AsIOBind()
|
||||||
|
if _, err := q.bcheckExpr(n.IO(), 0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if n.Keyword() == t.IDIOBind {
|
if n.Keyword() == t.IDIOBind {
|
||||||
for _, o := range n.InFields() {
|
// No-op.
|
||||||
if _, err := q.bcheckExpr(o.AsExpr(), 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if _, err := q.bcheckExpr(n.IO(), 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := q.bcheckExpr(n.Limit(), 0); err != nil {
|
if _, err := q.bcheckExpr(n.Limit(), 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-18
@@ -120,25 +120,17 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
|||||||
|
|
||||||
case a.KIOBind:
|
case a.KIOBind:
|
||||||
n := n.AsIOBind()
|
n := n.AsIOBind()
|
||||||
if n.Keyword() == t.IDIOBind {
|
if err := q.tcheckExpr(n.IO(), 0); err != nil {
|
||||||
for _, o := range n.InFields() {
|
return err
|
||||||
if err := q.tcheckExpr(o.AsExpr(), 0); err != nil {
|
}
|
||||||
return err
|
if typ := n.IO().MType(); !typ.IsIOType() {
|
||||||
}
|
return fmt.Errorf("check: %s expression %q, of type %q, does not have an I/O type",
|
||||||
if typ := o.AsExpr().MType(); !typ.IsIOType() {
|
n.Keyword().Str(q.tm), n.IO().Str(q.tm), typ.Str(q.tm))
|
||||||
return fmt.Errorf("check: io_bind expression %q, of type %q, does not have an I/O type",
|
}
|
||||||
o.AsExpr().Str(q.tm), typ.Str(q.tm))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err := q.tcheckExpr(n.IO(), 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if typ := n.IO().MType(); !typ.IsIOType() {
|
|
||||||
return fmt.Errorf("check: %s expression %q, of type %q, does not have an I/O type",
|
|
||||||
n.Keyword().Str(q.tm), n.IO().Str(q.tm), typ.Str(q.tm))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if n.Keyword() == t.IDIOBind {
|
||||||
|
// No-op.
|
||||||
|
} else {
|
||||||
if err := q.tcheckExpr(n.Limit(), 0); err != nil {
|
if err := q.tcheckExpr(n.Limit(), 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-35
@@ -669,18 +669,7 @@ func (p *parser) parseAsserts() ([]*a.Node, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) parseIOBindNode() (*a.Node, error) {
|
func (p *parser) parseIOBindNode() (*a.Node, error) {
|
||||||
if p.peek1() == t.IDIOBind {
|
keyword := p.peek1()
|
||||||
p.src = p.src[1:]
|
|
||||||
in_fields, err := p.parseList(t.IDCloseParen, (*parser).parseIOBindExprNode)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body, err := p.parseBlock()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return a.NewIOBind(t.IDIOBind, nil, nil, in_fields, body).AsNode(), nil
|
|
||||||
}
|
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
|
|
||||||
if x := p.peek1(); x != t.IDOpenParen {
|
if x := p.peek1(); x != t.IDOpenParen {
|
||||||
@@ -710,31 +699,38 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
|
|||||||
io.Str(p.tm), p.filename, p.line())
|
io.Str(p.tm), p.filename, p.line())
|
||||||
}
|
}
|
||||||
|
|
||||||
if x := p.peek1(); x != t.IDComma {
|
limit := (*a.Expr)(nil)
|
||||||
got := p.tm.ByID(x)
|
if keyword == t.IDIOBind {
|
||||||
return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line())
|
// No-op.
|
||||||
}
|
|
||||||
p.src = p.src[1:]
|
|
||||||
|
|
||||||
if x := p.peek1(); x != t.IDLimit {
|
} else {
|
||||||
got := p.tm.ByID(x)
|
if x := p.peek1(); x != t.IDComma {
|
||||||
return nil, fmt.Errorf(`parse: expected "limit", got %q at %s:%d`, got, p.filename, p.line())
|
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:]
|
}
|
||||||
|
p.src = p.src[1:]
|
||||||
|
|
||||||
if x := p.peek1(); x != t.IDColon {
|
if x := p.peek1(); x != t.IDLimit {
|
||||||
got := p.tm.ByID(x)
|
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 "limit", got %q at %s:%d`, got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
|
|
||||||
limit, err := p.parseExpr()
|
if x := p.peek1(); x != t.IDColon {
|
||||||
if err != nil {
|
got := p.tm.ByID(x)
|
||||||
return nil, err
|
return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
if limit.Effect() != 0 {
|
p.src = p.src[1:]
|
||||||
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
|
|
||||||
io.Str(p.tm), p.filename, p.line())
|
var err error
|
||||||
|
limit, err = p.parseExpr()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if limit.Effect() != 0 {
|
||||||
|
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
|
||||||
|
io.Str(p.tm), p.filename, p.line())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if x := p.peek1(); x != t.IDCloseParen {
|
if x := p.peek1(); x != t.IDCloseParen {
|
||||||
@@ -748,7 +744,7 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.NewIOBind(t.IDIOLimit, io, limit, nil, body).AsNode(), nil
|
return a.NewIOBind(keyword, io, limit, body).AsNode(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) parseIf() (*a.If, error) {
|
func (p *parser) parseIf() (*a.If, error) {
|
||||||
|
|||||||
@@ -638,7 +638,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
|
|
||||||
while:inner true {
|
while:inner true {
|
||||||
var w base.io_writer
|
var w base.io_writer
|
||||||
io_bind (w) {
|
io_bind (io:w) {
|
||||||
w.set!(s:this.uncompressed[this.uncompressed_wi:])
|
w.set!(s:this.uncompressed[this.uncompressed_wi:])
|
||||||
io_limit (io:args.src, limit:block_size) {
|
io_limit (io:args.src, limit:block_size) {
|
||||||
args.src.set_mark!()
|
args.src.set_mark!()
|
||||||
|
|||||||
Reference in new issue
Block a user