void PDrawObject::SetColor(Variant col)
{


    PEBLObjectBase::SetProperty("COLOR",col);
    mColor = *dynamic_cast<PColor*>(col.GetComplexData()->GetObject().get());

}
Example #2
0
///
/// Assignment Operator (overloaded)
Variant Variant::operator = (const Variant & value)
{

    //First, clean up 'this' if it contains data on free store
    // (e.g., a Variable or a string)
    free_mData();

    mDataType=value.GetDataType();
    switch(mDataType)
        {
        case P_DATA_NUMBER_INTEGER:  // an integer
            mData.iNumber = value.GetInteger();
            break;

        case P_DATA_NUMBER_FLOAT:    // a float
            mData.fNumber = value.GetFloat();
            break;

        case P_DATA_STRING:
            mData.String = strdup(value.GetString().c_str());
            break;

        case P_DATA_LOCALVARIABLE:        // a char* variable name
        case P_DATA_GLOBALVARIABLE:        // a char* variable name
            mData.Variable = strdup(value.GetVariableName().c_str());
            break;

        case P_DATA_FUNCTION:
            mData.Function = strdup(value.GetFunctionName().c_str());
            break;

        case P_DATA_FUNCTION_POINTER:
            mData.pFunction = value.GetFunctionPointer();
            break;

        case P_DATA_STACK_SIGNAL:
            mData.Signal = value.GetSignal();
            break;

        case P_DATA_COMPLEXDATA:
            {
            PComplexData * tmp = value.GetComplexData();
            //tmp is a pointer to complex data, which
            //is just a holder for the object.  We want to make a 
            //copy of tmp
            mComplexData = new PComplexData(*tmp);
            break;
            }
        case P_DATA_UNDEFINED: // undefined, error
        default:
            PError::SignalFatalError( "Undefined Variant type in Variant::operator = (Variant).");
            break;
        }
    return (*this);
}
Example #3
0
string PError::GetTypeName(Variant v)
{
	//Get the name of the type: if it a complex data type, extract the name from that structure.
    string typeName;
	if(v.IsComplexData())
        {
            typeName = (v.GetComplexData())->GetTypeName();
        }
	else
        {
            typeName = v.GetDataTypeName();
        }

	return typeName;
}
bool PlatformLabel::SetProperty(std::string name, Variant v)
{

    if(name == "TEXT")
        {
            SetText(v);
        }
    else if(PLabel::SetProperty(name,v))
    {
        // If we set it at higher level, don't worry.
    }
    else if (name == "FONT")
        {
            SetFont(v.GetComplexData()->GetObject());
            
        }
    else return false;
    
    return true;
}
void  PDrawObject::SetOutlineColor(Variant  ocol)
{
    PEBLObjectBase::SetProperty("OUTLINECOLOR",ocol);
    mOutlineColor = *dynamic_cast<PColor*>(ocol.GetComplexData()->GetObject().get());
}
Example #6
0
///This function makes sure that a value has the proper
///underlying type.  If it doesn't, it will cause a fatal error and 
///report whereabouts the error happened.
void PError::AssertType(Variant v, int type, const string & outsideMessage)
{

	string message;

	switch(type)
		{

		case PEAT_STACK_SIGNAL:
			if( !v.IsStackSignal())
				{
                    message = outsideMessage;
                    message += "Wanted stack signal but got a " + GetTypeName(v) + ": " + v.GetString();
                    SignalFatalError(message);
				}

			break;


		case PEAT_FUNCTION:
			if( !v.IsFunction())
				{
                      message = outsideMessage;
					message += "Wanted function but got a " + GetTypeName(v) + ": "  + v.GetString();
					SignalFatalError(message);
				}

			break;
		case PEAT_FUNCTION_POINTER:
			if( !v.IsFunction())
				{
                    message = outsideMessage;
					message += "Wanted function pointer but got " + GetTypeName(v) + ": " + v.GetString();
					SignalFatalError(message);
				}

			break;
		case PEAT_NUMBER:
			if( !v.IsNumber())
				{
                    message = outsideMessage;
					message += "Wanted number but got " + GetTypeName(v) + ": " + v.GetString();
					SignalFatalError(message);
				}
			break;

		case PEAT_INTEGER:

			if( !v.IsInteger())
				{
                    message = outsideMessage;
                    message += "Wanted integer but got " + GetTypeName(v) + ": " + v.GetString();
					SignalFatalError(message);
				}
			break;
		case PEAT_FLOAT:
			if( !v.IsNumber())
				{
                    message = outsideMessage;
					message +="Wanted floating-point number but got " + GetTypeName(v) + ": "+ v.GetString();
					SignalFatalError(message);
				}
			break;

		case PEAT_STRING:
			if( !v.IsString())
				{
                    message = outsideMessage;
					message +="Wanted string but got " + GetTypeName(v) + ": "+ v.GetString();
					SignalFatalError(message);
				}
			break;

		case PEAT_VARIABLE:
            
			if( v.IsGlobalVariable() || v.IsLocalVariable())
				{
                    return;
                }
            message = outsideMessage;
            message +="Wanted variable but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
			break;


        case PEAT_AUDIOOUT:
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsAudioOut())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted AudioOut stream but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
			
			break;
        case PEAT_COLOR:
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsColor())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            
            message = outsideMessage;
            message +="Wanted PEBL Color but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);           
          break;
          
        case PEAT_ENVIRONMENT:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsEnvironment())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Environment but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;

        case PEAT_FILESTREAM:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsFileStream())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted FileStream but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;
          

        case PEAT_FONT:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsFont())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            
            message = outsideMessage;
            message +="Wanted font but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;


        case PEAT_IMAGEBOX:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsImageBox())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Image but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;



        case PEAT_JOYSTICK:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsJoystick())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Joystick but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;


        case PEAT_KEYBOARD:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsKeyboard())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Keyboard but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;

        case PEAT_LIST:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsList())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted list but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;


      case PEAT_WIDGET:
          
          if(v.IsComplexData())
              {
                  if((v.GetComplexData())->IsWidget())
                      {
                          //Everything is fine, return without error.
                          return;
                      }
              }
          message = outsideMessage;
          message +="Wanted Widget but got " + GetTypeName(v) + ": "+ v.GetString();
          SignalFatalError(message);
          
          break;


      case PEAT_OBJECT:
          if(v.IsComplexData())
              {
                  //Any complex data is a PEBLObject (except maybe a list?)
                  return;
              }
          message = outsideMessage;
          message +="Wanted Object but got " + GetTypeName(v) + ": "+ v.GetString();
          SignalFatalError(message);
          
          break;
          

      case PEAT_WINDOW:
          
          if(v.IsComplexData())
              {
                  if((v.GetComplexData())->IsWindow())
                      {
                          //Everything is fine, return without error.
                          return;
                      }
              }
          message = outsideMessage;
          message +="Wanted Window but got " + GetTypeName(v) + ": "+ v.GetString();
          SignalFatalError(message);
          
          break;
          
        case PEAT_TEXTOBJECT:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsTextObject())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted TextObject but got " + GetTypeName(v) + ": " + v.GetString();
            SignalFatalError(message);

            break;


        case PEAT_LABEL:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsLabel())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Label but got " + GetTypeName(v) + ": " + v.GetString();
            SignalFatalError(message);

            break;
            


        case PEAT_TEXTBOX:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsTextBox())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Text Box but got " + GetTypeName(v) + ": " + v.GetString();
            SignalFatalError(message);

            break;
            
        case PEAT_NETWORKCONNECTION:
             
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsNetworkConnection())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted network but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;
          
          
        case PEAT_PARALLELPORT:
             
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsParallelPort())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted parallelport but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;
          
        case PEAT_COMPORT:
             
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsComPort())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted ComPort but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;

        case PEAT_MOVIE:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsMovie())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Movie but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;

            
        case PEAT_UNDEFINED:
		default:
            
            message = outsideMessage;
            message += string("Undefined type in PErrorAssert: ") + v.GetString();
            SignalFatalError(message);
            break;
        }

}
Example #7
0
Variant::Variant(const Variant &v):
    mComplexData(NULL)
{

    
    //This should behave differently depending on what type of variant v is
    mDataType = v.GetDataType();

    switch(mDataType)
        {

        case P_DATA_NUMBER_INTEGER:  // an integer
            mData.iNumber = v.GetInteger();
            break;

        case P_DATA_NUMBER_FLOAT:    // a float
            mData.fNumber = v.GetFloat();
            break;

        case P_DATA_STRING:
            //            cout << "testing case string:<" << v << ">"<<endl;
            mData.String = strdup(v.GetString().c_str());
            break;

        case P_DATA_LOCALVARIABLE:        // a variable name
        case P_DATA_GLOBALVARIABLE:        // a variable name
            mData.Variable = strdup(v.GetVariableName().c_str());
            break;

        case P_DATA_FUNCTION:
            //Memory problem here, diagnosed by efence:
            mData.Function = strdup(v.GetFunctionName().c_str());
            break;

        case P_DATA_FUNCTION_POINTER:
            mData.pFunction = v.GetFunctionPointer();
            break;


        case P_DATA_STACK_SIGNAL:
            mData.Signal = v.GetSignal();
            break;

            //This needs to  make a deep copy

        case P_DATA_COMPLEXDATA:
            {

                //cout<<"TYPE:" << v << endl;
                PComplexData * pcd = v.GetComplexData();

                if(pcd)
                    mComplexData  = new PComplexData(*pcd);
                else 
                    mComplexData = NULL;

            }
            break;

        case P_DATA_UNDEFINED: // undefined, not an error
            break;
        default:

            cerr << "Undefined Data Type in Variant copy constructor. Type: " << mDataType << endl;
            cerr << v << endl;
            PError::SignalFatalError("Undefined Data Type.");
        break;

        }

}
Example #8
0
int PEBLInterpret( int argc, std::vector<std::string> argv )
{
#if defined(PEBL_UNIX) and not defined(PEBL_OSX)
    if(argc==2 && strcmp(argv[1].c_str(), "--install")==0)
        {
            string basedir = "";
            BrInitError error;
            if (br_init (&error) == 0 && error != BR_INIT_ERROR_DISABLED)
                {
                    PError::SignalWarning("Warning: BinReloc failed to initialize.\n Will fallback to hardcoded default path.\n");
                    basedir = "/usr/local/share/pebl/";
                }

            string prefix = br_find_prefix("/usr/local/");
            basedir = prefix + string("/share/pebl/battery/");
            string destdir = "~/Documents/pebl-exp.0.14";

            //Now, copy everything in 'battery' to your documents directory.
            std::cerr << "Creating Documents/pebl-exp.0.14 Directory\n";
            PEBLUtility::SystemCall("mkdir ~/Documents","");
            //PEBLUtility::SystemCall("mkdir "+destdir,"");
            std::cerr << "Copying files to ["+destdir+ "]\n";
            PEBLUtility::SystemCall("cp -R "+ basedir + " " + destdir,"");
            exit(0);
        }
#endif

    PNode * tmp = NULL;

    //Cycle through command-line parameters extracting the files.
    //This does not check for file validity, it just removes any other command-line options,
    //i.e. ones that are of the form <-flag> <option> or whatever.
   //

#if 0
    //THis is just for debugging purposes.
    cout << "Arguments: "<< argv.size()<<"\n";
    std::vector<std::string>::iterator ii = argv.begin();
     while(ii != argv.end())
     {
         cout << *ii << endl;
         ii++;
         cout << "********\n";
     }
#endif

    std::list<std::string> files = GetFiles(argc, argv);

    //Set up the search path.
    Evaluator::gPath.Initialize(files);

    cerr << Evaluator::gPath;

    //Add the built-in PEBL libraries to the files list.
    files.push_back("Design.pbl");
    files.push_back("Utility.pbl");
    files.push_back("Math.pbl");
    files.push_back("Graphics.pbl");
    files.push_back("UI.pbl");

    //    files.push_back("Taguchi.pbl"); //not ready


#ifdef PEBL_EMSCRIPTEN
	std::cout << "Loading filename:[test.pbl]\n";
	string inputfilename = Evaluator::gPath.FindFile("test.pbl");

    if(inputfilename != "")
        {
            cerr << "Processing PEBL Source File1: " <<  inputfilename << endl;
            head  = parse(inputfilename.c_str());
        }
    else
        {
            PError::SignalFatalError("Unable to find file: [" + inputfilename + "].");
        }

#else
    //Process the first command-line argument.
    std::list<std::string>::iterator i = files.begin();
    i++;

    //-----------------------------------------------------------
    //        Process all files on the command-line
    //-----------------------------------------------------------

	std::cout << "Loading filename:[" << *i << "]\n";
	string inputfilename = Evaluator::gPath.FindFile(*i);
    string otherfilename;

    head = NULL;
    if(inputfilename != "")
        {
            cerr << "Processing PEBL Source File1: " <<  inputfilename << endl;
            head  = parse(inputfilename.c_str());
        }
    else
        {
            PError::SignalFatalError("Unable to find file: [" + inputfilename + "].");
        }
i++;
    //If there are any more arguments, process them by accomodating them
    //inside a function list.

    //Increment the iterator to move to the second command-line
   // i++;
    while(i != files.end())
        {
            std::cerr << "********************\n";
        	std::cerr << "Loading file name: ["      << *i <<"]"<< endl;
            otherfilename = Evaluator::gPath.FindFile(*i);
            std::cerr << "Resolved as: [" <<otherfilename <<"]"<< endl;
            if(inputfilename != "")
                {
                    cerr << "Processing PEBL Source File2: " <<  otherfilename << endl;

                    //A filename could be a directory (e.g., with media in it.)
                    //If so, don't parse it.
                    if(!Evaluator::gPath.IsDirectory(otherfilename))
                        {
                            //Make a new node.
                            tmp = parse(otherfilename.c_str());

                            //Now, make a new node that contains head and tmp.
                            head = new OpNode(PEBL_FUNCTIONS, head, tmp, "INTERNAL PEBL STRUCTURE", -1);
                        }
                }
            else
                {
                    PError::SignalFatalError("Unable to find file: ["+*i+"] at [" + otherfilename + "]");
                        //ignore mis-loaded files after the first; this is causing us
                            //problems on osx
                }
            i++;
       }

    //       Done processing files.
    //-----------------------------------------------------
#endif

    cerr << "---------Loading Program---------" << endl;
    //Now, load it into the environment:

    // Create a loader that will load functions into the functionmap
    myLoader = new Loader();
    myLoader->LoadUserFunctions((OpNode*)head);


    cerr <<"Analyzing code for functions." << endl;
    myLoader->FindFunctions(head);


    cerr << "Loading Library functions." << endl;
    myLoader->LoadLibraryFunctions();

    //This just destroys the function tree, not the
    //parsed node structure that is contained within
    //mFunctionMap.
    cerr << "Removing residual function tree\n";
    ((OpNode*)head)->DestroyFunctionTree();
    delete head;
    head = NULL;

#if 0
    cerr << "\n\n--------------------------------\n";
    cerr << "Functions used in program: " << endl;
    cerr << "--------------------------------\n";
    Evaluator::mFunctionMap.DumpValues();
    cerr << "--------------------------------\n\n";
#endif

    //Parse command-line arguments.

    PList *  pList =  new PList();
    PList *  arglist = new PList();


    //Use the current screen resolution as a startingp


    //Initialize display size here with a non-interesting one.
    //It may get set by a command-line argument later.
    std::string displaySize="0x0";


    std::string depth = "32";  //used to be 16; does this matter?
    enum PEBLVideoMode displayMode;
    enum PEBLVideoDepth displayDepth;
    bool windowed = true;
    bool resizeable = false;
    bool unicode = true;
    Variant lang = "en";
    Variant subnum = 0;

    //default the parameter file to ./params/SCRIPTNAME.par
    Variant pfile = Variant("params/")+Variant(inputfilename)+Variant(".par");

    //Extract the command-line variables to bind
    for(int j = 1; j < argc; j++)
        {

            if(strcmp(argv[j].c_str(), "-v")==0 ||
                    strcmp(argv[j].c_str(), "-V")==0)
                {
                    Variant tmp = argv[++j];
					//cout <<"Content of passed-in variable " << j << ":" << tmp << endl;
                    arglist->PushBack(tmp);
                }

            else if(strcmp(argv[j].c_str(), "-s")==0 ||
                    strcmp(argv[j].c_str(), "-S")==0)
                {
                    subnum  = argv[++j];
					//cout << "collecting Subject Number "<< subnum << endl;
  				}
            //set the driver directly from the command-line, if necessary.
            else if(strcmp(argv[j].c_str(),"--driver")==0)
                {
                    if(j+1 < argc)
                        {
                            j++;

                            //This now works on Windows; windib versus directx.
#if defined(PEBL_UNIX)
                            setenv("SDL_VIDEODRIVER", argv[j].c_str() ,1);
#elif defined(PEBL_WINDOWS)

                            _putenv((std::string("SDL_VIDEODRIVER=") + std::string(argv[j])).c_str());
#endif
                        }
                }
            else if(strcmp(argv[j].c_str(),"--display")==0)
                {
                    displaySize = argv[++j];
                }

            else if(strcmp(argv[j].c_str(),"--depth")==0)
                {
                    depth = argv[++j];

                }

            else if (strcmp(argv[j].c_str(),"--fullscreen")==0)
                {
                    windowed = false;
                }
            else if(strcmp(argv[j].c_str(),"--windowed")==0)
                {
                    windowed = true;
                }
            else if(strcmp(argv[j].c_str(),"--unicode")==0)
                {
                    unicode = true;
                }
            else if(strcmp(argv[j].c_str(),"--language")==0)
                {
                    lang = argv[++j];
                }

            else if(strcmp(argv[j].c_str(),"--pfile")==0)
                {
                    pfile = Variant("params/") +Variant(argv[++j]);
                }

            else if(strcmp(argv[j].c_str(),"--resizeable")==0 ||
                    strcmp(argv[j].c_str(),"--resizable")==0  )
                {
                    if(windowed)
                        resizeable = true;
                }

        }


    //Now, set the display modes variables based on the command-line options.
    displayMode = PEBLUtility::GetVideoMode(displaySize);
    displayDepth = PEBLUtility::GetVideoDepth(depth);



    //This sets the video driver, and other platform-specific stuff.
#if defined(PEBL_UNIX)

    //Do specific *nix stuff here (excluding OSX).
    //These can be controlled by a command-line option
    // setenv("SDL_VIDEODRIVER", "dga",1);  //Requires root privileges to run;  fullscreen.
    //setenv("SDL_VIDEODRIVER", "svgalib",1);  //Requires root and special library; allows you to run on virtual terminal.
    // setenv("SDL_VIDEODRIVER", "x11",1);


    //Now, set the priority to the highest it can go.

    //setpriority(PRIO_PROCESS,0,PRIO_MIN);
     setpriority(PRIO_PROCESS,0,0);
    int priority = getpriority(PRIO_PROCESS,0);
    cerr << "Process running at a nice value of " << priority << endl;

    /*
      struct sched_param mysched;
      mysched.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1;
      if( sched_setscheduler( 0, SCHED_RR, &mysched ) == -1 )
      {
      cout << "Unable to enable round-robin scheduling.  Must have root priviledges.\n";
      }
      else
      {
      cout << "Round-robin scheduling enabled.\n";
      }

      struct timespec interval;
      if(sched_rr_get_interval(0,&interval)== -1)
      {
      cout << "Unable to get Round-robin scheduling interval.\n";
      }
      else
      {
      cout << "Round Robin Scheduling Interval: [" <<interval.tv_sec * 1000 + interval.tv_nsec / 1000 <<"] ms.\n";
      }

    */


#elif defined(PEBL_WIN32)
     //Do specific win32 stuff here.

    //SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS);
    //REALTIME causes program to hang on keyboard input.
    SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS);

    //setenv()
