hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit d64e9e57870e8e4abf32839f4a67add77f3cd34d
parent ed762a228e72661c590da68177ae1a3011853915
Author: Sebastian <sebastian@sebsite.pw>
Date:   Fri,  4 Aug 2023 00:32:35 -0400

Don't rely on loose pointer assignability semantics

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mcrypto/bigint/arithm.ha | 4++--
Mcrypto/ed25519/edwards25519.ha | 2+-
Mregex/regex.ha | 2+-
Mstrings/tokenize.ha | 3+++
Munix/signal/+freebsd.ha | 12++++++------
Munix/signal/+linux.ha | 12++++++------
6 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/crypto/bigint/arithm.ha b/crypto/bigint/arithm.ha @@ -312,7 +312,7 @@ export fn reduce(x: []word, a: const []word, m: const []word) void = { // Copies 'src' to 'dest' if ctl is 1. The length of 'src' must match the length // of 'dest'. -fn ccopyu32(ctl: u32, dest: []u32, src: const []u32) void = { +fn ccopyword(ctl: u32, dest: []word, src: const []word) void = { for (let i = 0z; i < len(dest); i += 1) { const x = src[i]; const y = dest[i]; @@ -443,7 +443,7 @@ export fn modpow( // product only if the exponent bits are not all-zero. montymul(t1, x, t2, m, m0i); - ccopyu32(nequ32(bits, 0), x[..mwlen], t1[..mwlen]); + ccopyword(nequ32(bits, 0), x[..mwlen], t1[..mwlen]); }; // Convert back from Montgomery representation, and exit. diff --git a/crypto/ed25519/edwards25519.ha b/crypto/ed25519/edwards25519.ha @@ -302,7 +302,7 @@ fn scalarmult_base(p: *point, s: const *scalar) *point = { return scalarmult(p, &B, s); }; -fn point_encode(out: *[POINTSZ]u8, p: *point) void = { +fn point_encode(out: *scalar, p: *point) void = { let tx: elem = [0...]; let ty: elem = [0...]; let zi: elem = [0...]; diff --git a/regex/regex.ha b/regex/regex.ha @@ -796,7 +796,7 @@ export fn find(re: *regex, string: str) result = { // non-overlapping matches as a slice of [[result]]s. The caller must free the // return value with [[result_freeall]]. export fn findall(re: *regex, string: str) []result = { - let res: [][]capture = []; + let res: []result = []; let str_idx = 0z, str_bytesize = 0z; let substring = string; let strm = memio::fixed(strings::toutf8(string)); diff --git a/strings/tokenize.ha b/strings/tokenize.ha @@ -39,6 +39,7 @@ export fn rtokenize(s: str, delim: str) tokenizer = // Returns the next string from a tokenizer, and advances the cursor. Returns // void if there are no tokens left. export fn next_token(s: *tokenizer) (str | void) = { + let s = s: *bytes::tokenizer; return match (bytes::next_token(s)) { case let b: []u8 => yield fromutf8_unsafe(b); @@ -48,6 +49,7 @@ export fn next_token(s: *tokenizer) (str | void) = { // Same as next_token(), but does not advance the cursor export fn peek_token(s: *tokenizer) (str | void) = { + let s = s: *bytes::tokenizer; return match (bytes::peek_token(s)) { case let b: []u8 => yield fromutf8_unsafe(b); @@ -58,6 +60,7 @@ export fn peek_token(s: *tokenizer) (str | void) = { // Returns the remainder of the string associated with a tokenizer, without doing // any further tokenization. export fn remaining_tokens(s: *tokenizer) str = { + let s = s: *bytes::tokenizer; return fromutf8_unsafe(bytes::remaining_tokens(s)); }; diff --git a/unix/signal/+freebsd.ha b/unix/signal/+freebsd.ha @@ -47,7 +47,7 @@ export fn handle( // Restores previous signal behavior following [[handle]]. export fn restore(signum: sig, action: *sigaction) void = { - match (rt::sigaction(signum, action, null)) { + match (rt::sigaction(signum, action: *rt::sigact, null)) { case int => yield; case rt::errno => @@ -121,7 +121,7 @@ export fn unblock(signals: sig...) sigset = { // Sets the process's signal mask, returning the previous mask. export fn setprocmask(how: how, mask: *sigset) sigset = { let old = sigset { ... }; - rt::sigprocmask(how, mask, &old)!; + rt::sigprocmask(how, mask: *rt::sigset, &old)!; return old; }; @@ -157,26 +157,26 @@ export fn newsigset(items: sig...) sigset = { // Sets a [[sigset]] to empty. export fn sigset_empty(set: *sigset) void = { - rt::sigemptyset(set); + rt::sigemptyset(set: *rt::sigset); }; // Adds signals to a [[sigset]]. export fn sigset_add(set: *sigset, items: sig...) void = { for (let i = 0z; i < len(items); i += 1) { - rt::sigaddset(set, items[i])!; + rt::sigaddset(set: *rt::sigset, items[i])!; }; }; // Removes signals from a [[sigset]]. export fn sigset_del(set: *sigset, items: sig...) void = { for (let i = 0z; i < len(items); i += 1) { - rt::sigdelset(set, items[i])!; + rt::sigdelset(set: *rt::sigset, items[i])!; }; }; // Returns true if the given signal is a member of this [[sigset]]. export fn sigset_member(set: *sigset, item: sig) bool = { - return rt::sigismember(set, item)!; + return rt::sigismember(set: *rt::sigset, item)!; }; // Provides additional information about signal deliveries. Only the members diff --git a/unix/signal/+linux.ha b/unix/signal/+linux.ha @@ -53,7 +53,7 @@ export fn handle( // Restores previous signal behavior following [[handle]]. export fn restore(signum: sig, action: *sigaction) void = { - match (rt::sigaction(signum, action, null)) { + match (rt::sigaction(signum, action: *rt::sigact, null)) { case int => yield; case rt::errno => @@ -125,7 +125,7 @@ export fn unblock(signals: sig...) sigset = { // Sets the process's signal mask, returning the previous mask. export fn setprocmask(how: how, mask: *sigset) sigset = { let old = sigset { ... }; - rt::sigprocmask(how, mask, &old)!; + rt::sigprocmask(how, mask: *rt::sigset, &old)!; return old; }; @@ -161,26 +161,26 @@ export fn newsigset(items: sig...) sigset = { // Sets a [[sigset]] to empty. export fn sigset_empty(set: *sigset) void = { - rt::sigemptyset(set); + rt::sigemptyset(set: *rt::sigset); }; // Adds signals to a [[sigset]]. export fn sigset_add(set: *sigset, items: sig...) void = { for (let i = 0z; i < len(items); i += 1) { - rt::sigaddset(set, items[i])!; + rt::sigaddset(set: *rt::sigset, items[i])!; }; }; // Removes signals from a [[sigset]]. export fn sigset_del(set: *sigset, items: sig...) void = { for (let i = 0z; i < len(items); i += 1) { - rt::sigdelset(set, items[i])!; + rt::sigdelset(set: *rt::sigset, items[i])!; }; }; // Returns true if the given signal is a member of this [[sigset]]. export fn sigset_member(set: *sigset, item: sig) bool = { - return rt::sigismember(set, item)!; + return rt::sigismember(set: *rt::sigset, item)!; }; // Provides additional information about signal deliveries. Only the members