-
Notifications
You must be signed in to change notification settings - Fork 182
Description
Reading the source, I saw how to run a program whose source is defined in a file, and do it by either calling main() or not calling it (as a script). This is in picoc.c
Also in picoc.c, I found how to run a program stored in a string rather than in a file, in what's called "surveyor host" mode, but it does it without calling main().
I want both things: Running a program which is already stored in a string, and start its execution at main().
My guess is the following code snippet, but is this correct? I'm afraid the program would be run twice (first time when calling PicocParse()
and second time when calling PicocCallMain()
) by doing it this way, but I don't know how to achieve it in other way. Didn't find any docs explaining it.
Is the following guess correct? How should I do it?
int picocrun(const char *src, int argc, char **argv)
{
Picoc pc;
int StackSize = 128*1024; /* space for the stack */
PicocInitialise(&pc, StackSize);
if (PicocPlatformSetExitPoint(&pc))
{
PicocCleanup(&pc);
return pc.PicocExitValue;
}
PicocParse(&pc, "nofile", src, strlen(src), TRUE, FALSE, TRUE, TRUE);
PicocCallMain(&pc, argc, argv);
PicocCleanup(&pc);
return pc.PicocExitValue;
}