33#ifdef PEBL_ITERATIVE_EVAL
34#include "../base/Evaluator-es.h"
35#include "../devices/PEventLoop-es.h"
38#include "../base/Evaluator.h"
39#include "../devices/PEventLoop.h"
43#include <emscripten.h>
44#include <emscripten/html5.h>
49 var
event =
new CustomEvent(
'peblTestComplete', {
51 status: UTF8ToString($0),
55 document.dispatchEvent(event);
56 console.log(
'PEBL test completed with status:', UTF8ToString($0));
66#include "../base/grammar.tab.hpp"
67#include "../base/PNode.h"
68#include "../base/Loader.h"
69#include "../base/PComplexData.h"
70#include "../base/PList.h"
71#include "../base/FunctionMap.h"
72#include "../base/VariableMap.h"
73#include "../base/Variant.h"
75#include "../libs/PEBLObjects.h"
77#include "../utility/PError.h"
78#include "../utility/PEBLPath.h"
79#include "../utility/PEBLUtility.h"
80#include "../utility/rc_ptrs.h"
81#include "../utility/BinReloc.h"
94#include <sys/resource.h>
100#elif defined(PEBL_WIN32)
107STICKYKEYS g_StartupStickyKeys = {
sizeof(STICKYKEYS), 0};
108TOGGLEKEYS g_StartupToggleKeys = {
sizeof(TOGGLEKEYS), 0};
109FILTERKEYS g_StartupFilterKeys = {
sizeof(FILTERKEYS), 0};
114void AllowAccessibilityShortcutKeys(
bool bAllowKeys )
123 SystemParametersInfo(SPI_SETSTICKYKEYS,
sizeof(STICKYKEYS), &g_StartupStickyKeys, 0);
124 SystemParametersInfo(SPI_SETTOGGLEKEYS,
sizeof(TOGGLEKEYS), &g_StartupToggleKeys, 0);
125 SystemParametersInfo(SPI_SETFILTERKEYS,
sizeof(FILTERKEYS), &g_StartupFilterKeys, 0);
132 STICKYKEYS skOff = g_StartupStickyKeys;
133 if( (skOff.dwFlags & SKF_STICKYKEYSON) == 0 )
136 skOff.dwFlags &= ~SKF_HOTKEYACTIVE;
137 skOff.dwFlags &= ~SKF_CONFIRMHOTKEY;
139 SystemParametersInfo(SPI_SETSTICKYKEYS,
sizeof(STICKYKEYS), &skOff, 0);
142 TOGGLEKEYS tkOff = g_StartupToggleKeys;
143 if( (tkOff.dwFlags & TKF_TOGGLEKEYSON) == 0 )
146 tkOff.dwFlags &= ~TKF_HOTKEYACTIVE;
147 tkOff.dwFlags &= ~TKF_CONFIRMHOTKEY;
149 SystemParametersInfo(SPI_SETTOGGLEKEYS,
sizeof(TOGGLEKEYS), &tkOff, 0);
152 FILTERKEYS fkOff = g_StartupFilterKeys;
153 if( (fkOff.dwFlags & FKF_FILTERKEYSON) == 0 )
156 fkOff.dwFlags &= ~FKF_HOTKEYACTIVE;
157 fkOff.dwFlags &= ~FKF_CONFIRMHOTKEY;
159 SystemParametersInfo(SPI_SETFILTERKEYS,
sizeof(FILTERKEYS), &fkOff, 0);
175#include <mach-o/dyld.h>
176#include <CoreFoundation/CFBundle.h>
184#include "../platforms/sdl/PlatformEnvironment.h"
185#include "../platforms/sdl/SDLUtility.h"
207std::list<string>
GetFiles(
int argc, std::vector<std::string> argv);
225#ifdef PEBL_EMSCRIPTEN
232#ifdef PEBL_EMSCRIPTEN
233 EM_ASM(console.log(
"=== PEBLInterpret() called ==="));
236 std::cerr <<
"**************Starting PEBLInterpret\n";
237 std::cerr <<
"**************argc:" << argc << endl;
239#if defined(PEBL_UNIX) and not defined(PEBL_OSX)
240 if(argc==2 && strcmp(argv[1].c_str(),
"--install")==0)
246 PError::SignalWarning(
"Warning: BinReloc failed to initialize.\n Will fallback to hardcoded default path.\n");
248 basedir =
"/usr/local/share/pebl2";
252 basedir = prefix + string(
"/share/pebl2/battery/");
253 string destdir = string(
"~/Documents/pebl-exp.") +
PEBL_VERSION;
259 std::cerr <<
"Copying files to ["+destdir+
"]\n";
274 cerr <<
"************Arguments: "<< argv.size()<<
"\n";
275 std::vector<std::string>::iterator ii = argv.begin();
276 while(ii != argv.end())
280 cerr <<
"********\n";
286 std::list<std::string> files =
GetFiles(argc, argv);
294 files.push_back(
"Design.pbl");
295 files.push_back(
"Utility.pbl");
296 files.push_back(
"Math.pbl");
297 files.push_back(
"Graphics.pbl");
298 files.push_back(
"UI.pbl");
299 files.push_back(
"HTML.pbl");
300 files.push_back(
"Transfer.pbl");
301 files.push_back(
"Layout.pbl");
303#ifdef PEBL_EMSCRIPTEN
304 files.push_back(
"EM.pbl");
311#ifdef PEBL_EMSCRIPTEN
318 std::list<std::string>::iterator i = files.begin();
325 std::cerr <<
"Loading filename:[" << *i <<
"]\n";
327 string otherfilename;
330 if(inputfilename !=
"")
332 cerr <<
"Processing PEBL Source File1: " << inputfilename << endl;
345 while(i != files.end())
347 std::cerr <<
"********************\n";
348 std::cerr <<
"Loading file name: [" << *i <<
"]"<< endl;
350 std::cerr <<
"Resolved as: [" <<otherfilename <<
"]"<< endl;
351 if(inputfilename !=
"")
353 cerr <<
"Processing PEBL Source File2: " << otherfilename << endl;
360 tmp =
parse(otherfilename.c_str());
363 head =
new OpNode(PEBL_FUNCTIONS,
head, tmp,
"INTERNAL PEBL STRUCTURE", -1);
378 cerr <<
"---------Loading Program---------" << endl;
386 cerr <<
"Analyzing code for functions." << endl;
390 cerr <<
"Loading Library functions." << endl;
402 cerr <<
"\n\n--------------------------------\n";
403 cerr <<
"Functions used in program: " << endl;
404 cerr <<
"--------------------------------\n";
406 cerr <<
"--------------------------------\n\n";
420 std::string displaySize=
"0x0";
423 std::string depth =
"32";
426 bool windowed =
true;
428 bool softrender =
false;
429 bool resizeable =
false;
432 bool showHelp =
false;
433 bool showTestResults =
false;
434 bool lslEnabled =
false;
450 for(
int j = 1; j < argc; j++)
453 if(strcmp(argv[j].c_str(),
"-v")==0 ||
454 strcmp(argv[j].c_str(),
"-V")==0)
461 else if(strcmp(argv[j].c_str(),
"-s")==0 ||
462 strcmp(argv[j].c_str(),
"-S")==0)
468 else if(strcmp(argv[j].c_str(),
"--driver")==0)
476 else if(strcmp(argv[j].c_str(),
"--display")==0)
478 displaySize = argv[++j];
481 else if(strcmp(argv[j].c_str(),
"--depth")==0)
487 else if (strcmp(argv[j].c_str(),
"--fullscreen")==0)
491 else if(strcmp(argv[j].c_str(),
"--windowed")==0)
495 else if(strcmp(argv[j].c_str(),
"--unicode")==0)
499 else if(strcmp(argv[j].c_str(),
"--language")==0)
504 else if(strcmp(argv[j].c_str(),
"--pfile")==0)
506 std::string pfileArg = argv[++j];
508 if(pfileArg.compare(0, 7,
"http://") == 0 || pfileArg.compare(0, 8,
"https://") == 0)
518 else if(strcmp(argv[j].c_str(),
"--upload")==0)
522 uploadConfigFile =
Variant(argv[++j]);
523 cerr <<
"setting upload file: [" << uploadConfigFile <<
"]\n";
526 else if(strcmp(argv[j].c_str(),
"--lsl")==0)
530 if(j+1 < argc && argv[j+1].c_str()[0] !=
'-')
532 lslStreamName =
Variant(argv[++j]);
533 cerr <<
"LSL enabled with stream name: [" << lslStreamName <<
"]\n";
537 cerr <<
"LSL enabled (auto-generate stream name)\n";
541 else if(strcmp(argv[j].c_str(),
"--resizeable")==0 ||
542 strcmp(argv[j].c_str(),
"--resizable")==0 )
547 else if(strcmp(argv[j].c_str(),
"--vsyncon")==0)
552 else if(strcmp(argv[j].c_str(),
"--vsyncoff")==0)
556 else if(strcmp(argv[j].c_str(),
"--softrender")==0)
560 else if(strcmp(argv[j].c_str(),
"--help")==0)
564 else if(strcmp(argv[j].c_str(),
"--showtestresults")==0)
566 showTestResults =
true;
581#if defined(PEBL_UNIX)
587 cerr <<
"Priority set here**************************\n";
588 int priority = getpriority(PRIO_PROCESS,0);
589 cerr <<
"Process running at a nice value of " << priority << endl;
590 cerr <<
"attempting to set priority to: " << PRIO_MIN << endl;
592 setpriority(PRIO_PROCESS,0,PRIO_MIN);
593 priority = getpriority(PRIO_PROCESS,0);
595 cerr <<
"Process running at a nice value of " << priority << endl;
622#elif defined(PEBL_WIN32)
627 SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS);
639 cerr <<
"Environment created\n";
643 srand((
unsigned int)time(0));
645 cerr <<
"---------Creating Evaluator-----" << endl;
649#if defined(PEBL_EMSCRIPTEN)
650 std::cerr <<
"--------o-o-o-o-o-o--\n";
660 cerr <<
"No command line arguments given\n";
682 std::list<PNode> tmpcallstack;
688#if defined(PEBL_LINUX) || defined(PEBL_UNIX)
690 const char* appimage_path = getenv(
"APPIMAGE");
691 if (appimage_path !=
NULL) {
694 cerr <<
"Running from AppImage: " << appimage_path << endl;
698 if (exe_path !=
NULL) {
701 cerr <<
"Executable path: " << exe_path << endl;
734 size_t found = displaySize.find(
"x");
735 if(found == string::npos)
742 cerr <<
"Size from command line argument: " << displaySize.substr(0,found)<<
"|"<< displaySize.substr(found+1) <<endl;
744 width = atoi(displaySize.substr(0,found).c_str());
745 height = atoi(displaySize.substr(found+1).c_str());
781 std::string tmps =lang;
782 transform(tmps.begin(),tmps.end(),tmps.begin(),toupper);
822 cerr <<
"---------Evaluating Program-----" << endl;
826#ifdef PEBL_ITERATIVE_EVAL
828 cerr <<
"Starting evaluation with iterative evaluator\n";
842 OpNode* startCall =
new OpNode(PEBL_FUNCTION, funcNameNode, args,
"", 0);
846 cerr <<
"Running evaluator loop\n";
853 cerr <<
"Starting evaluation with recursive evaluator\n";
859 int scriptReturnCode = 0;
864 scriptReturnCode = (int)returnVal;
865 cerr <<
"Script returned: " << scriptReturnCode << endl;
869#ifdef PEBL_EMSCRIPTEN
871 cerr <<
"========================================" << endl;
872 cerr <<
"PEBL program completed successfully." << endl;
873 cerr <<
"========================================" << endl;
906 cerr <<
"Exiting with code: " << scriptReturnCode << endl;
907 _exit(scriptReturnCode);
915 return scriptReturnCode;
919 cerr <<
"Error: Can't evaluate program" << endl;
932 cerr <<
"Exiting PEBL because of captured signal.\n";
936 AllowAccessibilityShortcutKeys(
false );
968int main(
int argc,
char *argv[])
971#ifdef PEBL_EMSCRIPTEN
972 EM_ASM(console.log(
"=== main() called in PEBL.cpp ==="));
1013 std::vector<std::string> newargv;
1018#if defined(PEBL_OSX)
1021 CFBundleRef mainBundle = CFBundleGetMainBundle();
1022 CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
1023 char resourcepath[PATH_MAX];
1024 if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)resourcepath, PATH_MAX))
1028 CFRelease(resourcesURL);
1032 std::string script =
"/launcher.pbl";
1033 std::string basedir = (std::string)resourcepath ;
1034 std::string launch = basedir + script;
1038 std::cerr <<
"Basedir:" << basedir << endl;
1039 std::cerr <<
"launch: " << launch << endl;
1042#elif defined(PEBL_WIN32)
1045 SystemParametersInfo(SPI_GETSTICKYKEYS,
sizeof(STICKYKEYS), &g_StartupStickyKeys, 0);
1046 SystemParametersInfo(SPI_GETTOGGLEKEYS,
sizeof(TOGGLEKEYS), &g_StartupToggleKeys, 0);
1047 SystemParametersInfo(SPI_GETFILTERKEYS,
sizeof(FILTERKEYS), &g_StartupFilterKeys, 0);
1050 AllowAccessibilityShortcutKeys(
false );
1054 std::string resourcepath = basedir;
1055 std::string launch =
"launcher.pbl";
1056 std::string script = resourcepath+
"/pebl-lib/"+launch;
1063#elif defined (PEBL_LINUX)
1070 PError::SignalWarning(
"Warning: BinReloc failed to initialize.\n Will fallback to current directory.\n");
1075 if (exe_dir !=
NULL) {
1077 basedir = string(exe_dir) + string(
"/../");
1078 std::cerr <<
"Executable directory: [" << exe_dir <<
"]\n";
1085 std::string resourcepath = basedir;
1086 std::string launch = basedir +
"bin/launcher.pbl";
1087 std::string script =
"";
1096#elif defined (PEBL_EMSCRIPTEN)
1098 std::string basedir =
"/usr/local/share/pebl2";
1100 std::string resourcepath = basedir;
1103 std::string launch =
"";
1104 std::string script =
"";
1113 std::string home =
"";
1114 char* val = getenv(
"HOME");
1126#if defined(PEBL_LINUX)
1130 cout <<
"\nTo launch the graphical study manager, run: pebl-launcher\n";
1132#elif defined(PEBL_WIN32)
1137 std::cerr <<
"No script specified. Launching: " << launcherExe <<
"\n";
1138 HINSTANCE result = ShellExecuteA(
NULL,
"open",
1139 launcherExe.c_str(),
1143 if ((INT_PTR)result <= 32)
1148 cerr <<
"\nNote: pebl-launcher.exe not found at " << launcherExe <<
"\n";
1161 for(
int i=0; i < argc; i++)
1163 newargv.push_back(argv[i]);
1185std::list<std::string>
GetFiles(
int argc, std::vector<std::string> argv)
1188 std::list<std::string> tmp;
1189 std::vector<std::string>::iterator i = argv.begin();
1194 while(i != argv.end())
1196 if(i->compare(
"-v")==0 ||
1197 i->compare(
"-V")==0 ||
1198 i->compare(
"-s")==0 ||
1199 i->compare(
"-S") == 0 ||
1200 i->compare(
"--language")==0 ||
1201 i->compare(
"--pfile")==0 ||
1202 i->compare(
"--upload")==0)
1208 else if(i->compare(
"--lsl")==0)
1211 std::vector<std::string>::iterator next = i;
1213 if(next != argv.end() &&
1214 next->c_str()[0] !=
'-' &&
1215 next->find(
".pbl") == std::string::npos)
1222 else if (i->compare(
"--driver")==0 ||
1223 i->compare(
"--display")==0 ||
1224 i->compare(
"--depth")==0 )
1230 else if (i->compare(
"--windowed")==0 ||
1231 i->compare(
"--fullscreen")==0 ||
1232 i->compare(
"--unicode")==0 ||
1233 i->compare(
"--resizeable")==0 ||
1234 i->compare(
"--resizable")==0||
1235 i->compare(
"--vsyncoff")==0||
1236 i->compare(
"--vsyncon")==0 ||
1237 i->compare(
"--softrender")==0 ||
1238 i->compare(
"--help")==0 ||
1239 i->compare(
"--showtestresults")==0
1251 tmp.push_back(std::string(*i));
1260 cout <<
"-------------------------------------------------------------------------------\n";
1261 cout <<
"PEBL: The Psychology Experiment Building Language\n";
1263 cout <<
"(c) 2003-2026 Shane T. Mueller, Ph.D.\n";
1264 cout <<
"smueller@obereed.net http://pebl.sf.net\n";
1265 cout <<
"-------------------------------------------------------------------------------\n";
1267 cout <<
"Usage: Invoke pebl with the experiment script files (.pbl) and command-line\n";
1268 cout <<
"arguments.\n\n";
1269 cout <<
"example: pebl experiment.pbl -v sub1 --fullscreen --display 800x600 --driver opengl\n\n";
1270 cout <<
"COMMAND-LINE OPTIONS:\n";
1271 cout <<
"-v VALUE1 -v VALUE2\n";
1272 cout <<
" Invokes script and passes VALUE1 and VALUE2 (and any text immediately\n" ;
1273 cout <<
" following -v) to a list in the argument of the Start() function.\n\n";
1274 cout <<
"-s IDENTIFIER\n";
1275 cout <<
" Initiates the global variable gSubNum to IDENTIFIER. If not set here,\n";
1276 cout <<
" gSubNum is initiated to 0.\n\n";
1277 cout <<
"--driver <drivername>\n";
1278 cout <<
" Sets the preferred video driver via a hint, alternatives include direct3d opengl\n";
1279 cout <<
" opengles2 opengles and software\n";
1280 cout <<
"--display <widthxheight>\n";
1281 cout <<
" Controls the screen width and height (in pixels). Screen resolution defaults\n";
1282 cout <<
" to the current screen resolution. In fullscreen mode, PEBL will check whether \n";
1283 cout <<
" the resolution is available for the video screen, and use the default mode if not\n";
1284 cout <<
" Note: Custom screen dimensions can be controlled in-script.\n\n";
1285 cout <<
"--depth\n";
1286 cout <<
" Controls the pixel depth. Depends on your video card. Currently,\n";
1287 cout <<
" depths of 2,8,15,16,24, and 32 are allowed on the command-line.\n";
1288 cout <<
"--language <2 char lang code>\n";
1289 cout <<
" Allows you to specify at the command line a language to enable \n selecting different text labels.\n";
1290 cout <<
"--windowed\n";
1291 cout <<
"--fullscreen\n";
1292 cout <<
" Controls whether the script will run in a window or fullscreen.\n\n";
1293 cout <<
"--resizeable\n";
1294 cout <<
"--resizable\n";
1295 cout <<
" Controls whether the window will be resizeable (only in windowed mode)\n\n";
1296 cout <<
"--unicode\n";
1297 cout <<
" Turns on unicode handling, with slight overhead\n";
1298 cout <<
"--pfile <filename>\n";
1299 cout <<
" Specifies which parameter file to use, gets bound to variable gParamFile.\n";
1300 cout <<
" --upload <fname>\n";
1301 cout <<
" specifies an upload.json file to use to sync with data server\n";
1302 cout <<
" --vsyncon\n";
1303 cout <<
" Turns Vsync ON (for special tasks where you need precise control of video refresh, but may be tfussy on some hardware.\n";
1305 cout <<
" --softrender\n";
1306 cout <<
" Uses software renderer instead of accelerated hardware fallback. Disables vsync setting\n";
1308 cout <<
" --lsl [streamname]\n";
1309 cout <<
" Enables Lab Streaming Layer (LSL) output for EEG/eye-tracker synchronization.\n";
1310 cout <<
" Optional streamname overrides the auto-generated stream name (PEBL_<scriptname>).\n";
1311 cout <<
" Use InitializeLSL(), LSLMarker(), and FinalizeLSL() in your script.\n";
1313 cout <<
" --help\n";
1314 cout <<
" Display this output screen\n";
1316 cout <<
" --showtestresults\n";
1317 cout <<
" Sets global variable gShowTestResults to 1 vs 0. Allows a test to automatically show a screen with results at the end.\n";
char * br_find_prefix(const char *default_prefix)
int br_init(BrInitError *error)
char * br_find_exe_dir(const char *default_dir)
char * br_find_exe(const char *default_exe)
void SignalTestComplete(const char *status="completed")
int main(int argc, char *argv[])
PlatformEnvironment * myEnv
int PEBLInterpret(int argc, std::vector< std::string > argv)
std::list< string > GetFiles(int argc, std::vector< std::string > argv)
void CaptureSignal(int signal)
This class has got everything you need to evaluate stuff.
bool Evaluate(const PNode *node)
static const PNode * gEvalNode
static PCallStack gCallStack
static PEventLoop * mEventLoop
static VariableMap gGlobalVariableMap
static FunctionMap mFunctionMap
Initiate some static member data.
void LoadUserFunctions(OpNode *node)
void LoadLibraryFunctions()
void FindFunctions(const PNode *Node)
PNode * GetMainPEBLFunction()
std::string FindFile(const string &filename)
void Initialize(std::list< std::string >)
Variant Nth(unsigned int n)
unsigned long Length() const
void PushBack(const Variant &v)
void AddVariable(const std::string &varname, const Variant &val)
PComplexData * GetComplexData() const
bool IsNumber() const
This tests whether the Variant is a number (i.e., a float or an integer.)
void MakeEnvironment(PEBLVideoMode mode, PEBLVideoDepth depth, bool windowed, bool resizeable, bool unicode)
This function instantiates the namespace-viewable.
Variant SystemCall(std::string path, std::string args)
PEBLVideoDepth GetVideoDepth(std::string depthline)
const std::string GetBaseFileName(const std::string &file)
const std::string StripFile(const std::string &file)
std::string GetFontForLanguageOrScript(const std::string &code, int fontType)
Variant GetWorkingDirectory()
PEBLVideoMode GetVideoMode(std::string modeline)
void SignalWarning(const std::string &message)
void SignalFatalError(const std::string &message)
Variant GetCurrentScreenResolution()