Add a data:etc argument to io_bind

This commit is contained in:
Nigel Tao committed 2018-12-09 09:53:46 +11:00
1 parent badbdfc487
commit 6d2bb77bb7
9 files changed
+77 -75

No files matched your search

+4 -8
View File
@@ -344,15 +344,11 @@ func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, sef subExprFil
}
func (h *resumabilityHelper) doIOBind(r resumabilities, n *a.IOBind, depth uint32) error {
if n.IO() != nil {
if err := h.doExpr(r, n.IO()); err != nil {
return err
}
if err := h.doExpr(r, n.IO()); err != nil {
return err
}
if n.Limit() != nil {
if err := h.doExpr(r, n.Limit()); err != nil {
return err
}
if err := h.doExpr(r, n.Arg1()); err != nil {
return err
}
return h.doBlock(r, n.Body(), depth)
}
+20 -7
View File
@@ -237,6 +237,8 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
b.writes("{\n")
{
e := n.IO()
// TODO: restrict (in the type checker or parser) that e is either a
// local variable or args.foo?
prefix := vPrefix
if e.Operator() != 0 {
prefix = aPrefix
@@ -249,13 +251,6 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
b.printf("wuffs_base__io_%s %s%d_%s%s = %s%s;\n",
cTyp, oPrefix, ioBindNum, prefix, name, prefix, name)
if n.Keyword() == t.IDIOLimit {
b.printf("wuffs_base__io_%s__set_limit(&%s%s, iop_%s%s,\n", cTyp, prefix, name, prefix, name)
if err := g.writeExpr(b, n.Limit(), 0); err != nil {
return err
}
b.printf(");\n")
}
// TODO: save / restore all iop vars, not just for local IO vars? How
// does this work if the io_bind body advances these pointers, either
// directly or by calling other funcs?
@@ -265,6 +260,24 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
b.printf("uint8_t *%s%d_%s%s%s = %s%s%s;\n",
oPrefix, ioBindNum, io1Prefix, prefix, name, io1Prefix, prefix, name)
}
if n.Keyword() == t.IDIOBind {
b.printf("wuffs_base__io_%s__set(&%s%s, &u_%s, &iop_%s%s, &io1_%s%s,",
cTyp, prefix, name, name, prefix, name, prefix, name)
if err := g.writeExpr(b, n.Arg1(), 0); err != nil {
return err
}
b.writes(");\n")
} else {
// TODO: restrict (in the type checker or parser) that e is
// args.foo?
b.printf("wuffs_base__io_%s__set_limit(&%s%s, iop_%s%s,\n", cTyp, prefix, name, prefix, name)
if err := g.writeExpr(b, n.Arg1(), 0); err != nil {
return err
}
b.writes(");\n")
}
}
for _, o := range n.Body() {
+6 -6
View File
@@ -482,26 +482,26 @@ func NewField(name t.ID, xType *TypeExpr) *Field {
}
}
// IOBind is "io_bind (io:LHS) { List2 }" or "io_limit (io:LHS, limit:MHS) {
// List2 }":
// IOBind is "io_bind (io:LHS, data:MHS) { List2 }" or "io_limit (io:LHS,
// limit:MHS) { List2 }":
// - ID0: <IDIOBind|IDIOLimit>
// - LHS: <Expr>
// - MHS: <nil|Expr>
// - MHS: <Expr>
// - List2: <Statement> body
type IOBind Node
func (n *IOBind) AsNode() *Node { return (*Node)(n) }
func (n *IOBind) Keyword() t.ID { return n.id0 }
func (n *IOBind) IO() *Expr { return n.lhs.AsExpr() }
func (n *IOBind) Limit() *Expr { return n.mhs.AsExpr() }
func (n *IOBind) Arg1() *Expr { return n.mhs.AsExpr() }
func (n *IOBind) Body() []*Node { return n.list2 }
func NewIOBind(keyword t.ID, io *Expr, limit *Expr, body []*Node) *IOBind {
func NewIOBind(keyword t.ID, io *Expr, arg1 *Expr, body []*Node) *IOBind {
return &IOBind{
kind: KIOBind,
id0: keyword,
lhs: io.AsNode(),
mhs: limit.AsNode(),
mhs: arg1.AsNode(),
list2: body,
}
}
+4 -4
View File
@@ -204,8 +204,8 @@ var Funcs = []string{
"io_reader.available() u64",
"io_reader.position() u64",
"io_reader.set!(s slice u8, closed bool)",
"io_reader.set_limit!(l u64)", // TODO: remove, as it's no longer used?
"io_reader.set!(s slice u8, closed bool)", // TODO: remove, as it's no longer used?
"io_reader.set_limit!(l u64)", // TODO: remove, as it's no longer used?
"io_reader.set_mark!()",
"io_reader.since_mark() slice u8",
@@ -258,8 +258,8 @@ var Funcs = []string{
"io_writer.available() u64",
"io_writer.position() u64",
"io_writer.set!(s slice u8)",
"io_writer.set_limit!(l u64)",
"io_writer.set!(s slice u8)", // TODO: remove, as it's no longer used?
"io_writer.set_limit!(l u64)", // TODO: remove, as it's no longer used?
"io_writer.set_mark!()",
"io_writer.since_mark() slice u8",
+2 -6
View File
@@ -237,12 +237,8 @@ func (q *checker) bcheckStatement(n *a.Node) error {
if _, err := q.bcheckExpr(n.IO(), 0); err != nil {
return err
}
if n.Keyword() == t.IDIOBind {
// No-op.
} else {
if _, err := q.bcheckExpr(n.Limit(), 0); err != nil {
return err
}
if _, err := q.bcheckExpr(n.Arg1(), 0); err != nil {
return err
}
if err := q.bcheckBlock(n.Body()); err != nil {
return err
+11 -10
View File
@@ -128,17 +128,18 @@ func (q *checker) tcheckStatement(n *a.Node) error {
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 {
return err
}
if typ := n.Limit().MType(); !typ.Eq(typeExprU64) {
return fmt.Errorf("check: %s expression %q, of type %q, does not have base.u64 type",
n.Keyword().Str(q.tm), n.Limit().Str(q.tm), typ.Str(q.tm))
}
arg1Typ := typeExprSliceU8
if n.Keyword() == t.IDIOLimit {
arg1Typ = typeExprU64
}
if err := q.tcheckExpr(n.Arg1(), 0); err != nil {
return err
}
if typ := n.Arg1().MType(); !typ.Eq(arg1Typ) {
return fmt.Errorf("check: %s expression %q, of type %q, does not have type %q",
n.Keyword().Str(q.tm), n.Arg1().Str(q.tm), typ.Str(q.tm), arg1Typ.Str(q.tm))
}
for _, o := range n.Body() {
// TODO: prohibit jumps (breaks, continues), rets (returns, yields)
// and retry-calling ? methods while inside an io_bind body.
+27 -30
View File
@@ -699,38 +699,35 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
io.Str(p.tm), p.filename, p.line())
}
limit := (*a.Expr)(nil)
if keyword == t.IDIOBind {
// No-op.
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())
}
p.src = p.src[1:]
} else {
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())
}
p.src = p.src[1:]
arg1Name := t.IDData
if keyword == t.IDIOLimit {
arg1Name = t.IDLimit
}
if x := p.peek1(); x != arg1Name {
got := p.tm.ByID(x)
return nil, fmt.Errorf(`parse: expected %q, got %q at %s:%d`, arg1Name.Str(p.tm), got, p.filename, p.line())
}
p.src = p.src[1:]
if x := p.peek1(); x != t.IDLimit {
got := p.tm.ByID(x)
return nil, fmt.Errorf(`parse: expected "limit", 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:]
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:]
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())
}
arg1, err := p.parseExpr()
if err != nil {
return nil, err
}
if arg1.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 {
@@ -744,7 +741,7 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
return nil, err
}
return a.NewIOBind(keyword, io, limit, body).AsNode(), nil
return a.NewIOBind(keyword, io, arg1, body).AsNode(), nil
}
func (p *parser) parseIf() (*a.If, error) {
+2
View File
@@ -591,6 +591,7 @@ const (
IDWidth = ID(0x247)
IDIO = ID(0x248)
IDLimit = ID(0x249)
IDData = ID(0x24A)
)
var builtInsByID = [nBuiltInIDs]string{
@@ -914,6 +915,7 @@ var builtInsByID = [nBuiltInIDs]string{
IDWidth: "width",
IDIO: "io",
IDLimit: "limit",
IDData: "data",
}
var builtInsByName = map[string]ID{}
+1 -4
View File
@@ -140,8 +140,6 @@ pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_
(this.frame_rect_y1 == this.height)
if args.dst != nullptr {
// TODO: rename initialize to set?
//
// TODO: a Wuffs (not just C) name for the
// WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL magic pixfmt constant.
args.dst.initialize!(
@@ -638,8 +636,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
while:inner true {
var w base.io_writer
io_bind (io:w) {
w.set!(s:this.uncompressed[this.uncompressed_wi:])
io_bind (io:w, data:this.uncompressed[this.uncompressed_wi:]) {
io_limit (io:args.src, limit:block_size) {
args.src.set_mark!()
var z base.status =? this.lzw.decode!??(dst:w, src:args.src)