git.haldean.org ubik / 6ced6ec
XXX getting pretty close to a (probably buggy) finish line Haldean Brown 4 years ago
4 changed file(s) with 60 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
435435 for (i = 0; i < tsys->interfaces.n; i++)
436436 {
437437 iface = tsys->interfaces.elems[i];
438 /* TODO: actual package handling here. */
439 if (strcmp(expr_cs->interface, iface->name) == 0)
440 {
441 found = true;
442 break;
443 }
438 if (strcmp(expr_cs->interface.package,
439 iface->package) != 0)
440 continue;
441 if (strcmp(expr_cs->interface.name, iface->name) != 0)
442 continue;
443 found = true;
444 break;
444445 }
445446 if (!found)
446447 return ubik_raise(
455456 params = params->next, i++)
456457 {
457458 impl->params[i].name.name =
458 ubik_strdup(params->name, region);
459 ubik_strdup(params->name.name, region);
460 impl->params[i].name.package =
461 ubik_strdup(params->name.package, region);
459462 impl->params[i].type_expr_type = TYPE_EXPR_VAR;
460463 }
461464 if (params != NULL || i != iface->n_params)
496499 return err;
497500
498501 case TYPE_EXPR_VAR:
499 if (strcmp(expr->name, sub->varname) != 0)
502 if (strcmp(expr->name.name, sub->var.name) != 0)
503 return OK;
504 if (strcmp(expr->name.package, sub->var.package) != 0)
500505 return OK;
501506 *expr = *(sub->val);
502507 return OK;
567572 /* variables in the constraint match anything */
568573 if (cp->type_expr_type == TYPE_EXPR_VAR)
569574 continue;
570 if (strcmp(ip->name, cp->name) != 0)
575 if (strcmp(ip->name.name, cp->name.name) != 0)
576 {
577 match = false;
578 break;
579 }
580 if (strcmp(ip->name.package, cp->name.package) != 0)
571581 {
572582 match = false;
573583 break;
666676 ubik_asprintf(
667677 &unified->failure_info,
668678 region,
669 "%s %s",
679 "%s %s:%s",
670680 unified->failure_info,
671 constraint->params[j].name);
681 constraint->params[j].name.package,
682 constraint->params[j].name.name);
672683 }
673684 ubik_asprintf(
674685 &unified->failure_info,
688699 for (i = 0; i < unified->substs.n; i++)
689700 {
690701 sub = unified->substs.elems[i];
691 printf("(%s => ", sub->varname);
702 printf("(%s:%s => ", sub->var.package, sub->var.name);
692703 ubik_assert(ubik_type_expr_print(sub->val) == OK);
693704 printf(") ");
694705 }
698709 printf("requiring impl %s ", constraint->iface->name);
699710 for (j = 0; j < constraint->iface->n_params; j++)
700711 {
701 printf("%s ", constraint->params[j].name);
712 printf("%s:%s ",
713 constraint->params[j].name.package,
714 constraint->params[j].name.name);
702715 }
703716 }
704717 printf(", result=%d\n", unified->success);
745758 {
746759 case TYPE_EXPR_ATOM:
747760 /* TODO: should have package! */
748 return ubik_typesystem_get(res, tsys, t->name, NULL);
761 return ubik_typesystem_get(
762 res, tsys, t->name.name, t->name.package);
749763
750764 case TYPE_EXPR_VAR:
751765 return ubik_raise(
173173
174174 ubik_alloc1(&bind->type_expr, struct ubik_type_expr, &req->region);
175175 bind->type_expr->type_expr_type = TYPE_EXPR_ATOM;
176 bind->type_expr->name = ubik_strdup(UBIK_TYPE_CONSTRUCTOR, &req->region);
176 bind->type_expr->name.name =
177 ubik_strdup(UBIK_TYPE_CONSTRUCTOR, &req->region);
178 bind->type_expr->name.package =
179 ubik_strdup(UBIK_PACKAGE, &req->region);
177180
178181 err = ubik_vector_append(&ast->bindings, bind);
179182 if (err != OK)
205208
206209 ubik_alloc1(&t0, struct ubik_type_expr, &req->region);
207210 t0->type_expr_type = TYPE_EXPR_ATOM;
208 t0->name = type->name;
211 t0->name.name = type->name;
212 t0->name.package = req->package_name;
209213 err = ubik_vector_append(&rev_types, t0);
210214 if (err != OK)
211215 return err;
240240 switch (type_expr->type_expr_type)
241241 {
242242 case TYPE_EXPR_ATOM:
243 printf("%s", type_expr->name);
243 printf("%s:%s", type_expr->name.package, type_expr->name.name);
244244 return OK;
245245 case TYPE_EXPR_APPLY:
246246 err = ubik_type_expr_print(type_expr->apply.head);
253253 printf(")");
254254 return OK;
255255 case TYPE_EXPR_VAR:
256 printf("%s", type_expr->name);
256 printf("%s:%s", type_expr->name.package, type_expr->name.name);
257257 return OK;
258258 case TYPE_EXPR_CONSTRAINED:
259259 err = ubik_type_expr_print(type_expr->constrained.term);
263263 constr = type_expr->constrained.constraints;
264264 for (; constr != NULL; constr = constr->next)
265265 {
266 printf(" ' %s", constr->interface);
266 printf(" ' %s:%s",
267 constr->interface.package,
268 constr->interface.name);
267269 params = constr->params;
268270 for (; params != NULL; params = params->next)
269 printf(" %s", params->name);
271 printf(" %s:%s",
272 params->name.package,
273 params->name.name);
270274 }
271275 return OK;
272276 }
324328 p = type->adt.params;
325329 while (p != NULL)
326330 {
327 printf(" %s", p->name);
331 printf(" %s:%s", p->name.name, p->name.package);
328332 p = p->next;
329333 if (p != NULL)
330334 printf(" ");
336340 c = type->adt.constraints;
337341 while (c != NULL)
338342 {
339 printf(" ' %s", c->interface);
343 printf(" ' %s:%s",
344 c->interface.name, c->interface.package);
340345 p = c->params;
341346 while (p != NULL)
342347 {
0 ` *list
1 ` *boolean
0 ` list
1 ` boolean
22 ~ ubik-tests/filter
33
4 # : filter
5 # ^ (a -> Boolean) -> List a -> List a
6 # = \f l -> ? l {
7 # . Nil => Nil
8 # . Cons head tail => ? {
9 # . f head => Cons head (filter f tail)
10 # . => filter f tail
11 # }
12 # }
413 : filter
5 ^ (a -> Boolean) -> List a -> List a
14 ^ (a -> boolean:Boolean) -> list:List a -> list:List a
615 = \f l -> ? l {
7 . Nil => Nil
8 . Cons head tail => ? {
9 . f head => Cons head (filter f tail)
16 . list:Nil => list:Nil
17 . list:Cons head tail => ? {
18 . f head => list:Cons head (filter f tail)
1019 . => filter f tail
1120 }
1221 }
13 ?: filter (\x -> eq 0 (% x 2)) (range 0 5) = Cons 0 (Cons 2 (Cons 4 Nil))