mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Generate a C placeholder for "in.src.read_u8?()".
This commit is contained in:
1 parent
0646f4472c
commit
1758637f89
7 files changed
+65
-8
No files matched your search
+19
-2
@@ -673,8 +673,13 @@ func (g *gen) writeExprOther(n *a.Expr, depth uint32) error {
|
||||
return nil
|
||||
|
||||
case t.KeyOpenParen:
|
||||
// n is a function call.
|
||||
// TODO.
|
||||
// n is a function call.
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
||||
if isInSrcReadU8(g.idMap, n.LHS().Expr()) && len(n.Args()) == 0 {
|
||||
// TODO.
|
||||
g.writes("42")
|
||||
return nil
|
||||
}
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
// n is an index.
|
||||
@@ -698,6 +703,18 @@ func (g *gen) writeExprOther(n *a.Expr, depth uint32) error {
|
||||
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExprOther", n.ID0().Key())
|
||||
}
|
||||
|
||||
func isInSrcReadU8(m *t.IDMap, n *a.Expr) bool {
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != t.KeyReadU8 {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1() != m.ByName("src") {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
func (g *gen) writeExprUnaryOp(n *a.Expr, depth uint32) error {
|
||||
// TODO.
|
||||
return nil
|
||||
|
||||
+1
-1
@@ -214,7 +214,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
v_width = (self->f_literal_width + 1);
|
||||
while (1) {
|
||||
while ((v_n_bits < v_width)) {
|
||||
v_bits |= ((uint32_t)(0));
|
||||
v_bits |= ((uint32_t)(42));
|
||||
v_n_bits += 8;
|
||||
}
|
||||
v_bits >>= v_width;
|
||||
|
||||
@@ -428,6 +428,8 @@ const MaxTypeExprDepth = 63
|
||||
// "foo". ID0 is the "pkg" or zero, ID1 is the "foo". Such a type can be
|
||||
// refined as "foo[LHS..MHS]". LHS and MHS are Expr's, possibly nil. For
|
||||
// example, the LHS for "u32[..4095]" is nil.
|
||||
//
|
||||
// TODO: function / method types.
|
||||
type TypeExpr Node
|
||||
|
||||
func (n *TypeExpr) Node() *Node { return (*Node)(n) }
|
||||
|
||||
@@ -444,7 +444,10 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
// No-op.
|
||||
|
||||
case t.KeyOpenParen:
|
||||
// TODO.
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
||||
if isInSrcReadU8(q.idMap, n.LHS().Expr()) && len(n.Args()) == 0 {
|
||||
break
|
||||
}
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprOther", n.ID0().Key())
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
|
||||
+10
-2
@@ -48,11 +48,11 @@ func (e *Error) Error() string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// TypeExprFoo is an *ast.Node MType (implicit type) that means that n is a
|
||||
// boolean or a ideal numeric constant.
|
||||
// TypeExprFoo is an *ast.Node MType (implicit type).
|
||||
var (
|
||||
TypeExprBoolean = a.NewTypeExpr(0, t.IDBool, nil, nil, nil)
|
||||
TypeExprIdealNumber = a.NewTypeExpr(0, t.IDIdeal, nil, nil, nil)
|
||||
TypeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil)
|
||||
)
|
||||
|
||||
func numeric(n *a.TypeExpr) bool { return n == TypeExprIdealNumber || n.IsNumType() }
|
||||
@@ -349,6 +349,14 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
|
||||
n.Node().SetTypeChecked()
|
||||
if err := n.Node().Walk(func(o *a.Node) error {
|
||||
if !o.TypeChecked() {
|
||||
switch o.Kind() {
|
||||
case a.KExpr:
|
||||
return fmt.Errorf("check: internal error: unchecked %s node %q",
|
||||
o.Kind(), o.Expr().String(q.idMap))
|
||||
case a.KTypeExpr:
|
||||
return fmt.Errorf("check: internal error: unchecked %s node %q",
|
||||
o.Kind(), o.TypeExpr().String(q.idMap))
|
||||
}
|
||||
return fmt.Errorf("check: internal error: unchecked %s node", o.Kind())
|
||||
}
|
||||
if o.Kind() == a.KExpr {
|
||||
|
||||
+28
-1
@@ -293,7 +293,14 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
|
||||
case t.KeyOpenParen:
|
||||
// n is a function call.
|
||||
// TODO.
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
||||
if isInSrcReadU8(q.idMap, n.LHS().Expr()) && len(n.Args()) == 0 {
|
||||
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
n.SetMType(TypeExprU8)
|
||||
return nil
|
||||
}
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
// n is an index.
|
||||
@@ -309,6 +316,18 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprOther", n.ID0().Key())
|
||||
}
|
||||
|
||||
func isInSrcReadU8(m *t.IDMap, n *a.Expr) bool {
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != t.KeyReadU8 {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1() != m.ByName("src") {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
lhs := n.LHS().Expr()
|
||||
if err := q.tcheckExpr(lhs, depth); err != nil {
|
||||
@@ -330,6 +349,14 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
s = q.f.Func.In()
|
||||
case t.KeyOut:
|
||||
s = q.f.Func.Out()
|
||||
case t.KeyBuf1:
|
||||
// TODO: remove this hack and be more principled about the built-in
|
||||
// buf1 type.
|
||||
//
|
||||
// Another hack is using TypeExprU8 until a TypeExpr can represent
|
||||
// function types.
|
||||
n.SetMType(TypeExprU8)
|
||||
return nil
|
||||
default:
|
||||
s = q.c.structs[name].Struct
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
||||
post n_bits >= width,
|
||||
{
|
||||
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
|
||||
bits |= 0 as u32 // TODO
|
||||
bits |= in.src.read_u8?() as u32 // TODO
|
||||
n_bits += 8
|
||||
}
|
||||
// TODO: var code u32[..4095] = bits.low_bits(width)
|
||||
|
||||
Reference in new issue
Block a user