~lbnz/xr0

7e47ade10e33b2a116bf0d442e3d9ef5dc6c5968 — Leibniz Founders 7 months ago 4547e6c
change print
M include/ast.h => include/ast.h +3 -0
@@ 554,6 554,9 @@ ast_function_destroy(struct ast_function *);
char *
ast_function_str(struct ast_function *f);

char *
ast_function_name(struct ast_function *f);

struct ast_function *
ast_function_copy(struct ast_function *);


M include/state.h => include/state.h +2 -2
@@ 22,7 22,7 @@ struct value;
struct state;

struct state *
state_create(struct externals *, struct ast_type *result_type);
state_create(char *func, struct externals *, struct ast_type *result_type);

struct state *
state_copy(struct state *);


@@ 37,7 37,7 @@ struct externals *
state_getext(struct state *);

void
state_pushframe(struct state *, struct ast_type *ret_type);
state_pushframe(struct state *, char *func, struct ast_type *ret_type);

void
state_popframe(struct state *);

M src/ast/ast.c => src/ast/ast.c +6 -0
@@ 1948,6 1948,12 @@ ast_function_str(struct ast_function *f)
	return strbuilder_build(b);
}

char *
ast_function_name(struct ast_function *f)
{
	return f->name;
}

struct ast_function *
ast_function_copy(struct ast_function *f)
{

M src/state/stack.c => src/state/stack.c +10 -7
@@ 13,6 13,7 @@
#include "util.h"

struct stack {
	char *name;
	struct block_arr *frame;

	/* lvalues of blocks in frame */


@@ 32,11 33,12 @@ stack_newblock(struct stack *stack)
}

struct stack *
stack_create(struct stack *prev, struct ast_type *result_type)
stack_create(char *name, struct stack *prev, struct ast_type *result_type)
{
	struct stack *stack = calloc(1, sizeof(struct stack));
	assert(stack);

	stack->name = name;
	stack->frame = block_arr_create();

	stack->varmap = map_create();


@@ 77,6 79,7 @@ struct stack *
stack_copy(struct stack *stack)
{
	struct stack *copy = calloc(1, sizeof(struct stack));
	copy->name = dynamic_str(stack->name);
	copy->frame = block_arr_copy(stack->frame);
	copy->varmap = varmap_copy(stack->varmap);
	copy->result = variable_copy(stack->result);


@@ 116,14 119,14 @@ stack_str(struct stack *stack, struct state *state)
	char *result = variable_str(stack->result, stack, state);
	strbuilder_printf(b, "\tresult: %s\n", result);
	free(result);
	strbuilder_printf(b, "\t");
	/* TODO: fix length of line */
	for (int i = 0, len = 30; i < len-2; i++ ) {
		strbuilder_putc(b, '-');
	}
	strbuilder_printf(b, " %s\n", stack->name);
	if (stack->prev) {
		strbuilder_printf(b, "\t");
		char *prev = stack_str(stack->prev, state);
		/* TODO: fix length of line */
		for (int i = 0, len = 30; i < len-2; i++ ) {
			strbuilder_putc(b, '-');
		}
		strbuilder_printf(b, "\n");
		strbuilder_printf(b, prev);
		free(prev);
	}

M src/state/stack.h => src/state/stack.h +1 -1
@@ 7,7 7,7 @@
struct stack;

struct stack *
stack_create(struct stack *prev, struct ast_type *ret_type);
stack_create(char *name, struct stack *prev, struct ast_type *ret_type);

struct location *
stack_newblock(struct stack *stack);

M src/state/state.c => src/state/state.c +4 -4
@@ 22,13 22,13 @@ struct state {
};

struct state *
state_create(struct externals *ext, struct ast_type *result_type)
state_create(char *func, struct externals *ext, struct ast_type *result_type)
{
	struct state *state = malloc(sizeof(struct state));
	assert(state);
	state->ext = ext;
	state->vconst = vconst_create();
	state->stack = stack_create(NULL, result_type);
	state->stack = stack_create(func, NULL, result_type);
	state->heap = heap_create();
	return state;
}


@@ 95,9 95,9 @@ state_getfunc(struct state *state, char *f)
}

void
state_pushframe(struct state *state, struct ast_type *ret_type)
state_pushframe(struct state *state, char *func, struct ast_type *ret_type)
{
	state->stack = stack_create(state->stack, ret_type);
	state->stack = stack_create(func, state->stack, ret_type);
}

void

M src/verify/verify.c => src/verify/verify.c +23 -6
@@ 61,7 61,9 @@ path_verify(struct ast_function *f, struct state *state, struct externals *);
struct error *
path_verify_withstate(struct ast_function *f, struct externals *ext)
{
	struct state *state = state_create(ext, ast_function_type(f));
	struct state *state = state_create(
		dynamic_str(ast_function_name(f)), ext, ast_function_type(f)
	);
	struct error *err = path_verify(f, state, ext);
	state_destroy(state);
	return err;


@@ 1089,12 1091,15 @@ static struct result
expr_call_eval(struct ast_expr *expr, struct state *state)
{
	struct result_arr *args = prepare_arguments(expr, state);
	state_pushframe(state, ast_function_type(expr_as_func(expr, state)));
	struct ast_function *f = expr_as_func(expr, state);
	state_pushframe(
		state, dynamic_str(ast_function_name(f)), ast_function_type(f)
	);
	struct result res = call_eval_inframe(expr, state, args);
	result_arr_destroy(args);
	if (result_iserror(res)) {
		return res;
	}
	result_arr_destroy(args);
	if (result_hasvalue(res)) { /* preserve value through pop */
		res = result_value_create(value_copy(result_as_value(res)));
	}


@@ 1128,7 1133,9 @@ call_eval_inframe(struct ast_expr *expr, struct state *state, struct result_arr 
	assert(f);

	struct error *err = prepare_parameters(f, args, state);
	assert(!err);
	if (err) {
		return result_error_create(err);
	}

	return function_absexec(ast_function_abstract(f), state);
}


@@ 1148,7 1155,15 @@ prepare_parameters(struct ast_function *f, struct result_arr *args,

		struct result res = args->res[i];
		if (result_iserror(res)) {
			return result_as_error(res);
			printf("state: %s\n", state_str(state));
			struct strbuilder *b = strbuilder_create();
			strbuilder_printf(
				b, "param `%s': ",
				ast_variable_name(param[i])
			);
			return error_prepend(
				result_as_error(res), strbuilder_build(b)
			);
		}

		if (!result_hasvalue(res)) {


@@ 1501,7 1516,9 @@ abstract_audit(struct ast_function *f, struct state *actual_state,
	}
	/*printf("actual: %s\n", state_str(actual_state));*/

	struct state *alleged_state = state_create(ext, ast_function_type(f));
	struct state *alleged_state = state_create(
		dynamic_str(ast_function_name(f)), ext, ast_function_type(f)
	);
	if ((err = parameterise_state(alleged_state, f))) {
		return err;
	}

A tests/0-basic/200-free-param.x => tests/0-basic/200-free-param.x +7 -0
@@ 0,0 1,7 @@
#include <stdlib.h>

void
unit(void *p) [ .dealloc p; ]
{
	free(p);
}