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

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

Overview
Comment:Backport parser.y changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c7ace0a428ca1220c1bd73216f24ac11141b8c0b
User & Date: pmacdona 2019-04-28 17:00:11
Context
2019-05-01
00:01
Add missing semi check-in: c2c4f88703 user: pmacdona tags: trunk
2019-04-28
17:00
Backport parser.y changes. check-in: c7ace0a428 user: pmacdona tags: trunk
15:19
Add cdata map demo check-in: ee01fbb629 user: pmacdona tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/jsiParser.y.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
...
229
230
231
232
233
234
235
236




237
238
239
240
241
242
243
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
269
270
271
272
273
274
275

276
277
278
279
280
281
282
...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
...
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
...
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
...
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
...
731
732
733
734
735
736
737





738
739
740
        if (pstate->eval_flag) ret = codes_join(code_local(pstate, &I.ln, B), ret);
        jsi_PstatePop(pstate);
        A = ret;
    }

func_prefix(A) ::= FUNC IDENTIFIER(B). [MAX_PRI] {
        if (!pstate->eval_flag) {
            jsi_PstateAddVar(pstate, B.str);
        }
        A = B.str;
    }

iterstatement(A) ::= for_statement(B).      { A = B; }
iterstatement(A) ::=  while_statement(B).   { A = B; }
iterstatement(A) ::=  do_statement(B).      { A = B; }
................................................................................
            cl->off = allstats->code_len;
            allstats = codes_join(allstats, cl->es->stat);

            jsi_CaseList *t = cl;
            cl = cl->next;
            
            if (t->es->isdefault) {
                if (cldefault) yyerror(&I.ln, pstate, "More then one switch default\n");




                cldefault = t;
            } else {
                t->next = head;
                head = t;
            }
        }
        code_reserved_replace(allstats, 0, 1, D, 1);
................................................................................
            ophead = codes_join(code_jmp(ophead->code_len + cldefault->off + 1), ophead);
            if (cldefault->es)
                Jsi_Free(cldefault->es);
            Jsi_Free(cldefault);
        }
        while (head) {
            Jsi_OpCodes *e = codes_join4(code_push_top(), head->es->expr, 
                                        code_equal(), code_jtrue(ophead->code_len + head->off + 1));
            ophead = codes_join(e, ophead);
            jsi_CaseList *t = head;
            head = head->next;
            if (t->es)
                Jsi_Free(t->es);
            Jsi_Free(t);
        }
................................................................................

cases(A) ::= case(B).           { A = caselist_new(pstate, B); }
cases(A) ::= cases(B) case(C).    { A = caselist_insert(pstate, B, C); }


case(A) ::= CASE expr(B) COLON statements(C).    { A = exprstat_new(pstate, B, C, 0); }
case(A) ::= DEFAULT COLON statements(B).    { A = exprstat_new(pstate, NULL, B, 1); }

case(A) ::= CASE expr(B) COLON.    { A = exprstat_new(pstate, B, code_nop(), 0); }


