~lbnz/xr0

a00f89de97aae208a03b59f09b4a9224d0ced6a8 — Xr0 Team 10 months ago f5b2275 feat/program-1-zero-order
success
M include/state.h => include/state.h +0 -3
@@ 51,9 51,6 @@ state_popframe(struct state *);
void
state_declare(struct state *, struct ast_variable *var, bool isparam);

void
state_undeclarevars(struct state *s);

struct object *
state_getresult(struct state *);


M src/ast/ast.c => src/ast/ast.c +1 -1
@@ 93,7 93,7 @@ result_as_error(struct result *res)
struct value *
result_as_value(struct result *res)
{
	assert(!res->err && res->val);
	assert(!res->err);
	return res->val;
}


M src/ast/expr/verify.c => src/ast/expr/verify.c +4 -3
@@ 34,7 34,6 @@ ast_expr_decide(struct ast_expr *expr, struct state *state)
	case EXPR_BINARY:
		return expr_binary_decide(expr, state);
	default:
		printf("expr: %s\n", ast_expr_str(expr));
		assert(false);
	}
}


@@ 376,12 375,14 @@ expr_structmember_eval(struct ast_expr *expr, struct state *s)
	if (result_iserror(res)) {
		return res;
	}
	struct value *v = value_copy(object_as_value(
	/* XXX */
	struct value *obj_value = object_as_value(
		value_struct_member(
			result_as_value(res),
			ast_expr_member_field(expr)
		)
	));
	);
	struct value *v = obj_value ? value_copy(obj_value) : NULL;
	result_destroy(res);
	return result_value_create(v);
}

M src/ast/function/function.c => src/ast/function/function.c +0 -2
@@ 236,7 236,6 @@ path_verify(struct ast_function *f, struct state *state, struct externals *ext)
			break;
		}
	}
	state_undeclarevars(state);
	/* TODO: verify that `result' is of same type as f->result */
	if ((err = abstract_audit(f, state, ext))) {
		return error_prepend(err, "qed error: ");


@@ 322,7 321,6 @@ ast_function_absexec(struct ast_function *f, struct state *state)
		}
		result_destroy(res);
	}
	state_undeclarevars(state);

	/* wrap result and return */ 
	struct object *obj = state_getresult(state);

M src/ast/stmt/verify.c => src/ast/stmt/verify.c +3 -1
@@ 263,7 263,6 @@ stmt_jump_exec(struct ast_stmt *stmt, struct state *state)
		assert(obj);
		object_assign(obj, value_copy(result_as_value(res)));
		result_destroy(res);
		state_undeclarevars(state);
	}
	return NULL;
}


@@ 330,6 329,9 @@ iter_absexec(struct ast_stmt *stmt, struct state *state)
		return result_up;
	}

	/*printf("stmt: %s\n", ast_stmt_str(stmt));*/
	/*printf("state: %s\n", state_str(state));*/

	struct ast_expr *res_lw = value_to_expr(result_as_value(result_lw)),
			*res_up = value_to_expr(result_as_value(result_up));


M src/state/state.c => src/state/state.c +23 -13
@@ 55,6 55,7 @@ state_copy(struct state *state)
	copy->vconst = vconst_copy(state->vconst);
	copy->stack = stack_copy(state->stack);
	copy->heap = heap_copy(state->heap);
	copy->props = props_copy(state->props);
	return copy;
}



@@ 124,14 125,6 @@ state_declare(struct state *state, struct ast_variable *var, bool isparam)
	stack_declare(state->stack, var, isparam);
}

void
state_undeclarevars(struct state *s)
{
	heap_undeclare(s->heap, s);
	vconst_undeclare(s->vconst);
	stack_undeclare(s->stack, s);
}

struct value *
state_vconst(struct state *state, struct ast_type *t, char *comment, bool persist)
{


@@ 342,16 335,33 @@ state_eval(struct state *s, struct ast_expr *e)
	return vconst_eval(s->vconst, e);
}

static void
state_undeclarevars(struct state *s);

bool
state_equal(struct state *s1, struct state *s2)
{
	bool equal;
	char *str1 = state_str(s1),
	     *str2 = state_str(s2);
	equal = strcmp(str1, str2) == 0;

	struct state *s1_c = state_copy(s1),
		     *s2_c = state_copy(s2);
	state_undeclarevars(s1_c);
	state_undeclarevars(s2_c);

	char *str1 = state_str(s1_c),
	     *str2 = state_str(s2_c);
	bool equal = strcmp(str1, str2) == 0;
	free(str2);
	free(str1);

	state_destroy(s2_c);
	state_destroy(s1_c);

	return equal;
}

static void
state_undeclarevars(struct state *s)
{
	heap_undeclare(s->heap, s);
	vconst_undeclare(s->vconst);
	stack_undeclare(s->stack, s);
}