git.haldean.org expel / 03cdef5
start on the great untyping of input nodes. stuff is broken right now. Haldean Brown 6 years ago
12 changed file(s) with 52 addition(s) and 125 deletion(s). Raw diff Collapse all Expand all
296296 8-15 The number of nodes in the graph
297297 16-23 The index of the result node in the graph
298298 24-31 The value index of the identity URI of the graph
299 32-39 The value index of the type of the graph
299300
300301 The identity URI represents the meaning of the graph; in most cases this
301302 will be the URI of whatever the graph is bound to. The result node
354355
355356 Byte index Field
356357 0-7 Argument index of the node
357 8-15 Value index of the tree-encoded type requirement on
358 the argument
359358
360359 Nodes with node type ` cond` have the following body:
361360
88 input nodes shouldn't have required_type, it should be taken from graph type
99 interface files
1010 real parser for URIs instead of hacky shit
11 untangle gen.c
8282 struct xl_dagc_node head;
8383 /* The argument that this corresponds to */
8484 xl_word arg_num;
85 /* The type required by the program */
86 struct xl_value *required_type;
8785 };
8886
8987 struct xl_dagc_ref
5555 err = _create_op(&ngraph, 2, DEF_OP_EVAL);
5656 if (err != OK)
5757 return err;
58 err = DEF_ARG_TYPE(
59 ((struct xl_dagc_input *) ngraph->inputs[0])->required_type);
60 if (err != OK)
61 return err;
62 err = DEF_ARG_TYPE(
63 ((struct xl_dagc_input *) ngraph->inputs[1])->required_type);
64 if (err != OK)
65 return err;
6658
6759 err = _native_uri(&uri, DEF_OP_URI);
6860 if (err != OK)
109101 err = _create_op(&ngraph, 1, DEF_OP_EVAL);
110102 if (err != OK)
111103 return err;
112 err = DEF_ARG_TYPE(
113 ((struct xl_dagc_input *) ngraph->inputs[0])->required_type);
114 if (err != OK)
115 return err;
116104
117105 err = _native_uri(&uri, DEF_OP_URI);
118106 if (err != OK)
183183
184184 /* The result node in the graph. */
185185 struct xl_dagc_node *result;
186
187 /* The effective type of the graph. */
188 struct xl_value *type;
186189 };
187190
188191 /* Starts the expel runtime.
437437 struct xl_dagc_load *l;
438438 struct xl_dagc_store *s;
439439 struct xl_dagc_const *c;
440 struct xl_dagc_input *i;
441440 xl_error err;
442441
443442 if (node->known.any != NULL)
459458 case DAGC_NODE_NATIVE:
460459 case DAGC_NODE_COND:
461460 case DAGC_NODE_REF:
462 return OK;
463
464461 case DAGC_NODE_INPUT:
465 i = (struct xl_dagc_input *) node;
466 return xl_take(i->required_type);
462 return OK;
467463
468464 case DAGC_NODE_LOAD:
469465 l = (struct xl_dagc_load *) node;
589585 return err;
590586 }
591587
588 err = xl_take(result->type);
589 if (err != OK)
590 return err;
591
592592 return OK;
593593 }
3232 struct xl_dagc *result;
3333 struct xl_dagc *proto;
3434 size_t i;
35 char *msg;
3635
3736 unused(env);
3837
6665 for (i = 0; i < result->in_arity; i++)
6766 result->inputs[i] = result->inputs[i + 1];
6867
69 if (!xl_type_satisfied(input->required_type, node->arg->known_type))
70 {
71 fprintf(stderr, "could not apply argument to function:\n");
72
73 msg = xl_type_explain(input->required_type);
74 fprintf(stderr, "required type: %s\n", msg);
75 free(msg);
76
77 msg = xl_type_explain(node->arg->known_type);
78 fprintf(stderr, "got type: %s\n", msg);
79 free(msg);
80
81 return xl_raise(
82 ERR_BAD_TYPE, "input type and arg type incompatible");
83 }
84
8568 input->head.flags = XL_DAGC_FLAG_COMPLETE;
8669
8770 input->head.known_type = node->arg->known_type;
9881 if (err != OK)
9982 return err;
10083 err = xl_type_func_apply(node->head.known_type, node->func->known_type);
84 if (err != OK)
85 return err;
86 err = xl_type_func_apply(result->type, proto->type);
10187 if (err != OK)
10288 return err;
10389
454454 {
455455 case DAGC_NODE_APPLY:
456456 case DAGC_NODE_COND:
457 case DAGC_NODE_INPUT:
457458 case DAGC_NODE_NATIVE:
458459 case DAGC_NODE_REF:
459460 break;
475476
476477 case DAGC_NODE_STORE:
477478 err = xl_release(n->as_store.loc);
478 if (err != OK)
479 return err;
480 break;
481
482 case DAGC_NODE_INPUT:
483 err = xl_release(n->as_input.required_type);
484479 if (err != OK)
485480 return err;
486481 break;
592587 if (err != OK)
593588 return err;
594589 }
590 err = xl_release(g->type);
591 if (err != OK)
592 return err;
595593
596594 bzero(g, sizeof(*g));
597595 free(g);
3838 _assign_nodes(
3939 struct xl_graph_builder *builder,
4040 struct xl_ast_expr *expr,
41 struct xl_ast_arg_list *args_in_scope,
42 struct xl_ast_type_expr *known_type);
41 struct xl_ast_arg_list *args_in_scope);
4342
4443 /* Returns true if the given name is in the arg list, and sets input_node to the
4544 * input node corresponding to the argument in the list. */
252251 no_ignore static xl_error
253252 _assign_lambda(
254253 union xl_dagc_any_node *n,
255 struct xl_ast_expr *expr,
256 struct xl_ast_type_expr *known_type)
254 struct xl_ast_expr *expr)
257255 {
258256 struct xl_graph_builder builder;
259257 struct xl_dagc *subgraph;
271269 i = 0;
272270 while (t->name != NULL)
273271 {
274 /* failing this means the type signature does not have enough
275 * types for all arguments in the function. */
276 xl_assert(known_type != NULL);
277
278272 input_node = calloc(1, sizeof(struct xl_dagc_input));
279273 if (input_node == NULL)
280274 return xl_raise(ERR_NO_MEMORY, "input node alloc");
283277 input_node->head.id = 0;
284278 input_node->arg_num = i++;
285279
286 err = xl_value_new(&input_node->required_type);
287 if (err != OK)
288 return err;
289 err = xl_type_builtin_from_name(
290 input_node->required_type,
291 known_type->type_expr_type == TYPE_EXPR_APPLY
292 ? known_type->apply.head->name
293 : known_type->name);
294 if (err != OK)
295 return err;
296
297 if (known_type->type_expr_type == TYPE_EXPR_APPLY)
298 known_type = known_type->apply.tail;
299 else
300 known_type = NULL;
301
302280 err = xl_bdagc_push_node(
303281 &builder, (struct xl_dagc_node *) input_node);
304282 if (err != OK)
309287 }
310288
311289 err = _assign_nodes(
312 &builder, expr->lambda.body, expr->lambda.args, NULL);
290 &builder, expr->lambda.body, expr->lambda.args);
313291 if (err != OK)
314292 return err;
315293
339317 _assign_nodes(
340318 struct xl_graph_builder *builder,
341319 struct xl_ast_expr *expr,
342 struct xl_ast_arg_list *args_in_scope,
343 struct xl_ast_type_expr *known_type)
320 struct xl_ast_arg_list *args_in_scope)
344321 {
345322 union xl_dagc_any_node *n;
346323 xl_error err;
357334
358335 case EXPR_APPLY:
359336 err = _assign_nodes(
360 builder, expr->apply.head, args_in_scope, NULL);
337 builder, expr->apply.head, args_in_scope);
361338 if (err != OK)
362339 return err;
363340
364341 err = _assign_nodes(
365 builder, expr->apply.tail, args_in_scope, NULL);
342 builder, expr->apply.tail, args_in_scope);
366343 if (err != OK)
367344 return err;
368345
373350
374351 case EXPR_CONDITIONAL:
375352 err = _assign_nodes(
376 builder, expr->condition.cond, args_in_scope, NULL);
353 builder, expr->condition.cond, args_in_scope);
377354 if (err != OK)
378355 return err;
379356
380357 err = _assign_nodes(
381 builder, expr->condition.implied, args_in_scope, NULL);
358 builder, expr->condition.implied, args_in_scope);
382359 if (err != OK)
383360 return err;
384361
385362 err = _assign_nodes(
386 builder, expr->condition.opposed, args_in_scope, NULL);
363 builder, expr->condition.opposed, args_in_scope);
387364 if (err != OK)
388365 return err;
389366
393370 break;
394371
395372 case EXPR_LAMBDA:
396 err = _assign_lambda(n, expr, known_type);
373 err = _assign_lambda(n, expr);
397374 if (err != OK)
398375 return err;
399376 break;
435412 if (err != OK)
436413 return err;
437414
438 err = _assign_nodes(&builder, binding->expr, NULL, binding->type_expr);
415 err = _assign_nodes(&builder, binding->expr, NULL);
439416 if (err != OK)
440417 return err;
441418
736713 if (ast->immediate != NULL
737714 && (load_reason == LOAD_MAIN || load_reason == LOAD_BLOCK))
738715 {
739 err = _assign_nodes(&builder, ast->immediate, NULL, NULL);
716 err = _assign_nodes(&builder, ast->immediate, NULL);
740717 if (err != OK)
741718 return err;
742719 ast->immediate->gen->is_terminal = true;
238238 no_ignore static xl_error
239239 _load_input(
240240 struct xl_dagc_input *node,
241 struct xl_stream *sp,
242 struct xl_value **values,
243 size_t n_values)
244 {
245 xl_word value_index;
241 struct xl_stream *sp)
242 {
246243 xl_word arg_num;
247 xl_error err;
248244
249245 READ_INTO(arg_num, sp);
250246 node->arg_num = ntohw(arg_num);
251247
252 READ_INTO(value_index, sp);
253 value_index = ntohw(value_index);
254 if (value_index >= n_values)
255 return xl_raise(ERR_OUT_OF_BOUNDS, "input value index");
256 node->required_type = values[value_index];
257 err = xl_take(node->required_type);
258 return err;
248 return OK;
259249 }
260250
261251 no_ignore static xl_error
331321 err = _load_store(&n->as_store, sp, values, n_values);
332322 break;
333323 case DAGC_NODE_INPUT:
334 err = _load_input(&n->as_input, sp, values, n_values);
324 err = _load_input(&n->as_input, sp);
335325 break;
336326 case DAGC_NODE_COND:
337327 err = _load_cond(&n->as_cond, sp);
492482 xl_word n_nodes;
493483 xl_word result_idx;
494484 xl_word identity_idx;
485 xl_word type_idx;
495486 size_t i;
496487 xl_error err;
497488 xl_tag tag;
515506
516507 READ_INTO(identity_idx, sp);
517508 identity_idx = ntohw(identity_idx);
509
510 READ_INTO(type_idx, sp);
511 type_idx = ntohw(type_idx);
518512
519513 /* This binary is too large to be read on this machine. Note that
520514 * performing this check up front means that we don't have to worry
579573 else
580574 (*graph)->identity = NULL;
581575
576 if (type_idx >= n_values)
577 return xl_raise(ERR_BAD_HEADER, "type_idx > n_values");
578 (*graph)->type = values[type_idx];
579 err = xl_take((*graph)->type);
580 if (err != OK)
581 return err;
582
582583 (*graph)->tag = tag;
583584 return OK;
584585 }
7777 in->head.is_terminal = 0x00;
7878 in->head.flags = 0x00;
7979 in->arg_num = i;
80 err = xl_value_new(&in->required_type);
81 if (err != OK)
82 return err;
8380 }
8481
8582 /* Create output native node */
9087 graph->nodes[arity]->flags = 0x00;
9188
9289 graph->result = graph->nodes[arity];
90
91 err = xl_value_new(&graph->type);
92 if (err != OK)
93 return err;
9394
9495 err = xl_dagc_init(graph);
9596 if (err != OK)
430431 err = _create_op(&wgraph, 1, _native_humanize_word);
431432 if (err != OK)
432433 return err;
433 err = xl_type_word(
434 ((struct xl_dagc_input *) wgraph->inputs[0])->required_type);
435 if (err != OK)
436 return err;
437434
438435 fgraph = NULL;
439436 err = _create_op(&fgraph, 1, _native_humanize_float);
440437 if (err != OK)
441438 return err;
442 err = xl_type_float(
443 ((struct xl_dagc_input *) fgraph->inputs[0])->required_type);
444 if (err != OK)
445 return err;
446439
447440 #include "humanize-poly.h"
448441
158158 {
159159 case DAGC_NODE_APPLY:
160160 case DAGC_NODE_COND:
161 case DAGC_NODE_INPUT:
161162 case DAGC_NODE_REF:
162163 break;
163164
183184 return err;
184185 break;
185186
186 case DAGC_NODE_INPUT:
187 err = xl_pointer_set_add(
188 NULL, values, n->as_input.required_type);
189 if (err != OK)
190 return err;
191 break;
192
193187 case DAGC_NODE_LOAD:
194188 err = xl_uri_attach_value(n->as_load.loc);
195189 if (err != OK)
342336 no_ignore static xl_error
343337 _store_input(
344338 struct xl_stream *sp,
345 struct xl_dagc_input *n,
346 struct xl_vector *values)
347 {
348 xl_error err;
339 struct xl_dagc_input *n)
340 {
349341 xl_word t;
350 xl_word index;
351 size_t sindex;
352342
353343 t = htonw(n->arg_num);
354344 WRITE_INTO(sp, t);
355
356 err = xl_pointer_set_find(&sindex, values, n->required_type);
357 if (err != OK)
358 return err;
359 index = sindex;
360 index = htonw(index);
361 WRITE_INTO(sp, index);
362345
363346 return OK;
364347 }
521504 break;
522505
523506 case DAGC_NODE_INPUT:
524 err = _store_input(sp, &n->as_input, values);
507 err = _store_input(sp, &n->as_input);
525508 break;
526509
527510 case DAGC_NODE_LOAD: