Last active
December 16, 2015 06:19
-
-
Save Ikke/5390715 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/components/compiler/assembler.c b/src/components/compiler/assembler.c | |
| index 42dad59..2a36bfe 100644 | |
| --- a/src/components/compiler/assembler.c | |
| +++ b/src/components/compiler/assembler.c | |
| @@ -446,6 +446,7 @@ static void _assembler_output_frame(t_dll *frame, FILE *f) { | |
| case OPERATOR_XOR : fprintf(f, "XOR"); break; | |
| case OPERATOR_SHL : fprintf(f, "SHL"); break; | |
| case OPERATOR_SHR : fprintf(f, "SHR"); break; | |
| + case OPERATOR_COA : fprintf(f, "COA"); break; | |
| } | |
| break; | |
| case ASM_LINE_TYPE_OP_COMPARE : | |
| diff --git a/src/components/compiler/ast_walker.c b/src/components/compiler/ast_walker.c | |
| index 23b573c..493718f 100644 | |
| --- a/src/components/compiler/ast_walker.c | |
| +++ b/src/components/compiler/ast_walker.c | |
| @@ -193,6 +193,7 @@ static void __ast_walker(t_ast_element *leaf, t_hash_table *output, t_dll *frame | |
| case '^' : op = OPERATOR_XOR; break; | |
| case T_SHIFT_LEFT : op = OPERATOR_SHL; break; | |
| case T_SHIFT_RIGHT : op = OPERATOR_SHR; break; | |
| + case T_COALESCE : op = OPERATOR_COA; break; | |
| } | |
| opr1 = asm_create_opr(ASM_LINE_TYPE_OP_OPERATOR, NULL, op); | |
| diff --git a/src/components/compiler/saffire.l b/src/components/compiler/saffire.l | |
| index 411c484..ea13864 100644 | |
| --- a/src/components/compiler/saffire.l | |
| +++ b/src/components/compiler/saffire.l | |
| @@ -127,6 +127,7 @@ ml_comment "/*"([^\*]|\*[^/])*"*/" | |
| "||" { saffire_push_state(st_regex); return T_OR; } | |
| "&&" { saffire_push_state(st_regex); return T_AND; } | |
| +"??" { saffire_push_state(st_regex); return T_COALESCE; } | |
| "<<" { saffire_push_state(st_regex); return T_SHIFT_LEFT; } | |
| ">>" { saffire_push_state(st_regex); return T_SHIFT_RIGHT; } | |
| diff --git a/src/components/compiler/saffire.y b/src/components/compiler/saffire.y | |
| index 871d7d8..8f8f4cd 100644 | |
| --- a/src/components/compiler/saffire.y | |
| +++ b/src/components/compiler/saffire.y | |
| @@ -92,7 +92,7 @@ | |
| %left T_ASSIGNMENT T_GE T_LE T_EQ T_NE '>' '<' '^' T_IN T_RE T_REGEX | |
| %left '+' '-' | |
| %left '*' '/' | |
| -%token T_AND T_OR T_SHIFT_LEFT T_SHIFT_RIGHT | |
| +%token T_AND T_OR T_SHIFT_LEFT T_SHIFT_RIGHT T_COALESCE | |
| %token T_CLASS T_EXTENDS T_ABSTRACT T_FINAL T_IMPLEMENTS T_INHERITS T_INTERFACE | |
| %token T_PUBLIC T_PRIVATE T_PROTECTED T_CONST T_STATIC T_PROPERTY | |
| %token T_LABEL T_CALL T_ARITHMIC T_LOGICAL T_PROGRAM | |
| @@ -113,7 +113,7 @@ | |
| %type <nPtr> if_statement switch_statement class_constant_definition | |
| %type <nPtr> unary_expression primary_expression pe_no_parenthesis data_structure | |
| %type <nPtr> logical_unary_operator multiplicative_expression additive_expression shift_expression regex_expression | |
| -%type <nPtr> catch_header conditional_expression assignment_expression real_scalar_value | |
| +%type <nPtr> catch_header conditional_expression coalesce_expression assignment_expression real_scalar_value | |
| %type <nPtr> method_argument interface_inner_statement interface_method_declaration interface_property_declaration | |
| %type <nPtr> class_method_definition class_property_definition qualified_name calling_method_argument_list | |
| %type <nPtr> logical_unary_expression equality_expression and_expression inclusive_or_expression | |
| @@ -335,6 +335,7 @@ expression: | |
| assignment_expression: | |
| conditional_expression { $$ = $1; } | |
| + | coalesce_expression { $$ = $1; } | |
| | unary_expression assignment_operator assignment_expression { $$ = ast_assignment($2, $1, $3); } | |
| ; | |
| @@ -373,6 +374,11 @@ equality_expression: | |
| | equality_expression comparison_operator regex_expression { $$ = ast_comparison($2, $1, $3); } | |
| ; | |
| +coalesce_expression: | |
| + T_IDENTIFIER T_COALESCE scalar_value { $$ = ast_opr(T_COALESCE, 2, $1, $3); } | |
| +; | |
| + | |
| + | |
| comparison_operator: | |
| T_EQ { $$ = T_EQ; } | |
| | T_NE { $$ = T_NE; } | |
| diff --git a/src/include/objects/object.h b/src/include/objects/object.h | |
| index 6e4ea99..34cb80b 100644 | |
| --- a/src/include/objects/object.h | |
| +++ b/src/include/objects/object.h | |
| @@ -65,6 +65,7 @@ | |
| #define OPERATOR_XOR 7 | |
| #define OPERATOR_SHL 8 | |
| #define OPERATOR_SHR 9 | |
| + #define OPERATOR_COA 10 | |
| #define COMPARISON_EQ 0 // Equals |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment