Skip to content

Commit 615bf58

Browse files
committedAug 3, 2024
porting from gitlab
0 parents  commit 615bf58

13 files changed

+188
-0
lines changed
 

‎.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
/target/
4+
5+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7+
Cargo.lock
8+
9+
# These are backup files generated by rustfmt
10+
**/*.rs.bk
11+
12+
**/*.exe
13+
osmon

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Osmon
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# osmon-examples
2+
3+
The examples of Osmon programming language

‎const_func.osm

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
///
2+
/// run this example with --consteval or with -O3
3+
///
4+
import "std/libc.osm"
5+
6+
constexpr func fac(x: i32) i32 {
7+
if x == 0 {
8+
return 1;
9+
} else {
10+
return fac(x - 1) * x;
11+
}
12+
13+
return -1;
14+
}
15+
16+
pub func main() i32 {
17+
var n = fac(5);
18+
printf("%i\n",n);
19+
return 0;
20+
}

‎constexpr.osm

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
constexpr TEST = x * 2
2+
3+
extern func printf(fmt: *char,...) void;
4+
5+
pub func main() i32 {
6+
7+
var x = 4
8+
printf("%i\n",TEST)
9+
10+
11+
return 0;
12+
}

‎factorial.osm

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func fac(x: i32) i32 {
2+
if x == 0 {
3+
return 1;
4+
} else {
5+
return fac(x - 1) * x;
6+
}
7+
8+
return 0; // gccjit gives error on unterminated blocks,place return there
9+
10+
}
11+
12+
pub func main() i32 {
13+
return fac(5);
14+
}

‎function_overloading.osm

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import "std/libc.osm"
2+
3+
pub func print(f: f64) void {
4+
printf("%f\n",f);
5+
return;
6+
}
7+
8+
pub func print(i: i32) void {
9+
printf("%i\n",i);
10+
11+
return;
12+
}
13+
14+
pub func print(str: *char) void {
15+
printf("%s\n",str);
16+
return;
17+
}
18+
19+
pub func print(s: *u8) void {
20+
printf("%p\n",s);
21+
22+
return;
23+
}
24+
25+
pub func main() i32 {
26+
print(0.0);
27+
print(0);
28+
print("Hello,world!");
29+
return 0;
30+
}

‎globals.osm

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extern func printf(fmt: *char,...) i32;
2+
3+
var string: *char = "Hello,world!";
4+
5+
func f() i32 {
6+
string = "Hi!";
7+
8+
return 0;
9+
}
10+
11+
pub func main() i32 {
12+
printf("%s\n",string);
13+
14+
f();
15+
16+
printf("%s\n",string);
17+
18+
return 0;
19+
}

‎hello_world.osm

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extern func printf(fmt: *char,...) void;
2+
3+
pub func main() i32 {
4+
printf("Hello,world!\n");
5+
return 0;
6+
}

‎imports/child.osm

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub func fac(x: i32) i32 {
2+
if x == 0 {
3+
return 1;
4+
} else {
5+
return fac(x - 1) * x;
6+
}
7+
8+
return 0;
9+
}

‎imports/main.osm

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "child.osm"
2+
3+
extern func printf(fmt: *char,...) void;
4+
5+
pub func main() i32 {
6+
var f = fac(6);
7+
printf("%i\n", f);
8+
return fac(5);
9+
}

‎struct_creation.osm

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Point {
2+
x: i32,
3+
y: i32
4+
}
5+
6+
pub func main() i32 {
7+
var p: Point = Point {x: 0,y: 27};
8+
p.x = 25;
9+
return p.y;
10+
}

‎structures.osm

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extern func printf(fmt: *char,...) void;
2+
extern func calloc(c: i32,size: i32) *u8;
3+
4+
pub struct Point {
5+
x: i32,
6+
y: i32
7+
}
8+
9+
pub func point_print(p: *Point) void {
10+
printf("(%i;%i)\n",p.x,p.y);
11+
return;
12+
}
13+
14+
pub func main() i32 {
15+
var p: *Point;
16+
p = calloc(1,8) as *Point;
17+
p.x = 3;
18+
p.y = 4;
19+
point_print(p);
20+
printf("0x%lx\n",17179869187L);
21+
return 0;
22+
}

0 commit comments

Comments
 (0)
Please sign in to comment.