This commit is contained in:
gingerBill
2018-02-09 18:03:06 +00:00
parent 8f913c656c
commit 54976c3249
3 changed files with 49 additions and 9 deletions
+43 -2
View File
@@ -13,6 +13,7 @@ import "core:types.odin"
import "core:utf16.odin"
import "core:utf8.odin"
// File scope `when` statements
when ODIN_OS == "windows" {
import "core:atomics.odin"
import "core:thread.odin"
@@ -643,6 +644,7 @@ array_programming :: proc() {
using println in import "core:fmt.odin"
using_in :: proc() {
fmt.println("# using in");
using print in fmt;
println("Hellope1");
@@ -660,7 +662,9 @@ using_in :: proc() {
println(f);
}
named_proc_parameters :: proc() {
named_proc_return_parameters :: proc() {
fmt.println("# named proc return parameters");
foo0 :: proc() -> int {
return 123;
}
@@ -681,6 +685,8 @@ named_proc_parameters :: proc() {
enum_export :: proc() {
fmt.println("# enum #export");
Foo :: enum #export {A, B, C};
f0 := A;
@@ -689,6 +695,40 @@ enum_export :: proc() {
fmt.println(f0, f1, f2);
}
explicit_procedure_overloading :: proc() {
fmt.println("# explicit procedure overloading");
add_ints :: proc(a, b: int) -> int {
x := a + b;
fmt.println("add_ints", x);
return x;
}
add_floats :: proc(a, b: f32) -> f32 {
x := a + b;
fmt.println("add_floats", x);
return x;
}
add_numbers :: proc(a: int, b: f32, c: u8) -> int {
x := int(a) + int(b) + int(c);
fmt.println("add_numbers", x);
return x;
}
add :: proc[add_ints, add_floats, add_numbers];
add(int(1), int(2));
add(f32(1), f32(2));
add(int(1), f32(2), u8(3));
add(1, 2); // untyped ints coerce to int tighter than f32
add(1.0, 2.0); // untyped floats coerce to f32 tighter than int
add(1, 2, 3); // three parameters
// Ambiguous answers
// add(1.0, 2);
// add(1, 2.0);
}
main :: proc() {
when false {
general_stuff();
@@ -698,7 +738,8 @@ main :: proc() {
threading_example();
array_programming();
using_in();
named_proc_parameters();
named_proc_return_parameters();
enum_export();
explicit_procedure_overloading();
}
}
+1 -1
View File
@@ -309,7 +309,7 @@ String get_fullpath_core(gbAllocator a, String path) {
}
String const ODIN_VERSION = str_lit("0.8.0-dev");
String const ODIN_VERSION = str_lit("0.8.0");
String cross_compile_target = str_lit("");
String cross_compile_lib_dir = str_lit("");
+5 -6
View File
@@ -387,12 +387,6 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
}
struct TypeAndToken {
Type *type;
Token token;
};
void check_when_stmt(Checker *c, AstNodeWhenStmt *ws, u32 flags) {
Operand operand = {Addressing_Invalid};
check_expr(c, &operand, ws->cond);
@@ -634,6 +628,11 @@ void check_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
}
}
struct TypeAndToken {
Type *type;
Token token;
};
Map<TypeAndToken> seen = {}; // NOTE(bill): Multimap
map_init(&seen, heap_allocator());
defer (map_destroy(&seen));