#endif

    //cout <<"About to create environment\n";

    // We can't use any SDL-related functions before this function is called.
    // But we may want to know current screen resolution before we set displaymode
    PEBLObjects::MakeEnvironment(displayMode, displayDepth, windowed,resizeable,unicode);

    cerr << "Environment created\n";


    //Seed the random number generator with time of day.
    srand((unsigned int)time(0));

    cerr << "---------Creating Evaluator-----" << endl;
    //Create evaluator, because it contains a function map as a static member variable.
    //Create it with the command-line -v parameters as a list  bound to the argument.

#if defined(PEBL_EMSCRIPTEN)
    std::cerr <<"--------o-o-o-o-o-o--\n";
    arglist->PushBack(Variant(0));
    PComplexData * pcd = new PComplexData(counted_ptr<PEBLObjectBase>(arglist));
    pList->PushBack(Variant(pcd));
#else
    //Now, arglist should contain any values specified with the -v flag.
    if(arglist->Length()==0)
        {
            arglist->PushBack(Variant(0));
            PComplexData * pcd = new PComplexData(counted_ptr<PEBLObjectBase>(arglist));
            pList->PushBack(Variant(pcd));
        }
    else
        {
            PComplexData * pcd = new PComplexData(counted_ptr<PEBLObjectBase>(arglist));
            pList->PushBack(Variant(pcd));
        }