try_statement(A) ::= TRY(I) func_statement_block(B) CATCH(J) LPAREN IDENTIFIER(C) RPAREN func_statement_block(D). {
        Jsi_OpCodes *catchblock = codes_join3(code_scatch(pstate, &J.ln, C.str), D, code_ecatch(pstate, &J.ln));
        Jsi_OpCodes *finallyblock = codes_join(code_sfinal(pstate, &I.ln), code_efinal(pstate, &J.ln));
        Jsi_OpCodes *tryblock = codes_join(B, code_etry(pstate, &I.ln));
................................................................................
vardecs(A) ::= vardecs(B) COMMA vardec(C).    { A = codes_join(B, C); }

vardec(A) ::= IDENTIFIER(B).             {
        Jsi_OpCodes *ret = codes_join4(code_push_index(pstate, &B.ln, B.str, 1),
                            code_push_undef(),
                            code_assign(pstate, &B.ln, 1),
                            code_pop(1));
        if (!pstate->eval_flag) jsi_PstateAddVar(pstate, B.str);
        else ret = codes_join(code_local(pstate, &B.ln, B.str), ret);
        A = ret;
    }
vardec(A) ::=  IDENTIFIER(B) EQUAL expr(C).   {
        Jsi_OpCodes *ret = codes_join4(code_push_index(pstate, &B.ln, B.str, 1),
                            C,
                            code_assign(pstate, &B.ln, 1),
                            code_pop(1));
        if (!pstate->eval_flag) jsi_PstateAddVar(pstate, B.str);
        else ret = codes_join(code_local(pstate, &B.ln, B.str), ret);
        A = ret;
    }

delete_statement(A) ::= DELETE lvalue(B) SEMICOLON.       {
        if (B->lvalue_flag == 2) {
            A = codes_join(B, code_delete(2));
................................................................................
        Jsi_OpCodes *lval;
        if (fv->varname) lval = code_push_index(pstate, &I.ln, fv->varname, 1);
        else lval = fv->lval;
        
        Jsi_OpCodes *ret = make_forin(lval, &I.ln, E, S, B, (inof!=0));
        if (fv->varname && fv->local) {
            if (!pstate->eval_flag) {
                jsi_PstateAddVar(pstate,fv->varname);
                jsi_FreeOpcodes(fv->local);
            } else ret = codes_join(fv->local, ret);
        }
        Jsi_Free(fv);
        A = ret;
    }
for_statement(A) ::= label_opt(B) FOR(I) LPAREN lvalue(C) inof(D) expr(E) RPAREN statement_or_empty(F). {
................................................................................
        Jsi_OpCodes *lval;
        if (fv->varname) lval = code_push_index(pstate, &I.ln, fv->varname, 0);
        else lval = fv->lval;
        
        Jsi_OpCodes *ret = make_forin(lval, &I.ln, E, F, B, (inof!=0));
        if (fv->varname && fv->local) {
            if (!pstate->eval_flag) {
                jsi_PstateAddVar(pstate,fv->varname);
                jsi_FreeOpcodes(fv->local);
            } else ret = codes_join(fv->local, ret);
        }
        Jsi_Free(fv);
        A = ret;
    }

................................................................................
        Jsi_OpCodes *pref;
        Jsi_OpCodes *lval = B;
        const char *n1 = lval->lvalue_name;
        if (lval->lvalue_flag == 2) {
            const char *n2 = NULL;
            pref = codes_join3(B, code_chthis(pstate, &I.ln, 1), code_subscript(pstate, &I.ln, 1));
            if (pref->code_len>=2 && pref->codes[0].op == OP_PUSHVAR && pref->codes[1].op == OP_PUSHSTR && !n1) {
                FastVar *fv = (FastVar*)pref->codes[0].data;
                n2 = fv->var.varname;
                n1 = (const char*)pref->codes[1].data;
            }
            A = codes_join3(pref, (opl ? opl : code_nop()), code_fcall(pstate, &I.ln, expr_cnt, n1, n2, opl, NULL));
        } else {
            if (lval->lvalue_name && Jsi_Strcmp(lval->lvalue_name, "eval") == 0) {
                A = codes_join((opl ? opl : code_nop()), code_eval(pstate, &I.ln, expr_cnt, lval));
            } else {
................................................................................
        int cnt = (B)->expr_counter + 1;
        A = codes_join(B, C);
        (A)->expr_counter = cnt;
    }

item(A) ::= IDENTIFIER(B) COLON expr(C). { A = codes_join(code_push_string(pstate, &B.ln, B.str), C); }
item(A) ::= STRING(B) COLON expr(C).   { A = codes_join(code_push_string(pstate, &B.ln, B.str), C); }






array(A) ::= LBRACKET(I) exprlist(B) RBRACKET. { A = codes_join(B, code_array(pstate, &I.ln, (B)->expr_counter)); }
array(A) ::= LBRACKET(I) RBRACKET. { A = code_array(pstate, &I.ln, 0); }







|







 







|
>
>
>
>







 







|







 







>







 







|








|







 







|







 







|







 







|
|







 







>
>
>
>
>



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
...
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
...
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
        if (pstate->eval_flag) ret = codes_join(code_local(pstate, &I.ln, B), ret);
        jsi_PstatePop(pstate);
        A = ret;
    }

func_prefix(A) ::= FUNC IDENTIFIER(B). [MAX_PRI] {
        if (!pstate->eval_flag) {
            jsi_PstateAddVar(pstate, &B.ln, B.str);
        }
        A = B.str;
    }

iterstatement(A) ::= for_statement(B).      { A = B; }
iterstatement(A) ::=  while_statement(B).   { A = B; }
iterstatement(A) ::=  do_statement(B).      { A = B; }
................................................................................
            cl->off = allstats->code_len;
            allstats = codes_join(allstats, cl->es->stat);

            jsi_CaseList *t = cl;
            cl = cl->next;
            
            if (t->es->isdefault) {
                if (cldefault) {
                    if (cldefault->es) Jsi_Free(cldefault->es);
                    Jsi_Free(cldefault);
                    yyerror(&I.ln, pstate, "switch with more then one default\n");
                }
                cldefault = t;
            } else {
                t->next = head;
                head = t;
            }
        }
        code_reserved_replace(allstats, 0, 1, D, 1);
................................................................................
            ophead = codes_join(code_jmp(ophead->code_len + cldefault->off + 1), ophead);
            if (cldefault->es)
                Jsi_Free(cldefault->es);
            Jsi_Free(cldefault);
        }
        while (head) {
            Jsi_OpCodes *e = codes_join4(code_push_top(), head->es->expr, 
                                        code_eequ(), code_jtrue(ophead->code_len + head->off + 1));
            ophead = codes_join(e, ophead);
            jsi_CaseList *t = head;
            head = head->next;
            if (t->es)
                Jsi_Free(t->es);
            Jsi_Free(t);
        }
