Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
03d6936
AST-33: codegen for Word8/16
ggreif Mar 5, 2019
9f9a4dd
generate special code for Word8/16 infectious operations
ggreif Mar 5, 2019
3a12d86
fix embarrassing thinko about Xor
ggreif Mar 6, 2019
f3287ec
oooops, cannot share, type dependent
ggreif Mar 6, 2019
16d81ef
refactoring
ggreif Mar 6, 2019
fb5ae0c
add Word32 test actor
ggreif Mar 6, 2019
489e6f1
Merge remote-tracking branch 'origin/master' into gabor/conversions
ggreif Mar 6, 2019
00777ed
use share_code1 and provide dummy PowOp
ggreif Mar 6, 2019
cae5449
very naive pow for Word32
ggreif Mar 6, 2019
4d7bb4a
silly me
ggreif Mar 6, 2019
c8e3074
fix tests (hint: they look a bit strange)
ggreif Mar 6, 2019
00f5ab2
pow16
ggreif Mar 6, 2019
895ad21
add GC and serialisation support for SmallWord
ggreif Mar 6, 2019
2a2c1e3
third one's the charm: Word8
ggreif Mar 7, 2019
11f9646
finish up demo
ggreif Mar 7, 2019
0bb9d8e
implement codegen for Word8/16 Rotl/Rotr
ggreif Mar 7, 2019
da9f84e
Merge branch 'master' into gabor/conversions
ggreif Mar 7, 2019
ea6caf7
also test Word16 in actors
ggreif Mar 7, 2019
395b402
clamp_shift_amount
ggreif Mar 7, 2019
72b83be
Merge branch 'master' into gabor/conversions
ggreif Mar 8, 2019
94e73d0
bug fixed
ggreif Mar 8, 2019
4271874
refactor
ggreif Mar 8, 2019
31459b1
a bit more of refactoring
ggreif Mar 8, 2019
40c4e87
bit-fiddling doesn't need an environment
ggreif Mar 8, 2019
09ce369
lognot is unary (^)
ggreif Mar 8, 2019
de66184
add Char<->Word32 interpreter conversions
ggreif Mar 8, 2019
97e3682
complation of Char
ggreif Mar 8, 2019
d4e02a0
these pass now
ggreif Mar 8, 2019
b761cb6
Chars are comparable now
ggreif Mar 8, 2019
385715e
inline printW16/32 definitions
ggreif Mar 9, 2019
f73e393
adapt output
ggreif Mar 9, 2019
2cb8ce1
spice up with FileCheck tests
ggreif Mar 9, 2019
fa676b5
add exotic bitwise operations
ggreif Mar 9, 2019
7db75e3
accept success!
ggreif Mar 9, 2019
e7ac92a
implement 'shrs' for Word32
ggreif Mar 9, 2019
292daac
tighten checks
ggreif Mar 9, 2019
22a9ea5
Merge branch 'master' into gabor/conversions
ggreif Mar 9, 2019
98ea8b5
use the 2n+k algorithm for pow
ggreif Mar 9, 2019
9e6b9a1
try go green
ggreif Mar 9, 2019
6cef59a
undo bad change
ggreif Mar 10, 2019
57bc97e
refacor pow generator
ggreif Mar 10, 2019
4781ab6
sanitise left shift
ggreif Mar 10, 2019
269c571
minor tweak
ggreif Mar 10, 2019
40732d6
simplify
ggreif Mar 10, 2019
6d70731
another attempt to go green
ggreif Mar 10, 2019
a82204b
ok files
ggreif Mar 10, 2019
32c105c
no idea where this comes from
ggreif Mar 10, 2019
e6a48b1
262858d Revert "ok files"
ggreif Mar 10, 2019
25cdb78
move helper functions
ggreif Mar 10, 2019
322db4c
review feedback
ggreif Mar 11, 2019
aa8c8da
use load_field/store_field
ggreif Mar 11, 2019
4dcc7ec
use Tagged.obj
ggreif Mar 11, 2019
3d3cbb9
Merge branch 'master' into gabor/conversions
ggreif Mar 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
316 changes: 233 additions & 83 deletions src/compile.ml

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions src/prelude.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ func word32ToNat(n : Word32) : Nat = (prim "Word32->Nat" : Word32 -> Nat) n;
func intToWord32(n : Int) : Word32 = (prim "Int->Word32" : Int -> Word32) n;
func word32ToInt(n : Word32) : Int = (prim "Word32->Int" : Word32 -> Int) n;

func charToWord32(c : Char) : Word32 = (prim "Char->Word32" : Char -> Word32) c;
func word32ToChar(w : Word32) : Char = (prim "Word32->Char" : Word32 -> Char) w;

