Skip to content

Commit 0aea5b9

Browse files
authored
Merge pull request #1979 from andrew-johnson-4/lmcommon-start-merging-lib12-fdsuiiii
Lmcommon start merging lib12 fdsuiiii
2 parents cec77d4 + a375b27 commit 0aea5b9

10 files changed

Lines changed: 2864 additions & 2579 deletions

File tree

BOOTSTRAP/cli.c

Lines changed: 2725 additions & 2578 deletions
Large diffs are not rendered by default.

LM23COMMON/type-definition.lsts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ let .retain(t: Type): Type = (
3131
};
3232
t
3333
);
34+
35+
# TODO: remove
36+
let .release(tt: x[]): Nil = ();
37+
let .retain(tt: x[]): x[] = tt;

PLUGINS/FRONTEND/LSTS/lsts-parse.lsts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ let lsts-parse-type-conjugate(tokens: List<Token>): Tuple<Type,List<Token>> = (
363363
};
364364
if not(config-v3) and base==c"OwnedData" and args.length==1 {
365365
head(args);
366+
} else if base==c"CompatOwnedData" and args.length==1 {
367+
t1(c"OwnedData",head(args));
368+
} else if base==c"CompatMustRetain" and args.length==0 {
369+
t0(c"MustRetain");
370+
} else if base==c"CompatMustRelease" and args.length==0 {
371+
t0(c"MustRelease");
366372
} else TGround ( base, close(args) );
367373
};
368374
while lsts-parse-head(tokens) == c"[" or lsts-parse-head(tokens)==c"?" {
@@ -1093,7 +1099,6 @@ let lsts-parse-let(tokens: List<Token>): (AST, List<Token>) = (
10931099
} else {
10941100
mk-glb( with-location(mk-token(name),loc), return-term );
10951101
};
1096-
if not(config-v3) and (name==c".retain" or name==c".release") then rvalue = mk-nil();
10971102
(rvalue, tokens)
10981103
);
10991104

lib/std/default.lsts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ import std/cmp.lsts;
3333
import std/print.lsts;
3434
import std/collections.lsts;
3535
import std/regex.lsts;
36+
import std/phi.lsts;
37+
import std/owned-data.lsts;

lib/std/list.lsts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,7 @@ let deep-hash(ts: List<t>): U64 = (
197197
for list t0 in ts { return = return + deep-hash(t0); };
198198
return;
199199
);
200+
201+
# TODO: remove
202+
let .release(tt: List<x>): Nil = ();
203+
let .retain(tt: List<x>): List<x> = tt;

lib/std/minimal.lsts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ import std/regex.lsts;
3030
import std/cmp.lsts;
3131
import std/print.lsts;
3232
import std/collections.lsts;
33+
import std/owned-data.lsts;
34+
import std/phi.lsts;

