Skip to content

Commit 40f7434

Browse files
committed
test: new codegen tests, rename hello.
1 parent 53e934c commit 40f7434

8 files changed

+65
-0
lines changed

Diff for: src/test/codegen/iterate-over-array.cc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdlib.h>
2+
#include <assert.h>
3+
4+
struct slice {
5+
int const *p;
6+
size_t len;
7+
};
8+
9+
extern "C"
10+
size_t test(slice s) {
11+
size_t y = 0;
12+
for (int i = 0; i < s.len; ++i) {
13+
assert(i < s.len);
14+
y += s.p[i];
15+
}
16+
return y;
17+
}

Diff for: src/test/codegen/iterate-over-array.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[no_mangle]
2+
fn test(x: &[int]) -> int {
3+
let mut y = 0;
4+
let mut i = 0;
5+
while (i < x.len()) {
6+
y += x[i];
7+
i += 1;
8+
}
9+
y
10+
}

Diff for: src/test/codegen/scalar-function-call.cc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdlib.h>
2+
3+
size_t foo(size_t x) {
4+
return x * x;
5+
}
6+
7+
extern "C"
8+
void test() {
9+
size_t x = foo(10);
10+
}

Diff for: src/test/codegen/scalar-function-call.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn foo(x: int) -> int {
2+
x * x
3+
}
4+
5+
#[no_mangle]
6+
fn test() {
7+
let x = foo(10);
8+
}

Diff for: src/test/codegen/small-dense-int-switch.cc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdlib.h>
2+
3+
extern "C"
4+
size_t test(size_t x, size_t y) {
5+
switch (x) {
6+
case 1: return y;
7+
case 2: return y*2;
8+
case 4: return y*3;
9+
default: return 11;
10+
}
11+
}

Diff for: src/test/codegen/small-dense-int-switch.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[no_mangle]
2+
fn test(x: int, y: int) -> int {
3+
match x {
4+
1 => y,
5+
2 => y*2,
6+
4 => y*3,
7+
_ => 11
8+
}
9+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)