Browse Source

changes for fake standalone mode; import probably broken

master
Ian Piumarta 2 years ago
parent
commit
21b1e91ee4
1 changed files with 31 additions and 14 deletions
  1. +31
    -14
      parse.leg

+ 31
- 14
parse.leg View File

@ -588,16 +588,12 @@ oop newTry(oop try, oop exception, oop catch, oop finally)
return obj; return obj;
} }
#define YY_INPUT(buf, result, max_size) \
#define YY_INPUT(yy, buf, result, max_size) \
{ \ { \
int yyc= feof(inputStack->file) ? EOF : getc(inputStack->file); \ int yyc= feof(inputStack->file) ? EOF : getc(inputStack->file); \
result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \ result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
} }
#define YYSTYPE oop
YYSTYPE yylval;
int errorLine= 1; int errorLine= 1;
void syntaxError(char *text) void syntaxError(char *text)
@ -608,9 +604,17 @@ void syntaxError(char *text)
oop eval(oop scope, oop ast); oop eval(oop scope, oop ast);
struct _yycontext;
#define YYSTYPE oop
YYSTYPE yylval;
#define YY_ACTION(T) static T
int yyparsefrom(int (*yystart)(struct _yycontext *yy));
#define YY_CTX_LOCAL 1
#define YYPARSEFROM yymeta_parsefrom
#define YYPARSE yymeta_parse
#define YYRELEASE yymeta_release
%} %}
@ -2017,7 +2021,7 @@ oop evalArgs(oop scope, oop asts)
oop AST= NULL; oop AST= NULL;
void readEvalPrint(oop scope, char *fileName)
void readEvalPrint(yycontext *yy, oop scope, char *fileName)
{ {
inputStackPush(fileName); inputStackPush(fileName);
input_t *top= inputStack; input_t *top= inputStack;
@ -2026,7 +2030,7 @@ void readEvalPrint(oop scope, char *fileName)
int jbt= sigsetjmp(jbs->jb, 0); int jbt= sigsetjmp(jbs->jb, 0);
if (0 == jbt) { if (0 == jbt) {
while (yyparse()) {
while (YYPARSE(yy)) {
if (opt_v > 1) printf("%s:%i: ", get(inputStack->name, String, value), inputStack->lineNumber); if (opt_v > 1) printf("%s:%i: ", get(inputStack->name, String, value), inputStack->lineNumber);
if (!yylval) { if (!yylval) {
fclose(inputStack->file); fclose(inputStack->file);
@ -2059,13 +2063,16 @@ void readEvalPrint(oop scope, char *fileName)
oop prim_import(oop scope, oop params) oop prim_import(oop scope, oop params)
{ {
yycontext yy, *yyctx = &yy;
memset(yyctx, 0, sizeof(yy));
if (map_hasIntegerKey(params, 0)) { if (map_hasIntegerKey(params, 0)) {
char *file= get(get(params, Map, elements)[0].value, String, value); char *file= get(get(params, Map, elements)[0].value, String, value);
if (yyctx->__pos < yyctx->__limit) { if (yyctx->__pos < yyctx->__limit) {
yyctx->__limit--; yyctx->__limit--;
ungetc(yyctx->__buf[yyctx->__limit], inputStack->file); ungetc(yyctx->__buf[yyctx->__limit], inputStack->file);
} }
readEvalPrint(scope, file);
readEvalPrint(yyctx, scope, file);
} }
return null; return null;
} }
@ -2314,7 +2321,7 @@ oop prim_microseconds(oop scope, oop params)
return makeInteger(ru.ru_utime.tv_sec * 1000*1000 + ru.ru_utime.tv_usec); return makeInteger(ru.ru_utime.tv_sec * 1000*1000 + ru.ru_utime.tv_usec);
} }
int main(int argc, char **argv)
void meta_init(void)
{ {
# if (USE_GC) # if (USE_GC)
GC_INIT(); GC_INIT();
@ -2364,6 +2371,13 @@ int main(int argc, char **argv)
#undef _DO #undef _DO
fixScope(globals); fixScope(globals);
}
int main(int argc, char **argv)
{
meta_init();
yycontext yy;
int repled = 0; int repled = 0;
while (argc-- > 1) { while (argc-- > 1) {
@ -2371,16 +2385,19 @@ int main(int argc, char **argv)
if (!strcmp(*argv, "-g")) ++opt_g; if (!strcmp(*argv, "-g")) ++opt_g;
else if (!strcmp(*argv, "-v")) ++opt_v; else if (!strcmp(*argv, "-v")) ++opt_v;
else if (!strcmp(*argv, "-")) { else if (!strcmp(*argv, "-")) {
readEvalPrint(globals, NULL);
memset(&yy, 0, sizeof(yy));
readEvalPrint(&yy, globals, NULL);
repled= 1; repled= 1;
} }
else { else {
readEvalPrint(globals, *argv);
memset(&yy, 0, sizeof(yy));
readEvalPrint(&yy, globals, *argv);
repled= 1; repled= 1;
} }
} }
if (!repled) { if (!repled) {
readEvalPrint(globals, NULL);
memset(&yy, 0, sizeof(yy));
readEvalPrint(&yy, globals, NULL);
} }
if (opt_g) { if (opt_g) {

Loading…
Cancel
Save