/ Check-in [10502f4b73]
DEMO | DOWNLOAD | DEPLOY | SEARCH
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Release "2.8.31". Fix parser bug in strings with line ending in backslash.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:10502f4b73babb747048aff16355af6af4d24257
User & Date: pmacdona 2019-05-23 04:15:55
References
2019-05-23
04:19 Ticket [f8d3a82011] NUL bytes not encodable status still Open with 3 other changes artifact: ef2034994d user: pmacdona
Context
2019-05-23
14:24
Release "2.8.32". Fix embedded nulls in format() and elsewhere. check-in: 53d32b6f33 user: pmacdona tags: trunk
04:15
Release "2.8.31". Fix parser bug in strings with line ending in backslash. check-in: 10502f4b73 user: pmacdona tags: trunk
2019-05-22
22:14
Release "2.8.30". Handle JSON.parse of embedded null. Fix indexing into blob-string with embedded null. Reject utf null code literal. check-in: ce1f147224 user: pmacdona tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/Jsi_CData.jsi.

459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
...
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
...
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
            self.init[name] = init;
        } else
            definit=0;
        self.pre0 += sc;
        //self.pre1 += aspre;
        if (bsgets.length) {
            var rc = "\n/* A set/get bitfield function for the struct \"name\". */\n"
                + "static Jsi_RC jsi_cs_bsget_"+name+"(Jsi_Interp *interp, void *data, Jsi_Wide *s, Jsi_OptionSpec *spec, int idx, bool isSet) \{\n"
                + "  int same;\n  const char *fname=\"\";\n"
                + "  struct "+name+" *p = (struct "+name+" *)data;\n"
                + "  switch (idx) \{\n";
            for (var k in bsgets) {
                var i = bsgets[k][0];
                var j = bsgets[k][1];
                var btyp = bsgets[k][2];
                var bidx = bsgets[k][3];
                var tvar = (btyp.substr(0,1) == 'u'?'Jsi_UWide':'Jsi_Wide');
                var rr =  "      "+tvar+"* t = ("+tvar+"*)s;\n"
................................................................................
                    + "          p->"+i+" = oldv;\n"
                    + "          fname = \""+j+"\";\n"
                    + "      }\n"
                    + "      break;\n";
                rc += "\n    case "+bidx+": {\n"+rr+"    }\n";
            }
            rc += "\n    default: {Jsi_LogWarn(\"bad index: %d\",idx); return JSI_ERROR; }\n";
            rc += "  \}\n"
                    + "  if (!same) { Jsi_LogWarn(\"value %\" PRId64 \" out of range for field '%s'\",*s, fname); return JSI_ERROR; }\n"
                + "  return JSI_OK;\n\}\n\n";
            self.out += rc;
        }

        var specname = name+'_Specs';
        self.pre0 += '#define '+name+'_Sig '+sig+'\n\n';
        self.iout += aspre + "\n  static Jsi_StructSpec "+specname+"[] = {\n"+ fieldstr
            +"    JSI_OPT_END_(JSI_SIG_OPTS_STRUCT, "+name+', .help="'+def.label+'")\n  };\n\n';
................................................................................
        /*+ "#ifndef _JSI_CDEFS_"+name+"_H_\n"
        + "#define _JSI_CDEFS_"+name+"_H_\n\n"
        + '#define _GNU_SOURCE\n#include <string.h>\n#ifdef JSI_CDATA_MAIN\n#define JSI_CDATA_IMPL\n\n'
        + '#ifdef JSI_CDATA_SHARED\n#define JSI_USE_STUBS 1\n#include "jsi.h"\n#else\n#include "jsi.c"\n#endif\n#endif\n\n' */
        + self.pre0 + '\n' + self.pre + "\n#ifdef JSI_CDATA_IMPL\n\nJSI_EXTENSION_INI\n#undef JSI_EXTENSION_INI\n#define JSI_EXTENSION_INI\n"
        + self.out0 + self.out + self.out1
        + self.pre1 + '\n' + self.iout
        + "\n  static Jsi_EnumSpec CS_ENUMS_"+name+"\[\] = {\n"
        + self.enums 
        + "    {}\n  };\n"
        + "\n  static Jsi_StructSpec CS_STRUCTS_"+name+"\[\] = {\n"
        + self.structs 
        + "    {}\n  };\n"
        + "\n  static Jsi_OptionTypedef CS_TYPES_"+name+"\[\] = {\n"
        + self.types 
        + "    {}\n  };\n"
        + "\n   static Jsi_VarSpec CS_VARS_"+name+"\[\] = {\n"
        + self.vardefs 
        + "    {}\n  };\n\n"
        
        + "  static Jsi_CData_Static CS_STATICS_"+name+" = { .name=\""+name+"\", .structs=CS_STRUCTS_"+name
        +", .enums=CS_ENUMS_"+name
        +', .vars=CS_VARS_'+name
        +", .types=CS_TYPES_"+name







|


|







 







|

|







 







|


|


|


|







459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
...
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
...
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
            self.init[name] = init;
        } else
            definit=0;
        self.pre0 += sc;
        //self.pre1 += aspre;
        if (bsgets.length) {
            var rc = "\n/* A set/get bitfield function for the struct \"name\". */\n"
                + "static Jsi_RC jsi_cs_bsget_"+name+"(Jsi_Interp *interp, void *data, Jsi_Wide *s, Jsi_OptionSpec *spec, int idx, bool isSet) {\n"
                + "  int same;\n  const char *fname=\"\";\n"
                + "  struct "+name+" *p = (struct "+name+" *)data;\n"
                + "  switch (idx) {\n";
            for (var k in bsgets) {
                var i = bsgets[k][0];
                var j = bsgets[k][1];
                var btyp = bsgets[k][2];
                var bidx = bsgets[k][3];
                var tvar = (btyp.substr(0,1) == 'u'?'Jsi_UWide':'Jsi_Wide');
                var rr =  "      "+tvar+"* t = ("+tvar+"*)s;\n"
................................................................................
                    + "          p->"+i+" = oldv;\n"
                    + "          fname = \""+j+"\";\n"
                    + "      }\n"
                    + "      break;\n";
                rc += "\n    case "+bidx+": {\n"+rr+"    }\n";
            }
            rc += "\n    default: {Jsi_LogWarn(\"bad index: %d\",idx); return JSI_ERROR; }\n";
            rc += "  }\n"
                    + "  if (!same) { Jsi_LogWarn(\"value %\" PRId64 \" out of range for field '%s'\",*s, fname); return JSI_ERROR; }\n"
                + "  return JSI_OK;\n}\n\n";
            self.out += rc;
        }

        var specname = name+'_Specs';
        self.pre0 += '#define '+name+'_Sig '+sig+'\n\n';
        self.iout += aspre + "\n  static Jsi_StructSpec "+specname+"[] = {\n"+ fieldstr
            +"    JSI_OPT_END_(JSI_SIG_OPTS_STRUCT, "+name+', .help="'+def.label+'")\n  };\n\n';