lib/std/owned-data.lsts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
type OwnedData<t> = {
3+
reference-count: USize,
4+
occupied: USize,
5+
capacity: USize,
6+
data: t[]+FlexibleArrayMember
7+
};
8+
9+
let mk-owned-data(tt: Type<t>, capacity: USize, occupied: USize): CompatOwnedData<t>[] = (
10+
let od = safe-alloc(
11+
# TODO: make sizeof return USize
12+
(sizeof(CompatOwnedData<t>) as USize) + (sizeof(t) as USize) * capacity,
13+
type(CompatOwnedData<t>)
14+
);
15+
od.reference-count = 1;
16+
od.occupied = occupied;
17+
od.capacity = capacity;
18+
od
19+
);
20+
21+
let mk-owned-data(tt: Type<t>, capacity: USize): CompatOwnedData<t>[] = (
22+
mk-owned-data(tt, capacity, 0)
23+
);
24+
25+
let $"[]"(od: CompatOwnedData<t>[], idx: USize): t = (
26+
if (od as USize)==0
27+
then fail(c"OwnedData [] Access Null Pointer");
28+
if idx >= od.occupied then fail("OwnedData [\{idx}] Index Access Out of Bounds");
29+
od.data[idx]
30+
);
31+
32+
let $"set[]"(od: CompatOwnedData<t>[], idx: USize, val: t): Nil = (
33+
if (od as USize)==0
34+
then fail(c"OwnedData set[] Access Null Pointer");
35+
if idx >= od.occupied then fail("OwnedData set[\{idx}] Index Access Out of Bounds");
36+
if type(t) <: type(MustRelease) then od.data[idx].release;
37+
od.data[idx] = val;
38+
);
39+
40+
let .push(od: CompatOwnedData<t>[], d: t): Nil = (
41+
if (od as USize)==0
42+
then fail(c"OwnedData .push Into Null Pointer");
43+
if od.occupied >= od.capacity
44+
then fail(c"OwnedData .push Exceeds Maximum Length");
45+
od.data[od.occupied] = d;
46+
od.occupied = od.occupied + 1;
47+
);
48+
49+
let .pop(od: CompatOwnedData<t>[]): t = (
50+
if (od as USize)==0
51+
then fail(c"OwnedData .pop From Null Pointer");
52+
if od.occupied == 0
53+
then fail(c"OwnedData .pop From Empty Data");
54+
od.occupied = od.occupied - 1;
55+
od.data[od.occupied]
56+
);
57+
58+
let open(od: CompatOwnedData<t>[]): t = (
59+
od[0];
60+
);
61+
62+
let close-owned(d: t): CompatOwnedData<t>[] = (
63+
let od = mk-owned-data(type(t), 1);
64+
od.push(d);
65+
od
66+
);
67+
68+
let .release(od: CompatOwnedData<t>[]): Nil = (
69+
if (od as USize)!=0 {
70+
if od.reference-count==0 then fail(c"OwnedData.release called when reference count is already zero. This object has already been freed!");
71+
od.reference-count = od.reference-count - 1;
72+
if od.reference-count == 0 {
73+
if type(t) <: type(MustRelease) {
74+
let dlo = 0_sz;
75+
let dhi = od.occupied;
76+
while dlo < dhi {
77+
od.data[dlo].release;
78+
dlo = dlo + 1;
79+
};
80+
};
81+
safe-free(od);
82+
};
83+
};
84+
);
85+
86+
let .retain(od: CompatOwnedData<t>[]): Nil = (
87+
if (od as USize)!=0 {
88+
if od.reference-count==0 then fail(c"OwnedData.retain called when reference count is zero. This object has already been freed!");
89+
od.reference-count = od.reference-count + 1;
90+
}
91+
);

lib/std/phi.lsts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
type phi MustRelease = ToRelease{ promise:'a } | Released;
3+
4+
let :Blob mark-as-released(x: x+(MustRelease::ToRelease<'a> ~> MustRelease::Released)+MustNotRetain): Nil = (
5+
$":frame"($":frame"(x));
6+
$":expression"($":expression"(x));
7+
);
8+
let :Blob mark-as-released(x: x+(MustRelease::Released ~> MustRelease::Released)+MustNotRetain): Nil = (
9+
$":frame"($":frame"(x));
10+
$":expression"($":expression"(x));
11+
);
12+
let :Blob mark-as-released(x: x): Nil = (
13+
$":frame"($":frame"(x));
14+
$":expression"($":expression"(x));
15+
);
16+
17+
let :Blob destroy(x: x+MustNotRetain): Nil = (
18+
$":frame"();
19+
$":expression"(l"memset(&"; $":expression"(x); l",0,sizeof "; $":expression"(x); l");");
20+
);
21+

lib/std/vector.lsts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,6 @@ let deep-hash(ts: Vector<t>): U64 = (
262262
# ignore, don't port to lib2
263263
# for compatibility in lmcommon
264264
let .buffer-into-string(c: Vector<U8>): Vector<U8> = c;
265+
266+
let .release(v: Vector<x>): Nil = ();
267+
let .retain(v: Vector<x>): Vector<x> = v;

lib2/core/owned-data.lsts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ let open(od: OwnedData<t>[]): t = (
5959
od[0];
6060
);
6161

62+
let close-owned(d: t): OwnedData<t>[] = (
63+
let od = mk-owned-data(type(t), 1);
64+
od.push(d);
65+
od
66+
);
67+
6268
let close(d: t): OwnedData<t>[] = (
6369
let od = mk-owned-data(type(t), 1);
6470
od.push(d);

0 commit comments

Comments
 (0)