Have crc32's ieee.update return u32

This commit is contained in:
Nigel Tao committed 2018-03-25 17:04:14 +11:00
1 parent 917737ec97
commit 008bce65f2
5 files changed
+40 -16

No files matched your search

+14 -2
View File
@@ -171,11 +171,18 @@ func (g *gen) gatherFuncImpl(_ *buffer, n *a.Func) error {
func (g *gen) writeFuncImplHeader(b *buffer) error {
// Check the previous status and the "self" arg.
if g.currFunk.public && !g.currFunk.astFunc.Receiver().IsZero() {
outFields := g.currFunk.astFunc.Out().Fields()
b.writes("if (!self) {")
if g.currFunk.suspendible {
b.printf("return %sERROR_BAD_RECEIVER;", g.PKGPREFIX)
} else {
} else if len(outFields) == 0 {
b.printf("return;")
} else if len(outFields) == 1 {
// TODO: don't assume that the return type is an integer.
b.printf("return 0;")
} else {
return fmt.Errorf("TODO: handle structured return types")
}
b.writes("}")
@@ -185,8 +192,13 @@ func (g *gen) writeFuncImplHeader(b *buffer) error {
b.writes("if (self->private_impl.status < 0) {")
if g.currFunk.suspendible {
b.writes("return self->private_impl.status;")
} else {
} else if len(outFields) == 0 {
b.writes("return;")
} else if len(outFields) == 1 {
// TODO: don't assume that the return type is an integer.
b.writes("return 0;")
} else {
return fmt.Errorf("TODO: handle structured return types")
}
b.writes("}\n")
}
+10 -6
View File
@@ -231,6 +231,8 @@ typedef struct {
wuffs_crc32__status status;
uint32_t magic;
uint32_t f_state;
} private_impl;
} wuffs_crc32__ieee;
@@ -247,8 +249,8 @@ void wuffs_crc32__ieee__initialize(wuffs_crc32__ieee* self,
// ---------------- Public Function Prototypes
void wuffs_crc32__ieee__update(wuffs_crc32__ieee* self,
wuffs_base__slice_u8 a_x);
uint32_t wuffs_crc32__ieee__update(wuffs_crc32__ieee* self,
wuffs_base__slice_u8 a_x);
#ifdef __cplusplus
} // extern "C"
@@ -682,15 +684,17 @@ void wuffs_crc32__ieee__initialize(wuffs_crc32__ieee* self,
// ---------------- Function Implementations
void wuffs_crc32__ieee__update(wuffs_crc32__ieee* self,
wuffs_base__slice_u8 a_x) {
uint32_t wuffs_crc32__ieee__update(wuffs_crc32__ieee* self,
wuffs_base__slice_u8 a_x) {
if (!self) {
return;
return 0;
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
self->private_impl.status = WUFFS_CRC32__ERROR_INITIALIZER_NOT_CALLED;
}
if (self->private_impl.status < 0) {
return;
return 0;
}
return self->private_impl.f_state;
}
+4 -2
View File
@@ -231,6 +231,8 @@ typedef struct {
wuffs_crc32__status status;
uint32_t magic;
uint32_t f_state;
} private_impl;
} wuffs_crc32__ieee;
@@ -247,8 +249,8 @@ void wuffs_crc32__ieee__initialize(wuffs_crc32__ieee* self,
// ---------------- Public Function Prototypes
void wuffs_crc32__ieee__update(wuffs_crc32__ieee* self,
wuffs_base__slice_u8 a_x);
uint32_t wuffs_crc32__ieee__update(wuffs_crc32__ieee* self,
wuffs_base__slice_u8 a_x);
#ifdef __cplusplus
} // extern "C"
+7 -1
View File
@@ -16,9 +16,15 @@ packageid "crc3"
// TODO: drop the '?' but still generate wuffs_crc32__ieee__initialize?
pub struct ieee?(
state u32,
)
// TODO: add a ! as this function is impure.
pub func ieee.update(x[] u8)() {
//
// TODO: should it be ? instead of ! because it's public, and might need a way
// to signal "initializer not called"? Should the return type, in the generated
// C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"?
pub func ieee.update(x[] u8)(checksum u32) {
// TODO: implement.
return this.state
}
+5 -5
View File
@@ -74,11 +74,11 @@ const char* wuffs_bench_crc32(wuffs_base__buf1* dst,
// TODO: don't ignore wlimit and rlimit.
wuffs_crc32__ieee checksum;
wuffs_crc32__ieee__initialize(&checksum, WUFFS_VERSION, 0);
// TODO: global_wuffs_crc32_unused_u32 =
wuffs_crc32__ieee__update(&checksum, ((wuffs_base__slice_u8){
.ptr = src->ptr + src->ri,
.len = src->wi - src->ri,
}));
global_wuffs_crc32_unused_u32 =
wuffs_crc32__ieee__update(&checksum, ((wuffs_base__slice_u8){
.ptr = src->ptr + src->ri,
.len = src->wi - src->ri,
}));
src->ri = src->wi;
return NULL;
}