test: new codegen tests, rename hello.

This commit is contained in:
Graydon Hoare 2013-07-16 17:42:28 -07:00
parent 53e934c2ab
commit 40f74341f3
8 changed files with 65 additions and 0 deletions

View File

@ -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;
}

View File

@ -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
}

View File

@ -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);
}

View File

@ -0,0 +1,8 @@
fn foo(x: int) -> int {
x * x
}
#[no_mangle]
fn test() {
let x = foo(10);
}

View File

@ -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;
}
}

View File

@ -0,0 +1,9 @@
#[no_mangle]
fn test(x: int, y: int) -> int {
match x {
1 => y,
2 => y*2,
4 => y*3,
_ => 11
}
}