................................................................................

cases(A) ::= case(B).           { A = caselist_new(pstate, B); }
cases(A) ::= cases(B) case(C).    { A = caselist_insert(pstate, B, C); }


case(A) ::= CASE expr(B) COLON statements(C).    { A = exprstat_new(pstate, B, C, 0); }
case(A) ::= DEFAULT COLON statements(B).    { A = exprstat_new(pstate, NULL, B, 1); }
case(A) ::= DEFAULT COLON.                  { A = exprstat_new(pstate, NULL, code_nop(), 1); }
case(A) ::= CASE expr(B) COLON.    { A = exprstat_new(pstate, B, code_nop(), 0); }


try_statement(A) ::= TRY(I) func_statement_block(B) CATCH(J) LPAREN IDENTIFIER(C) RPAREN func_statement_block(D). {
        Jsi_OpCodes *catchblock = codes_join3(code_scatch(pstate, &J.ln, C.str), D, code_ecatch(pstate, &J.ln));
        Jsi_OpCodes *finallyblock = codes_join(code_sfinal(pstate, &I.ln), code_efinal(pstate, &J.ln));
        Jsi_OpCodes *tryblock = codes_join(B, code_etry(pstate, &I.ln));
................................................................................
vardecs(A) ::= vardecs(B) COMMA vardec(C).    { A = codes_join(B, C); }

vardec(A) ::= IDENTIFIER(B).             {
        Jsi_OpCodes *ret = codes_join4(code_push_index(pstate, &B.ln, B.str, 1),
                            code_push_undef(),
                            code_assign(pstate, &B.ln, 1),
                            code_pop(1));
        if (!pstate->eval_flag) jsi_PstateAddVar(pstate, &B.ln, B.str);
        else ret = codes_join(code_local(pstate, &B.ln, B.str), ret);
        A = ret;
    }
vardec(A) ::=  IDENTIFIER(B) EQUAL expr(C).   {
        Jsi_OpCodes *ret = codes_join4(code_push_index(pstate, &B.ln, B.str, 1),
                            C,
                            code_assign(pstate, &B.ln, 1),
                            code_pop(1));
        if (!pstate->eval_flag) jsi_PstateAddVar(pstate, &B.ln, B.str);
        else ret = codes_join(code_local(pstate, &B.ln, B.str), ret);
        A = ret;
    }

delete_statement(A) ::= DELETE lvalue(B) SEMICOLON.       {
        if (B->lvalue_flag == 2) {
            A = codes_join(B, code_delete(2));
................................................................................
        Jsi_OpCodes *lval;
        if (fv->varname) lval = code_push_index(pstate, &I.ln, fv->varname, 1);
        else lval = fv->lval;
        
        Jsi_OpCodes *ret = make_forin(lval, &I.ln, E, S, B, (inof!=0));
        if (fv->varname && fv->local) {
            if (!pstate->eval_flag) {
                jsi_PstateAddVar(pstate, &I.ln, fv->varname);
                jsi_FreeOpcodes(fv->local);
            } else ret = codes_join(fv->local, ret);
        }
        Jsi_Free(fv);
        A = ret;
    }
for_statement(A) ::= label_opt(B) FOR(I) LPAREN lvalue(C) inof(D) expr(E) RPAREN statement_or_empty(F). {
................................................................................
        Jsi_OpCodes *lval;
        if (fv->varname) lval = code_push_index(pstate, &I.ln, fv->varname, 0);
        else lval = fv->lval;
        
        Jsi_OpCodes *ret = make_forin(lval, &I.ln, E, F, B, (inof!=0));
        if (fv->varname && fv->local) {
            if (!pstate->eval_flag) {
                jsi_PstateAddVar(pstate, &I.ln,fv->varname);
                jsi_FreeOpcodes(fv->local);
            } else ret = codes_join(fv->local, ret);
        }
        Jsi_Free(fv);
        A = ret;
    }

................................................................................
        Jsi_OpCodes *pref;
        Jsi_OpCodes *lval = B;
        const char *n1 = lval->lvalue_name;
        if (lval->lvalue_flag == 2) {
            const char *n2 = NULL;
            pref = codes_join3(B, code_chthis(pstate, &I.ln, 1), code_subscript(pstate, &I.ln, 1));
            if (pref->code_len>=2 && pref->codes[0].op == OP_PUSHVAR && pref->codes[1].op == OP_PUSHSTR && !n1) {
                jsi_FastVar *fv = (jsi_FastVar*)pref->codes[0].data;
                n2 = fv->varname;
                n1 = (const char*)pref->codes[1].data;
            }
            A = codes_join3(pref, (opl ? opl : code_nop()), code_fcall(pstate, &I.ln, expr_cnt, n1, n2, opl, NULL));
        } else {
            if (lval->lvalue_name && Jsi_Strcmp(lval->lvalue_name, "eval") == 0) {
                A = codes_join((opl ? opl : code_nop()), code_eval(pstate, &I.ln, expr_cnt, lval));
            } else {
................................................................................
        int cnt = (B)->expr_counter + 1;
        A = codes_join(B, C);
        (A)->expr_counter = cnt;
    }

item(A) ::= IDENTIFIER(B) COLON expr(C). { A = codes_join(code_push_string(pstate, &B.ln, B.str), C); }
item(A) ::= STRING(B) COLON expr(C).   { A = codes_join(code_push_string(pstate, &B.ln, B.str), C); }
item(A) ::= FNUMBER(B) COLON expr(C).   { A = codes_join(code_push_num(B.num), C); }
item(A) ::= JSTRUE COLON expr(C).   { A = codes_join(code_push_bool(1), C); }
item(A) ::= JSFALSE COLON expr(C).   { A = codes_join(code_push_bool(0), C); }
item(A) ::= UNDEF COLON expr(C).   { A = codes_join(code_push_undef(), C); }
item(A) ::= TYPENULL COLON expr(C).   { A = codes_join(code_push_null(), C); }

array(A) ::= LBRACKET(I) exprlist(B) RBRACKET. { A = codes_join(B, code_array(pstate, &I.ln, (B)->expr_counter)); }
array(A) ::= LBRACKET(I) RBRACKET. { A = code_array(pstate, &I.ln, 0); }