#endif

    PComplexData * pcd2 = new PComplexData(counted_ptr<PEBLObjectBase>(pList));
    Variant v = Variant(pcd2);


    std::list<PNode> tmpcallstack;

    //myEval is now a global, because we have moved to a single-evaluator model:
    myEval = new Evaluator(v,"Start");

    //Set the executable name here:
    myEval->gGlobalVariableMap.AddVariable("gExecutableName", argv[0]);

    //Set the default screen resolution based on the current one.
    Variant cursize = SDLUtility::GetCurrentScreenResolution();

#ifdef PEBL_EMSCRIPTEN

    Variant width = 800;
    Variant height = 600;
#else

    PList * plist = cursize.GetComplexData()->GetList();
    Variant width = plist->First(); //plist->PopFront();
    Variant height = plist->Nth(2);//plist->PopFront();
#endif
    myEval->gGlobalVariableMap.AddVariable("gVideoWidth", width);
    myEval->gGlobalVariableMap.AddVariable("gVideoHeight", height);


    //displaysize may have been set at the command line.  If so, we will need to
    //override it.  It is currently a string called displaysize.


    size_t found = displaySize.find("x");
    if(found == string::npos)
        {
            //Nothing is found.  Use 0s to indicate an invalid displaysize
            width = 0;
            height = 0;
        } else
        {
            cerr <<"Size from command line argument: "  << displaySize.substr(0,found)<< "|"<< displaySize.substr(found+1) <<endl;
            //something was found.
            width =  atoi(displaySize.substr(0,found).c_str());
            height = atoi(displaySize.substr(found+1).c_str());
        }


    if((pInt)width>0  & (pInt)height>0)
        {
            Evaluator::gGlobalVariableMap.AddVariable("gVideoWidth",width);
            Evaluator::gGlobalVariableMap.AddVariable("gVideoHeight",height);
        }


    //Add the subject identifier.
    Evaluator::gGlobalVariableMap.AddVariable("gSubNum",subnum);
    //If this is set to 1, we have reset the subject code, and
    //it is presumably good for all future resets.
    Evaluator::gGlobalVariableMap.AddVariable("gResetSubNum",0);


    //Translate lang to the uppercase 2-letter code
    std::string tmps =lang;
    transform(tmps.begin(),tmps.end(),tmps.begin(),toupper);
    Evaluator::gGlobalVariableMap.AddVariable("gLanguage",Variant(tmps));


    //Add a special 'quote' character.
    Evaluator::gGlobalVariableMap.AddVariable("gQuote",Variant("\""));


    //Add a the default 'base font' names
    //gPEBLBaseFont defaults to a sans serif font
    if((tmps == "CN") | (tmps== "KO") |(tmps == "JP"))
        {
            //ukai handles chinese
            Evaluator::gGlobalVariableMap.AddVariable("gPEBLBaseFont",Variant("wqy-zenhei.ttc"));
            Evaluator::gGlobalVariableMap.AddVariable("gPEBLBaseFontMono",Variant("wqy-zenhei.ttc"));
            Evaluator::gGlobalVariableMap.AddVariable("gPEBLBaseFontSerif",Variant("wqy-zenhei.ttc"));

        } else
        {
            //DejaVu handles most western fonts.
            Evaluator::gGlobalVariableMap.AddVariable("gPEBLBaseFont",Variant("DejaVuSans.ttf"));
            Evaluator::gGlobalVariableMap.AddVariable("gPEBLBaseFontMono",Variant("DejaVuSansMono.ttf"));
            Evaluator::gGlobalVariableMap.AddVariable("gPEBLBaseFontSerif",Variant("DejaVuSerif.ttf"));
        }

    //load the parameter file into a global variable
    Evaluator::gGlobalVariableMap.AddVariable("gParamFile",Variant(pfile));

    //Now, everything should be F-I-N-E fine.
    head = myLoader->GetMainPEBLFunction();

    if(head)
        {
            cerr << "---------Evaluating Program-----" << endl;
            //Execute everything


#ifdef PEBL_EMSCRIPTEN

            myEval->Evaluate1(head);
            //cout << "Finished evaluating head1\n";

            //            while(myEval->GetNodeStackDepth()>0)
            //                {
            //                    myEval->Evaluate1();
            //                    cout << "step complete1\n";
            //                }
            //cout << "Evaluating first step\n";
            myEval -> Evaluate1();
            cerr << "Exiting main loop; going asynchronous\n";
            return 0;
#else

#ifdef PEBL_ITERATIVE_EVAL

            //This creates an iterative evaluator
            myEval->Evaluate1(head);

            while(myEval->GetNodeStackDepth()>0)
                {
                    myEval->Evaluate1();
                }
#else
            //Use traditional recursive version.
            myEval->Evaluate(head);
#endif

            Evaluator::gGlobalVariableMap.Destroy();

            delete myLoader;
            if(myEnv) delete myEnv;
            Evaluator::mFunctionMap.Destroy();

            delete myEval;
            myEval = NULL;
            //Evaluator::gGlobalVariableMap.DumpValues();
#ifdef PEBL_MOVIES
            //Close the wave player library.
            WV_waaveClose();
#endif

            //Be sure SDL quits.  It should probably be handled elsewhere,
            //but this seems to work.

            SDL_Quit();
#endif

            return 0;
        }
    else
        {
            cerr << "Error: Can't evaluate program" << endl;
            return 1;
            delete myLoader;
        }

    return 0;

}