Changeset 1ebc1a62 in mainline for uspace/app/sbi/src/imode.c


Ignore:
Timestamp:
2010-03-29T20:30:29Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a95310e
Parents:
5da468e
Message:

Update SBI to rev. 157.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/imode.c

    r5da468e r1ebc1a62  
    2727 */
    2828
    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 */
    3039
    3140#include <stdio.h>
    3241#include <stdlib.h>
    3342#include "ancr.h"
     43#include "assert.h"
    3444#include "builtin.h"
     45#include "intmap.h"
    3546#include "list.h"
    3647#include "mytypes.h"
     48#include "rdata.h"
    3749#include "stree.h"
    3850#include "strtab.h"
     
    4557#include "imode.h"
    4658
     59/** Run in interactive mode.
     60 *
     61 * Repeatedly read in statements from the user and execute them.
     62 */
    4763void imode_run(void)
    4864{
     
    5672        stree_symbol_t *fun_sym;
    5773        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;
    5878
    5979        run_t run;
     
    7292        ancr_module_process(program, program->module);
    7393
     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
    74124        quit_im = b_false;
    75125        while (quit_im != b_true) {
     126                parse.error = b_false;
     127                stype.error = b_false;
     128
    76129                input_new_interactive(&input);
    77130
     
    85138                stat = parse_stat(&parse);
    86139
    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;
    108142
    109143                /* Type statement. */
    110                 stype_stat(&stype, stat);
     144                stype_stat(&stype, stat, b_true);
     145
     146                if (stype.error != b_false)
     147                        continue;
    111148
    112149                /* Run statement. */
    113150                run_init(&run);
    114151                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                }
    116164        }
     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);
    117170
    118171        printf("\nBye!\n");
Note: See TracChangeset for help on using the changeset viewer.