................................................................................
        /*+ "#ifndef _JSI_CDEFS_"+name+"_H_\n"
        + "#define _JSI_CDEFS_"+name+"_H_\n\n"
        + '#define _GNU_SOURCE\n#include <string.h>\n#ifdef JSI_CDATA_MAIN\n#define JSI_CDATA_IMPL\n\n'
        + '#ifdef JSI_CDATA_SHARED\n#define JSI_USE_STUBS 1\n#include "jsi.h"\n#else\n#include "jsi.c"\n#endif\n#endif\n\n' */
        + self.pre0 + '\n' + self.pre + "\n#ifdef JSI_CDATA_IMPL\n\nJSI_EXTENSION_INI\n#undef JSI_EXTENSION_INI\n#define JSI_EXTENSION_INI\n"
        + self.out0 + self.out + self.out1
        + self.pre1 + '\n' + self.iout
        + "\n  static Jsi_EnumSpec CS_ENUMS_"+name+"[] = {\n"
        + self.enums 
        + "    {}\n  };\n"
        + "\n  static Jsi_StructSpec CS_STRUCTS_"+name+"[] = {\n"
        + self.structs 
        + "    {}\n  };\n"
        + "\n  static Jsi_OptionTypedef CS_TYPES_"+name+"[] = {\n"
        + self.types 
        + "    {}\n  };\n"
        + "\n   static Jsi_VarSpec CS_VARS_"+name+"[] = {\n"
        + self.vardefs 
        + "    {}\n  };\n\n"
        
        + "  static Jsi_CData_Static CS_STATICS_"+name+" = { .name=\""+name+"\", .structs=CS_STRUCTS_"+name
        +", .enums=CS_ENUMS_"+name
        +', .vars=CS_VARS_'+name
        +", .types=CS_TYPES_"+name

Changes to lib/Jsi_Markdown.jsi.

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
            var curFile = files[i];
            var s = File.read(curFile);
            rc += Util.markdown(s).data;
        }

        return rc;
    }
    file = Util.argArray(files);
    if (files && files.length)
        return parse(files);
        
    self.parse = parse;
    return self;
}

provide(Jsi_Markdown);

if (isMain())
    runModule(Jsi_Markdown);








|












16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
            var curFile = files[i];
            var s = File.read(curFile);
            rc += Util.markdown(s).data;
        }

        return rc;
    }
    //var file = Util.argArray(files);
    if (files && files.length)
        return parse(files);
        
    self.parse = parse;
    return self;
}

provide(Jsi_Markdown);

if (isMain())
    runModule(Jsi_Markdown);

Changes to src/jsi.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
....
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
....
8230
8231
8232
8233
8234
8235
8236

8237
8238
8239
8240
8241
8242
8243
....
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
.....
15935
15936
15937
15938
15939
15940
15941







15942
15943
15944
15945
15946
15947
15948
.....
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
.....
16100
16101
16102
16103
16104
16105
16106




16107





16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122

16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
.....
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
.....
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
.....
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
.....
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
.....
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
.....
23091
23092
23093
23094
23095
23096
23097



23098
23099
23100
23101
23102
23103
23104
.....
68255
68256
68257
68258
68259
68260
68261
68262
68263
68264
68265
68266
68267
68268
68269
68270
68271
68272
68273
68274
68275


68276

68277
68278
68279
68280
68281
68282
68283
/* jsi.h : External API header file for Jsi. */
#ifndef __JSI_H__
#define __JSI_H__

#define JSI_VERSION_MAJOR   2
#define JSI_VERSION_MINOR   8
#define JSI_VERSION_RELEASE 30

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

#ifndef JSI_EXTERN
#define JSI_EXTERN extern
#endif

................................................................................
    struct jsi_Lexer *lexer;        /* seq provider */

    int _context_id;            /* used in FastVar-locating */
    Jsi_Value *last_exception;
    Jsi_Interp *interp;
    Jsi_HashEntry *hPtr;
    Jsi_Hash *argsTbl;
    Jsi_Hash *strTbl;
    Jsi_Hash *fastVarTbl;
    int argType;                // Used during parsing to aggregate type.
    Jsi_ScopeStrs *args;        // Last push.
} jsi_Pstate;


Jsi_ScopeStrs *jsi_ScopeStrsNew(void);
................................................................................
        char *str;          /* LT_STRING */
    } d;
    int last_token;         /* last token returned */
    int ungot, unch[100];
    int cur;                /* LT_STRING, current char */
    int cur_line;           /* current line no. */
    int cur_char;           /* current column no. */

    jsi_Pstate *pstate;
} jsi_Lexer;

int yylex (YYSTYPE *yylvalp, YYLTYPE *yyllocp, jsi_Pstate *pstate);
void yyerror(YYLTYPE *yylloc, jsi_Pstate *ps, const char *msg);

typedef struct {
................................................................................
    Jsi_Value *execZip;
    void (*logHook)(char *buf, va_list va);
    const char *name;
    Jsi_Value *pkgDirs;
    bool selfZvfs;
    int inParse;
    Jsi_Value *retValue;       /* Return value from eval */
    jsi_Pstate *ps;
    Jsi_Value *argv0;
    Jsi_Value *args;
    Jsi_Value *console;
    Jsi_Value *scriptFile;  /* Start script returned by info.argv0(). */
    const char *scriptStr;
    const char *curFile;
    const char *curFunction;
................................................................................
    } else {
        if (lex->ungot) {
            c = lex->unch[--lex->ungot];
        } else {
            c = lex->d.str[lex->cur];
            if (c != 0) lex->cur++;
        }







    }
    //printf("%c", c);
    if (c == '\n') {
        //printf("!!!!!!!!!!\n");
        lex->cur_line++;
        lex->cur_char = 0;
    }
................................................................................
        return (uintptr_t)Jsi_HashValueGet(hPtr);
    return 0;
}

static char *jsi_do_string(jsi_Lexer *lex)
{
    Jsi_Interp *interp = lex->pstate->interp;
    Jsi_HashEntry *hPtr = NULL;
    int n, c = lexer_getchar(lex);
    int endchar = c;
    
    int bufi = 0, bsiz, done = 0;
    char unibuf[bsiz=JSI_BUFSIZ], *buf = unibuf, *ret = NULL;
    
    while (!done) {
................................................................................
                }
                case EOF: 
                case 0:
saw_eof:
                    Jsi_LogError("Unexpected EOF parsing string.");
                    buf[bufi++] = 0;
                    goto done;




                default: buf[bufi++] = n;





            }
        } else {
            buf[bufi++] = c;
        }
        if (c == endchar) {
            bufi --;
            break;
        }
    }
    buf[bufi] = 0;
    hPtr = Jsi_HashSet(lex->pstate->strTbl, buf, NULL);
    ret = (char*)Jsi_HashKeyGet(hPtr);
