source: mainline/uspace/app/sbi/src/imode.c@ 5da468e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5da468e was 4204ad9, checked in by Jiri Svoboda <jiri@…>, 16 years ago

Add missing new files.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2010 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @file Interactive mode. */
30
31#include <stdio.h>
32#include <stdlib.h>
33#include "ancr.h"
34#include "builtin.h"
35#include "list.h"
36#include "mytypes.h"
37#include "stree.h"
38#include "strtab.h"
39#include "stype.h"
40#include "input.h"
41#include "lex.h"
42#include "parse.h"
43#include "run.h"
44
45#include "imode.h"
46
47void imode_run(void)
48{
49 input_t *input;
50 lex_t lex;
51 parse_t parse;
52 stree_program_t *program;
53 stree_stat_t *stat;
54 stree_proc_t *proc;
55 stree_fun_t *fun;
56 stree_symbol_t *fun_sym;
57 stype_t stype;
58
59 run_t run;
60 run_proc_ar_t *proc_ar;
61
62 bool_t quit_im;
63
64 /* Create an empty program. */
65 program = stree_program_new();
66 program->module = stree_module_new();
67
68 /* Declare builtin symbols. */
69 builtin_declare(program);
70
71 /* Resolve ancestry. */
72 ancr_module_process(program, program->module);
73
74 quit_im = b_false;
75 while (quit_im != b_true) {
76 input_new_interactive(&input);
77
78 /* Parse input. */
79 lex_init(&lex, input);
80 parse_init(&parse, program, &lex);
81
82 if (lcur_lc(&parse) == lc_eof)
83 break;
84
85 stat = parse_stat(&parse);
86
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);
108
109 /* Type statement. */
110 stype_stat(&stype, stat);
111
112 /* Run statement. */
113 run_init(&run);
114 run.program = program;
115 run_stat(&run, stat);
116 }
117
118 printf("\nBye!\n");
119}
Note: See TracBrowser for help on using the repository browser.