diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-07-09 15:10:12 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-07-09 15:10:12 -0700 |
commit | cfe3269e978e06cf0fb3f27f248bfde0a77d0038 (patch) | |
tree | 042a9b463e383f280b014af54f3a035710376e07 | |
parent | feb8eefb2fc97e5f8ccc831f28ef10e67717ec22 (diff) | |
download | txr-cfe3269e978e06cf0fb3f27f248bfde0a77d0038.tar.gz txr-cfe3269e978e06cf0fb3f27f248bfde0a77d0038.tar.bz2 txr-cfe3269e978e06cf0fb3f27f248bfde0a77d0038.zip |
chksum: generate more with TXR.
* genchksum.txr, chksum.c: The declarations of the symbol
variables, COBJ class handles, and most of the chksum_init
function is also generated now. A comment is added explaining
what parts of the file are generated, and what parts are
scraped, and giving some advice to the maintainer.
-rw-r--r-- | chksum.c | 34 | ||||
-rw-r--r-- | genchksum.txr | 39 |
2 files changed, 64 insertions, 9 deletions
@@ -1,4 +1,4 @@ -/* This file is generated by genchksum.txr */ +/* This file is partially generated by genchksum.txr; see comment below. */ /* Copyright 2019-2023 * Kaz Kylheku <kaz@kylheku.com> @@ -51,8 +51,29 @@ #include "chksums/md5.h" #include "chksum.h" -static val sha1_ctx_s, sha256_ctx_s, md5_ctx_s; -static struct cobj_class *sha1_ctx_cls, *sha256_ctx_cls, *md5_ctx_cls; +/* This file is not entirely generated. Parts of it are maintained by + * hand. The genchksum.txr program will extract the hand-maintained + * parts, and merge it with the generated parts. + * + * After working on this file, save your work (perhaps into a commit). + * Then run txr ./genchksum.txr and ensure that the updated + * chksum.c file is identical to your saved copy. + * + * The generated parts are these: + * + * - everything starting with the declaration "static val sha1_ctx_s ..." + * up to just before the crc32 section: the crc32_stream function. + * + * - the crc32 function section starting with the crc32_stream function, + * to just before the checksum_ + * + * - a portion fo the chksum_init(void) function, up to the line + * which registers the crc32-stream function. + * + * Thus, material outside of these sections is editable; but edits + * must be validated to make sure they don't break the generation + * program. + */ static val chksum_ensure_buf(val self, val buf_in, val len, unsigned char **phash, @@ -70,6 +91,9 @@ static val chksum_ensure_buf(val self, val buf_in, } } +static val sha1_ctx_s, sha256_ctx_s, md5_ctx_s; +static struct cobj_class *sha1_ctx_cls, *sha256_ctx_cls, *md5_ctx_cls; + static void sha1_stream_impl(val stream, val nbytes, unsigned char *hash, val self) { @@ -729,11 +753,11 @@ void chksum_init(void) reg_fun(intern(lit("sha256-begin"), user_package), func_n0(sha256_begin)); reg_fun(intern(lit("sha256-hash"), user_package), func_n2(sha256_hash)); reg_fun(intern(lit("sha256-end"), user_package), func_n2o(sha256_end, 1)); - reg_fun(intern(lit("crc32-stream"), user_package), func_n3o(crc32_stream, 1)); - reg_fun(intern(lit("crc32"), user_package), func_n2o(crc32, 1)); reg_fun(intern(lit("md5-stream"), user_package), func_n3o(md5_stream, 1)); reg_fun(intern(lit("md5"), user_package), func_n2o(md5, 1)); reg_fun(intern(lit("md5-begin"), user_package), func_n0(md5_begin)); reg_fun(intern(lit("md5-hash"), user_package), func_n2(md5_hash)); reg_fun(intern(lit("md5-end"), user_package), func_n2o(md5_end, 1)); + reg_fun(intern(lit("crc32-stream"), user_package), func_n3o(crc32_stream, 1)); + reg_fun(intern(lit("crc32"), user_package), func_n2o(crc32, 1)); } diff --git a/genchksum.txr b/genchksum.txr index 932f2813..b86108fb 100644 --- a/genchksum.txr +++ b/genchksum.txr @@ -24,24 +24,37 @@ MD5_init MD5_update MD5_final @ (bind s @(new (chksum cname type strname hashlen init update final))) @(end) @(next "chksum.c") -/* This file is generated by genchksum.txr */ +/* This file is partially generated by genchksum.txr; see comment below. */ @(collect) @ prolog @(until) -static void @{nil}_stream_impl(val stream, val nbytes, +static val @{nil}_ctx_s, @nil @(end) @(skip) -@(data epilog) +@(data crc32-start) val crc32_stream(val stream, val nbytes, val init) +@(skip) +@(data chksum-init-start) +void chksum_init(void) +{ +@(skip) +@(data epilog) + reg_fun(intern(lit("crc32-stream"), user_package), func_n3o(crc32_stream, 1)); + reg_fun(intern(lit("crc32"), user_package), func_n2o(crc32, 1)); +} +@(bind crc32 @(ldiff crc32-start chksum-init-start)) @(output "chksum.c") -/* This file is generated by genchksum.txr */ +/* This file is partially generated by genchksum.txr; see comment below. */ @(repeat) @ prolog @(end) +static val @(rep)@{s.cname}_ctx_s, @(last)@{s.cname}_ctx_s;@(end) +static struct cobj_class @(rep)*@{s.cname}_ctx_cls, @(last)*@{s.cname}_ctx_cls;@(end) + @(repeat) static void @{s.cname}_stream_impl(val stream, val nbytes, unsigned char *hash, val self) @@ -230,6 +243,24 @@ val @{s.cname}_end(val ctx, val buf_in) @(end) @(repeat) +@ crc32 +@(end) +void chksum_init(void) +{ +@(repeat) + @{s.cname}_ctx_s = intern(lit("@{s.cname}-ctx"), user_package); +@(end) +@(repeat) + @{s.cname}_ctx_cls = cobj_register(@{s.cname}_ctx_s); +@(end) +@(repeat) + reg_fun(intern(lit("@{s.cname}-stream"), user_package), func_n3o(@{s.cname}_stream, 1)); + reg_fun(intern(lit("@{s.cname}"), user_package), func_n2o(@{s.cname}, 1)); + reg_fun(intern(lit("@{s.cname}-begin"), user_package), func_n0(@{s.cname}_begin)); + reg_fun(intern(lit("@{s.cname}-hash"), user_package), func_n2(@{s.cname}_hash)); + reg_fun(intern(lit("@{s.cname}-end"), user_package), func_n2o(@{s.cname}_end, 1)); +@(end) +@(repeat) @ epilog @(end) @(end) |