Add a skeleton of an adler.update method.

This commit is contained in:
Nigel Tao committed 2017-10-19 18:58:17 +11:00
1 parent 5b0d6f6f3e
commit 50369c782c
5 files changed
+38 -2

No files matched your search

+8 -1
View File
@@ -61,8 +61,15 @@ func (g *gen) writeFuncSignature(b *buffer, n *a.Func) error {
// TODO: write n's return values.
if n.Suspendible() {
b.printf("%sstatus ", g.pkgPrefix)
} else {
} else if outFields := n.Out().Fields(); len(outFields) == 0 {
b.writes("void ")
} else if len(outFields) == 1 {
// TODO: does this generate the right C if the XType is an array?
if err := g.writeCTypeName(b, outFields[0].Field().XType(), "", ""); err != nil {
return err
}
} else {
return fmt.Errorf("TODO: multiple return values")
}
b.writes(g.pkgPrefix)
+14 -1
View File
@@ -173,7 +173,20 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
}
return g.writeCoroSuspPoint(b, true)
}
return fmt.Errorf("TODO: return statements in non-suspendible functions")
b.writes("return ")
if len(g.currFunk.astFunc.Out().Fields()) == 0 {
if retExpr != nil {
return fmt.Errorf("return expression %q incompatible with empty return type", retExpr.String(g.tm))
}
} else if retExpr == nil {
// TODO: should a bare "return" imply "return out"?
return fmt.Errorf("empty return expression incompatible with non-empty return type")
} else if err := g.writeExpr(b, retExpr, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
return err
}
b.writeb(';')
return nil
case a.KVar:
n := n.Var()
+8
View File
@@ -697,6 +697,9 @@ puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self,
uint32_t a_n_codes1,
uint32_t a_base_symbol);
uint32_t puffs_flate_adler_update(puffs_flate_adler* self,
puffs_base_slice_u8 a_x);
// ---------------- Initializer Implementations
// PUFFS_MAGIC is a magic number to check that initializers are called. It's
@@ -2416,3 +2419,8 @@ short_read_src:
status = PUFFS_FLATE_SUSPENSION_SHORT_READ;
goto suspend;
}
uint32_t puffs_flate_adler_update(puffs_flate_adler* self,
puffs_base_slice_u8 a_x) {
return self->private_impl.f_state;
}
+4
View File
@@ -429,6 +429,10 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
}
n.Out().Node().SetTypeChecked()
// TODO: check somewhere that, if n.Out() is non-empty (or we are
// suspendible), that we end with a return statement? Or is that an
// implicit "return out"?
qid := n.QID()
if other, ok := c.funcs[qid]; ok {
return &Error{
+4
View File
@@ -46,3 +46,7 @@ pub func zlib_decoder.decode?(dst writer1, src reader1)() {
pri struct adler?(
state u32 = 1,
)
pri func adler.update(x[] u8)(checksum u32) {
return this.state
}