source: mainline/uspace/app/sbi/src/main.c@ a95310e

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

Update SBI to rev. 157.

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[09ababb7]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
[1ebc1a62]29/** @file Main module.
30 *
31 * Main entry point for SBI, the Sysel Bootstrap Interpreter.
32 * When run without parameters, the interpreter will enter interactive
33 * mode.
34 */
[09ababb7]35
36#include <stdio.h>
37#include <stdlib.h>
38#include "ancr.h"
39#include "builtin.h"
[37f527b]40#include "imode.h"
[09ababb7]41#include "mytypes.h"
42#include "strtab.h"
43#include "stree.h"
[39e8406]44#include "stype.h"
[09ababb7]45#include "input.h"
46#include "lex.h"
47#include "parse.h"
48#include "run.h"
49
50void syntax_print(void);
51
[1ebc1a62]52/** Main entry point.
53 *
54 * @return Zero on success, non-zero on error.
55 */
[09ababb7]56int main(int argc, char *argv[])
57{
58 input_t *input;
59 lex_t lex;
60 parse_t parse;
61 stree_program_t *program;
[39e8406]62 stype_t stype;
[09ababb7]63 run_t run;
64 int rc;
65
[37f527b]66 if (argc == 1) {
67 /* Enter interactive mode */
68 strtab_init();
69 imode_run();
70 return 0;
71 }
72
[09ababb7]73 if (argc != 2) {
74 syntax_print();
75 exit(1);
76 }
77
[37f527b]78 rc = input_new_file(&input, argv[1]);
[09ababb7]79 if (rc != EOK) {
[fa36f29]80 printf("Failed opening source file '%s'.\n", argv[1]);
[09ababb7]81 exit(1);
82 }
83
84 strtab_init();
85 program = stree_program_new();
86 program->module = stree_module_new();
87
88 /* Declare builtin symbols. */
89 builtin_declare(program);
90
91 /* Parse input file. */
92 lex_init(&lex, input);
93 parse_init(&parse, program, &lex);
94 parse_module(&parse);
95
[1ebc1a62]96 if (parse.error)
97 return 1;
98
[09ababb7]99 /* Resolve ancestry. */
100 ancr_module_process(program, parse.cur_mod);
101
[39e8406]102 /* Type program. */
103 stype.program = program;
[1ebc1a62]104 stype.error = b_false;
[39e8406]105 stype_module(&stype, program->module);
106
[1ebc1a62]107 if (stype.error)
108 return 1;
109
[09ababb7]110 /* Run program. */
111 run_init(&run);
112 run_program(&run, program);
113
114 return 0;
115}
116
[1ebc1a62]117/** Print command-line syntax help. */
[09ababb7]118void syntax_print(void)
119{
120 printf("Missing or invalid arguments.\n");
121 printf("Syntax: sbi <source_file.sy>\n");
122}
Note: See TracBrowser for help on using the repository browser.