Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit e40a580

Browse files
committed
WIP nullary functions – typecheck, migrate primitives
work on #14
1 parent cc3f6a9 commit e40a580

File tree

150 files changed

+1399
-1287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+1399
-1287
lines changed

bench/binarytrees/binarytrees-mt.core

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const DEFAULT_THREADS: Int32 = 4i32;
44

55
fun main(): Unit {
66
let maxDepth = if std::argc() > 0i32 {
7-
std::argv(0i32).toInt32().getOrPanic()
7+
std::argv(0i32).toInt32.getOrPanic()
88
} else {
99
DEFAULT_DEPTH
1010
};
1111

1212
let number_threads = if std::argc() > 1i32 {
13-
std::argv(1i32).toInt32().getOrPanic()
13+
std::argv(1i32).toInt32.getOrPanic()
1414
} else {
1515
DEFAULT_THREADS
1616
};
@@ -24,7 +24,7 @@ fun main(): Unit {
2424
var i = 0i32;
2525
let threads = List[std::Thread]::new();
2626
let nextDepth = std::AtomicInt32::new(MIN_DEPTH);
27-
let results = Array[String]::fill((maxDepth - MIN_DEPTH).toInt64() / 2i64 + 1i64, "");
27+
let results = Array[String]::fill((maxDepth - MIN_DEPTH).toInt64 / 2i64 + 1i64, "");
2828

2929
while i < number_threads {
3030
let thread = std::thread::spawn(||: Unit {
@@ -62,7 +62,7 @@ impl TreeThread {
6262
let depth = self.nextDepth.fetchAdd(2i32);
6363
if depth > self.maxDepth { return }
6464
let result = loops(self.maxDepth, depth);
65-
self.results((depth - MIN_DEPTH).toInt64() / 2i64) = result;
65+
self.results((depth - MIN_DEPTH).toInt64 / 2i64) = result;
6666
}
6767
}
6868
}

bench/binarytrees/binarytrees.core

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fun main(): Unit {
22
var maxDepth = 6i32;
33

44
if std::argc() > 0i32 {
5-
maxDepth = std::argv(0i32).toInt32().getOrPanic();
5+
maxDepth = std::argv(0i32).toInt32.getOrPanic();
66
}
77

88
if 6i32 > maxDepth {

bench/falsesharing/falsesharing.core

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ fun main(): Unit {
33
println("usage: falsesharing <threads> <iterations>");
44
}
55

6-
let threads = argv(0).toInt64().getOrPanic();
7-
let iterations = argv(1).toInt32().getOrPanic();
6+
let threads = argv(0).toInt64.getOrPanic();
7+
let iterations = argv(1).toInt32.getOrPanic();
88
let objects = construct(8096i64);
99
forceCollect();
1010

@@ -22,14 +22,14 @@ fun construct(size: Int64): Array[Foo] {
2222

2323
var i = 0i64;
2424

25-
while i < objects.size() {
25+
while i < objects.size {
2626
objects(i) = Foo(nil, nil);
2727
i = i + 1i64;
2828
}
2929

3030
i = 0i64;
3131

32-
while i < objects.size() {
32+
while i < objects.size {
3333
if i == 0i64 {
3434
objects(0i64).left = objects(size-1i64);
3535
} else {
@@ -50,7 +50,7 @@ fun construct(size: Int64): Array[Foo] {
5050

5151
class MyThread(let thread_idx: Int64, let threads: Int64, let iters: Int32, let objects: Array[Foo]) extends Thread {
5252
@override fun run(): Unit {
53-
let size = self.objects.size();
53+
let size = self.objects.size;
5454
let objects_per_thread = size / self.threads;
5555
assert(size.remainder(self.threads) == 0i64);
5656
let start_idx = self.thread_idx * objects_per_thread;

bench/fannkuchredux/fannkuchredux.core

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
fun main(): Unit {
22
var n = 7i32;
3-
if std::argc() > 0i32 { n = std::argv(0i32).toInt32().getOrPanic(); }
3+
if std::argc() > 0i32 { n = std::argv(0i32).toInt32.getOrPanic(); }
44
println("Pfannkuchen ("+n.toString()+") = " + fannkuch(n).toString());
55
}
66

77
fun fannkuch(n: Int32): Int32 {
8-
let perm = Array[Int32]::fill(n.toInt64(), 0i32);
9-
let perm1 = Array[Int32]::fill(n.toInt64(), 0i32);
10-
let count = Array[Int32]::fill(n.toInt64(), 0i32);
8+
let perm = Array[Int32]::fill(n.toInt64, 0i32);
9+
let perm1 = Array[Int32]::fill(n.toInt64, 0i32);
10+
let count = Array[Int32]::fill(n.toInt64, 0i32);
1111
var maxFlipsCount = 0i32;
1212
var permCount = 0i32;
1313
var checksum = 0i32;
1414

1515
var i = 0i32;
1616
while i < n {
17-
perm1(i.toInt64()) = i;
17+
perm1(i.toInt64) = i;
1818
i = i + 1i32;
1919
}
2020

2121
var r = n;
2222

2323
while true {
2424
while r != 1i32 {
25-
count((r-1i32).toInt64()) = r;
25+
count((r-1i32).toInt64) = r;
2626
r = r - 1i32;
2727
}
2828

2929
var i = 0i32;
3030
while i < n {
31-
perm(i.toInt64()) = perm1(i.toInt64());
31+
perm(i.toInt64) = perm1(i.toInt64);
3232
i = i + 1i32;
3333
}
3434

@@ -40,9 +40,9 @@ fun fannkuch(n: Int32): Int32 {
4040

4141
var i = 0i32;
4242
while i < k2 {
43-
let temp = perm(i.toInt64());
44-
perm(i.toInt64()) = perm((k-i).toInt64());
45-
perm((k-i).toInt64()) = temp;
43+
let temp = perm(i.toInt64);
44+
perm(i.toInt64) = perm((k-i).toInt64);
45+
perm((k-i).toInt64) = temp;
4646

4747
i = i + 1i32;
4848
}
@@ -71,15 +71,15 @@ fun fannkuch(n: Int32): Int32 {
7171

7272
while i < r {
7373
let j = i + 1i32;
74-
perm1(i.toInt64()) = perm1(j.toInt64());
74+
perm1(i.toInt64) = perm1(j.toInt64);
7575
i = j;
7676
}
7777

78-
perm1(r.toInt64()) = perm0;
78+
perm1(r.toInt64) = perm0;
7979

80-
count(r.toInt64()) = count(r.toInt64()) - 1i32;
80+
count(r.toInt64) = count(r.toInt64) - 1i32;
8181

82-
if count(r.toInt64()) > 0i32 {
82+
if count(r.toInt64) > 0i32 {
8383
continue = false;
8484
} else {
8585
r = r + 1i32;

bench/gcbench/gcbench.core

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fun timeConstruction(depth: Int32): Unit {
6565
}
6666

6767
let finish = timestamp();
68-
let msecs = (finish - start).toFloat32() / 1000.0f32 / 1000.0f32;
68+
let msecs = (finish - start).toFloat32 / 1000.0f32 / 1000.0f32;
6969
println("\tTop down construction took " + msecs.toString() + "ms");
7070

7171
let start = finish;
@@ -78,7 +78,7 @@ fun timeConstruction(depth: Int32): Unit {
7878
}
7979

8080
let finish = timestamp();
81-
let msecs = (finish - start).toFloat32() / 1000.0f32 / 1000.0f32;
81+
let msecs = (finish - start).toFloat32 / 1000.0f32 / 1000.0f32;
8282
println("\tBottom up construction took " + msecs.toString() + "ms");
8383
}
8484

@@ -88,7 +88,7 @@ fun main(): Unit {
8888
std::exit(1i32);
8989
}
9090

91-
let depth = argv(0i32).toInt32().getOrPanic();
91+
let depth = argv(0i32).toInt32.getOrPanic();
9292

9393
stretchTreeDepth = depth+1i32;
9494
longLivedTreeDepth = depth;
@@ -103,12 +103,12 @@ fun main(): Unit {
103103
populate(longLivedTreeDepth, longLivedTree);
104104

105105
println("Creating a long-lived array of " + kArraySize.toString() + " doubles");
106-
let array = Array[Float64]::fill(kArraySize.toInt64(), 0.0);
106+
let array = Array[Float64]::fill(kArraySize.toInt64, 0.0);
107107

108108
var i = 0i32;
109109

110110
while i < kArraySize / 2i32 {
111-
array(i.toInt64()) = 1.0/i.toFloat64();
111+
array(i.toInt64) = 1.0/i.toFloat64;
112112
i = i + 1i32;
113113
}
114114

@@ -121,6 +121,6 @@ fun main(): Unit {
121121

122122
assert(longLivedTree.i == 0i32 && array(1000i64) == 1.0/1000.0);
123123
let finish = timestamp();
124-
let elapsed = (finish - start).toFloat32() / 1000.0f32 / 1000.0f32;
124+
let elapsed = (finish - start).toFloat32 / 1000.0f32 / 1000.0f32;
125125
println("Completed in " + elapsed.toString() + "ms.");
126126
}

bench/gcold/gcold.core

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fun heightToNodes(h: Int32): Int64 {
6060
}
6161

6262
fun heightToBytes(h: Int32): Int64 {
63-
return BYTES_PER_NODE.toInt64() * heightToNodes(h);
63+
return BYTES_PER_NODE.toInt64 * heightToNodes(h);
6464
}
6565

6666
fun nodesToHeight(nnodes: Int64): Int32 {
@@ -76,7 +76,7 @@ fun nodesToHeight(nnodes: Int64): Int32 {
7676
}
7777

7878
fun bytesToHeight(bytes: Int64): Int32 {
79-
return nodesToHeight(bytes / BYTES_PER_NODE.toInt64());
79+
return nodesToHeight(bytes / BYTES_PER_NODE.toInt64);
8080
}
8181

8282
fun makeTree(h: Int32): TreeNode {
@@ -91,7 +91,7 @@ fun makeTree(h: Int32): TreeNode {
9191
}
9292

9393
fun initialize(): Unit {
94-
let ntrees = (size * MEG).toInt64() / treeSize;
94+
let ntrees = (size * MEG).toInt64 / treeSize;
9595
let default = TreeNode(Option[TreeNode]::None, Option[TreeNode]::None, 0i32);
9696
trees = Array[TreeNode]::fill(ntrees, default);
9797

@@ -133,17 +133,17 @@ fun replaceTreeWork(full: TreeNode, partial: TreeNode, dir: Bool): Unit {
133133

134134
if canGoLeft && canGoRight {
135135
if dir {
136-
replaceTreeWork(full.left.getOrPanic(), partial, dir.not());
136+
replaceTreeWork(full.left.getOrPanic(), partial, dir.not);
137137
} else {
138-
replaceTreeWork(full.right.getOrPanic(), partial, dir.not());
138+
replaceTreeWork(full.right.getOrPanic(), partial, dir.not);
139139
}
140-
} else if canGoLeft.not() && canGoRight.not() {
140+
} else if canGoLeft.not && canGoRight.not {
141141
if dir {
142142
full.left = Option[TreeNode]::Some(partial);
143143
} else {
144144
full.right = Option[TreeNode]::Some(partial);
145145
}
146-
} else if canGoLeft.not() {
146+
} else if canGoLeft.not {
147147
full.left = Option[TreeNode]::Some(partial);
148148
} else {
149149
full.right = Option[TreeNode]::Some(partial);
@@ -162,10 +162,10 @@ fun oldGenAlloc(n: Int64): Unit {
162162

163163
var i = 0i64;
164164
while i < full {
165-
trees(where.toInt64()) = makeTree(treeHeight);
165+
trees(where.toInt64) = makeTree(treeHeight);
166166
where = where + 1i32;
167167

168-
if where.toInt64() == trees.size() {
168+
if where.toInt64 == trees.size() {
169169
where = 0i32;
170170
}
171171

@@ -175,10 +175,10 @@ fun oldGenAlloc(n: Int64): Unit {
175175
while partial > INSIGNIFICANT {
176176
let h = bytesToHeight(partial);
177177
let newTree = makeTree(h);
178-
replaceTree(trees(where.toInt64()), newTree);
178+
replaceTree(trees(where.toInt64), newTree);
179179
where = where + 1i32;
180180

181-
if where.toInt64() == trees.size() {
181+
if where.toInt64 == trees.size() {
182182
where = 0i32;
183183
}
184184

@@ -187,13 +187,13 @@ fun oldGenAlloc(n: Int64): Unit {
187187
}
188188

189189
fun oldGenSwapSubtrees(): Unit {
190-
let index1 = rnd.nextInt32WithBound(trees.size().toInt32());
191-
let index2 = rnd.nextInt32WithBound(trees.size().toInt32());
190+
let index1 = rnd.nextInt32WithBound(trees.size().toInt32);
191+
let index2 = rnd.nextInt32WithBound(trees.size().toInt32);
192192
let depth = rnd.nextInt32WithBound(treeHeight);
193193
var path = rnd.nextInt32();
194194

195-
var tn1 = trees(index1.toInt64());
196-
var tn2 = trees(index2.toInt64());
195+
var tn1 = trees(index1.toInt64);
196+
var tn2 = trees(index2.toInt64);
197197

198198
var i = 0i32;
199199

@@ -233,7 +233,7 @@ fun oldGenMut(n: Int64): Unit {
233233

234234
fun doMutWork(n: Int64): Unit {
235235
var sum = 0i32;
236-
let limit = workUnits.toInt64() * n / 10i64;
236+
let limit = workUnits.toInt64 * n / 10i64;
237237

238238
var k = 0i64;
239239

@@ -242,16 +242,16 @@ fun doMutWork(n: Int64): Unit {
242242
k = k + 1i64;
243243
}
244244

245-
mutatorSum = mutatorSum + sum.toInt64();
245+
mutatorSum = mutatorSum + sum.toInt64;
246246
}
247247

248248
fun doYoungGenAlloc(n: Int64, nwords: Int32): Unit {
249249
let nbytes = nwords * BYTES_PER_WORD;
250250
var allocated = 0i64;
251251

252252
while allocated < n {
253-
aexport = Array[Int64]::zero(nwords.toInt64());
254-
allocated = allocated + nbytes.toInt64();
253+
aexport = Array[Int64]::zero(nwords.toInt64);
254+
allocated = allocated + nbytes.toInt64;
255255
}
256256

257257
youngBytes = youngBytes + allocated;
@@ -262,8 +262,8 @@ fun doStep(n: Int64): Unit {
262262

263263
doYoungGenAlloc(n, WORDS_DEAD);
264264
doMutWork(n);
265-
oldGenAlloc(n / promoteRate.toInt64());
266-
oldGenMut(Int64::max(0i64, (mutations + ptrMutRate.toInt64()) - actuallyMut));
265+
oldGenAlloc(n / promoteRate.toInt64);
266+
oldGenMut(Int64::max(0i64, (mutations + ptrMutRate.toInt64) - actuallyMut));
267267
}
268268

269269
fun main(): Unit {
@@ -281,11 +281,11 @@ fun main(): Unit {
281281

282282
treeSize = heightToBytes(treeHeight);
283283

284-
size = std::argv(0i32).toInt32().getOrPanic();
285-
workUnits = std::argv(1i32).toInt32().getOrPanic();
286-
promoteRate = std::argv(2i32).toInt32().getOrPanic();
287-
ptrMutRate = std::argv(3i32).toInt32().getOrPanic();
288-
steps = std::argv(4i32).toInt32().getOrPanic();
284+
size = std::argv(0i32).toInt32.getOrPanic();
285+
workUnits = std::argv(1i32).toInt32.getOrPanic();
286+
promoteRate = std::argv(2i32).toInt32.getOrPanic();
287+
ptrMutRate = std::argv(3i32).toInt32.getOrPanic();
288+
steps = std::argv(4i32).toInt32.getOrPanic();
289289

290290
println("GCOld: version 1.0");
291291
println(size.toString() + " megabytes of live storage");
@@ -306,28 +306,28 @@ fun main(): Unit {
306306
var step = 0i32;
307307

308308
while step < steps {
309-
doStep(MEG.toInt64());
309+
doStep(MEG.toInt64);
310310
step = step + 1i32;
311311
}
312312

313313
let end = std::timestamp();
314-
let secs = (end - start).toFloat32() / 1000.0f32 / 1000.0f32 / 1000.0f32;
314+
let secs = (end - start).toFloat32 / 1000.0f32 / 1000.0f32 / 1000.0f32;
315315

316316
checkTrees();
317317

318318
println("\nTook " + secs.toString() + " sec in steady state.");
319319
println("Allocated " + steps.toString() + " Mb of young gen garbage"
320-
+ " (= " + (steps.toFloat32() / secs).toString() + " Mb/sec)");
320+
+ " (= " + (steps.toFloat32 / secs).toString() + " Mb/sec)");
321321
println(" (actually allocated "
322-
+ (youngBytes.toFloat32() / MEG.toFloat32()).toString() + " megabytes)");
323-
let promoted = steps.toFloat32() / promoteRate.toFloat32();
322+
+ (youngBytes.toFloat32 / MEG.toFloat32).toString() + " megabytes)");
323+
let promoted = steps.toFloat32 / promoteRate.toFloat32;
324324
println("Promoted " + promoted.toString()
325325
+ " Mb (= " + (promoted / secs).toString() + " Mb/sec)");
326-
println(" (actually promoted " + ((nodes * BYTES_PER_NODE.toInt64()).toFloat32() / MEG.toFloat32()).toString() + " megabytes)");
326+
println(" (actually promoted " + ((nodes * BYTES_PER_NODE.toInt64).toFloat32 / MEG.toFloat32).toString() + " megabytes)");
327327

328328
if ptrMutRate != 0i32 {
329329
println("Mutated " + actuallyMut.toString() +
330-
" pointers (= " + (actuallyMut.toFloat32() / secs).toString() + " ptrs/sec)");
330+
" pointers (= " + (actuallyMut.toFloat32 / secs).toString() + " ptrs/sec)");
331331
}
332332

333333
println("Checksum = " + (mutatorSum + aexport.size()).toString());

0 commit comments

Comments
 (0)