root/trunk/orca/qt/main.cpp

Revision 144, 3.4 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 - A REBOL Interpreter
3    Copyright (C) 2005  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 "qorca.h"
23
24
25#define ESC     27
26
27#ifdef _WIN32
28extern "C" void redirectIOToConsole();
29#define OPEN_CONSOLE    redirectIOToConsole();
30#else
31#define OPEN_CONSOLE
32#endif
33
34
35int main( int argc, char** argv )
36{
37    OEnv env;
38    QOrcaApp app( argc, argv );
39    char cmd[ 128 ];
40    int ret = 0;
41
42
43    orInitEnv( &env, 0, 0 );
44    qoInitEnv();
45   
46
47    if( argc > 1 )
48    {
49        OIndex strN;
50        OValue* tos;
51
52        tos = orTOS;
53        strN = orMakeCString( argv[1], -1 );
54        orSetTF(tos, OT_FILE );
55        orSetSeries(tos, strN, 0 );
56
57        orDoNative( tos );
58        if( orErrorThrown )
59        {
60            if( ! orErrorIsType(OR_ERROR_QUIT) )
61            {
62                OPEN_CONSOLE
63
64                if( ! orErrorIsType(OR_ERROR_HALT) )
65                {
66                    orResetEnv( &env );
67                    goto halt;
68                }
69
70                orPrintNative( orErrorThrown );
71                ret = -1;
72            }
73        }
74    }
75    else
76    {
77        OPEN_CONSOLE
78        printf( "ORCA-Qt %s (%s)\n", OR_VERSION_STR, __DATE__ );
79
80halt:
81        while( 1 )
82        {
83            printf( "O> " );
84            fflush( stdout );   /* Required on Windows. */
85            fgets( cmd, 128, stdin );
86
87#if 0
88            {
89                char* cp = cmd;
90                while( *cp != '\n' )
91                    printf( " %d", (int) *cp++ );
92                printf( "\n" );
93            }
94#endif
95
96            if( cmd[0] == ESC )
97            {
98                // Up   27 91 65
99                // Down 27 91 66
100                printf( "\n" );
101            }
102            else if( cmd[0] != '\n' )
103            {
104                orEvalCStr( cmd, -1 );
105
106                if( orErrorThrown )
107                {
108                    if( orErrorIsType(OR_ERROR_QUIT) )
109                        break;
110                    if( ! orErrorIsType(OR_ERROR_HALT) )
111                        orPrintNative( orErrorThrown );
112                    orResetEnv( &env );
113                }
114                else
115                {
116                    OValue* val;
117                    val = orTOS;
118                    if( (val->type != OT_UNSET) &&
119                        (val->type != OT_OBJECT) &&
120                        (val->type != OT_FUNCTION) )
121                    {
122                        printf( "== " );
123                        orProbe( val );
124                    }
125                }
126            }
127        }
128    }
129
130    qoFreeEnv();
131    orFreeEnv( &env );
132
133    return ret;
134}
135
136
137/*EOF*/
Note: See TracBrowser for help on using the browser.