done:
    if (buf != unibuf)
        Jsi_Free(buf);

    return ret;
}

static char *jsi_do_regex(jsi_Lexer *lex)
{
    Jsi_Interp *interp = lex->pstate->interp;
    Jsi_HashEntry *hPtr = NULL;
    int n, bufi = 0, bsiz;
    char unibuf[bsiz=JSI_BUFSIZ], *buf = unibuf, *ret = NULL;
    
    buf[bufi++] = lexer_getchar(lex);     /* first '/'*/
    while (1) {
        if (bufi >= (bsiz-5)) {
            int nsiz = bsiz+=JSI_BUFSIZ;
................................................................................
            buf[bufi-1] = 0;
            lexer_ungetc(c, lex);
            break;
        } else {
            buf[bufi++] = c;
        }
    }
    hPtr = Jsi_HashSet(lex->pstate->strTbl, buf, NULL);
    ret = (char*)Jsi_HashKeyGet(hPtr);
    ret = Jsi_Strdup(buf);
done:
    if (buf != unibuf)
        Jsi_Free(buf);
    return ret;
}

................................................................................
jsi_Pstate *jsi_PstateNew(Jsi_Interp *interp)
{
    jsi_Pstate *ps = (jsi_Pstate *)Jsi_Calloc(1,sizeof(*ps));
    SIGINIT(ps,PARSER);
    ps->lexer = (jsi_Lexer*)Jsi_Calloc(1,sizeof(*ps->lexer));
    ps->lexer->pstate = ps;
    ps->interp = interp;
   // ps->argsTbl = Jsi_HashNew(interp, JSI_KEYS_ONEWORD, jsi_ArglistFree);
    ps->fastVarTbl = Jsi_HashNew(interp, JSI_KEYS_ONEWORD, NULL /*fastVarFree*/);
    ps->strTbl = Jsi_HashNew(interp, JSI_KEYS_STRING, NULL);
    return ps;
}

