From ac793d33bc99be05b3f516d8a1fffc50aef316bb Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 22 Oct 2017 13:57:37 +1100 Subject: [PATCH] Generate placeholder code for "mark in.dst". --- cmd/puffs-c/internal/cgen/statement.go | 4 ++++ doc/puffs-the-language.md | 3 ++- gen/c/std/flate.c | 1 + lang/ast/ast.go | 24 ++++++++++++++++++++++++ lang/check/bounds.go | 4 ++++ lang/check/type.go | 12 ++++++++++++ lang/parse/parse.go | 8 ++++++++ lang/token/list.go | 3 +++ std/flate/decode_flate.puffs | 5 +++++ 9 files changed, 63 insertions(+), 1 deletion(-) diff --git a/cmd/puffs-c/internal/cgen/statement.go b/cmd/puffs-c/internal/cgen/statement.go index 49956713..09118fdb 100644 --- a/cmd/puffs-c/internal/cgen/statement.go +++ b/cmd/puffs-c/internal/cgen/statement.go @@ -68,6 +68,10 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error { b.writes(";\n") return nil + case a.KIO: + b.writes("/* placeholder */\n") + return nil + case a.KIf: // TODO: for writeSuspendibles, make sure that we get order of // sub-expression evaluation correct. diff --git a/doc/puffs-the-language.md b/doc/puffs-the-language.md index 01654a8c..6a3975f2 100644 --- a/doc/puffs-the-language.md +++ b/doc/puffs-the-language.md @@ -54,9 +54,10 @@ be enclosed by curly `{}`s. There is no 'dangling else' ambiguity. - `var` -1 keyword deals with I/O: +2 keywords deal with I/O: - `limit` +- `mark` TODO: categorize and, or, not, as, ref, deref, false, true, in, out, this, u8, u16, etc. diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index 696e2807..457ccc41 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -831,6 +831,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode( switch (coro_susp_point) { PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0); + /* placeholder */ while (true) { PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); if (a_dst.buf) { diff --git a/lang/ast/ast.go b/lang/ast/ast.go index 7146313e..33ab7892 100644 --- a/lang/ast/ast.go +++ b/lang/ast/ast.go @@ -40,6 +40,7 @@ const ( KField KFile KFunc + KIO KIf KIterate KJump @@ -71,6 +72,7 @@ var kindStrings = [...]string{ KField: "KField", KFile: "KFile", KFunc: "KFunc", + KIO: "KIO", KIf: "KIf", KIterate: "KIterate", KJump: "KJump", @@ -133,6 +135,7 @@ func (n *Node) Expr() *Expr { return (*Expr)(n) } func (n *Node) Field() *Field { return (*Field)(n) } func (n *Node) File() *File { return (*File)(n) } func (n *Node) Func() *Func { return (*Func)(n) } +func (n *Node) IO() *IO { return (*IO)(n) } func (n *Node) If() *If { return (*If)(n) } func (n *Node) Iterate() *Iterate { return (*Iterate)(n) } func (n *Node) Jump() *Jump { return (*Jump)(n) } @@ -480,6 +483,27 @@ func NewIf(condition *Expr, elseIf *If, bodyIfTrue []*Node, bodyIfFalse []*Node) } } +// IO is "mark LHS": +// - ID0: +// - LHS: +// +// TODO: "mark LHS { List2 }"? +// +// TODO: also represent "limit LHS"? +type IO Node + +func (n *IO) Node() *Node { return (*Node)(n) } +func (n *IO) Keyword() t.ID { return n.id0 } +func (n *IO) Value() *Expr { return n.lhs.Expr() } + +func NewIO(keyword t.ID, value *Expr) *IO { + return &IO{ + kind: KIO, + id0: keyword, + lhs: value.Node(), + } +} + // Return is "return LHS", "return error ID1" or "return suspension ID1": // - ID0: <0|IDError|IDSuspension> // - ID1: message diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 18ff1f32..c517f2dc 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -241,6 +241,10 @@ func (q *checker) bcheckStatement(n *a.Node) error { _, _, err := q.bcheckExpr(n.Expr(), 0) return err + case a.KIO: + _, _, err := q.bcheckExpr(n.IO().Value(), 0) + return err + case a.KIf: return q.bcheckIf(n.If()) diff --git a/lang/check/type.go b/lang/check/type.go index 38ee5990..df4bb099 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -84,6 +84,18 @@ func (q *checker) tcheckStatement(n *a.Node) error { case a.KExpr: return q.tcheckExpr(n.Expr(), 0) + case a.KIO: + n := n.IO() + val := n.Value() + if err := q.tcheckExpr(val, 0); err != nil { + return err + } + typ := val.MType() + if key := typ.Name().Key(); typ.Decorator() != 0 || (key != t.KeyReader1 && key != t.KeyWriter1) { + return fmt.Errorf("check: %s expression %q, of type %q, does not have an I/O type", + n.Keyword().String(q.tm), val.String(q.tm), typ.String(q.tm)) + } + case a.KIf: for n := n.If(); n != nil; n = n.ElseIf() { cond := n.Condition() diff --git a/lang/parse/parse.go b/lang/parse/parse.go index ab0ce69e..ef29acf9 100644 --- a/lang/parse/parse.go +++ b/lang/parse/parse.go @@ -632,6 +632,14 @@ func (p *parser) parseStatement1() (*a.Node, error) { o, err := p.parseIf() return o.Node(), err + case t.KeyMark: + p.src = p.src[1:] + value, err := p.parseExpr() + if err != nil { + return nil, err + } + return a.NewIO(x, value).Node(), nil + case t.KeyReturn: p.src = p.src[1:] keyword, message, value, err := t.ID(0), t.ID(0), (*a.Expr)(nil), error(nil) diff --git a/lang/token/list.go b/lang/token/list.go index a11499dc..a6c90fcd 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -242,6 +242,7 @@ const ( KeyConst = Key(IDConst >> KeyShift) KeyTry = Key(IDTry >> KeyShift) KeyIterate = Key(IDIterate >> KeyShift) + KeyMark = Key(IDMark >> KeyShift) KeyFalse = Key(IDFalse >> KeyShift) KeyTrue = Key(IDTrue >> KeyShift) @@ -428,6 +429,7 @@ const ( IDConst = ID(0x77<