@@ -789,7 +789,7 @@ rd_eval_space_read(E_Space space, void *out, Rng1U64 range)
789789 //- rjf: meta-config reads
790790 case RD_EvalSpaceKind_MetaCfg:
791791 {
792- // rjf: unpack cfg
792+ //- rjf: unpack cfg
793793 CFG_Node *root_cfg = rd_cfg_from_eval_space(space);
794794 String8 child_key = e_string_from_id(space.u64s[1]);
795795 CFG_Node *cfg = root_cfg;
@@ -798,54 +798,85 @@ rd_eval_space_read(E_Space space, void *out, Rng1U64 range)
798798 cfg = cfg_node_child_from_string(root_cfg, child_key);
799799 }
800800
801- // rjf: determine data to read from, depending on child type in schema
801+ //- rjf: determine data to read from, depending on child type in schema
802802 String8 read_data = {0};
803803 if(child_key.size != 0)
804804 {
805- MD_NodePtrList schemas = cfg_schemas_from_name(scratch.arena, rd_state->cfg_schema_table, root_cfg->string);
806- MD_Node *expr_child_schema = &md_nil_node;
805+ // rjf: get schemas for the accessed child
807806 MD_Node *child_schema = &md_nil_node;
808- for(MD_NodePtrNode *n = schemas.first; n != 0 && child_schema == & md_nil_node; n = n->next)
807+ MD_Node *expr_child_schema = & md_nil_node;
809808 {
810- child_schema = md_child_from_string(n->v, child_key, 0 );
811- if(child_schema != & md_nil_node)
809+ MD_NodePtrList schemas = cfg_schemas_from_name(scratch.arena, rd_state->cfg_schema_table, root_cfg->string );
810+ for(MD_NodePtrNode *n = schemas.first; n != 0 && child_schema == & md_nil_node; n = n->next )
812811 {
813- expr_child_schema = md_child_from_string(n->v, str8_lit("expression"), 0);
812+ child_schema = md_child_from_string(n->v, child_key, 0);
813+ if(child_schema != &md_nil_node)
814+ {
815+ expr_child_schema = md_child_from_string(n->v, str8_lit("expression"), 0);
816+ }
814817 }
815818 }
816819 String8 child_type_name = child_schema->first->string;
820+
821+ // rjf: get value string (or default fallback)
822+ String8 value_string = cfg->first->string;
823+ if(value_string.size == 0)
824+ {
825+ value_string = md_tag_from_string(child_schema, str8_lit("default"), 0)->first->string;
826+ }
827+
828+ // rjf: if this is an override child to a parent, fall back on defaults from parents
829+ if(value_string.size == 0 && !md_node_is_nil(md_tag_from_string(child_schema, str8_lit("override"), 0)))
830+ {
831+ for(CFG_Node *parent = root_cfg->parent; parent != &cfg_nil_node; parent = parent->parent)
832+ {
833+ CFG_Node *parent_child_w_key = cfg_node_child_from_string(parent, child_key);
834+ if(parent_child_w_key != &cfg_nil_node)
835+ {
836+ value_string = parent_child_w_key->first->string;
837+ break;
838+ }
839+ value_string = rd_default_setting_from_names(parent->string, child_key);
840+ if(value_string.size != 0)
841+ {
842+ break;
843+ }
844+ }
845+ }
846+
847+ // rjf: if this is a query -> compute the value string based on query path
848+ if(md_node_has_tag(child_schema, str8_lit("query"), 0))
849+ {
850+ // TODO(rjf): this needs to be replaced by hooks
851+ if(str8_match(child_schema->string, str8_lit("guid"), 0))
852+ {
853+ Access *access = access_open();
854+ String8 path = rd_path_from_cfg(root_cfg);
855+ U64 timestamp = 0;
856+ try_u64_from_str8_c_rules(cfg_node_child_from_string(root_cfg, str8_lit("timestamp"))->first->string, ×tamp);
857+ DI_Key key = di_key_from_path_timestamp(path, timestamp);
858+ RDI_Parsed *rdi = di_rdi_from_key(access, key, 0, 0);
859+ RDI_TopLevelInfo *tli = rdi_element_from_name_idx(rdi, TopLevelInfo, 0);
860+ Guid guid = {0};
861+ MemoryCopy(&guid, &tli->guid, Min(sizeof guid, sizeof tli->guid));
862+ value_string = string_from_guid(scratch.arena, guid);
863+ access_close(access);
864+ }
865+ }
866+
867+ // rjf: textual data
817868 if(str8_match(child_type_name, str8_lit("path"), 0) ||
818869 str8_match(child_type_name, str8_lit("path_pt"), 0) ||
819870 str8_match(child_type_name, str8_lit("code_string"), 0) ||
820871 str8_match(child_type_name, str8_lit("expr_string"), 0) ||
821872 str8_match(child_type_name, str8_lit("string"), 0))
822873 {
823- read_data = cfg->first->string ;
874+ read_data = value_string ;
824875 }
876+
877+ // rjf: non-textual data
825878 else
826879 {
827- String8 value_string = cfg->first->string;
828- if(value_string.size == 0)
829- {
830- value_string = md_tag_from_string(child_schema, str8_lit("default"), 0)->first->string;
831- }
832- if(value_string.size == 0 && !md_node_is_nil(md_tag_from_string(child_schema, str8_lit("override"), 0)))
833- {
834- for(CFG_Node *parent = root_cfg->parent; parent != &cfg_nil_node; parent = parent->parent)
835- {
836- CFG_Node *parent_child_w_key = cfg_node_child_from_string(parent, child_key);
837- if(parent_child_w_key != &cfg_nil_node)
838- {
839- value_string = parent_child_w_key->first->string;
840- break;
841- }
842- value_string = rd_default_setting_from_names(parent->string, child_key);
843- if(value_string.size != 0)
844- {
845- break;
846- }
847- }
848- }
849880 E_Key parent_key = {0};
850881 if(expr_child_schema != &md_nil_node && child_schema != expr_child_schema)
851882 {
@@ -11471,6 +11502,18 @@ rd_frame(void)
1147111502 .id_from_num = E_TYPE_EXPAND_ID_FROM_NUM_FUNCTION_NAME(cfgs_slice),
1147211503 .num_from_id = E_TYPE_EXPAND_NUM_FROM_ID_FUNCTION_NAME(cfgs_slice),
1147311504 }));
11505+ e_string2typekey_map_insert(rd_frame_arena(), rd_state->meta_name2type_map, str8_lit("environment"),
11506+ e_type_key_cons(.kind = E_TypeKind_Set,
11507+ .name = str8_lit("environment"),
11508+ .irext = E_TYPE_IREXT_FUNCTION_NAME(environment),
11509+ .access = E_TYPE_ACCESS_FUNCTION_NAME(environment),
11510+ .expand =
11511+ {
11512+ .info = E_TYPE_EXPAND_INFO_FUNCTION_NAME(environment),
11513+ .range = E_TYPE_EXPAND_RANGE_FUNCTION_NAME(environment),
11514+ .id_from_num = E_TYPE_EXPAND_ID_FROM_NUM_FUNCTION_NAME(environment),
11515+ .num_from_id = E_TYPE_EXPAND_NUM_FROM_ID_FUNCTION_NAME(environment),
11516+ }));
1147411517 }
1147511518
1147611519 //- rjf: add macro for collections with specific lookup rules (but no unique id rules)
0 commit comments