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

Commit d5a64eb

Browse files
committed
lang: implement nullary functions and migrate standard library
fixes #14
1 parent b6a2edd commit d5a64eb

File tree

260 files changed

+2210
-1925
lines changed

Some content is hidden

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

260 files changed

+2210
-1925
lines changed

bench/binarytrees/binarytrees-mt.core

Lines changed: 5 additions & 5 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
}
@@ -95,7 +95,7 @@ fun createTree(depth: Int32): TreeNode {
9595
}
9696

9797
fun checkTree(node: TreeNode): Int32 {
98-
if node.left.isNone() {
98+
if node.left.isNone {
9999
return 1i32;
100100
}
101101

bench/binarytrees/binarytrees.core

Lines changed: 2 additions & 2 deletions
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 {
@@ -58,7 +58,7 @@ fun createTree(depth: Int32): TreeNode {
5858
}
5959

6060
fun checkTree(node: TreeNode): Int32 {
61-
if node.left.isNone() {
61+
if node.left.isNone {
6262
return 1i32;
6363
}
6464

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
}

0 commit comments

Comments
 (0)