Executable now prints a pretty string description of the returned value.
[panda.git] / src / main.c
blobf91c21ddb7372c28ef1dfa7593422b40ec0c69d8
2 #include <st-types.h>
3 #include <st-symbol.h>
4 #include <st-compiler.h>
5 #include <st-cpu.h>
6 #include <st-array.h>
7 #include <st-lexer.h>
8 #include <st-node.h>
9 #include <st-universe.h>
10 #include <st-object.h>
11 #include <st-float.h>
12 #include <optparse.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <stdbool.h>
17 #include <sys/time.h>
19 #define BUF_SIZE 2000
21 static const char version[] =
22 PACKAGE_STRING"\n"
23 "Copyright (C) 2007-2008 Vincent Geddes";
25 static bool verbose = false;
27 struct opt_spec options[] = {
28 {opt_help, "h", "--help", NULL, "Show help information", NULL},
29 {opt_version, "V", "--version", NULL, "Show version information" , (char *) version},
30 {opt_store_1, "v", "--verbose", NULL, "Show verbose messages" , &verbose},
31 {NULL}
35 static void
36 read_compile_stdin (void)
38 st_compiler_error error;
39 char buffer[BUF_SIZE];
40 char *string;
41 char c;
42 int i = 0;
44 while ((c = getchar ()) != EOF && i < (BUF_SIZE - 1))
45 buffer[i++] = c;
46 buffer[i] = '\0';
48 string = st_strconcat ("doIt ^ [", buffer, "] value", NULL);
50 if (!st_compile_string (ST_UNDEFINED_OBJECT_CLASS, string, &error)) {
51 fprintf (stderr, "test-processor:%i: %s\n",
52 error.line, error.message);
53 exit (1);
56 st_free (string);
59 static double
60 get_elapsed_time (struct timeval before, struct timeval after)
62 return after.tv_sec - before.tv_sec + (after.tv_usec - before.tv_usec) / 1.e6;
65 int
66 main (int argc, char *argv[])
68 st_oop value;
70 opt_basename (argv[0], '/');
71 // opt_message ("Read Smalltalk expressions from standard input and evaluate them.");
72 opt_parse ("Usage: %s [options]", options, argv);
74 st_set_verbosity (verbose);
76 st_bootstrap_universe ();
77 read_compile_stdin ();
79 st_cpu_initialize ();
80 st_cpu_main ();
82 /* inspect the returned value on top of the stack */
83 value = ST_STACK_PEEK ((&__cpu));
84 if (st_object_format (value) != ST_FORMAT_BYTE_ARRAY)
85 abort ();
87 putchar ('\n');
88 printf ("result: %s\n", (char *) st_byte_array_bytes (value));
90 return 0;