test: new codegen tests, rename hello.
This commit is contained in:
parent
53e934c2ab
commit
40f74341f3
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fn foo(x: int) -> int {
|
||||
x * x
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
fn test() {
|
||||
let x = foo(10);
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#[no_mangle]
|
||||
fn test(x: int, y: int) -> int {
|
||||
match x {
|
||||
1 => y,
|
||||
2 => y*2,
|
||||
4 => y*3,
|
||||
_ => 11
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue