HelenOS sources
This source file includes following definitions.
- imode_run
#include <stdio.h>
#include <stdlib.h>
#include "os/os.h"
#include "ancr.h"
#include "assert.h"
#include "builtin.h"
#include "intmap.h"
#include "list.h"
#include "mytypes.h"
#include "program.h"
#include "rdata.h"
#include "stree.h"
#include "strtab.h"
#include "stype.h"
#include "input.h"
#include "lex.h"
#include "parse.h"
#include "run.h"
#include "imode.h"
void imode_run(void)
{
input_t *input;
lex_t lex;
parse_t parse;
stree_program_t *program;
stree_stat_t *stat;
stree_proc_t *proc;
stree_fun_t *fun;
stree_symbol_t *fun_sym;
stype_t stype;
stype_block_vr_t *block_vr;
list_node_t *bvr_n;
rdata_item_t *rexpr;
rdata_item_t *rexpr_vi;
run_t run;
run_proc_ar_t *proc_ar;
bool_t quit_im;
program = stree_program_new();
program->module = stree_module_new();
builtin_declare(program);
if (program_lib_process(program) != EOK)
exit(1);
ancr_module_process(program, program->module);
builtin_bind(program->builtin);
ancr_module_process(program, program->module);
stype.program = program;
stype.proc_vr = stype_proc_vr_new();
list_init(&stype.proc_vr->block_vr);
stype.current_csi = NULL;
proc = stree_proc_new();
fun = stree_fun_new();
fun_sym = stree_symbol_new(sc_fun);
fun_sym->u.fun = fun;
fun->name = stree_ident_new();
fun->name->sid = strtab_get_sid("$imode");
fun->sig = stree_fun_sig_new();
stype.proc_vr->proc = proc;
fun->symbol = fun_sym;
proc->outer_symbol = fun_sym;
block_vr = stype_block_vr_new();
intmap_init(&block_vr->vdecls);
list_append(&stype.proc_vr->block_vr, block_vr);
run_gdata_init(&run);
run.thread_ar = run_thread_ar_new();
list_init(&run.thread_ar->proc_ar);
run_proc_ar_create(&run, run.gdata, proc, &proc_ar);
list_append(&run.thread_ar->proc_ar, proc_ar);
printf("SBI interactive mode. ");
os_input_disp_help();
quit_im = b_false;
while (quit_im != b_true) {
parse.error = b_false;
stype.error = b_false;
run.thread_ar->exc_payload = NULL;
run.thread_ar->bo_mode = bm_none;
input_new_interactive(&input);
lex_init(&lex, input);
parse_init(&parse, program, &lex);
if (lcur_lc(&parse) == lc_eof)
break;
stat = parse_stat(&parse);
if (parse.error != b_false)
continue;
stype_stat(&stype, stat, b_true);
if (stype.error != b_false)
continue;
run_init(&run);
run.program = program;
run_stat(&run, stat, &rexpr);
run_exc_check_unhandled(&run);
if (rexpr != NULL) {
run_cvt_value_item(&run, rexpr, &rexpr_vi);
rdata_item_destroy(rexpr);
run_exc_check_unhandled(&run);
} else {
rexpr_vi = NULL;
}
if (rexpr_vi != NULL) {
assert(rexpr_vi->ic == ic_value);
printf("Result: ");
rdata_value_print(rexpr_vi->u.value);
printf("\n");
rdata_item_destroy(rexpr_vi);
}
}
run_proc_ar_destroy(&run, proc_ar);
bvr_n = list_last(&stype.proc_vr->block_vr);
assert(list_node_data(bvr_n, stype_block_vr_t *) == block_vr);
list_remove(&stype.proc_vr->block_vr, bvr_n);
printf("\nBye!\n");
}
HelenOS homepage, sources at GitHub