}
print :: (tree: ^AVL_Tree) {
- use package core {print as std_print, printf}
+ use core {
+ std_print :: print,
+ printf
+ }
if tree == null {
std_print("_ ");
as_iterator :: #match {}
#local __iterable_test :: macro (i: Iterator($V)) {}
-Iterable :: interface (T as t) {
+Iterable :: interface (t: $T) {
as_iterator(t) |> __iterable_test();
}
}
#local {
- ValidKey :: interface (T as t) {
+ ValidKey :: interface (t: $T) {
// In order to use a certain type as a key in a Map, you must
// provide an implementation of core.hash.to_u32() for that type,
// and you must provide an operator overload for ==.
math :: package core.math
}
-#local SetValue :: interface (T as t) {
+#local SetValue :: interface (t: $T) {
{ hash.to_u32(t) } -> u32;
{ t == t } -> bool;
}
(key: type_expr) -> u32 do return to_u32(cast(u32) key);
}
-Hashable :: interface (T as t) {
+Hashable :: interface (t: $T) {
{ to_u32(t) } -> u32;
}
use package core.alloc
// You can also restrict and partially rename the symbols that collide
- use package core.string { free as string_free }
+ use package core.string { string_free :: free }
}
{
// expressions do not type check correctly, then the set of parameters does not
// satisfy the interface.
- CanAdd :: interface (T as t) {
+ CanAdd :: interface (t: $T) {
t + t;
}
// These have to be defined out here because #operator and #match are only allowed
// as top level expressions currently.
-NumberLike :: interface (T as t) {
+NumberLike :: interface (t: $T) {
// The constraints here are a little stricter than before. This syntax
// allows you to specify the expected type of the expression. If the type
// of the expression and the type after the arrow do not match, then the
// when the are combined with overloaded procedures.
// Take this example. Here is the same CanAdd interface from before.
- CanAdd :: interface (T as t) {
+ CanAdd :: interface (t: $T) {
t + t;
}
Token_Type_Keyword_Elseif,
Token_Type_Keyword_Return,
Token_Type_Keyword_Global,
- Token_Type_Keyword_As,
Token_Type_Keyword_Cast,
Token_Type_Keyword_While,
Token_Type_Keyword_For,
"elseif",
"return",
"global",
- "as",
"cast",
"while",
"for",
switch (curr) {
case 'a':
LITERAL_TOKEN("alignof", 1, Token_Type_Keyword_Alignof);
- LITERAL_TOKEN("as", 1, Token_Type_Keyword_As);
break;
case 'b':
LITERAL_TOKEN("break", 1, Token_Type_Keyword_Break);
if (parser->hit_unexpected_token) return NULL;
QualifiedUse qu;
- qu.symbol_name = expect_token(parser, Token_Type_Symbol);
+ qu.as_name = expect_token(parser, Token_Type_Symbol);
+ qu.symbol_name = qu.as_name;
- if (consume_token_if_next(parser, Token_Type_Keyword_As))
- qu.as_name = expect_token(parser, Token_Type_Symbol);
- else
- qu.as_name = qu.symbol_name;
+ if (consume_token_if_next(parser, ':')) {
+ expect_token(parser, ':');
+ qu.symbol_name = expect_token(parser, Token_Type_Symbol);
+ }
bh_arr_push(use_node->only, qu);
if (parser->hit_unexpected_token) return interface;
InterfaceParam ip;
- ip.type_token = expect_token(parser, Token_Type_Symbol);
- expect_token(parser, Token_Type_Keyword_As);
ip.value_token = expect_token(parser, Token_Type_Symbol);
+ expect_token(parser, ':');
+ expect_token(parser, '$');
+ ip.type_token = expect_token(parser, Token_Type_Symbol);
bh_arr_push(interface->params, ip);
goto submit_binding_to_entities;
}
+ case '(': {
+ AstTyped *retval = NULL;
+ if (parse_possible_function_definition(parser, &retval)) {
+ ENTITY_SUBMIT(retval);
+ return;
+ }
+ if (parse_possible_quick_function_definition(parser, &retval)) {
+ ENTITY_SUBMIT(retval);
+ return;
+ }
+ break;
+ }
+
case '#': {
if (next_tokens_are(parser, 2, '#', Token_Type_Keyword_If)) {
AstIf* static_if = parse_static_if_stmt(parser, 0);
return g(f(a));
}
- Number :: interface (T as t) {
+ Number :: interface (t: $T) {
{ t * t } -> T;
}
use package core
-Hashable :: interface (T as t) {
+Hashable :: interface (t :$T) {
{ hash.to_u32(t) } -> u32;
}
},
}
-CanCastTo :: interface (T as t, D as d) {
+CanCastTo :: interface (t: $T, d: $D) {
{ cast(D) t } -> D;
}
return x + y + x * y;
}
-SemiRing :: interface (T as t) {
+SemiRing :: interface (t: $T) {
{t + t} -> T;
{t * t} -> T;
}
return (x & y) | (x ^ y);
}
-BitField :: interface (T as t) {
+BitField :: interface (t: $T) {
{ ~t } -> T;
{ t & t } -> T;
{ t | t } -> T;