mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-21 02:23:20 +00:00
simplify
This commit is contained in:
parent
55e01a676b
commit
4ef0b00a02
4 changed files with 2 additions and 93 deletions
|
|
@ -344,7 +344,6 @@ mlr_dsl_cst_statement_t* alloc_local_variable_definition(
|
|||
mlr_dsl_cst_statement_allocator_t alloc_nonindexed_local_variable_assignment;
|
||||
mlr_dsl_cst_statement_allocator_t alloc_indexed_local_variable_assignment;
|
||||
mlr_dsl_cst_statement_allocator_t alloc_oosvar_assignment;
|
||||
mlr_dsl_cst_statement_allocator_t alloc_oosvar_from_full_srec_assignment; // xxx fold into previous
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// mapping/mlr_dsl_cst_unset_statements.c
|
||||
|
|
|
|||
|
|
@ -791,7 +791,7 @@ mlr_dsl_cst_statement_t* alloc_for_map_literal(mlr_dsl_cst_t* pcst, mlr_dsl_ast_
|
|||
// Left child node is list of bound variables.
|
||||
// Left subnode is namelist for key boundvars.
|
||||
// Right subnode is name for value boundvar.
|
||||
// Middle child node is keylist for basepoint in the local mlhmmv. // xxx update
|
||||
// Middle child node is keylist for basepoint in the localvar/mlhmmv.
|
||||
// Right child node is the list of statements in the body.
|
||||
mlr_dsl_ast_node_t* pleft = pnode->pchildren->phead->pvvalue;
|
||||
mlr_dsl_ast_node_t* psubleft = pleft->pchildren->phead->pvvalue;
|
||||
|
|
|
|||
|
|
@ -4,15 +4,6 @@
|
|||
#include "mlr_dsl_cst.h"
|
||||
#include "context_flags.h"
|
||||
|
||||
// xxx:
|
||||
//
|
||||
// assign LHS full-srec from RHS localvar ref & write elementwise
|
||||
// assign LHS full-srec from RHS oosvar ref & write elementwise
|
||||
// assign LHS full-srec from RHS full-oosvar ref & write elementwise
|
||||
// assign LHS full-srec from RHS full-srec no-op
|
||||
// assign LHS full-srec from RHS maplit alloc ephem & write elementwise
|
||||
// assign LHS full-srec from RHS func-retval alloc ephem & move
|
||||
|
||||
// ================================================================
|
||||
typedef struct _full_srec_assignment_state_t {
|
||||
rxval_evaluator_t* prhs_xevaluator;
|
||||
|
|
@ -456,84 +447,3 @@ static void handle_oosvar_assignment_from_xval(
|
|||
|
||||
sllmv_free(plhskeys);
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// All assignments produce a mlrval on the RHS and store it on the left -- except if both LHS and RHS
|
||||
// are oosvars in which case there are recursive copies, or in case of $* on the LHS or RHS.
|
||||
|
||||
typedef struct _oosvar_from_full_srec_assignment_state_t {
|
||||
sllv_t* plhs_keylist_evaluators;
|
||||
} oosvar_from_full_srec_assignment_state_t;
|
||||
|
||||
static mlr_dsl_cst_statement_handler_t handle_oosvar_from_full_srec_assignment;
|
||||
static mlr_dsl_cst_statement_freer_t free_oosvar_from_full_srec_assignment;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
mlr_dsl_cst_statement_t* alloc_oosvar_from_full_srec_assignment(mlr_dsl_cst_t* pcst, mlr_dsl_ast_node_t* pnode,
|
||||
int type_inferencing, int context_flags)
|
||||
{
|
||||
oosvar_from_full_srec_assignment_state_t* pstate = mlr_malloc_or_die(sizeof(
|
||||
oosvar_from_full_srec_assignment_state_t));
|
||||
|
||||
mlr_dsl_ast_node_t* plhs_node = pnode->pchildren->phead->pvvalue;
|
||||
mlr_dsl_ast_node_t* prhs_node = pnode->pchildren->phead->pnext->pvvalue;
|
||||
|
||||
MLR_INTERNAL_CODING_ERROR_IF(plhs_node->type != MD_AST_NODE_TYPE_OOSVAR_KEYLIST);
|
||||
MLR_INTERNAL_CODING_ERROR_IF(prhs_node->type != MD_AST_NODE_TYPE_FULL_SREC);
|
||||
|
||||
pstate->plhs_keylist_evaluators = allocate_keylist_evaluators_from_ast_node(
|
||||
plhs_node, pcst->pfmgr, type_inferencing, context_flags);
|
||||
|
||||
return mlr_dsl_cst_statement_valloc(
|
||||
pnode,
|
||||
handle_oosvar_from_full_srec_assignment,
|
||||
free_oosvar_from_full_srec_assignment,
|
||||
pstate);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static void free_oosvar_from_full_srec_assignment(mlr_dsl_cst_statement_t* pstatement) {
|
||||
oosvar_from_full_srec_assignment_state_t* pstate = pstatement->pvstate;
|
||||
|
||||
for (sllve_t* pe = pstate->plhs_keylist_evaluators->phead; pe != NULL; pe = pe->pnext) {
|
||||
rval_evaluator_t* pev = pe->pvvalue;
|
||||
pev->pfree_func(pev);
|
||||
}
|
||||
sllv_free(pstate->plhs_keylist_evaluators);
|
||||
|
||||
free(pstate);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static void handle_oosvar_from_full_srec_assignment(
|
||||
mlr_dsl_cst_statement_t* pstatement,
|
||||
variables_t* pvars,
|
||||
cst_outputs_t* pcst_outputs)
|
||||
{
|
||||
oosvar_from_full_srec_assignment_state_t* pstate = pstatement->pvstate;
|
||||
|
||||
int all_non_null_or_error = TRUE;
|
||||
sllmv_t* plhskeys = evaluate_list(pstate->plhs_keylist_evaluators, pvars, &all_non_null_or_error);
|
||||
if (all_non_null_or_error) {
|
||||
|
||||
mlhmmv_level_t* plevel = mlhmmv_root_look_up_or_create_then_ref_level(pvars->poosvars, plhskeys);
|
||||
if (plevel != NULL) {
|
||||
|
||||
mlhmmv_level_clear(plevel);
|
||||
|
||||
for (lrece_t* pe = pvars->pinrec->phead; pe != NULL; pe = pe->pnext) {
|
||||
mv_t k = mv_from_string(pe->key, NO_FREE); // mlhmmv_level_put_terminal will copy
|
||||
sllmve_t e = { .value = k, .free_flags = 0, .pnext = NULL };
|
||||
mv_t* pomv = lhmsmv_get(pvars->ptyped_overlay, pe->key);
|
||||
if (pomv != NULL) {
|
||||
mlhmmv_level_put_terminal(plevel, &e, pomv);
|
||||
} else {
|
||||
mv_t v = mv_from_string(pe->value, NO_FREE); // mlhmmv_level_put_terminal will copy
|
||||
mlhmmv_level_put_terminal(plevel, &e, &v);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
sllmv_free(plhskeys);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ mlr_dsl_cst_statement_t* mlr_dsl_cst_alloc_statement(mlr_dsl_cst_t* pcst, mlr_ds
|
|||
MLR_GLOBALS.bargv0);
|
||||
exit(1);
|
||||
}
|
||||
return alloc_oosvar_from_full_srec_assignment(pcst, pnode, type_inferencing, context_flags);
|
||||
return alloc_oosvar_assignment(pcst, pnode, type_inferencing, context_flags);
|
||||
break;
|
||||
|
||||
case MD_AST_NODE_TYPE_FULL_SREC_ASSIGNMENT:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue