00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include "os/os.h"
00043 #include "ancr.h"
00044 #include "assert.h"
00045 #include "builtin.h"
00046 #include "intmap.h"
00047 #include "list.h"
00048 #include "mytypes.h"
00049 #include "program.h"
00050 #include "rdata.h"
00051 #include "stree.h"
00052 #include "strtab.h"
00053 #include "stype.h"
00054 #include "input.h"
00055 #include "lex.h"
00056 #include "parse.h"
00057 #include "run.h"
00058
00059 #include "imode.h"
00060
00065 void imode_run(void)
00066 {
00067 input_t *input;
00068 lex_t lex;
00069 parse_t parse;
00070 stree_program_t *program;
00071 stree_stat_t *stat;
00072 stree_proc_t *proc;
00073 stree_fun_t *fun;
00074 stree_symbol_t *fun_sym;
00075 stype_t stype;
00076 stype_block_vr_t *block_vr;
00077 list_node_t *bvr_n;
00078 rdata_item_t *rexpr;
00079 rdata_item_t *rexpr_vi;
00080
00081 run_t run;
00082 run_proc_ar_t *proc_ar;
00083
00084 bool_t quit_im;
00085
00086
00087 program = stree_program_new();
00088 program->module = stree_module_new();
00089
00090
00091 builtin_declare(program);
00092
00093
00094 if (program_lib_process(program) != EOK)
00095 exit(1);
00096
00097
00098 ancr_module_process(program, program->module);
00099
00100
00101 builtin_bind(program->builtin);
00102
00103
00104 ancr_module_process(program, program->module);
00105
00106
00107 stype.program = program;
00108 stype.proc_vr = stype_proc_vr_new();
00109 list_init(&stype.proc_vr->block_vr);
00110 stype.current_csi = NULL;
00111 proc = stree_proc_new();
00112
00113 fun = stree_fun_new();
00114 fun_sym = stree_symbol_new(sc_fun);
00115 fun_sym->u.fun = fun;
00116 fun->name = stree_ident_new();
00117 fun->name->sid = strtab_get_sid("$imode");
00118 fun->sig = stree_fun_sig_new();
00119
00120 stype.proc_vr->proc = proc;
00121 fun->symbol = fun_sym;
00122 proc->outer_symbol = fun_sym;
00123
00124
00125 block_vr = stype_block_vr_new();
00126 intmap_init(&block_vr->vdecls);
00127
00128
00129 list_append(&stype.proc_vr->block_vr, block_vr);
00130
00131
00132 run_gdata_init(&run);
00133
00134 run.thread_ar = run_thread_ar_new();
00135 list_init(&run.thread_ar->proc_ar);
00136 run_proc_ar_create(&run, run.gdata, proc, &proc_ar);
00137 list_append(&run.thread_ar->proc_ar, proc_ar);
00138
00139 printf("SBI interactive mode. ");
00140 os_input_disp_help();
00141
00142 quit_im = b_false;
00143 while (quit_im != b_true) {
00144 parse.error = b_false;
00145 stype.error = b_false;
00146 run.thread_ar->exc_payload = NULL;
00147 run.thread_ar->bo_mode = bm_none;
00148
00149 input_new_interactive(&input);
00150
00151
00152 lex_init(&lex, input);
00153 parse_init(&parse, program, &lex);
00154
00155 if (lcur_lc(&parse) == lc_eof)
00156 break;
00157
00158 stat = parse_stat(&parse);
00159
00160 if (parse.error != b_false)
00161 continue;
00162
00163
00164 stype_stat(&stype, stat, b_true);
00165
00166 if (stype.error != b_false)
00167 continue;
00168
00169
00170 run_init(&run);
00171 run.program = program;
00172 run_stat(&run, stat, &rexpr);
00173
00174
00175 run_exc_check_unhandled(&run);
00176
00177 if (rexpr != NULL) {
00178
00179 run_cvt_value_item(&run, rexpr, &rexpr_vi);
00180 rdata_item_destroy(rexpr);
00181
00182
00183 run_exc_check_unhandled(&run);
00184 } else {
00185 rexpr_vi = NULL;
00186 }
00187
00188
00189
00190
00191
00192 if (rexpr_vi != NULL) {
00193 assert(rexpr_vi->ic == ic_value);
00194
00195
00196 printf("Result: ");
00197 rdata_value_print(rexpr_vi->u.value);
00198 printf("\n");
00199
00200 rdata_item_destroy(rexpr_vi);
00201 }
00202 }
00203
00204 run_proc_ar_destroy(&run, proc_ar);
00205
00206
00207 bvr_n = list_last(&stype.proc_vr->block_vr);
00208 assert(list_node_data(bvr_n, stype_block_vr_t *) == block_vr);
00209 list_remove(&stype.proc_vr->block_vr, bvr_n);
00210
00211 printf("\nBye!\n");
00212 }