Skip to content

test: new codegen tests, rename hello. #7839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions src/test/codegen/iterate-over-array.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdlib.h>
#include <assert.h>

struct slice {
int const *p;
size_t len;
};

extern "C"
size_t test(slice s) {
size_t y = 0;
for (int i = 0; i < s.len; ++i) {
assert(i < s.len);
y += s.p[i];
}
return y;
}
10 changes: 10 additions & 0 deletions src/test/codegen/iterate-over-array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[no_mangle]
fn test(x: &[int]) -> int {
let mut y = 0;
let mut i = 0;
while (i < x.len()) {
y += x[i];
i += 1;
}
y
}
10 changes: 10 additions & 0 deletions src/test/codegen/scalar-function-call.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdlib.h>

size_t foo(size_t x) {
return x * x;
}

extern "C"
void test() {
size_t x = foo(10);
}
8 changes: 8 additions & 0 deletions src/test/codegen/scalar-function-call.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn foo(x: int) -> int {
x * x
}

#[no_mangle]
fn test() {
let x = foo(10);
}
11 changes: 11 additions & 0 deletions src/test/codegen/small-dense-int-switch.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdlib.h>

extern "C"
size_t test(size_t x, size_t y) {
switch (x) {
case 1: return y;
case 2: return y*2;
case 4: return y*3;
default: return 11;
}
}
9 changes: 9 additions & 0 deletions src/test/codegen/small-dense-int-switch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[no_mangle]
fn test(x: int, y: int) -> int {
match x {
1 => y,
2 => y*2,
4 => y*3,
_ => 11
}
}
File renamed without changes.
File renamed without changes.