-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.tin
62 lines (50 loc) · 1.43 KB
/
example.tin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
i32 a = 12;
i32 b = 34;
ptr i8 prompt = "Input a number: ";
fn i32 add(i32 x, i32 y)
{
i32 result = x + y;
return result;
}
fn i32 main
{
asm "ld t0,28(s0)";
ptr void example_ptr;
alloc example_ptr 32;
i32 result;
print prompt;
i32 choice; // new empty var
input choice; // initialise it to user input
if (choice > 5)
{
result = add(a, choice);
}
else if (choice < 3)
{
result = add(b, choice);
}
else
{
result = add(7, choice);
}
print result; // inbuilt keyword
free example_ptr;
return 0;
}
/*
- Rust style data types
- New inbuilt keywords instead of functions:
- alloc [pointer variable name] [n];
Stores a pointer to n bytes in memory
- asm [string];
Passes the given string directly to the backend, treated as assembly code.
- free [pointer variable name];
Frees an alloc'd pointer
- input [variable name];
Initialises the variable by immediately asking the user to input its value.
- print [string]
- print [variable name];
Outputs the value of the variable
Different implementations are picked at compile time depending on the data type. i.e. string or integer and the target (jupiter/linux/freertos)
If a feature is not possible on the selected target such as embedded hardware, error out.
*/