Generate C code for "in.dst.write_u8?(x:foo)".

This commit is contained in:
Nigel Tao committed 2017-06-09 16:41:59 +10:00
1 parent c1dff0ca41
commit f5af981f15
7 files changed
+128 -12

No files matched your search

+1
View File
@@ -509,6 +509,7 @@ const MaxBodyDepth = 255
// Statement means one of:
// - Assert
// - Assign
// - Expr
// - If
// - Jump
// - Return
+18 -2
View File
@@ -169,6 +169,10 @@ func (q *checker) bcheckStatement(n *a.Node) error {
n := n.Assign()
return q.bcheckAssignment(n.LHS(), n.Operator(), n.RHS())
case a.KExpr:
_, _, err := q.bcheckExpr(n.Expr(), 0)
return err
case a.KIf:
return q.bcheckIf(n.If())
@@ -589,8 +593,20 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
// No-op.
case t.KeyOpenParen:
// TODO: delete this hack that only matches "in.src.read_u8?()".
if isInSrcReadU8(q.tm, n) {
// TODO: delete this hack that only matches "in.src.read_u8?()" and
// "in.dst.write_u8?(x:bar)".
if isInSrcReadU8(q.tm, n) || isInDstWriteU8(q.tm, n) {
for _, o := range n.Args() {
// TODO: check that the arg range at the caller and the
// signature are compatible.
oMin, oMax, err := q.bcheckExpr(o.Arg().Value(), depth)
if err != nil {
return nil, nil, err
}
// TODO: check that oMin and oMax is within the function's
// declared arg bounds.
_, _ = oMin, oMax
}
break
}
// TODO: delete this hack that only matches "foo.low_bits(etc)".
+28 -2
View File
@@ -50,6 +50,9 @@ func (q *checker) tcheckStatement(n *a.Node) error {
return err
}
case a.KExpr:
return q.tcheckExpr(n.Expr(), 0)
case a.KIf:
for n := n.If(); n != nil; n = n.ElseIf() {
cond := n.Condition()
@@ -313,11 +316,17 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
case t.KeyOpenParen:
// n is a function call.
// TODO: delete this hack that only matches "in.src.read_u8?()".
if isInSrcReadU8(q.tm, n) {
// TODO: delete this hack that only matches "in.src.read_u8?()" and
// "in.dst.write_u8?(x:bar)".
if isInSrcReadU8(q.tm, n) || isInDstWriteU8(q.tm, n) {
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
return err
}
for _, o := range n.Args() {
if err := q.tcheckArg(o.Arg(), depth); err != nil {
return err
}
}
n.SetMType(TypeExprU8) // HACK.
return nil
}
@@ -368,6 +377,23 @@ func isInSrcReadU8(tm *t.Map, n *a.Expr) bool {
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
}
func isInDstWriteU8(tm *t.Map, n *a.Expr) bool {
// TODO: check that n.Args() is "(x:bar)".
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
return false
}
n = n.LHS().Expr()
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != t.KeyWriteU8 {
return false
}
n = n.LHS().Expr()
if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName("dst") {
return false
}
n = n.LHS().Expr()
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
}
func isLowBits(tm *t.Map, n *a.Expr) bool {
// TODO: check that n.Args() is "(n:bar)".
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {