root/trunk/orca/gl/main.c

Revision 144, 3.7 kB (checked in by krobillard, 3 years ago)

Native arguments are now kept on the stack until after the call and the
result is now always put into a1.

Line 
1/*============================================================================
2    ORCA Interpreter
3    Copyright (C) 2005-2006  Karl Robillard
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18===========================================================================*/
19
20
21#include <stdio.h>
22#include "gx.h"
23#include "audio.h"
24
25
26#define ESC     27
27
28#ifdef _WIN32
29extern void redirectIOToConsole();
30#define OPEN_CONSOLE    redirectIOToConsole();
31#else
32#define OPEN_CONSOLE
33#endif
34
35
36int main( int argc, char** argv )
37{
38    OEnv env;
39    char cmd[ 128 ];
40    int ret = 0;
41
42
43    gView = glv_create( GLV_ATTRIB_DOUBLEBUFFER );
44    if( ! gView )
45        return( -1 );
46
47#ifndef NO_AUDIO
48    audioStartup();
49#endif
50
51    orInitEnv( &env, 0, 0 );
52    gxInitEnv();
53   
54
55    if( argc > 1 )
56    {
57        OIndex strN;
58        OValue* tos;
59
60        tos = orTOS;
61        strN = orMakeCString( argv[1], -1 );
62        orSetTF(tos, OT_FILE );
63        orSetSeries(tos, strN, 0 );
64
65        orDoNative( tos );
66        if( orErrorThrown )
67        {
68            if( ! orErrorIsType(OR_ERROR_QUIT) )
69            {
70                OPEN_CONSOLE
71
72                if( orErrorIsType(OR_ERROR_HALT) )
73                {
74                    orErrorClear;
75                    // Reset stack.
76                    orEnv->dataStack.used = 0;
77                    orEnv->callStack.used = 0;
78                    goto halt;
79                }
80
81                orPrintNative( orErrorThrown );
82                ret = -1;
83            }
84        }
85    }
86    else
87    {
88        OPEN_CONSOLE
89        printf( "ORCA-GL %s (%s)\n", OR_VERSION_STR, __DATE__ );
90
91halt:
92        while( 1 )
93        {
94            printf( "O> " );
95            fflush( stdout );   /* Required on Windows. */
96            fgets( cmd, 128, stdin );
97
98#if 0
99            {
100                char* cp = cmd;
101                while( *cp != '\n' )
102                    printf( " %d", (int) *cp++ );
103                printf( "\n" );
104            }
105#endif
106
107            if( cmd[0] == ESC )
108            {
109                // Up   27 91 65
110                // Down 27 91 66
111                printf( "\n" );
112            }
113            else if( cmd[0] != '\n' )
114            {
115                orEvalCStr( cmd, -1 );
116
117                if( orErrorThrown )
118                {
119                    if( orErrorIsType(OR_ERROR_QUIT) )
120                        break;
121                    if( ! orErrorIsType(OR_ERROR_HALT) )
122                        orPrintNative( orErrorThrown );
123                    orErrorClear;
124                }
125                else
126                {
127                    OValue* val;
128                    val = orTOS;
129                    if( (val->type != OT_UNSET) &&
130                        (val->type != OT_OBJECT) &&
131                        (val->type != OT_FUNCTION) )
132                    {
133                        printf( "== " );
134                        orProbe( val );
135                    }
136                }
137            }
138        }
139    }
140
141    gxFreeEnv();
142    orFreeEnv( &env );
143
144#ifndef NO_AUDIO
145    audioShutdown();
146#endif
147
148    glv_destroy( gView );
149
150    return ret;
151}
152
153
154/*EOF*/
Note: See TracBrowser for help on using the browser.