// Exotic bitwise operations
func shrsWord32(w : Word32, amount : Word32) : Word32 = (prim "shrs" : (Word32, Word32) -> Word32) (w, amount);
func popcntWord32(w : Word32) : Word32 = (prim "popcnt" : Word32 -> Word32) w;
func clzWord32(w : Word32) : Word32 = (prim "clz" : Word32 -> Word32) w;
func ctzWord32(w : Word32) : Word32 = (prim "ctz" : Word32 -> Word32) w;


// This would be nicer as a objects, but lets do them as functions
// until the compiler has a concept of “static objects”
Expand Down Expand Up @@ -141,6 +150,25 @@ let prim = function
in k (Int (Big_int.big_int_of_int i))
| "Word32->Int" -> fun v k -> k (Int (Big_int.big_int_of_int32 (as_word32 v)))

| "Char->Word32" -> fun v k ->
let i = as_char v
in k (Word32 (Word32.of_int_u i))
| "Word32->Char" -> fun v k ->
let i = Conv.of_signed_Word32 (as_word32 v)
in k (Char i)
| "shrs" -> fun v k ->
let w, a = as_pair v in
let i = Word32.shr_s (as_word32 w) (as_word32 a)
in k (Word32 i)
| "popcnt" -> fun v k ->
let i = Word32.popcnt (as_word32 v)
in k (Word32 i)
| "clz" -> fun v k ->
let i = Word32.clz (as_word32 v)
in k (Word32 i)
| "ctz" -> fun v k ->
let i = Word32.ctz (as_word32 v)
in k (Word32 i)
| "print" -> fun v k -> Printf.printf "%s%!" (as_text v); k unit
| "printInt" -> fun v k -> Printf.printf "%d%!" (Int.to_int (as_int v)); k unit
| "Array.init" -> fun v k ->
Expand Down
151 changes: 150 additions & 1 deletion test/run-dfinity/data-params.as
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let a = actor {
printInt(c);
print("\n");
};
incnested(n1 : Nat, (n2 : Nat, n3: Nat)) : () {
incnested(n1 : Nat, (n2 : Nat, n3 : Nat)) : () {
c += n1 + n2 + n3;
printInt(c);
print("\n");
Expand Down Expand Up @@ -72,3 +72,152 @@ a.printLabeled("Foo1: ");
a.printLabeledOpt(?"Foo2: ");
// a.readCounter(func (n : Nat) = { printInt n; print("\n") });
a.incn(10000000000000);


let w32 = actor {
private var c : Word32 = 0;
incn(n : Word32) : () {
c += n;
printInt(word32ToInt(c));
print("\n");
};
incnn(n1 : Word32, n2 : Word32) : () {
c += n1 + n2;
printInt(word32ToInt(c));
print("\n");
};
incnested(n1 : Word32, (n2 : Word32, n3 : Word32)) : () {
c += n1 + n2 + n3;
printInt(word32ToInt(c));
print("\n");
};
incarray(a : [Word32]) : () {
for (i in a.vals()) { c += i };
printInt(word32ToInt(c));
print("\n");
};
incopt(a : ?Word32) : () {
switch a {
case null { c += 1000000 };
case (?a) { c += a };
};
printInt(word32ToInt(c));
print("\n");
};
increcord(a : shared { x : Word32; y : Word32 }) : () {
c += a.x;
c += a.y;
printInt(word32ToInt(c));
print("\n");
};
printCounter() {
printInt(word32ToInt(c));
print("\n");
};
printLabeled(l:Text) {
print l;
printInt(word32ToInt(c));
print("\n");
};
printLabeledOpt(?l:?Text) {
print l;
printInt(word32ToInt(c));
print("\n");
};
readCounter(f : shared Word32 -> ()) : () {
f(c);
};
};


w32.incn(1);
w32.incn(2);
w32.incn(3);
w32.incn(4);
w32.incn(1000);
w32.incnn(5,6);
w32.incnn(2000,3000);
w32.incnested(7,(8,9));
w32.incarray([10,11,12,13]);
w32.incopt(null);
w32.incopt(?14);
w32.increcord(shared {x = 15 : Word32; y = 16 : Word32});
w32.increcord(shared {x = 17 : Word32; y = 18 : Word32; z = 19 : Word32});
w32.printCounter();
w32.printLabeled("Foo1: ");
w32.printLabeledOpt(?"Foo2: ");



let w16 = actor {
private var c : Word16 = 0;
incn(n : Word16) : () {
c += n;
printInt(word16ToInt(c));
print("\n");
};
incnn(n1 : Word16, n2 : Word16) : () {
c += n1 + n2;
printInt(word16ToInt(c));
print("\n");
};
incnested(n1 : Word16, (n2 : Word16, n3 : Word16)) : () {
c += n1 + n2 + n3;
printInt(word16ToInt(c));
print("\n");
};
incarray(a : [Word16]) : () {
for (i in a.vals()) { c += i };
printInt(word16ToInt(c));
print("\n");
};
incopt(a : ?Word16) : () {
switch a {
case null { c += 10000 };
case (?a) { c += a };
};
printInt(word16ToInt(c));
print("\n");
};
increcord(a : shared { x : Word16; y : Word16 }) : () {
c += a.x;
c += a.y;
printInt(word16ToInt(c));
print("\n");
};
printCounter() {
printInt(word16ToInt(c));
print("\n");
};
printLabeled(l:Text) {
print l;
printInt(word16ToInt(c));
print("\n");
};
printLabeledOpt(?l:?Text) {
print l;
printInt(word16ToInt(c));
print("\n");
};
readCounter(f : shared Word16 -> ()) : () {
f(c);
};
};


w16.incn(1);
w16.incn(2);
w16.incn(3);
w16.incn(4);
w16.incn(1000);
w16.incnn(5,6);
w16.incnn(2000,3000);
w16.incnested(7,(8,9));
w16.incarray([10,11,12,13]);
w16.incopt(null);
w16.incopt(?14);
w16.increcord(shared {x = 15 : Word16; y = 16 : Word16});
w16.increcord(shared {x = 17 : Word16; y = 18 : Word16; z = 19 : Word16});
w16.printCounter();
w16.printLabeled("Foo1: ");
w16.printLabeledOpt(?"Foo2: ");
32 changes: 32 additions & 0 deletions test/run-dfinity/ok/data-params.dvm-run.ok
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,35 @@ Top-level code done.
Foo1: 1006171
Foo2: 1006171
1317141083
1
3
6
10
1010
1021
6021
6045
6091
1006091
1006105
1006136
1006171
1006171
Foo1: 1006171
Foo2: 1006171
1
3
6
10
1010
1021
6021
6045
6091
16091
16105
16136
16171
16171
Foo1: 16171
Foo2: 16171
34 changes: 34 additions & 0 deletions test/run-dfinity/ok/data-params.run-ir.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
data-params.as:46.19-46.27: warning, this pattern does not cover all possible values
data-params.as:122.19-122.27: warning, this pattern does not cover all possible values
data-params.as:197.19-197.27: warning, this pattern does not cover all possible values
1
3
6
Expand All @@ -16,3 +18,35 @@ data-params.as:46.19-46.27: warning, this pattern does not cover all possible va
Foo1: 1006171
Foo2: 1006171
10000001006171
1
3
6
10
1010
1021
6021
6045
6091
1006091
1006105
1006136
1006171
1006171
Foo1: 1006171
Foo2: 1006171
1
3
6
10
1010
1021
6021
6045
6091
16091
16105
16136
16171
16171
Foo1: 16171
Foo2: 16171
34 changes: 34 additions & 0 deletions test/run-dfinity/ok/data-params.run-low.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
data-params.as:46.19-46.27: warning, this pattern does not cover all possible values
data-params.as:122.19-122.27: warning, this pattern does not cover all possible values
data-params.as:197.19-197.27: warning, this pattern does not cover all possible values
1
3
6
Expand All @@ -16,3 +18,35 @@ data-params.as:46.19-46.27: warning, this pattern does not cover all possible va
Foo1: 1006171
Foo2: 1006171
10000001006171
1
3
6
10
1010
1021
6021
6045
6091
1006091
1006105
1006136
1006171
1006171
Foo1: 1006171
Foo2: 1006171
1
3
6
10
1010
1021
6021
6045
6091
16091
16105
16136
16171
16171
Foo1: 16171
Foo2: 16171
34 changes: 34 additions & 0 deletions test/run-dfinity/ok/data-params.run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
data-params.as:46.19-46.27: warning, this pattern does not cover all possible values
data-params.as:122.19-122.27: warning, this pattern does not cover all possible values
data-params.as:197.19-197.27: warning, this pattern does not cover all possible values
1
3
6
Expand All @@ -16,3 +18,35 @@ data-params.as:46.19-46.27: warning, this pattern does not cover all possible va
Foo1: 1006171
Foo2: 1006171
10000001006171
1
3
6
10
1010
1021
6021
6045
6091
1006091
1006105
1006136
1006171
1006171
Foo1: 1006171
Foo2: 1006171
1
3
6
10
1010
1021
6021
6045
6091
16091
16105
16136
16171
16171
Foo1: 16171
Foo2: 16171
2 changes: 2 additions & 0 deletions test/run-dfinity/ok/data-params.tc.ok
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
data-params.as:46.19-46.27: warning, this pattern does not cover all possible values
data-params.as:122.19-122.27: warning, this pattern does not cover all possible values
data-params.as:197.19-197.27: warning, this pattern does not cover all possible values
2 changes: 2 additions & 0 deletions test/run-dfinity/ok/data-params.wasm.stderr.ok
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
data-params.as:46.19-46.27: warning, this pattern does not cover all possible values
data-params.as:122.19-122.27: warning, this pattern does not cover all possible values
data-params.as:197.19-197.27: warning, this pattern does not cover all possible values
Loading