Esempio n. 1
0
const char* ast_serialize_to_string(const ast_node_t ast) {
	unsigned int size=0;
	char*ret,*tmp;
	ast_serialize(ast,incr,(void*)&size);
//	printf("serialize needs %i bytes\n",size);
	tmp=ret=(char*)malloc(size+1);
	ast_serialize(ast,str_put,(void*)&tmp);
//	printf("serialized to %s (%i)\n",ret,strlen(ret));
	return ret;
}
Esempio n. 2
0
void ast_ser_list(const ast_node_t ast,int(*func)(int,void*),void*param) {
	/* FIXME shouldn't happen */
	if(isAtom(ast)) {
		ast_serialize(ast,func,param);
		return;
	}

	if(getCar(ast)) {
		ast_serialize(getCar(ast),func,param);
	}
	if(getCdr(ast)) {
		func(' ',param);
		ast_ser_list(getCdr(ast),func,param);
	}
}
Esempio n. 3
0
VAL_LOC_T eval(
    struct AstNode *node,
    struct Runtime *rt,
    struct SymMap *sym_map,
    struct AstLocMap *alm)
{
    VAL_LOC_T begin, result, end;

#if LOG_LEVEL <= LLVL_TRACE
    char *node_string = ast_serialize(node);
    LOG_TRACE("eval BEGIN(%s)", node_string);
    mem_free(node_string);
#endif

    err_reset();

    /* The dispatch is delegated to another procedure as it is called
     * recursively during the evaluation while the current function is only
     * called by the top-level client.
     */
    begin = rt->stack.top;
    result = eval_dispatch(node, rt, sym_map, alm);
    end = rt->stack.top;

    if (err_state()) {
        stack_collapse(&rt->stack, begin, end);
        LOG_TRACE("eval END(error)");
        return -1;
    } else {
        LOG_TRACE("eval END(result=%td)", result);
        return result;
    }
}
Esempio n. 4
0
VAL_LOC_T eval_dispatch(
    struct AstNode *node,
    struct Runtime *rt,
    struct SymMap *sym_map,
    struct AstLocMap *alm)
{
    /* It is possible that the debugger flag will change during evaluation. */
    bool debug_begin_called = false;

    VAL_LOC_T begin = rt->stack.top;

#if LOG_LEVEL <= LLVL_TRACE
    char *node_string = ast_serialize(node);
    LOG_TRACE("eval_impl BEGIN(%s)", node_string);
    mem_free(node_string);
#endif

    if (rt->debug) {
        dbg_call_begin(&rt->debugger, node);
        debug_begin_called = true;
    }

    switch (node->type) {
    case AST_SYMBOL:
        eval_symbol(node, rt, sym_map, alm);
        break;

    case AST_SPECIAL:
        eval_special(node, rt, sym_map, alm);
        break;

    case AST_FUNCTION_CALL:
        eval_func_call(node, rt, sym_map, alm);
        break;

    case AST_LITERAL_COMPOUND:
        eval_literal_compound(node, rt, sym_map, alm);
        break;

    case AST_LITERAL_ATOMIC:
        eval_literal_atomic(node, rt, sym_map, alm);
        break;
    }

    if (err_state()) {

        VAL_LOC_T ret_val = -1;
        if (debug_begin_called) {
            dbg_call_end(&rt->debugger, rt, ret_val, true);
        }

        err_push_src("EVAL", alm_try_get(alm, node), "Failed evaluating expression");
        LOG_TRACE("eval_impl END(error)");
        return ret_val;

    } else {

        if (debug_begin_called) {
            dbg_call_end(&rt->debugger, rt, begin, false);
        }

        LOG_TRACE("eval_impl END(result=%td)", begin);
        return begin;
    }
}
Esempio n. 5
0
void ast_serialize_to_file(const ast_node_t ast,FILE*f) {
	ast_serialize(ast,file_put,(void*)f);
}