Skip to content

Commit c8cab78

Browse files
einsiedlerspielkanaka
authored andcommitted
hare: Update for hare 0.25.2
Allocations may return `!nomem`.
1 parent 2978cb7 commit c8cab78

File tree

16 files changed

+58
-58
lines changed

16 files changed

+58
-58
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ groovy ./stepX_YYY.groovy
572572

573573
### Hare
574574

575-
The hare implementation was tested against Hare 0.24.2.
575+
The hare implementation was tested against Hare 0.25.2.
576576

577577
```
578578
cd impls/hare

impls/hare/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:25.04
1+
FROM debian:testing
22
MAINTAINER Lou Woell <[email protected]>
33
LABEL org.opencontainers.image.source=https://github.com/kanaka/mal
44
LABEL org.opencontainers.image.description="mal test container: hare"

impls/hare/mal/core.ha

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ fn apply(args: []MalType) (MalType | error) = {
765765
case 0 =>
766766
yield [];
767767
case =>
768-
yield alloc([nil...], length);
768+
yield alloc([nil...], length)!;
769769
};
770770
defer free(ls);
771771

@@ -896,7 +896,7 @@ fn malkeyword(args: []MalType) (MalType | error) = {
896896

897897
match(args[0]){
898898
case let s: string =>
899-
let name = strings::lpad(s.data, ':', len(s.data) + 1);
899+
let name = strings::lpad(s.data, ':', len(s.data) + 1)!;
900900
defer free(name);
901901
return make_symbol(name);
902902
case let k: symbol =>

impls/hare/mal/env.ha

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export fn env_init(outer: nullable * env = null) *env ={
77
const new = alloc(env {
88
outer = outer,
99
data = hm_init(),
10-
});
10+
})!;
1111

12-
append(gc.memory.envs, new);
12+
append(gc.memory.envs, new)!;
1313
return new;
1414
};
1515

impls/hare/mal/gc.ha

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn finish_memory(memory: memory) void = {
7070

7171
fn mark_hash(hm: hashmap) void = {
7272

73-
append(gc.marked.hashs, hm);
73+
append(gc.marked.hashs, hm)!;
7474
mark(hm.meta);
7575

7676
for(let v .. hm.data){
@@ -85,7 +85,7 @@ fn mark_env(envi: *env) void = {
8585
if(e == envi) return void;
8686
};
8787

88-
append(gc.marked.envs, envi);
88+
append(gc.marked.envs, envi)!;
8989
mark(envi.data);
9090

9191
match(envi.outer){
@@ -114,21 +114,21 @@ fn mark (val: MalType) void = {
114114
for(let x .. gc.marked.vecs){
115115
if(x == v) return void;
116116
};
117-
append(gc.marked.vecs, v);
117+
append(gc.marked.vecs, v)!;
118118
mark_col(v.data);
119119
mark(v.meta);
120120
case let l: list =>
121121
for(let x .. gc.marked.lists){
122122
if(x == l) return void;
123123
};
124-
append(gc.marked.lists, l);
124+
append(gc.marked.lists, l)!;
125125
mark_col(l.data);
126126
mark(l.meta);
127127
case let f: function =>
128128
for(let x .. gc.marked.funcs){
129129
if(x == f) return void;
130130
};
131-
append(gc.marked.funcs, f);
131+
append(gc.marked.funcs, f)!;
132132
mark(f.meta);
133133
mark(f.body);
134134
mark_col(f.args);
@@ -137,14 +137,14 @@ fn mark (val: MalType) void = {
137137
for(let x .. gc.marked.intrinsics){
138138
if(x == i) return void;
139139
};
140-
append(gc.marked.intrinsics, i);
140+
append(gc.marked.intrinsics, i)!;
141141
mark(i.meta);
142142
case let m: macro =>
143143
let m = m:function;
144144
for(let x .. gc.marked.funcs){
145145
if(x == m) return void;
146146
};
147-
append(gc.marked.funcs, m);
147+
append(gc.marked.funcs, m)!;
148148
mark(m.meta);
149149
mark(m.body);
150150
mark_col(m.args);
@@ -164,13 +164,13 @@ fn mark (val: MalType) void = {
164164
for(let x .. gc.marked.strings){
165165
if(x == s) return void;
166166
};
167-
append(gc.marked.strings, s);
167+
append(gc.marked.strings, s)!;
168168
mark(s.meta);
169169
case let a: atom =>
170170
for(let x .. gc.marked.atoms){
171171
if(x == a) return void;
172172
};
173-
append(gc.marked.atoms, a);
173+
append(gc.marked.atoms, a)!;
174174
mark(*a);
175175
case => void;
176176
};

impls/hare/mal/hashmap.ha

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export fn hm_init(gcd: bool = true) hashmap = {
2626
let new: hashmap = alloc(struct {
2727
data: []hmap = [],
2828
meta: MalType = nil,
29-
});
29+
})!;
3030

31-
if(gcd) append(gc.memory.hashs, new);
31+
if(gcd) append(gc.memory.hashs, new)!;
3232

3333
return new;
3434
};
@@ -50,7 +50,7 @@ fn new(
5050
child: [4](size | void) = [void...],
5151
};
5252

53-
append(hm.data, new);
53+
append(hm.data, new)!;
5454

5555
match(p.child) {
5656
case void =>
@@ -180,7 +180,7 @@ fn hm_copy(hm: hashmap, filter: [](string | symbol) = []) hashmap = {
180180

181181
if(len(filter) == 0){
182182
for(let e .. hm.data) {
183-
append(new.data, e);
183+
append(new.data, e)!;
184184
};
185185
} else {
186186
for :map (let e .. hm.data) {

impls/hare/mal/printer.ha

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn print_string(
4343
print_readable: bool
4444
) void = {
4545

46-
let runes = strings::torunes(s.data);
46+
let runes = strings::torunes(s.data)!;
4747

4848

4949
if(!print_readable){

impls/hare/mal/reader.ha

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn read_collection(
153153
case hash_end =>
154154
return unbalanced;
155155
case let form: MalType =>
156-
append(res, form);
156+
append(res, form)!;
157157
continue;
158158
case io::EOF =>
159159
return unexpected_eof;
@@ -180,7 +180,7 @@ fn read_string(s: str) (string | error) = {
180180

181181
let strbuf = memio::dynamic();
182182
defer io::close(&strbuf)!;
183-
let runes = strings::torunes(s);
183+
let runes = strings::torunes(s)!;
184184

185185
for (let i: size = 0; i < len(runes); i += 1) {
186186
let rn = switch (runes[i]) {

impls/hare/mal/types.ha

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export fn make_intrinsic(
5151
const new = alloc(struct {
5252
eval: *fn([]MalType) (MalType | error) = func,
5353
meta: MalType = nil,
54-
});
54+
})!;
5555

56-
append(gc.memory.intrinsics, new);
56+
append(gc.memory.intrinsics, new)!;
5757
return new;
5858
};
5959

@@ -66,7 +66,7 @@ export fn make_func(
6666

6767
let arg_list: []MalType = [];
6868
if(len(args) > 0) {
69-
arg_list = alloc([nil...], len(args));
69+
arg_list = alloc([nil...], len(args))!;
7070
arg_list[0..] = args;
7171
};
7272

@@ -75,9 +75,9 @@ export fn make_func(
7575
envi: *env= envi,
7676
args: []MalType = arg_list,
7777
body: MalType = body,
78-
meta: MalType = nil });
78+
meta: MalType = nil })!;
7979

80-
append(gc.memory.funcs, new);
80+
append(gc.memory.funcs, new)!;
8181
return new;
8282
};
8383

@@ -91,14 +91,14 @@ export fn make_list(s: size, init: []MalType = []) list = {
9191
const new: list = alloc(struct {
9292
data: []MalType = [],
9393
meta: MalType = nil,
94-
});
94+
})!;
9595

9696
if (s == 0) return new;
9797

98-
new.data = alloc([nil...], s);
98+
new.data = alloc([nil...], s)!;
9999
new.data[0..len(init)] = init;
100100

101-
append(gc.memory.lists, new);
101+
append(gc.memory.lists, new)!;
102102
return new;
103103
};
104104

@@ -112,14 +112,14 @@ export fn make_vec(s: size, init: []MalType = []) vector = {
112112
const new: vector = alloc(struct {
113113
data: []MalType = [],
114114
meta: MalType = nil,
115-
});
115+
})!;
116116

117117
if (s == 0) return new;
118118

119-
new.data = alloc([nil...], s);
119+
new.data = alloc([nil...], s)!;
120120
new.data[0..len(init)] = init;
121121

122-
append(gc.memory.vecs, new);
122+
append(gc.memory.vecs, new)!;
123123
return new;
124124
};
125125

@@ -144,22 +144,22 @@ export fn make_symbol(name: str) symbol = {
144144
return s;
145145
};
146146

147-
const new = strings::dup(name): symbol;
147+
const new = strings::dup(name)!: symbol;
148148
hm_add(gc.memory.symbols: hashmap, new, new);
149149

150150
return new;
151151
};
152152

153153
export fn make_string(s: str) string = {
154154

155-
const new_str = strings::dup(s);
155+
const new_str = strings::dup(s)!;
156156

157157
const new = alloc(struct {
158158
data: str = new_str,
159159
meta: MalType = nil,
160-
});
160+
})!;
161161

162-
append(gc.memory.strings, new);
162+
append(gc.memory.strings, new)!;
163163
return new;
164164
};
165165

@@ -170,8 +170,8 @@ fn free_string(s: string) void = {
170170

171171
export fn make_atom(ref: MalType) atom = {
172172

173-
const new = alloc(ref);
174-
append(gc.memory.atoms, new);
173+
const new = alloc(ref)!;
174+
append(gc.memory.atoms, new)!;
175175
return new;
176176
};
177177

impls/hare/step4_if_fn_do.ha

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ fn eval_list(ls: mal::list, env: *mal::env) (mal::MalType | mal::error) = {
112112
let args: []mal::MalType = [];
113113
defer free(args);
114114
for(let arg .. ls.data[1..]){
115-
append(args, eval(arg, env)?);
115+
append(args, eval(arg, env)?)!;
116116
};
117117
return func.eval(args);
118118
case let func: mal::function =>
119119
let args: []mal::MalType = [];
120120
defer free(args);
121121
for(let arg .. ls.data[1..]){
122-
append(args, eval(arg, env)?);
122+
append(args, eval(arg, env)?)!;
123123
};
124124
let local = mal::env_init(func.envi);
125125
mal::env_bind(local, func.args, args);

0 commit comments

Comments
 (0)