const char *jsi_PstateGetFilename(jsi_Pstate *ps)
{
    Jsi_Interp *interp = ps->interp;
    return interp->curFile;
................................................................................
    Jsi_Free(ps->lexer);
    if (ps->opcodes)
        jsi_FreeOpcodes(ps->opcodes);
    if (ps->hPtr)
        Jsi_HashEntryDelete(ps->hPtr);
    if (ps->argsTbl)
        Jsi_HashDelete(ps->argsTbl);
    if (ps->strTbl)
        Jsi_HashDelete(ps->strTbl);
    if (ps->fastVarTbl)
        Jsi_HashDelete(ps->fastVarTbl);
    if (ps->last_exception)
        Jsi_DecrRefCount(ps->interp, ps->last_exception);
    _JSI_MEMCLEAR(ps);
    Jsi_Free(ps);
}
................................................................................
        interp = jsiIntData.mainInterp;
    LastInterp = interp;
    if (lastInterp != interp)
        noDups = 1;
    
    /* Filter out try/catch (TODO: and non-syntax errors??). */
    if (interp == NULL) {
nullInterp:
        if (logHook)
            (*logHook)(format, va);
        else {
            vfprintf(stderr, format, va);
            fputc('\n', stderr);
        }
        va_end(va);
................................................................................
    curFile = jsi_GetCurFile(interp);
    switch (code) {
        case JSI_LOG_INFO:  if (!interp->logOpts.Info) goto bail; break;
        case JSI_LOG_WARN:  if (!interp->logOpts.Warn) goto bail; break;
        case JSI_LOG_DEBUG: if (!interp->logOpts.Debug && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_TRACE: if (!interp->logOpts.Trace && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_TEST:  if (!interp->logOpts.Test && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_PARSE: if (!interp->parent) goto nullInterp; break;
        case JSI_LOG_ERROR: {
            if (!interp->logOpts.Error) goto bail;
            if ((interp->framePtr->tryDepth - interp->framePtr->withDepth)>0 && interp->inParse<=0 
                && (!interp->tryList || !(interp->tryList->inCatch|interp->tryList->inFinal))) { 
                /* Should only do the first or traceback? */
                if (!interp->errMsgBuf[0]) {
                    vsnprintf(interp->errMsgBuf, sizeof(interp->errMsgBuf), format, va);
................................................................................
        if (*ss && !isHelp)
            snprintf(pbuf, sizeof(pbuf), "    (at or near \"%s\")\n", ss);
    }
    pbuf[sizeof(pbuf)-1] = 0;
    if (interp->inParse && interp->parseLine) {
        line = interp->parseLine->first_line;
        lofs = interp->parseLine->first_column;



    } else if (interp->curIp) {
        if (interp->callerErr && interp->framePtr && interp->framePtr->parent) {
            jsi_Frame *fptr = interp->framePtr->parent;
            line = fptr->line;
            lofs = 0;
            curFile = fptr->fileName;
        } else {
................................................................................

static jsi_Pstate* jsiNewParser(Jsi_Interp* interp, char *codeStr, Jsi_Channel fp, int iseval)
{
    bool isNew;
    Jsi_HashEntry *hPtr = NULL;
    hPtr = Jsi_HashEntryNew(interp->codeTbl, (void*)codeStr, &isNew);
    if (!hPtr) return NULL;
    jsi_Pstate *ps;

    if (isNew==0 && ((ps = (jsi_Pstate *)Jsi_HashValueGet(hPtr)))) {
        interp->codeCacheHit++;
        return ps;
    }
    ps = jsi_PstateNew(interp);
    ps->eval_flag = iseval;
    if (codeStr)
        jsi_PstateSetString(ps, codeStr);
    else
        jsi_PstateSetFile(ps, fp, 1);
        
    interp->inParse++;


    yyparse(ps);

    interp->inParse--;
    
    if (ps->err_count) {
        Jsi_HashEntryDelete(hPtr);
        jsi_PstateFree(ps);
        return NULL;
    }






|







 







<







 







>







 







|







 







>
>
>
>
>
>
>







 







|







 







>
>
>
>
|
>
>
>
>
>










<
|



>






<







 







<
|







 







<

<







 







<
<







 







|







 







|







 







>
>
>







 







|













>
>

>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
....
8157
8158
8159
8160
8161
8162
8163

8164
8165
8166
8167
8168
8169
8170
....
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
....
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
.....
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
.....
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
.....
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133

16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144

16145
16146
16147
16148
16149
16150
16151
.....
16183
16184
16185
16186
16187
16188
16189

16190
16191
16192
16193
16194
16195
16196
16197
.....
19815
19816
19817
19818
19819
19820
19821

19822

19823
19824
19825
19826
19827
19828
19829
.....
19887
19888
19889
19890
19891
19892
19893


19894
19895
19896
19897
19898
19899
19900
.....
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
.....
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
.....
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
.....
68268
68269
68270
68271
68272
68273
68274
68275
68276
68277
68278
68279
68280
68281
68282
68283
68284
68285
68286
68287
68288
68289
68290
68291
68292
68293
68294
68295
68296
68297
68298
68299
/* jsi.h : External API header file for Jsi. */
#ifndef __JSI_H__
#define __JSI_H__

#define JSI_VERSION_MAJOR   2
#define JSI_VERSION_MINOR   8
#define JSI_VERSION_RELEASE 31

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

#ifndef JSI_EXTERN
#define JSI_EXTERN extern
#endif

................................................................................
    struct jsi_Lexer *lexer;        /* seq provider */

    int _context_id;            /* used in FastVar-locating */
    Jsi_Value *last_exception;
    Jsi_Interp *interp;
    Jsi_HashEntry *hPtr;
    Jsi_Hash *argsTbl;

    Jsi_Hash *fastVarTbl;
    int argType;                // Used during parsing to aggregate type.
    Jsi_ScopeStrs *args;        // Last push.
} jsi_Pstate;


Jsi_ScopeStrs *jsi_ScopeStrsNew(void);
................................................................................
        char *str;          /* LT_STRING */
    } d;
    int last_token;         /* last token returned */
    int ungot, unch[100];
    int cur;                /* LT_STRING, current char */
    int cur_line;           /* current line no. */
    int cur_char;           /* current column no. */
    int inStr;
    jsi_Pstate *pstate;
} jsi_Lexer;

int yylex (YYSTYPE *yylvalp, YYLTYPE *yyllocp, jsi_Pstate *pstate);
void yyerror(YYLTYPE *yylloc, jsi_Pstate *ps, const char *msg);

typedef struct {
................................................................................
    Jsi_Value *execZip;
    void (*logHook)(char *buf, va_list va);
    const char *name;
    Jsi_Value *pkgDirs;
    bool selfZvfs;
    int inParse;
    Jsi_Value *retValue;       /* Return value from eval */
    jsi_Pstate *ps, *parsePs;
    Jsi_Value *argv0;
    Jsi_Value *args;
    Jsi_Value *console;
    Jsi_Value *scriptFile;  /* Start script returned by info.argv0(). */
    const char *scriptStr;
    const char *curFile;
    const char *curFunction;
................................................................................
    } else {
        if (lex->ungot) {
            c = lex->unch[--lex->ungot];
        } else {
            c = lex->d.str[lex->cur];
            if (c != 0) lex->cur++;
        }
        if (lex->inStr && c == '\\') {
            int nc = (lex->ungot ? lex->unch[lex->ungot-1] : lex->d.str[lex->cur-1]);
            if (nc == '\n') {
                return lexer_getchar(lex);
                return lexer_getchar(lex);
            }
        }
    }
    //printf("%c", c);
    if (c == '\n') {
        //printf("!!!!!!!!!!\n");
        lex->cur_line++;
        lex->cur_char = 0;
    }
................................................................................
        return (uintptr_t)Jsi_HashValueGet(hPtr);
    return 0;
}

static char *jsi_do_string(jsi_Lexer *lex)
{
    Jsi_Interp *interp = lex->pstate->interp;
    lex->inStr = 1;
    int n, c = lexer_getchar(lex);
    int endchar = c;
    
    int bufi = 0, bsiz, done = 0;
    char unibuf[bsiz=JSI_BUFSIZ], *buf = unibuf, *ret = NULL;
    
    while (!done) {
................................................................................
                }
                case EOF: 
                case 0:
saw_eof:
                    Jsi_LogError("Unexpected EOF parsing string.");
                    buf[bufi++] = 0;
                    goto done;
                case '"':
                case '\'':
                case '\\':
                case '\n':
                    buf[bufi++] = n;
                    break;
                default: 
                    buf[bufi++] = n;
                    if (!interp->unitTest)
                        Jsi_LogParse("Unsupported string escape: \\%c", n);
            }
        } else {
            buf[bufi++] = c;
        }
        if (c == endchar) {
            bufi --;
            break;
        }
    }
    buf[bufi] = 0;

    ret = (char*)Jsi_KeyAdd(lex->pstate->interp, buf);
done:
    if (buf != unibuf)
        Jsi_Free(buf);
    lex->inStr = 0;
    return ret;
}

static char *jsi_do_regex(jsi_Lexer *lex)
{
    Jsi_Interp *interp = lex->pstate->interp;

    int n, bufi = 0, bsiz;
    char unibuf[bsiz=JSI_BUFSIZ], *buf = unibuf, *ret = NULL;
    
    buf[bufi++] = lexer_getchar(lex);     /* first '/'*/
    while (1) {
        if (bufi >= (bsiz-5)) {
            int nsiz = bsiz+=JSI_BUFSIZ;
................................................................................
            buf[bufi-1] = 0;
            lexer_ungetc(c, lex);
            break;
        } else {
            buf[bufi++] = c;
        }
    }

    ret = (char*)Jsi_KeyAdd(lex->pstate->interp, buf);
    ret = Jsi_Strdup(buf);
done:
    if (buf != unibuf)
        Jsi_Free(buf);
    return ret;
}

................................................................................
jsi_Pstate *jsi_PstateNew(Jsi_Interp *interp)
{
    jsi_Pstate *ps = (jsi_Pstate *)Jsi_Calloc(1,sizeof(*ps));
    SIGINIT(ps,PARSER);
    ps->lexer = (jsi_Lexer*)Jsi_Calloc(1,sizeof(*ps->lexer));
    ps->lexer->pstate = ps;
    ps->interp = interp;

    ps->fastVarTbl = Jsi_HashNew(interp, JSI_KEYS_ONEWORD, NULL /*fastVarFree*/);

    return ps;
}

const char *jsi_PstateGetFilename(jsi_Pstate *ps)
{
    Jsi_Interp *interp = ps->interp;
    return interp->curFile;
................................................................................
    Jsi_Free(ps->lexer);
    if (ps->opcodes)
        jsi_FreeOpcodes(ps->opcodes);
    if (ps->hPtr)
        Jsi_HashEntryDelete(ps->hPtr);
    if (ps->argsTbl)
        Jsi_HashDelete(ps->argsTbl);


    if (ps->fastVarTbl)
        Jsi_HashDelete(ps->fastVarTbl);
    if (ps->last_exception)
        Jsi_DecrRefCount(ps->interp, ps->last_exception);
    _JSI_MEMCLEAR(ps);
    Jsi_Free(ps);
}
................................................................................
        interp = jsiIntData.mainInterp;
    LastInterp = interp;
    if (lastInterp != interp)
        noDups = 1;
    
    /* Filter out try/catch (TODO: and non-syntax errors??). */
    if (interp == NULL) {
//nullInterp:
        if (logHook)
            (*logHook)(format, va);
        else {
            vfprintf(stderr, format, va);
            fputc('\n', stderr);
        }
        va_end(va);
................................................................................
    curFile = jsi_GetCurFile(interp);
    switch (code) {
        case JSI_LOG_INFO:  if (!interp->logOpts.Info) goto bail; break;
        case JSI_LOG_WARN:  if (!interp->logOpts.Warn) goto bail; break;
        case JSI_LOG_DEBUG: if (!interp->logOpts.Debug && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_TRACE: if (!interp->logOpts.Trace && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_TEST:  if (!interp->logOpts.Test && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_PARSE: break; //if (!interp->parent) goto nullInterp; break;
        case JSI_LOG_ERROR: {
            if (!interp->logOpts.Error) goto bail;
            if ((interp->framePtr->tryDepth - interp->framePtr->withDepth)>0 && interp->inParse<=0 
                && (!interp->tryList || !(interp->tryList->inCatch|interp->tryList->inFinal))) { 
                /* Should only do the first or traceback? */
                if (!interp->errMsgBuf[0]) {
                    vsnprintf(interp->errMsgBuf, sizeof(interp->errMsgBuf), format, va);
................................................................................
        if (*ss && !isHelp)
            snprintf(pbuf, sizeof(pbuf), "    (at or near \"%s\")\n", ss);
    }
    pbuf[sizeof(pbuf)-1] = 0;
    if (interp->inParse && interp->parseLine) {
        line = interp->parseLine->first_line;
        lofs = interp->parseLine->first_column;
    } else if (interp->inParse && interp->parsePs) {
        line = interp->parsePs->lexer->cur_line;
        lofs = interp->parsePs->lexer->cur_char;
    } else if (interp->curIp) {
        if (interp->callerErr && interp->framePtr && interp->framePtr->parent) {
            jsi_Frame *fptr = interp->framePtr->parent;
            line = fptr->line;
            lofs = 0;
            curFile = fptr->fileName;
        } else {
................................................................................

static jsi_Pstate* jsiNewParser(Jsi_Interp* interp, char *codeStr, Jsi_Channel fp, int iseval)
{
    bool isNew;
    Jsi_HashEntry *hPtr = NULL;
    hPtr = Jsi_HashEntryNew(interp->codeTbl, (void*)codeStr, &isNew);
    if (!hPtr) return NULL;
    jsi_Pstate *ps, *topPs;

    if (isNew==0 && ((ps = (jsi_Pstate *)Jsi_HashValueGet(hPtr)))) {
        interp->codeCacheHit++;
        return ps;
    }
    ps = jsi_PstateNew(interp);
    ps->eval_flag = iseval;
    if (codeStr)
        jsi_PstateSetString(ps, codeStr);
    else
        jsi_PstateSetFile(ps, fp, 1);
        
    interp->inParse++;
    topPs = interp->parsePs;
    interp->parsePs = ps;
    yyparse(ps);
    interp->parsePs = topPs;
    interp->inParse--;
    
    if (ps->err_count) {
        Jsi_HashEntryDelete(hPtr);
        jsi_PstateFree(ps);
        return NULL;
    }

Changes to src/jsi.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* jsi.h : External API header file for Jsi. */
#ifndef __JSI_H__
#define __JSI_H__

#define JSI_VERSION_MAJOR   2
#define JSI_VERSION_MINOR   8
#define JSI_VERSION_RELEASE 30

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

#ifndef JSI_EXTERN
#define JSI_EXTERN extern
#endif







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* jsi.h : External API header file for Jsi. */
#ifndef __JSI_H__
#define __JSI_H__

#define JSI_VERSION_MAJOR   2
#define JSI_VERSION_MINOR   8
#define JSI_VERSION_RELEASE 31

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

#ifndef JSI_EXTERN
#define JSI_EXTERN extern
#endif

Changes to src/jsiEval.c.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


43

44
45
46
47
48
49
50

static jsi_Pstate* jsiNewParser(Jsi_Interp* interp, char *codeStr, Jsi_Channel fp, int iseval)
{
    bool isNew;
    Jsi_HashEntry *hPtr = NULL;
    hPtr = Jsi_HashEntryNew(interp->codeTbl, (void*)codeStr, &isNew);
    if (!hPtr) return NULL;
    jsi_Pstate *ps;

    if (isNew==0 && ((ps = (jsi_Pstate *)Jsi_HashValueGet(hPtr)))) {
        interp->codeCacheHit++;
        return ps;
    }
    ps = jsi_PstateNew(interp);
    ps->eval_flag = iseval;
    if (codeStr)
        jsi_PstateSetString(ps, codeStr);
    else
        jsi_PstateSetFile(ps, fp, 1);
        
    interp->inParse++;


    yyparse(ps);

    interp->inParse--;
    
    if (ps->err_count) {
        Jsi_HashEntryDelete(hPtr);
        jsi_PstateFree(ps);
        return NULL;
    }







|













>
>

>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

static jsi_Pstate* jsiNewParser(Jsi_Interp* interp, char *codeStr, Jsi_Channel fp, int iseval)
{
    bool isNew;
    Jsi_HashEntry *hPtr = NULL;
    hPtr = Jsi_HashEntryNew(interp->codeTbl, (void*)codeStr, &isNew);
    if (!hPtr) return NULL;
    jsi_Pstate *ps, *topPs;

    if (isNew==0 && ((ps = (jsi_Pstate *)Jsi_HashValueGet(hPtr)))) {
        interp->codeCacheHit++;
        return ps;
    }
    ps = jsi_PstateNew(interp);
    ps->eval_flag = iseval;
    if (codeStr)
        jsi_PstateSetString(ps, codeStr);
    else
        jsi_PstateSetFile(ps, fp, 1);
        
    interp->inParse++;
    topPs = interp->parsePs;
    interp->parsePs = ps;
    yyparse(ps);
    interp->parsePs = topPs;
    interp->inParse--;
    
    if (ps->err_count) {
        Jsi_HashEntryDelete(hPtr);
        jsi_PstateFree(ps);
        return NULL;
    }

Changes to src/jsiInt.h.

727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
...
800
801
802
803
804
805
806

807
808
809
810
811
812
813
....
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
    struct jsi_Lexer *lexer;        /* seq provider */

    int _context_id;            /* used in FastVar-locating */
    Jsi_Value *last_exception;
    Jsi_Interp *interp;
    Jsi_HashEntry *hPtr;
    Jsi_Hash *argsTbl;
    Jsi_Hash *strTbl;
    Jsi_Hash *fastVarTbl;
    int argType;                // Used during parsing to aggregate type.
    Jsi_ScopeStrs *args;        // Last push.
} jsi_Pstate;


Jsi_ScopeStrs *jsi_ScopeStrsNew(void);
................................................................................
        char *str;          /* LT_STRING */
    } d;
    int last_token;         /* last token returned */
    int ungot, unch[100];
    int cur;                /* LT_STRING, current char */
    int cur_line;           /* current line no. */
    int cur_char;           /* current column no. */

    jsi_Pstate *pstate;
} jsi_Lexer;

int yylex (YYSTYPE *yylvalp, YYLTYPE *yyllocp, jsi_Pstate *pstate);
void yyerror(YYLTYPE *yylloc, jsi_Pstate *ps, const char *msg);

typedef struct {
................................................................................
    Jsi_Value *execZip;
    void (*logHook)(char *buf, va_list va);
    const char *name;
    Jsi_Value *pkgDirs;
    bool selfZvfs;
    int inParse;
    Jsi_Value *retValue;       /* Return value from eval */
    jsi_Pstate *ps;
    Jsi_Value *argv0;
    Jsi_Value *args;
    Jsi_Value *console;
    Jsi_Value *scriptFile;  /* Start script returned by info.argv0(). */
    const char *scriptStr;
    const char *curFile;
    const char *curFunction;







<







 







>







 







|







727
728
729
730
731
732
733

734
735
736
737
738
739
740
...
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
....
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
    struct jsi_Lexer *lexer;        /* seq provider */

    int _context_id;            /* used in FastVar-locating */
    Jsi_Value *last_exception;
    Jsi_Interp *interp;
    Jsi_HashEntry *hPtr;
    Jsi_Hash *argsTbl;

    Jsi_Hash *fastVarTbl;
    int argType;                // Used during parsing to aggregate type.
    Jsi_ScopeStrs *args;        // Last push.
} jsi_Pstate;


Jsi_ScopeStrs *jsi_ScopeStrsNew(void);
................................................................................
        char *str;          /* LT_STRING */
    } d;
    int last_token;         /* last token returned */
    int ungot, unch[100];
    int cur;                /* LT_STRING, current char */
    int cur_line;           /* current line no. */
    int cur_char;           /* current column no. */
    int inStr;
    jsi_Pstate *pstate;
} jsi_Lexer;

int yylex (YYSTYPE *yylvalp, YYLTYPE *yyllocp, jsi_Pstate *pstate);
void yyerror(YYLTYPE *yylloc, jsi_Pstate *ps, const char *msg);

typedef struct {
................................................................................
    Jsi_Value *execZip;
    void (*logHook)(char *buf, va_list va);
    const char *name;
    Jsi_Value *pkgDirs;
    bool selfZvfs;
    int inParse;
    Jsi_Value *retValue;       /* Return value from eval */
    jsi_Pstate *ps, *parsePs;
    Jsi_Value *argv0;
    Jsi_Value *args;
    Jsi_Value *console;
    Jsi_Value *scriptFile;  /* Start script returned by info.argv0(). */
    const char *scriptStr;
    const char *curFile;
    const char *curFunction;

Changes to src/jsiLexer.c.

15
16
17
18
19
20
21







22
23
24
25
26
27
28
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
180
181
182
183
184
185
186




187





188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
    } else {
        if (lex->ungot) {
            c = lex->unch[--lex->ungot];
        } else {
            c = lex->d.str[lex->cur];
            if (c != 0) lex->cur++;
        }







    }
    //printf("%c", c);
    if (c == '\n') {
        //printf("!!!!!!!!!!\n");
        lex->cur_line++;
        lex->cur_char = 0;
    }
................................................................................
        return (uintptr_t)Jsi_HashValueGet(hPtr);
    return 0;
}

static char *jsi_do_string(jsi_Lexer *lex)
{
    Jsi_Interp *interp = lex->pstate->interp;
    Jsi_HashEntry *hPtr = NULL;
    int n, c = lexer_getchar(lex);
    int endchar = c;
    
    int bufi = 0, bsiz, done = 0;
    char unibuf[bsiz=JSI_BUFSIZ], *buf = unibuf, *ret = NULL;
    
    while (!done) {
................................................................................
                }
                case EOF: 
                case 0:
saw_eof:
                    Jsi_LogError("Unexpected EOF parsing string.");
                    buf[bufi++] = 0;
                    goto done;




                default: buf[bufi++] = n;





            }
        } else {
            buf[bufi++] = c;
        }
        if (c == endchar) {
            bufi --;
            break;
        }
    }
    buf[bufi] = 0;
    hPtr = Jsi_HashSet(lex->pstate->strTbl, buf, NULL);
    ret = (char*)Jsi_HashKeyGet(hPtr);
done:
    if (buf != unibuf)
        Jsi_Free(buf);

    return ret;
}

static char *jsi_do_regex(jsi_Lexer *lex)
{
    Jsi_Interp *interp = lex->pstate->interp;
    Jsi_HashEntry *hPtr = NULL;
    int n, bufi = 0, bsiz;
    char unibuf[bsiz=JSI_BUFSIZ], *buf = unibuf, *ret = NULL;
    
    buf[bufi++] = lexer_getchar(lex);     /* first '/'*/
    while (1) {
        if (bufi >= (bsiz-5)) {
            int nsiz = bsiz+=JSI_BUFSIZ;
................................................................................
            buf[bufi-1] = 0;
            lexer_ungetc(c, lex);
            break;
        } else {
            buf[bufi++] = c;
        }
    }
    hPtr = Jsi_HashSet(lex->pstate->strTbl, buf, NULL);
    ret = (char*)Jsi_HashKeyGet(hPtr);
    ret = Jsi_Strdup(buf);
done:
    if (buf != unibuf)
        Jsi_Free(buf);
    return ret;
}








>
>
>
>
>
>
>







 







|







 







>
>
>
>
|
>
>
>
>
>










<
|



>






<







 







<
|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
...
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277
    } else {
        if (lex->ungot) {
            c = lex->unch[--lex->ungot];
        } else {
            c = lex->d.str[lex->cur];
            if (c != 0) lex->cur++;
        }
        if (lex->inStr && c == '\\') {
            int nc = (lex->ungot ? lex->unch[lex->ungot-1] : lex->d.str[lex->cur-1]);
            if (nc == '\n') {
                return lexer_getchar(lex);
                return lexer_getchar(lex);
            }
        }
    }
    //printf("%c", c);
    if (c == '\n') {
        //printf("!!!!!!!!!!\n");
        lex->cur_line++;
        lex->cur_char = 0;
    }
................................................................................
        return (uintptr_t)Jsi_HashValueGet(hPtr);
    return 0;
}

static char *jsi_do_string(jsi_Lexer *lex)
{
    Jsi_Interp *interp = lex->pstate->interp;
    lex->inStr = 1;
    int n, c = lexer_getchar(lex);
    int endchar = c;
    
    int bufi = 0, bsiz, done = 0;
    char unibuf[bsiz=JSI_BUFSIZ], *buf = unibuf, *ret = NULL;
    
    while (!done) {
................................................................................
                }
                case EOF: 
                case 0:
saw_eof:
                    Jsi_LogError("Unexpected EOF parsing string.");
                    buf[bufi++] = 0;
                    goto done;
                case '"':
                case '\'':
                case '\\':
                case '\n':
                    buf[bufi++] = n;
                    break;
                default: 
                    buf[bufi++] = n;
                    if (!interp->unitTest)
                        Jsi_LogParse("Unsupported string escape: \\%c", n);
            }
        } else {
            buf[bufi++] = c;
        }
        if (c == endchar) {
            bufi --;
            break;
        }
    }
    buf[bufi] = 0;

    ret = (char*)Jsi_KeyAdd(lex->pstate->interp, buf);
done:
    if (buf != unibuf)
        Jsi_Free(buf);
    lex->inStr = 0;
    return ret;
}

static char *jsi_do_regex(jsi_Lexer *lex)
{
    Jsi_Interp *interp = lex->pstate->interp;

    int n, bufi = 0, bsiz;
    char unibuf[bsiz=JSI_BUFSIZ], *buf = unibuf, *ret = NULL;
    
    buf[bufi++] = lexer_getchar(lex);     /* first '/'*/
    while (1) {
        if (bufi >= (bsiz-5)) {
            int nsiz = bsiz+=JSI_BUFSIZ;
................................................................................
            buf[bufi-1] = 0;
            lexer_ungetc(c, lex);
            break;
        } else {
            buf[bufi++] = c;
        }
    }

    ret = (char*)Jsi_KeyAdd(lex->pstate->interp, buf);
    ret = Jsi_Strdup(buf);
done:
    if (buf != unibuf)
        Jsi_Free(buf);
    return ret;
}

Changes to src/jsiPstate.c.

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
jsi_Pstate *jsi_PstateNew(Jsi_Interp *interp)
{
    jsi_Pstate *ps = (jsi_Pstate *)Jsi_Calloc(1,sizeof(*ps));
    SIGINIT(ps,PARSER);
    ps->lexer = (jsi_Lexer*)Jsi_Calloc(1,sizeof(*ps->lexer));
    ps->lexer->pstate = ps;
    ps->interp = interp;
   // ps->argsTbl = Jsi_HashNew(interp, JSI_KEYS_ONEWORD, jsi_ArglistFree);
    ps->fastVarTbl = Jsi_HashNew(interp, JSI_KEYS_ONEWORD, NULL /*fastVarFree*/);
    ps->strTbl = Jsi_HashNew(interp, JSI_KEYS_STRING, NULL);
    return ps;
}

const char *jsi_PstateGetFilename(jsi_Pstate *ps)
{
    Jsi_Interp *interp = ps->interp;
    return interp->curFile;
................................................................................
    Jsi_Free(ps->lexer);
    if (ps->opcodes)
        jsi_FreeOpcodes(ps->opcodes);
    if (ps->hPtr)
        Jsi_HashEntryDelete(ps->hPtr);
    if (ps->argsTbl)
        Jsi_HashDelete(ps->argsTbl);
    if (ps->strTbl)
        Jsi_HashDelete(ps->strTbl);
    if (ps->fastVarTbl)
        Jsi_HashDelete(ps->fastVarTbl);
    if (ps->last_exception)
        Jsi_DecrRefCount(ps->interp, ps->last_exception);
    _JSI_MEMCLEAR(ps);
    Jsi_Free(ps);
}

#endif







<

<







 







<
<









176
177
178
179
180
181
182

183

184
185
186
187
188
189
190
...
248
249
250
251
252
253
254


255
256
257
258
259
260
261
262
263
jsi_Pstate *jsi_PstateNew(Jsi_Interp *interp)
{
    jsi_Pstate *ps = (jsi_Pstate *)Jsi_Calloc(1,sizeof(*ps));
    SIGINIT(ps,PARSER);
    ps->lexer = (jsi_Lexer*)Jsi_Calloc(1,sizeof(*ps->lexer));
    ps->lexer->pstate = ps;
    ps->interp = interp;

    ps->fastVarTbl = Jsi_HashNew(interp, JSI_KEYS_ONEWORD, NULL /*fastVarFree*/);

    return ps;
}

const char *jsi_PstateGetFilename(jsi_Pstate *ps)
{
    Jsi_Interp *interp = ps->interp;
    return interp->curFile;
................................................................................
    Jsi_Free(ps->lexer);
    if (ps->opcodes)
        jsi_FreeOpcodes(ps->opcodes);
    if (ps->hPtr)
        Jsi_HashEntryDelete(ps->hPtr);
    if (ps->argsTbl)
        Jsi_HashDelete(ps->argsTbl);


    if (ps->fastVarTbl)
        Jsi_HashDelete(ps->fastVarTbl);
    if (ps->last_exception)
        Jsi_DecrRefCount(ps->interp, ps->last_exception);
    _JSI_MEMCLEAR(ps);
    Jsi_Free(ps);
}

#endif

Changes to src/jsiUtils.c.

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
212
213
214
215
216
217
218



219
220
221
222
223
224
225
        interp = jsiIntData.mainInterp;
    LastInterp = interp;
    if (lastInterp != interp)
        noDups = 1;
    
    /* Filter out try/catch (TODO: and non-syntax errors??). */
    if (interp == NULL) {
nullInterp:
        if (logHook)
            (*logHook)(format, va);
        else {
            vfprintf(stderr, format, va);
            fputc('\n', stderr);
        }
        va_end(va);
................................................................................
    curFile = jsi_GetCurFile(interp);
    switch (code) {
        case JSI_LOG_INFO:  if (!interp->logOpts.Info) goto bail; break;
        case JSI_LOG_WARN:  if (!interp->logOpts.Warn) goto bail; break;
        case JSI_LOG_DEBUG: if (!interp->logOpts.Debug && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_TRACE: if (!interp->logOpts.Trace && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_TEST:  if (!interp->logOpts.Test && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_PARSE: if (!interp->parent) goto nullInterp; break;
        case JSI_LOG_ERROR: {
            if (!interp->logOpts.Error) goto bail;
            if ((interp->framePtr->tryDepth - interp->framePtr->withDepth)>0 && interp->inParse<=0 
                && (!interp->tryList || !(interp->tryList->inCatch|interp->tryList->inFinal))) { 
                /* Should only do the first or traceback? */
                if (!interp->errMsgBuf[0]) {
                    vsnprintf(interp->errMsgBuf, sizeof(interp->errMsgBuf), format, va);
................................................................................
        if (*ss && !isHelp)
            snprintf(pbuf, sizeof(pbuf), "    (at or near \"%s\")\n", ss);
    }
    pbuf[sizeof(pbuf)-1] = 0;
    if (interp->inParse && interp->parseLine) {
        line = interp->parseLine->first_line;
        lofs = interp->parseLine->first_column;



    } else if (interp->curIp) {
        if (interp->callerErr && interp->framePtr && interp->framePtr->parent) {
            jsi_Frame *fptr = interp->framePtr->parent;
            line = fptr->line;
            lofs = 0;
            curFile = fptr->fileName;
        } else {







|







 







|







 







>
>
>







147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
        interp = jsiIntData.mainInterp;
    LastInterp = interp;
    if (lastInterp != interp)
        noDups = 1;
    
    /* Filter out try/catch (TODO: and non-syntax errors??). */
    if (interp == NULL) {
//nullInterp:
        if (logHook)
            (*logHook)(format, va);
        else {
            vfprintf(stderr, format, va);
            fputc('\n', stderr);
        }
        va_end(va);
................................................................................
    curFile = jsi_GetCurFile(interp);
    switch (code) {
        case JSI_LOG_INFO:  if (!interp->logOpts.Info) goto bail; break;
        case JSI_LOG_WARN:  if (!interp->logOpts.Warn) goto bail; break;
        case JSI_LOG_DEBUG: if (!interp->logOpts.Debug && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_TRACE: if (!interp->logOpts.Trace && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_TEST:  if (!interp->logOpts.Test && !jsi_LogEnabled(interp, code)) goto bail; break;
        case JSI_LOG_PARSE: break; //if (!interp->parent) goto nullInterp; break;
        case JSI_LOG_ERROR: {
            if (!interp->logOpts.Error) goto bail;
            if ((interp->framePtr->tryDepth - interp->framePtr->withDepth)>0 && interp->inParse<=0 
                && (!interp->tryList || !(interp->tryList->inCatch|interp->tryList->inFinal))) { 
                /* Should only do the first or traceback? */
                if (!interp->errMsgBuf[0]) {
                    vsnprintf(interp->errMsgBuf, sizeof(interp->errMsgBuf), format, va);
................................................................................
        if (*ss && !isHelp)
            snprintf(pbuf, sizeof(pbuf), "    (at or near \"%s\")\n", ss);
    }
    pbuf[sizeof(pbuf)-1] = 0;
    if (interp->inParse && interp->parseLine) {
        line = interp->parseLine->first_line;
        lofs = interp->parseLine->first_column;
    } else if (interp->inParse && interp->parsePs) {
        line = interp->parsePs->lexer->cur_line;
        lofs = interp->parsePs->lexer->cur_char;
    } else if (interp->curIp) {
        if (interp->callerErr && interp->framePtr && interp->framePtr->parent) {
            jsi_Frame *fptr = interp->framePtr->parent;
            line = fptr->line;
            lofs = 0;
            curFile = fptr->fileName;
        } else {

Changes to tests/brainfark.jsi.

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#o n   t h e   w a l l\
#####\
\
 [<]>>>>-    go to cell 4/subtract 1\
]           end loop when cell 4 is 0\
\
##############################################################\
### By this point verses 99\10 are displayed but to work   ###\
### with the lower numbered verses in a more readable way  ###\
### we initiate a new loop for verses 9{CODE} that will not    ###\
### use the fourth cell at all                             ###\
##############################################################\
\
+           add 1 to cell four (to keep it non\zero)\
<--         back to cell 3/subtract 2\
\
[            loop\
 [>]<<       go to last cell and back to LF\
 ..          output 2 newlines\
 [<]>        go to first cell\
\
................................................................................
 #X     b o t t l e s   o f   b e e r  \
 #.>.>.>.>.>.>.>.>.>.>.\
 #o n   t h e   w a l l\
 #####\
\
 [<]>>>-     go to cell 3/subtract 1\
]            end loop when cell 3 is 0\
+            add 1 to cell 3 to keep it non\zero\
\
[>]<.        go to last line/carriage return\
[<]>         go to first line\
\
########################\
### correct last line ##\
########################\







|





|







 







|







233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#o n   t h e   w a l l\
#####\
\
 [<]>>>>-    go to cell 4/subtract 1\
]           end loop when cell 4 is 0\
\
##############################################################\
### By this point verses 99\\10 are displayed but to work   ###\
### with the lower numbered verses in a more readable way  ###\
### we initiate a new loop for verses 9{CODE} that will not    ###\
### use the fourth cell at all                             ###\
##############################################################\
\
+           add 1 to cell four (to keep it non\\zero)\
<--         back to cell 3/subtract 2\
\
[            loop\
 [>]<<       go to last cell and back to LF\
 ..          output 2 newlines\
 [<]>        go to first cell\
\
................................................................................
 #X     b o t t l e s   o f   b e e r  \
 #.>.>.>.>.>.>.>.>.>.>.\
 #o n   t h e   w a l l\
 #####\
\
 [<]>>>-     go to cell 3/subtract 1\
]            end loop when cell 3 is 0\
+            add 1 to cell 3 to keep it non\\zero\
\
[>]<.        go to last line/carriage return\
[<]>         go to first line\
\
########################\
### correct last line ##\
########################\

Changes to tools/protos.jsi.

1
2
3
4
5
6
7
8
//JSI Command Prototypes: version 2.8.30
throw("NOT EXECUTABLE: USE FILE IN GEANY EDITOR FOR CMD LINE COMPLETION + GOTO TAG");

var Array = function(cmd,args) {};
Array.prototype.concat = function(...):array {};
Array.prototype.every = function(callback:function):any {};
Array.prototype.fill = function(value:any, start:number=0, end:number=-1):array {};
Array.prototype.filter = function(callback:function, this:object=void):array {};
|







1
2
3
4
5
6
7
8
//JSI Command Prototypes: version 2.8.31
throw("NOT EXECUTABLE: USE FILE IN GEANY EDITOR FOR CMD LINE COMPLETION + GOTO TAG");

var Array = function(cmd,args) {};
Array.prototype.concat = function(...):array {};
Array.prototype.every = function(callback:function):any {};
Array.prototype.fill = function(value:any, start:number=0, end:number=-1):array {};
Array.prototype.filter = function(callback:function, this:object=void):array {};