Changeset 1ebc1a62 in mainline for uspace/app/sbi/src/imode.c
- Timestamp:
- 2010-03-29T20:30:29Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a95310e
- Parents:
- 5da468e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/imode.c
r5da468e r1ebc1a62 27 27 */ 28 28 29 /** @file Interactive mode. */ 29 /** @file Interactive mode. 30 * 31 * In interactive mode the user types in statements. As soon as the outermost 32 * statement is complete (terminated with ';' or 'end'), the interpreter 33 * executes it. Otherwise it prompts the user until the entire statement 34 * is read in. 35 * 36 * The user interface depends on the OS. In HelenOS we use the CLUI library 37 * which gives us rich line editing capabilities. 38 */ 30 39 31 40 #include <stdio.h> 32 41 #include <stdlib.h> 33 42 #include "ancr.h" 43 #include "assert.h" 34 44 #include "builtin.h" 45 #include "intmap.h" 35 46 #include "list.h" 36 47 #include "mytypes.h" 48 #include "rdata.h" 37 49 #include "stree.h" 38 50 #include "strtab.h" … … 45 57 #include "imode.h" 46 58 59 /** Run in interactive mode. 60 * 61 * Repeatedly read in statements from the user and execute them. 62 */ 47 63 void imode_run(void) 48 64 { … … 56 72 stree_symbol_t *fun_sym; 57 73 stype_t stype; 74 stype_block_vr_t *block_vr; 75 list_node_t *bvr_n; 76 rdata_item_t *rexpr; 77 rdata_item_t *rexpr_vi; 58 78 59 79 run_t run; … … 72 92 ancr_module_process(program, program->module); 73 93 94 /* Construct typing context. */ 95 stype.program = program; 96 stype.proc_vr = stype_proc_vr_new(); 97 list_init(&stype.proc_vr->block_vr); 98 stype.current_csi = NULL; 99 proc = stree_proc_new(); 100 101 fun = stree_fun_new(); 102 fun_sym = stree_symbol_new(sc_fun); 103 fun_sym->u.fun = fun; 104 fun->name = stree_ident_new(); 105 fun->name->sid = strtab_get_sid("$imode"); 106 107 stype.proc_vr->proc = proc; 108 fun->symbol = fun_sym; 109 proc->outer_symbol = fun_sym; 110 111 /* Create block visit record. */ 112 block_vr = stype_block_vr_new(); 113 intmap_init(&block_vr->vdecls); 114 115 /* Add block visit record to the stack. */ 116 list_append(&stype.proc_vr->block_vr, block_vr); 117 118 /* Construct run context. */ 119 run.thread_ar = run_thread_ar_new(); 120 list_init(&run.thread_ar->proc_ar); 121 run_proc_ar_create(&run, NULL, proc, &proc_ar); 122 list_append(&run.thread_ar->proc_ar, proc_ar); 123 74 124 quit_im = b_false; 75 125 while (quit_im != b_true) { 126 parse.error = b_false; 127 stype.error = b_false; 128 76 129 input_new_interactive(&input); 77 130 … … 85 138 stat = parse_stat(&parse); 86 139 87 /* Construct typing context. */ 88 stype.program = program; 89 stype.proc_vr = stype_proc_vr_new(); 90 stype.current_csi = NULL; 91 proc = stree_proc_new(); 92 93 fun = stree_fun_new(); 94 fun_sym = stree_symbol_new(sc_fun); 95 fun_sym->u.fun = fun; 96 fun->name = stree_ident_new(); 97 fun->name->sid = strtab_get_sid("$imode"); 98 99 stype.proc_vr->proc = proc; 100 fun->symbol = fun_sym; 101 proc->outer_symbol = fun_sym; 102 103 /* Construct run context. */ 104 run.thread_ar = run_thread_ar_new(); 105 list_init(&run.thread_ar->proc_ar); 106 run_proc_ar_create(&run, NULL, proc, &proc_ar); 107 list_append(&run.thread_ar->proc_ar, proc_ar); 140 if (parse.error != b_false) 141 continue; 108 142 109 143 /* Type statement. */ 110 stype_stat(&stype, stat); 144 stype_stat(&stype, stat, b_true); 145 146 if (stype.error != b_false) 147 continue; 111 148 112 149 /* Run statement. */ 113 150 run_init(&run); 114 151 run.program = program; 115 run_stat(&run, stat); 152 run_stat(&run, stat, &rexpr); 153 154 if (rexpr != NULL) { 155 /* Convert expression result to value item. */ 156 run_cvt_value_item(&run, rexpr, &rexpr_vi); 157 assert(rexpr_vi->ic == ic_value); 158 159 /* Print result. */ 160 printf("Result: "); 161 rdata_value_print(rexpr_vi->u.value); 162 printf("\n"); 163 } 116 164 } 165 166 /* Remove block visit record from the stack, */ 167 bvr_n = list_last(&stype.proc_vr->block_vr); 168 assert(list_node_data(bvr_n, stype_block_vr_t *) == block_vr); 169 list_remove(&stype.proc_vr->block_vr, bvr_n); 117 170 118 171 printf("\nBye!\n");
Note:
See TracChangeset
for help on using the changeset viewer.