codegen basics
This commit is contained in:
parent
a62432bfbb
commit
c9a7493006
15 changed files with 1151 additions and 50 deletions
16
tests/basic_types.c
Normal file
16
tests/basic_types.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void);
|
||||
|
||||
|
||||
int main(void) {
|
||||
int x = 5;
|
||||
float y = 10.500000;
|
||||
bool z = true;
|
||||
char* s = "hello";
|
||||
return x;
|
||||
}
|
||||
|
||||
21
tests/control_flow.c
Normal file
21
tests/control_flow.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void);
|
||||
|
||||
|
||||
int main(void) {
|
||||
if (true) {
|
||||
1;
|
||||
} else {
|
||||
0;
|
||||
}
|
||||
int i = 0;
|
||||
while ((i < 5)) {
|
||||
i = (i + 1);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
19
tests/structs.c
Normal file
19
tests/structs.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
struct Point {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
int main(void);
|
||||
|
||||
|
||||
int main(void) {
|
||||
struct Point p = (struct Point){ .x = 5, .y = 10 };
|
||||
struct Person person = (struct Person){ .name = "Alice", .age = 30 };
|
||||
return (p.x + person.age);
|
||||
}
|
||||
|
||||
|
|
@ -9,8 +9,8 @@ struct Person<T>
|
|||
age: T,
|
||||
end
|
||||
|
||||
fn main() -> int do
|
||||
fn main() -> int do
|
||||
let p = Point { x: 5, y: 10 };
|
||||
let person = Person { name: "Alice", age: 30 };
|
||||
p.x
|
||||
p.x + person.age
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,5 +13,7 @@ impl Number : Show
|
|||
end
|
||||
|
||||
fn main() -> int do
|
||||
42
|
||||
let number = Number {value: 40};
|
||||
number.show();
|
||||
0
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue