diff --git a/c/containers/type_decl.h b/c/containers/type_decl.h index 4f21ff3b6..abfb7ddae 100644 --- a/c/containers/type_decl.h +++ b/c/containers/type_decl.h @@ -14,7 +14,7 @@ #define TYPE_MASK_FLOAT (1 << MT_FLOAT) #define TYPE_MASK_NUMERIC (TYPE_MASK_INT | TYPE_MASK_FLOAT) #define TYPE_MASK_BOOLEAN (1 << MT_BOOLEAN) -// Initial declaration is an empty map. +// Initial declaration is an empty map. // xxx update the logic as well as the comment // xxx maybe change that? For oosvars there's no empty map but for local mapvars there could be? what about after final unset? // Or, simply use the convention that empty map <=> absent? #define TYPE_MASK_MAP ((1 << MT_DIM) | (1 << MT_ABSENT)) diff --git a/c/dsls/mlr_dsl_parse.y b/c/dsls/mlr_dsl_parse.y index 0a4855520..2658ff596 100644 --- a/c/dsls/mlr_dsl_parse.y +++ b/c/dsls/mlr_dsl_parse.y @@ -130,7 +130,7 @@ md_statement_not_braced_end(A) ::= md_int_local_definition(B). { A = B; } md_statement_not_braced_end(A) ::= md_float_local_definition(B). { A = B; } md_statement_not_braced_end(A) ::= md_boolean_local_definition(B). { A = B; } md_statement_not_braced_end(A) ::= md_string_local_definition(B). { A = B; } -md_statement_not_braced_end(A) ::= md_map_local_declaration(B). { A = B; } +md_statement_not_braced_end(A) ::= md_map_local_definition(B). { A = B; } md_statement_not_braced_end(A) ::= md_nonindexed_local_assignment(B). { A = B; } md_statement_not_braced_end(A) ::= md_indexed_local_assignment(B). { A = B; } @@ -747,14 +747,11 @@ md_boolean_local_definition(A) ::= MD_TOKEN_BOOLEAN(T) md_nonindexed_local_varia md_string_local_definition(A) ::= MD_TOKEN_STRING(T) md_nonindexed_local_variable(N) MD_TOKEN_ASSIGN md_rhs(B). { A = mlr_dsl_ast_node_alloc_binary(T->text, MD_AST_NODE_TYPE_STRING_LOCAL_DEFINITION, N, B); } -md_map_local_declaration(A) ::= MD_TOKEN_MAP(T) md_nonindexed_local_variable(N). { - A = mlr_dsl_ast_node_alloc_unary(T->text, MD_AST_NODE_TYPE_MAP_LOCAL_DECLARATION, N); -} md_untyped_local_definition(A) ::= MD_TOKEN_VAR(T) md_nonindexed_local_variable(N) MD_TOKEN_ASSIGN md_map_literal(C). { - A = mlr_dsl_ast_node_alloc_binary(T->text, MD_AST_NODE_TYPE_MAP_LOCAL_DECLARATION, N, C); + A = mlr_dsl_ast_node_alloc_binary(T->text, MD_AST_NODE_TYPE_MAP_LOCAL_DEFINITION, N, C); } -md_map_local_declaration(A) ::= MD_TOKEN_MAP(T) md_nonindexed_local_variable(N) MD_TOKEN_ASSIGN md_map_literal(C). { - A = mlr_dsl_ast_node_alloc_binary(T->text, MD_AST_NODE_TYPE_MAP_LOCAL_DECLARATION, N, C); +md_map_local_definition(A) ::= MD_TOKEN_MAP(T) md_nonindexed_local_variable(N) MD_TOKEN_ASSIGN md_map_literal(C). { + A = mlr_dsl_ast_node_alloc_binary(T->text, MD_AST_NODE_TYPE_MAP_LOCAL_DEFINITION, N, C); } md_nonindexed_local_assignment(A) ::= md_nonindexed_local_variable(B) MD_TOKEN_ASSIGN(O) md_rhs(C). { diff --git a/c/mapping/mlr_dsl_ast.c b/c/mapping/mlr_dsl_ast.c index b98e428b1..2a03ba76c 100644 --- a/c/mapping/mlr_dsl_ast.c +++ b/c/mapping/mlr_dsl_ast.c @@ -273,7 +273,7 @@ char* mlr_dsl_ast_node_describe_type(mlr_dsl_ast_node_type_t type) { case MD_AST_NODE_TYPE_FLOAT_LOCAL_DEFINITION: return "FLOAT_LOCAL_DEFINITION"; break; case MD_AST_NODE_TYPE_BOOLEAN_LOCAL_DEFINITION: return "BOOLEAN_LOCAL_DEFINITION"; break; case MD_AST_NODE_TYPE_STRING_LOCAL_DEFINITION: return "STRING_LOCAL_DEFINITION"; break; - case MD_AST_NODE_TYPE_MAP_LOCAL_DECLARATION: return "MAP_LOCAL_DECLARATION"; break; + case MD_AST_NODE_TYPE_MAP_LOCAL_DEFINITION: return "MAP_LOCAL_DEFINITION"; break; case MD_AST_NODE_TYPE_UNTYPED_PARAMETER_DEFINITION: return "UNTYPED_PARAMETER_DEFINITION"; break; case MD_AST_NODE_TYPE_NUMERIC_PARAMETER_DEFINITION: return "NUMERIC_PARAMETER_DEFINITION"; break; case MD_AST_NODE_TYPE_INT_PARAMETER_DEFINITION: return "INT_PARAMETER_DEFINITION"; break; diff --git a/c/mapping/mlr_dsl_ast.h b/c/mapping/mlr_dsl_ast.h index bc52bf637..4aebb7aea 100644 --- a/c/mapping/mlr_dsl_ast.h +++ b/c/mapping/mlr_dsl_ast.h @@ -21,7 +21,7 @@ typedef enum _mlr_dsl_ast_node_type_t { MD_AST_NODE_TYPE_FLOAT_LOCAL_DEFINITION, MD_AST_NODE_TYPE_BOOLEAN_LOCAL_DEFINITION, MD_AST_NODE_TYPE_STRING_LOCAL_DEFINITION, - MD_AST_NODE_TYPE_MAP_LOCAL_DECLARATION, + MD_AST_NODE_TYPE_MAP_LOCAL_DEFINITION, MD_AST_NODE_TYPE_UNTYPED_PARAMETER_DEFINITION, MD_AST_NODE_TYPE_NUMERIC_PARAMETER_DEFINITION, MD_AST_NODE_TYPE_INT_PARAMETER_DEFINITION, diff --git a/c/mapping/mlr_dsl_cst_assignment_statements.c b/c/mapping/mlr_dsl_cst_assignment_statements.c index 4eccd9526..ffba9d339 100644 --- a/c/mapping/mlr_dsl_cst_assignment_statements.c +++ b/c/mapping/mlr_dsl_cst_assignment_statements.c @@ -685,7 +685,7 @@ typedef struct _local_variable_definition_state_t { } local_variable_definition_state_t; static mlr_dsl_cst_statement_handler_t handle_local_variable_definition; -static mlr_dsl_cst_statement_handler_t handle_local_map_declaration; +static mlr_dsl_cst_statement_handler_t handle_local_variable_definition_from_map_literal; static mlr_dsl_cst_statement_freer_t free_local_variable_definition; // ---------------------------------------------------------------- @@ -706,14 +706,12 @@ mlr_dsl_cst_statement_t* alloc_local_variable_definition( pstate->lhs_type_mask = type_mask; mlr_dsl_cst_statement_handler_t* pstatement_handler = NULL; - if (pnode->type == MD_AST_NODE_TYPE_MAP_LOCAL_DECLARATION) { // xxx remove - // 'map x' rather than 'map x = ...' so there is no initial right-hand side. - pstate->prhs_evaluator = NULL; - pstatement_handler = handle_local_map_declaration; + mlr_dsl_ast_node_t* prhs_node = pnode->pchildren->phead->pnext->pvvalue; + if (prhs_node->type == MD_AST_NODE_TYPE_MAP_LITERAL) { + pstate->prhs_evaluator = NULL; // xxx more to do for mapvars + pstatement_handler = handle_local_variable_definition_from_map_literal; } else { - mlr_dsl_ast_node_t* pvalue_node = pnode->pchildren->phead->pnext->pvvalue; - pstate->prhs_evaluator = rval_evaluator_alloc_from_ast(pvalue_node, pcst->pfmgr, - type_inferencing, context_flags); + pstate->prhs_evaluator = rval_evaluator_alloc_from_ast(prhs_node, pcst->pfmgr, type_inferencing, context_flags); pstatement_handler = handle_local_variable_definition; } @@ -756,15 +754,23 @@ static void handle_local_variable_definition( // xxx mapvar } // ---------------------------------------------------------------- -static void handle_local_map_declaration( // xxx rm +static void handle_local_variable_definition_from_map_literal( // xxx mapvar mlr_dsl_cst_statement_t* pstatement, variables_t* pvars, cst_outputs_t* pcst_outputs) { local_variable_definition_state_t* pstate = pstatement->pvstate; - local_stack_frame_t* pframe = local_stack_get_top_frame(pvars->plocal_stack); - local_stack_frame_define(pframe, - pstate->lhs_variable_name, pstate->lhs_frame_relative_index, - pstate->lhs_type_mask, mv_absent()); + //rval_evaluator_t* prhs_evaluator = pstate->prhs_evaluator; // xxx mapvar + //mv_t val = prhs_evaluator->pprocess_func(prhs_evaluator->pvstate, pvars); + // xxx mapvar stub + mv_t val = mv_absent(); + //if (mv_is_present(&val)) { + local_stack_frame_t* pframe = local_stack_get_top_frame(pvars->plocal_stack); + local_stack_frame_define(pframe, + pstate->lhs_variable_name, pstate->lhs_frame_relative_index, + /*pstate->lhs_type_mask*/ TYPE_MASK_MAP, val); // xxx temp stub + //} else { + //mv_free(&val); + //} } diff --git a/c/mapping/mlr_dsl_cst_return_statements.c b/c/mapping/mlr_dsl_cst_return_statements.c index 0ff516e01..087da8996 100644 --- a/c/mapping/mlr_dsl_cst_return_statements.c +++ b/c/mapping/mlr_dsl_cst_return_statements.c @@ -59,7 +59,7 @@ mlr_dsl_cst_statement_t* alloc_return_value( // $ mlr --from s put -v 'map v = {}' // AST ROOT: // text="block", type=STATEMENT_BLOCK: - // text="map", type=MAP_LOCAL_DECLARATION: + // text="map", type=MAP_LOCAL_DEFINITION: // text="v", type=NONINDEXED_LOCAL_VARIABLE. // text="map_literal", type=MAP_LITERAL: diff --git a/c/mapping/mlr_dsl_cst_statements.c b/c/mapping/mlr_dsl_cst_statements.c index 5d67e2744..ece10c28a 100644 --- a/c/mapping/mlr_dsl_cst_statements.c +++ b/c/mapping/mlr_dsl_cst_statements.c @@ -205,7 +205,7 @@ mlr_dsl_cst_statement_t* mlr_dsl_cst_alloc_statement(mlr_dsl_cst_t* pcst, mlr_ds return alloc_local_variable_definition(pcst, pnode, type_inferencing, context_flags, TYPE_MASK_STRING); break; - case MD_AST_NODE_TYPE_MAP_LOCAL_DECLARATION: + case MD_AST_NODE_TYPE_MAP_LOCAL_DEFINITION: return alloc_local_variable_definition(pcst, pnode, type_inferencing, context_flags, TYPE_MASK_MAP); break; diff --git a/c/mapping/mlr_dsl_stack_allocate.c b/c/mapping/mlr_dsl_stack_allocate.c index 73806fa9c..7dfd82c5e 100644 --- a/c/mapping/mlr_dsl_stack_allocate.c +++ b/c/mapping/mlr_dsl_stack_allocate.c @@ -387,7 +387,7 @@ static void pass_1_for_node(mlr_dsl_ast_node_t* pnode, stkalc_subframe_group_t* } else if (pnode->type == MD_AST_NODE_TYPE_STRING_LOCAL_DEFINITION) { // LHS pass_1_for_local_definition(pnode, pframe_group, pmax_subframe_depth, trace); - } else if (pnode->type == MD_AST_NODE_TYPE_MAP_LOCAL_DECLARATION) { // LHS + } else if (pnode->type == MD_AST_NODE_TYPE_MAP_LOCAL_DEFINITION) { // LHS pass_1_for_local_definition(pnode, pframe_group, pmax_subframe_depth, trace); } else if (pnode->type == MD_AST_NODE_TYPE_NONINDEXED_LOCAL_ASSIGNMENT) { // LHS diff --git a/c/reg_test/expected/out b/c/reg_test/expected/out index c1d333557..81d2a0f4f 100644 --- a/c/reg_test/expected/out +++ b/c/reg_test/expected/out @@ -45486,26 +45486,26 @@ x=3,y=4,z=5,a0=6,b1=7,c2=8,d3=9 LOCAL MAP-VARIABLE TYPE-DECL mlr --from ./reg_test/input/xyz345 put - map a; + map a = {}; x=3,y=4,z=5 mlr --from ./reg_test/input/xyz345 put - map a; + map a = {}; a[1]=2; a[3][4]=5; x=3,y=4,z=5 mlr --from ./reg_test/input/xyz345 put - map a; + map a = {}; a=2; a[3][4]=5; mlr: map type assertion for variable a unmet by value 2 with type int. mlr --from ./reg_test/input/xyz345 put - map a; + map a = {}; a[3][4]=5; a=2; diff --git a/c/reg_test/run b/c/reg_test/run index c063f34c7..66c160783 100755 --- a/c/reg_test/run +++ b/c/reg_test/run @@ -5130,23 +5130,23 @@ run_mlr --from $indir/xyz345 put -v -a ' announce LOCAL MAP-VARIABLE TYPE-DECL run_mlr --from $indir/xyz345 put ' - map a; + map a = {}; ' run_mlr --from $indir/xyz345 put ' - map a; + map a = {}; a[1]=2; a[3][4]=5; ' mlr_expect_fail --from $indir/xyz345 put ' - map a; + map a = {}; a=2; a[3][4]=5; ' mlr_expect_fail --from $indir/xyz345 put ' - map a; + map a = {}; a[3][4]=5; a=2; '