Improve demo.odin

This commit is contained in:
gingerBill
2019-08-29 15:25:46 +01:00
parent c89fc35e94
commit 2dc39a5cbd
+36
View File
@@ -544,6 +544,30 @@ parametric_polymorphism :: proc() {
for v, i in array { for v, i in array {
assert(v == T(i*i)); assert(v == T(i*i));
} }
// Matrix multiplication
mul :: proc(a: [$M][$N]$T, b: [N][$P]T) -> (c: [M][P]T) {
for i in 0..<M {
for j in 0..<P {
for k in 0..<N {
c[i][j] += a[i][k] * b[k][j];
}
}
}
return;
}
x := [2][3]f32{
{1, 2, 3},
{3, 2, 1},
};
y := [3][2]f32{
{0, 8},
{6, 2},
{8, 4},
};
z := mul(x, y);
assert(z == {{36, 24}, {20, 32}});
} }
} }
@@ -830,6 +854,8 @@ complete_switch :: proc() {
} }
cstring_example :: proc() { cstring_example :: proc() {
fmt.println("\n# cstring_example");
W :: "Hellope"; W :: "Hellope";
X :: cstring(W); X :: cstring(W);
Y :: string(X); Y :: string(X);
@@ -861,6 +887,8 @@ deprecated_attribute :: proc() {
} }
bit_set_type :: proc() { bit_set_type :: proc() {
fmt.println("\n# bit_set_type");
{ {
using Day :: enum { using Day :: enum {
Sunday, Sunday,
@@ -922,6 +950,8 @@ bit_set_type :: proc() {
} }
diverging_procedures :: proc() { diverging_procedures :: proc() {
fmt.println("\n# diverging_procedures");
// Diverging procedures may never return // Diverging procedures may never return
foo :: proc() -> ! { foo :: proc() -> ! {
fmt.println("I'm a diverging procedure"); fmt.println("I'm a diverging procedure");
@@ -931,6 +961,8 @@ diverging_procedures :: proc() {
} }
deferred_procedure_associations :: proc() { deferred_procedure_associations :: proc() {
fmt.println("\n# deferred_procedure_associations");
@(deferred_out=closure) @(deferred_out=closure)
open :: proc(s: string) -> bool { open :: proc(s: string) -> bool {
fmt.println(s); fmt.println(s);
@@ -1030,6 +1062,10 @@ quaternions :: proc() {
inline_for_statement :: proc() { inline_for_statement :: proc() {
fmt.println("\n#inline for statements"); fmt.println("\n#inline for statements");
// 'inline for' works the same as if the 'inline' prefix did not
// exist but these ranged loops are explicitly unrolled which can
// be very very useful for certain optimizations
fmt.println("Ranges"); fmt.println("Ranges");
inline for x, i in 1..<4 { inline for x, i in 1..<4 {
fmt.println(x, i); fmt.println(x, i);