aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorgingerBill <ginger.bill.22@gmail.com>2016-08-15 14:54:45 +0100
committergingerBill <ginger.bill.22@gmail.com>2016-08-15 15:02:45 +0100
commitdcbb2fcfbdbd3b35ddc44a4c542b7c6375e47214 (patch)
tree1670d1ea683c78be063649685c601a17c1dcb025 /examples
parent3ed75b22a357292393618fc684b18a1d167f4eb7 (diff)
Full Unicode Support
Diffstat (limited to 'examples')
-rw-r--r--examples/basic.odin6
-rw-r--r--examples/main.ll98
-rw-r--r--examples/main.odin9
3 files changed, 44 insertions, 69 deletions
diff --git a/examples/basic.odin b/examples/basic.odin
index 8177ca4da..12418553a 100644
--- a/examples/basic.odin
+++ b/examples/basic.odin
@@ -1,11 +1,15 @@
// CRT
-putchar :: proc(c: i32) -> i32 #foreign
+putchar :: proc(c: i32) -> i32 #foreign
+
heap_alloc :: proc(sz: int) -> rawptr #foreign "malloc"
heap_free :: proc(ptr: rawptr) #foreign "free"
+
mem_compare :: proc(dst, src : rawptr, len: int) -> i32 #foreign "memcmp"
mem_copy :: proc(dst, src : rawptr, len: int) -> i32 #foreign "memcpy"
mem_move :: proc(dst, src : rawptr, len: int) -> i32 #foreign "memmove"
+debug_trap :: proc() #foreign "llvm.debugtrap"
+
print_string :: proc(s: string) {
for i := 0; i < len(s); i++ {
diff --git a/examples/main.ll b/examples/main.ll
index 7c1ecad8f..85637b0a6 100644
--- a/examples/main.ll
+++ b/examples/main.ll
@@ -5,56 +5,16 @@ declare void @llvm.memmove.p0i8.p0i8.i64(i8*, i8*, i64, i32, i1) argmemonly noun
define void @main() {
entry.-.0:
- %0 = alloca %.string, align 8 ; a
- store %.string zeroinitializer, %.string* %0
- %1 = getelementptr inbounds [5 x i8], [5 x i8]* @.str0, i64 0, i64 0
- %2 = alloca %.string, align 8
- store %.string zeroinitializer, %.string* %2
- %3 = getelementptr inbounds %.string, %.string* %2, i64 0, i32 0
- %4 = getelementptr inbounds %.string, %.string* %2, i64 0, i32 1
- store i8* %1, i8** %3
- store i64 5, i64* %4
- %5 = load %.string, %.string* %2, align 8
- store %.string %5, %.string* %0
- %6 = load %.string, %.string* %0, align 8
- %7 = getelementptr inbounds [5 x i8], [5 x i8]* @.str1, i64 0, i64 0
- %8 = alloca %.string, align 8
- store %.string zeroinitializer, %.string* %8
- %9 = getelementptr inbounds %.string, %.string* %8, i64 0, i32 0
- %10 = getelementptr inbounds %.string, %.string* %8, i64 0, i32 1
- store i8* %7, i8** %9
- store i64 5, i64* %10
- %11 = load %.string, %.string* %8, align 8
- %12 = call i1 @__string_gt(%.string %6, %.string %11)
- br i1 %12, label %if.then.-.1, label %if.else.-.2
-
-if.then.-.1:
- %13 = getelementptr inbounds [2 x i8], [2 x i8]* @.str2, i64 0, i64 0
- %14 = alloca %.string, align 8
- store %.string zeroinitializer, %.string* %14
- %15 = getelementptr inbounds %.string, %.string* %14, i64 0, i32 0
- %16 = getelementptr inbounds %.string, %.string* %14, i64 0, i32 1
- store i8* %13, i8** %15
- store i64 2, i64* %16
- %17 = load %.string, %.string* %14, align 8
- call void @print_string(%.string %17)
- call void @main$nl-0()
- br label %if.done.-.3
-
-if.else.-.2:
- %18 = getelementptr inbounds [3 x i8], [3 x i8]* @.str3, i64 0, i64 0
- %19 = alloca %.string, align 8
- store %.string zeroinitializer, %.string* %19
- %20 = getelementptr inbounds %.string, %.string* %19, i64 0, i32 0
- %21 = getelementptr inbounds %.string, %.string* %19, i64 0, i32 1
- store i8* %18, i8** %20
- store i64 3, i64* %21
- %22 = load %.string, %.string* %19, align 8
- call void @print_string(%.string %22)
- call void @main$nl-0()
- br label %if.done.-.3
-
-if.done.-.3:
+ %0 = getelementptr inbounds [8 x i8], [8 x i8]* @.str1, i64 0, i64 0
+ %1 = alloca %.string, align 8
+ store %.string zeroinitializer, %.string* %1
+ %2 = getelementptr inbounds %.string, %.string* %1, i64 0, i32 0
+ %3 = getelementptr inbounds %.string, %.string* %1, i64 0, i32 1
+ store i8* %0, i8** %2
+ store i64 8, i64* %3
+ %4 = load %.string, %.string* %1, align 8
+ call void @print_string(%.string %4)
+ call void @"main$\E4\B8\96\E7\95\8C-1"()
ret void
}
@@ -64,6 +24,20 @@ entry.-.0:
ret void
}
+define void @"main$\E4\B8\96\E7\95\8C-1"() {
+entry.-.0:
+ %0 = getelementptr inbounds [9 x i8], [9 x i8]* @.str0, i64 0, i64 0
+ %1 = alloca %.string, align 8
+ store %.string zeroinitializer, %.string* %1
+ %2 = getelementptr inbounds %.string, %.string* %1, i64 0, i32 0
+ %3 = getelementptr inbounds %.string, %.string* %1, i64 0, i32 1
+ store i8* %0, i8** %2
+ store i64 9, i64* %3
+ %4 = load %.string, %.string* %1, align 8
+ call void @print_string(%.string %4)
+ ret void
+}
+
declare i32 @putchar(i32 %c) ; foreign procedure
declare %.rawptr @malloc(i64 %sz) ; foreign procedure
@@ -76,6 +50,8 @@ declare i32 @memcpy(%.rawptr %dst, %.rawptr %src, i64 %len) ; foreign procedure
declare i32 @memmove(%.rawptr %dst, %.rawptr %src, i64 %len) ; foreign procedure
+declare void @llvm.debugtrap() ; foreign procedure
+
define void @print_string(%.string %s) {
entry.-.0:
%0 = alloca %.string, align 8 ; s
@@ -455,7 +431,7 @@ for.body.-.6:
%18 = getelementptr inbounds [65 x i8], [65 x i8]* %2, i64 0, i64 0
%19 = load i64, i64* %3, align 8
%20 = getelementptr i8, i8* %18, i64 %19
- %21 = getelementptr inbounds [64 x i8], [64 x i8]* @.str4, i64 0, i64 0
+ %21 = getelementptr inbounds [64 x i8], [64 x i8]* @.str2, i64 0, i64 0
%22 = load i64, i64* %1, align 8
%23 = load i64, i64* %0, align 8
%24 = srem i64 %23, %22
@@ -597,7 +573,7 @@ for.body.-.6:
%18 = getelementptr inbounds [65 x i8], [65 x i8]* %2, i64 0, i64 0
%19 = load i64, i64* %3, align 8
%20 = getelementptr i8, i8* %18, i64 %19
- %21 = getelementptr inbounds [64 x i8], [64 x i8]* @.str5, i64 0, i64 0
+ %21 = getelementptr inbounds [64 x i8], [64 x i8]* @.str3, i64 0, i64 0
%22 = load i64, i64* %1, align 8
%23 = load i64, i64* %0, align 8
%24 = urem i64 %23, %22
@@ -684,7 +660,7 @@ entry.-.0:
br i1 %1, label %if.then.-.1, label %if.else.-.2
if.then.-.1:
- %2 = getelementptr inbounds [4 x i8], [4 x i8]* @.str6, i64 0, i64 0
+ %2 = getelementptr inbounds [4 x i8], [4 x i8]* @.str4, i64 0, i64 0
%3 = alloca %.string, align 8
store %.string zeroinitializer, %.string* %3
%4 = getelementptr inbounds %.string, %.string* %3, i64 0, i32 0
@@ -696,7 +672,7 @@ if.then.-.1:
br label %if.done.-.3
if.else.-.2:
- %7 = getelementptr inbounds [5 x i8], [5 x i8]* @.str7, i64 0, i64 0
+ %7 = getelementptr inbounds [5 x i8], [5 x i8]* @.str5, i64 0, i64 0
%8 = alloca %.string, align 8
store %.string zeroinitializer, %.string* %8
%9 = getelementptr inbounds %.string, %.string* %8, i64 0, i32 0
@@ -950,11 +926,9 @@ entry.-.0:
ret i1 %5
}
-@.str0 = global [5 x i8] c"Hello"
-@.str1 = global [5 x i8] c"Hello"
-@.str2 = global [2 x i8] c"\3AD"
-@.str3 = global [3 x i8] c"\3A\27\28"
-@.str4 = global [64 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\40$"
-@.str5 = global [64 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\40$"
-@.str6 = global [4 x i8] c"true"
-@.str7 = global [5 x i8] c"false"
+@.str0 = global [9 x i8] c"\E6\97\A5\E6\9C\AC\E8\AA\9E"
+@.str1 = global [8 x i8] c"Hellope\0A"
+@.str2 = global [64 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\40$"
+@.str3 = global [64 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\40$"
+@.str4 = global [4 x i8] c"true"
+@.str5 = global [5 x i8] c"false"
diff --git a/examples/main.odin b/examples/main.odin
index de746733a..3a9566233 100644
--- a/examples/main.odin
+++ b/examples/main.odin
@@ -4,13 +4,10 @@ TWO_HEARTS :: 'πŸ’•';
main :: proc() {
nl :: proc() { print_rune('\n'); }
+ δΈ–η•Œ :: proc() { print_string(`ζ—₯本θͺž`); }
- a := "Hello";
- if a >= "Hello" {
- print_string(":D"); nl();
- } else {
- print_string(":'("); nl();
- }
+ print_string("Hellope\n");
+ δΈ–η•Œ();
/*