2
PLIB - A Suite of Portable Game Libraries
3
Copyright (C) 1998,2002 Steve Baker
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
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
Library General Public License for more details.
15
You should have received a copy of the GNU Library 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
19
For further information visit http://plib.sourceforge.net
21
$Id: pslProgram.cxx,v 1.17 2003/01/06 05:10:14 sjbaker Exp $
27
pslProgram::pslProgram ( const pslExtension *ext, const char *_prgnm )
29
if ( ! _pslInitialised )
30
ulSetError ( UL_FATAL,
31
"PSL: You didn't call pslInit() before using PSL functions." ) ;
33
code = new pslOpcode [ MAX_CODE ] ;
39
if ( _prgnm == NULL ) _prgnm = "PSLprogram" ;
41
setProgName ( _prgnm ) ;
43
compiler = new pslCompiler ( this, code, ext, getProgName () ) ;
44
context = new pslContext ( this ) ;
49
const char *force_trace_env = getenv ( "PSL_TRACE" ) ;
50
const char *force_stack_env = getenv ( "PSL_STACK" ) ;
52
force_trace = ( force_trace_env != NULL &&
53
ulStrEqual ( force_trace_env, "always" ) ) ;
54
force_stacktrace = ( force_stack_env != NULL &&
55
ulStrEqual ( force_stack_env, "always" ) ) ;
58
compiler -> generateLineNumbers () ;
62
pslProgram::pslProgram ( pslProgram *src, const char *_prgnm )
66
if ( _prgnm == NULL ) _prgnm = src -> getProgName () ;
68
setProgName ( _prgnm ) ;
70
/* This will fail if this pslProgram is ever deleted */
71
/* We need ref-counting on code/compiler */
73
code = src -> getCode () ;
74
compiler = src -> getCompiler () ;
75
extensions = src -> getExtensions () ;
76
userData = src -> getUserData () ;
78
context = new pslContext ( this ) ;
83
pslProgram::~pslProgram ()
85
/* This will fail if this pslProgram was copy-constructed */
86
/* We need ref-counting on code/compiler */
95
void pslProgram::dump () const { compiler-> dump () ; }
96
void pslProgram::reset () { context -> reset () ; }
97
pslResult pslProgram::step () { return force_trace ?
99
context -> step () ; }
100
pslResult pslProgram::trace () { return context -> trace () ; }
104
int pslProgram::compile ( const char *memptr, const char *fname )
106
if ( strcmp ( getProgName(), "PSLprogram" ) == 0 )
107
setProgName ( fname ) ;
109
return compiler -> compile ( memptr, fname ) ;
113
int pslProgram::compile ( const char *fname )
115
if ( strcmp ( getProgName(), "PSLprogram" ) == 0 )
116
setProgName ( fname ) ;
118
return compiler -> compile ( fname ) ;
122
int pslProgram::compile ( FILE *fd )
124
return compiler -> compile ( fd ) ;