mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Generate C code for "this.lzw.set_literal_width".
This commit is contained in:
1 parent
93ca2f7496
commit
497a8776c2
5 files changed
+64
-6
No files matched your search
@@ -774,6 +774,16 @@ func (g *gen) writeStatement(n *a.Node, depth uint32) error {
|
||||
if n.CallSuspendible() {
|
||||
return nil
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
|
||||
if isSetLiteralWidth(g.tm, n) {
|
||||
g.printf("puffs_%s_lzw_decoder_set_literal_width(&self->private_impl.f_lzw, ", g.pkgName)
|
||||
a := n.Args()[0].Arg().Value()
|
||||
if err := g.writeExpr(a, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
g.writes(");\n")
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("TODO: generate code for foo() when foo is not a ? call-suspendible")
|
||||
|
||||
case a.KIf:
|
||||
@@ -1261,6 +1271,15 @@ func isLowBits(tm *t.Map, n *a.Expr) bool {
|
||||
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == t.KeyLowBits
|
||||
}
|
||||
|
||||
func isSetLiteralWidth(tm *t.Map, n *a.Expr) bool {
|
||||
// TODO: check that n.Args() is "(lw:bar)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0().Key() == t.KeyDot && n.ID1() == tm.ByName("set_literal_width")
|
||||
}
|
||||
|
||||
func (g *gen) writeExprUnaryOp(n *a.Expr, rp replacementPolicy, depth uint32) error {
|
||||
// TODO.
|
||||
return nil
|
||||
|
||||
+5
-3
@@ -504,7 +504,7 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||
uint8_t v_c[9];
|
||||
uint32_t v_i;
|
||||
bool v_interlace;
|
||||
uint8_t v_literal_width;
|
||||
uint8_t v_lw;
|
||||
uint8_t v_block_size;
|
||||
|
||||
for (size_t i = 0; i < 9; i++) {
|
||||
@@ -533,10 +533,12 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||
return status;
|
||||
}
|
||||
uint8_t t_1 = a_src.buf->ptr[a_src.buf->ri++];
|
||||
v_literal_width = t_1;
|
||||
if ((v_literal_width < 2) || (8 < v_literal_width)) {
|
||||
v_lw = t_1;
|
||||
if ((v_lw < 2) || (8 < v_lw)) {
|
||||
return puffs_gif_error_bad_lzw_literal_width;
|
||||
}
|
||||
puffs_gif_lzw_decoder_set_literal_width(&self->private_impl.f_lzw,
|
||||
((uint32_t)(v_lw)));
|
||||
while (true) {
|
||||
if (a_src.buf->ri >= a_src.buf->wi) {
|
||||
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||
|
||||
@@ -651,6 +651,18 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
}
|
||||
return zero, bitMask(int(aMax.Int64())), nil
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
|
||||
if isSetLiteralWidth(q.tm, n) {
|
||||
a := n.Args()[0].Arg().Value()
|
||||
aMin, aMax, err := q.bcheckExpr(a, depth)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if aMin.Cmp(big.NewInt(2)) < 0 || aMax.Cmp(big.NewInt(8)) > 0 {
|
||||
return nil, nil, fmt.Errorf("check: %q not in range [2..8]", a.String(q.tm))
|
||||
}
|
||||
return nil, nil, nil
|
||||
}
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprOther", n.ID0().Key())
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
|
||||
@@ -359,6 +359,22 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
n.SetMType(foo.MType().Unrefined())
|
||||
return nil
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
|
||||
if isSetLiteralWidth(q.tm, n) {
|
||||
foo := n.LHS().Expr().LHS().Expr()
|
||||
if err := q.tcheckExpr(foo, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
n.LHS().SetTypeChecked()
|
||||
n.LHS().Expr().SetMType(typeExprPlaceholder) // HACK.
|
||||
for _, o := range n.Args() {
|
||||
if err := q.tcheckArg(o.Arg(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
n.SetMType(typeExprPlaceholder) // HACK.
|
||||
return nil
|
||||
}
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
// n is an index.
|
||||
@@ -448,6 +464,15 @@ func isLowBits(tm *t.Map, n *a.Expr) bool {
|
||||
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == t.KeyLowBits
|
||||
}
|
||||
|
||||
func isSetLiteralWidth(tm *t.Map, n *a.Expr) bool {
|
||||
// TODO: check that n.Args() is "(lw:bar)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0().Key() == t.KeyDot && n.ID1() == tm.ByName("set_literal_width")
|
||||
}
|
||||
|
||||
func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
lhs := n.LHS().Expr()
|
||||
if err := q.tcheckExpr(lhs, depth); err != nil {
|
||||
|
||||
@@ -137,11 +137,11 @@ pri func decoder.decode_id?(src reader1)() {
|
||||
return error "TODO: unsupported Local Color Table"
|
||||
}
|
||||
|
||||
var literal_width u8 = in.src.read_u8?()
|
||||
// TODO: call this.lzw.set_literal_width.
|
||||
if (literal_width < 2) or (8 < literal_width) {
|
||||
var lw u8 = in.src.read_u8?()
|
||||
if (lw < 2) or (8 < lw) {
|
||||
return error "bad LZW literal width"
|
||||
}
|
||||
this.lzw.set_literal_width(lw:lw as u32)
|
||||
|
||||
// TODO: pass the data blocks' payload to this.lzw.
|
||||
while true {
|
||||
|
||||
Reference in new issue
Block a user