static Rel *pack(char *str, char *names[], Type types[], int len) { char *n[len]; Type t[len]; for (int i = 0; i < len; ++i) { n[i] = names[i]; t[i] = types[i]; } Head *head = head_new(n, t, len); TBuf *body = NULL; Error *err = pack_csv2rel(str, head, &body); if (err != NULL) fail(); Rel *res = NULL; if (body != NULL) { int idx = array_scan(vars->names, vars->len, "___param"); if (idx < 0) fail(); res = rel_load(head, "___param"); vars->vals[idx] = body; } mem_free(head); return res; }
void head_build(){ // code, type DAD H_ROOT = head_new(0, 0, 0); //type is DIR head_commit(H_ROOT); H_SYSTEM = head_new(0, 0, H_ROOT); head_commit(head_append_source(H_SYSTEM,"system // system internals",0)); H_TYPE = head_new(0, 0, H_SYSTEM); head_commit(head_append_source(H_TYPE,"TYPE // contains types",0)); H_DIR = head_new(0, 0, H_TYPE); //dad is TYPE head_commit(head_append_source(H_DIR,"DIR ",0)); H_PROC = head_new(0, H_TYPE, H_TYPE); head_commit(head_append_source(H_PROC,"PROC // procedure directory",0)); H_U32 = head_new(0, H_TYPE, H_TYPE); head_commit(head_append_source(H_U32,"U32 // procedure directory",0)); H_SYSVAR = head_new(0, H_TYPE, H_TYPE); head_commit(head_append_source(H_SYSVAR,"SYSVAR // procedure directory",0)); //H_U32 = head_new("U32",3, 0,H_TYPE, T_NA, H_TYPE); head_set_type(H_ROOT,H_DIR); head_set_type(H_SYSTEM,H_DIR); head_set_type(H_TYPE,H_DIR); head_set_type(H_DIR,H_TYPE); // head_dump_one(H_ROOT); //head_dump_one(H_ROOT); }
HINDEX head_find_or_create(char* path){ //printf("head_find_or_create [%s]\n",path); HINDEX dir = head_get_root(); //start at root char* name = strtok(path,"'"); while(name){ HINDEX found = head_locate(dir,name,strlen(name)); if(!found) { //printf("head_find_or_create CREATING [%s] in dir %p\n",name,dir); dir = head_new(0,H_DIR,dir); head_append_source(dir,name,0); head_commit(dir); //head_dump_one(dir); /*U8* q = lang_ql((U8*)dir); q=lang_ql(q); q=lang_ql(q); */ } else { dir = found; } name = strtok(NULL,"'"); } return dir; }
static void test_compound() { char *names[] = {"a", "b", "c"}; Type types[] = {Int, Real, String}; int a, b, c; Type ta, tb, tc; Head *h = head_new(names, types, 3); head_attr(h, "a", &a, &ta); head_attr(h, "b", &b, &tb); head_attr(h, "c", &c, &tc); int v_int = 3; double v_real = 1.01; char *v_str = "bbb"; Value vals[3]; vals[0] = val_new_int(&v_int); vals[1] = val_new_real(&v_real); vals[2] = val_new_str(v_str); Tuple *t = tuple_new(vals, 3); Expr *expr = expr_or(expr_gt(expr_attr(b, Real), expr_real(4.00)), expr_lt(expr_attr(a, Int), expr_int(2))); expr = expr_or(expr, expr_lt(expr_attr(c, String), expr_str("aab"))); if (expr_bool_val(expr, t, NULL)) fail(); expr_free(expr); tuple_free(t); mem_free(h); }