• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/interp/Program.cpp

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #include <spl/interp/Program.h>
00018 
00019 Program::Program()
00020 : m_cdata(), m_code(), m_argCount(0)
00021 {
00022         m_exitInstr.opCode = JSOP_EXIT;
00023         m_exitInstr.argSrc = JSOPARG_NONE;
00024         m_exitInstr.argIdx = 0;
00025 }
00026 
00027 Program::Program(const Program& program)
00028 :       m_cdata(program.m_cdata), 
00029         m_code(program.m_code),
00030         m_exitInstr(program.m_exitInstr),
00031         m_argCount(program.m_argCount)
00032 {
00033 }
00034 
00035 Program& Program::operator =(const Program& program)
00036 {
00037         m_cdata = program.m_cdata;
00038         m_code = program.m_code;
00039         m_argCount = program.m_argCount;
00040 
00041         return *this;
00042 }
00043 
00044 Program::~Program()
00045 {
00046 }
00047 
00048 void Program::Clear()
00049 {
00050         m_cdata.Clear();
00051         m_code.Clear();
00052         m_argCount = 0;
00053 }
00054 
00055 int Program::AddToTable(const String& s)
00056 {
00057         m_cdata.Add(VariantPtr(new Variant(s)));
00058         return m_cdata.Count() - 1;
00059 }
00060 
00061 int Program::AddToTable(const int32 i)
00062 {
00063         m_cdata.Add(VariantPtr(new Variant(i)));
00064         return m_cdata.Count() - 1;
00065 }
00066 
00067 int Program::AddToTable(const float64 f)
00068 {
00069         m_cdata.Add(VariantPtr(new Variant(f)));
00070         return m_cdata.Count() - 1;
00071 }
00072 
00073 int Program::AddToTable(const Date& dt)
00074 {
00075         m_cdata.Add(VariantPtr(new Variant(dt)));
00076         return m_cdata.Count() - 1;
00077 }
00078 
00079 int Program::AddToTable(const DateTime& dtm)
00080 {
00081         m_cdata.Add(VariantPtr(new Variant(dtm)));
00082         return m_cdata.Count() - 1;
00083 }
00084 
00085 int Program::AppendCode(enum JsOpCode c, JsOpCodeArgSrc s, int32 idx)
00086 {
00087         Instruction i;
00088         
00089         i.opCode = c;
00090         i.argSrc = s;
00091         i.argIdx = idx;
00092 
00093         m_code.Add(i);
00094 
00095         return m_code.Count() - 1;
00096 }
00097 
00098 void Program::FixupCode(int pos, int32 idx)
00099 {
00100         m_code.ElementAtRef(pos).argIdx = idx;
00101 }
00102 
00103 #if defined(DEBUG) || defined(_DEBUG)
00104 void Program::CheckMem() const
00105 {
00106         m_cdata.CheckMem();
00107         m_code.CheckMem();
00108 }
00109 
00110 void Program::ValidateMem() const
00111 {
00112         m_cdata.ValidateMem();
00113         m_code.CheckMem();
00114 }
00115 #endif