@@ -224,19 +224,31 @@ const EasyCoder_Compiler = {
224
224
} ) ;
225
225
// Add the action
226
226
this . compileOne ( ) ;
227
+ // If `continue` is set
228
+ if ( this . continue ) {
229
+ this . addCommand ( {
230
+ domain : `core` ,
231
+ keyword : `goto` ,
232
+ lino,
233
+ goto : this . getPc ( ) + 1
234
+ } ) ;
235
+ this . continue = false ;
236
+ }
227
237
// Add a 'stop'
228
- this . addCommand ( {
229
- domain : `core` ,
230
- keyword : `stop` ,
231
- lino,
232
- next : 0
233
- } ) ;
238
+ else {
239
+ this . addCommand ( {
240
+ domain : `core` ,
241
+ keyword : `stop` ,
242
+ lino,
243
+ next : 0
244
+ } ) ;
245
+ }
234
246
// Fixup the 'goto'
235
247
this . getCommandAt ( goto ) . goto = this . getPc ( ) ;
236
248
return true ;
237
249
} ,
238
250
239
- compileVariable : function ( domain , keyword , isValueHolder = false , extra = null ) {
251
+ compileVariable : function ( domain , keyword , isVHolder = false , extra = null ) {
240
252
this . next ( ) ;
241
253
const lino = this . getLino ( ) ;
242
254
const item = this . getTokens ( ) [ this . getIndex ( ) ] ;
@@ -252,7 +264,7 @@ const EasyCoder_Compiler = {
252
264
lino,
253
265
isSymbol : true ,
254
266
used : false ,
255
- isValueHolder ,
267
+ isVHolder ,
256
268
name : item . token ,
257
269
elements : 1 ,
258
270
index : 0 ,
@@ -399,7 +411,7 @@ const EasyCoder_Core = {
399
411
if ( compiler . isSymbol ( ) ) {
400
412
const symbol = compiler . getSymbol ( ) ;
401
413
const variable = compiler . getCommandAt ( symbol . pc ) ;
402
- if ( variable . isValueHolder ) {
414
+ if ( variable . isVHolder ) {
403
415
if ( compiler . peek ( ) === `giving` ) {
404
416
// This variable must be treated as a second value
405
417
const value2 = compiler . getValue ( ) ;
@@ -459,7 +471,7 @@ const EasyCoder_Core = {
459
471
const value1 = command . value1 ;
460
472
const value2 = command . value2 ;
461
473
const target = program . getSymbolRecord ( command . target ) ;
462
- if ( target . isValueHolder ) {
474
+ if ( target . isVHolder ) {
463
475
const value = target . value [ target . index ] ;
464
476
if ( value2 ) {
465
477
const result = program . getValue ( value2 ) +
@@ -540,7 +552,7 @@ const EasyCoder_Core = {
540
552
if ( compiler . tokenIs ( `to` ) ) {
541
553
if ( compiler . nextIsSymbol ( ) ) {
542
554
const symbolRecord = compiler . getSymbolRecord ( ) ;
543
- if ( symbolRecord . isValueHolder ) {
555
+ if ( symbolRecord . isVHolder ) {
544
556
compiler . next ( ) ;
545
557
compiler . addCommand ( {
546
558
domain : `core` ,
@@ -611,7 +623,7 @@ const EasyCoder_Core = {
611
623
compiler . next ( ) ;
612
624
if ( compiler . isSymbol ( ) ) {
613
625
const symbolRecord = compiler . getSymbolRecord ( ) ;
614
- if ( symbolRecord . isValueHolder ) {
626
+ if ( symbolRecord . isVHolder ) {
615
627
const symbol = compiler . getToken ( ) ;
616
628
compiler . next ( ) ;
617
629
compiler . addCommand ( {
@@ -630,7 +642,7 @@ const EasyCoder_Core = {
630
642
run : program => {
631
643
const command = program [ program . pc ] ;
632
644
const symbol = program . getSymbolRecord ( command . symbol ) ;
633
- if ( symbol . isValueHolder ) {
645
+ if ( symbol . isVHolder ) {
634
646
const handler = program . domain [ symbol . domain ] ;
635
647
handler . value . put ( symbol , {
636
648
type : `boolean` ,
@@ -673,6 +685,15 @@ const EasyCoder_Core = {
673
685
}
674
686
} ,
675
687
688
+ Continue : {
689
+
690
+ compile : compiler => {
691
+ compiler . next ( ) ;
692
+ compiler . continue = true ;
693
+ return true ;
694
+ }
695
+ } ,
696
+
676
697
Debug : {
677
698
678
699
compile : compiler => {
@@ -780,7 +801,7 @@ const EasyCoder_Core = {
780
801
run : program => {
781
802
const command = program [ program . pc ] ;
782
803
const target = program . getSymbolRecord ( command . symbol ) ;
783
- if ( target . isValueHolder ) {
804
+ if ( target . isVHolder ) {
784
805
const content = program . getValue ( target . value [ target . index ] ) ;
785
806
target . value [ target . index ] = {
786
807
type : `constant` ,
@@ -853,7 +874,7 @@ const EasyCoder_Core = {
853
874
const value1 = command . value1 ;
854
875
const value2 = command . value2 ;
855
876
const target = program . getSymbolRecord ( command . target ) ;
856
- if ( target . isValueHolder ) {
877
+ if ( target . isVHolder ) {
857
878
const value = target . value [ target . index ] ;
858
879
if ( value1 ) {
859
880
const result = program . getValue ( value1 ) / program . getValue ( value2 ) ;
@@ -920,7 +941,7 @@ const EasyCoder_Core = {
920
941
run : program => {
921
942
const command = program [ program . pc ] ;
922
943
const target = program . getSymbolRecord ( command . symbol ) ;
923
- if ( target . isValueHolder ) {
944
+ if ( target . isVHolder ) {
924
945
const content = program . getValue ( target . value [ target . index ] ) ;
925
946
target . value [ target . index ] = {
926
947
type : `constant` ,
@@ -1177,7 +1198,7 @@ const EasyCoder_Core = {
1177
1198
newRecord . exporter = symbolRecord . exporter ? symbolRecord . exporter : caller . script ;
1178
1199
newRecord . exportedName = symbolRecord . name ;
1179
1200
newRecord . extra = symbolRecord . extra ;
1180
- newRecord . isValueHolder = symbolRecord . isValueHolder ;
1201
+ newRecord . isVHolder = symbolRecord . isVHolder ;
1181
1202
if ( symbolRecord . program ) {
1182
1203
newRecord . program = symbolRecord . program . script ;
1183
1204
}
@@ -1355,7 +1376,7 @@ const EasyCoder_Core = {
1355
1376
const value1 = command . value1 ;
1356
1377
const value2 = command . value2 ;
1357
1378
const target = program . getSymbolRecord ( command . target ) ;
1358
- if ( target . isValueHolder ) {
1379
+ if ( target . isVHolder ) {
1359
1380
const value = target . value [ target . index ] ;
1360
1381
if ( value1 ) {
1361
1382
const result = program . getValue ( value1 ) *
@@ -1405,7 +1426,7 @@ const EasyCoder_Core = {
1405
1426
run : program => {
1406
1427
const command = program [ program . pc ] ;
1407
1428
const symbol = program . getSymbolRecord ( command . symbol ) ;
1408
- if ( symbol . isValueHolder ) {
1429
+ if ( symbol . isVHolder ) {
1409
1430
symbol . value [ symbol . index ] = {
1410
1431
type : `constant` ,
1411
1432
numeric : true ,
@@ -1530,7 +1551,7 @@ const EasyCoder_Core = {
1530
1551
run : program => {
1531
1552
const command = program [ program . pc ] ;
1532
1553
const target = program . getSymbolRecord ( command . target ) ;
1533
- if ( ! target . isValueHolder ) {
1554
+ if ( ! target . isVHolder ) {
1534
1555
program . variableDoesNotHoldAValueError ( command . lino , target . name ) ;
1535
1556
}
1536
1557
const value = program . evaluate ( command . value ) ;
@@ -1558,7 +1579,7 @@ const EasyCoder_Core = {
1558
1579
if ( compiler . tokenIs ( `in` ) ) {
1559
1580
if ( compiler . nextIsSymbol ( ) ) {
1560
1581
const targetRecord = compiler . getSymbolRecord ( ) ;
1561
- if ( targetRecord . isValueHolder ) {
1582
+ if ( targetRecord . isVHolder ) {
1562
1583
compiler . next ( ) ;
1563
1584
compiler . addCommand ( {
1564
1585
domain : `core` ,
@@ -1835,7 +1856,7 @@ const EasyCoder_Core = {
1835
1856
const lino = compiler . getLino ( ) ;
1836
1857
if ( compiler . nextIsSymbol ( ) ) {
1837
1858
const targetRecord = compiler . getSymbolRecord ( ) ;
1838
- if ( ! targetRecord . isValueHolder ) {
1859
+ if ( ! targetRecord . isVHolder ) {
1839
1860
return false ;
1840
1861
}
1841
1862
if ( compiler . nextTokenIs ( `to` ) ) {
@@ -2031,7 +2052,7 @@ const EasyCoder_Core = {
2031
2052
switch ( command . request ) {
2032
2053
case `setBoolean` :
2033
2054
const target = program . getSymbolRecord ( command . target ) ;
2034
- if ( target . isValueHolder ) {
2055
+ if ( target . isVHolder ) {
2035
2056
target . value [ target . index ] = {
2036
2057
type : `boolean` ,
2037
2058
content : true
@@ -2085,34 +2106,57 @@ const EasyCoder_Core = {
2085
2106
if ( ! targetValue ) {
2086
2107
targetValue = `{}` ;
2087
2108
}
2088
- let targetJSON = `` ;
2089
- try {
2090
- targetJSON = JSON . parse ( targetValue ) ;
2091
- } catch ( err ) {
2092
- program . runtimeError ( command . lino , `Can't parse ${ targetRecord . name } ` ) ;
2093
- return 0 ;
2094
- }
2109
+ // This is object whose property is being set
2110
+ let targetJSON = JSON . parse ( targetValue ) ;
2111
+ // This is the name of the property
2095
2112
const itemName = program . getValue ( command . name ) ;
2113
+ // This is the value of the property
2096
2114
const itemValue = program . evaluate ( command . value ) ;
2097
2115
let content = itemValue . content ;
2098
2116
if ( itemValue ) {
2099
- if ( content instanceof Array ) {
2100
- targetJSON [ itemName ] = content ;
2101
- } else if ( itemValue . type === `boolean` ) {
2102
- targetJSON [ itemName ] = content ;
2103
- } else if ( itemValue . numeric ) {
2104
- targetJSON [ itemName ] = content ;
2105
- } else if ( content . length >= 2 && [ `["` , `{"` ] . includes ( content . substr ( 0 , 2 ) ) ) {
2117
+ if ( content . length >= 2 && [ `[` , `{` ] . includes ( content [ 0 ] ) ) {
2106
2118
targetJSON [ itemName ] = JSON . parse ( itemValue . content ) ;
2107
- } else {
2108
- targetJSON [ itemName ] = content . split ( `"` ) . join ( `\\"` ) ;
2119
+ content = JSON . stringify ( targetJSON ) ;
2109
2120
}
2110
2121
targetRecord . value [ targetRecord . index ] = {
2111
2122
type : `constant` ,
2112
2123
numeric : false ,
2113
- content : JSON . stringify ( targetJSON )
2124
+ content
2114
2125
} ;
2115
2126
}
2127
+
2128
+ // let targetValue = program.getFormattedValue(targetRecord.value[targetRecord.index]);
2129
+ // if (!targetValue) {
2130
+ // targetValue = `{}`;
2131
+ // }
2132
+ // let targetJSON = ``;
2133
+ // try {
2134
+ // targetJSON = JSON.parse(targetValue);
2135
+ // } catch (err) {
2136
+ // program.runtimeError(command.lino, `Can't parse ${targetRecord.name}`);
2137
+ // return 0;
2138
+ // }
2139
+ // const itemName = program.getValue(command.name);
2140
+ // const itemValue = program.evaluate(command.value);
2141
+ // let content = itemValue.content;
2142
+ // if (itemValue) {
2143
+ // if (content instanceof Array) {
2144
+ // targetJSON[itemName] = content;
2145
+ // } else if (itemValue.type === `boolean`) {
2146
+ // targetJSON[itemName] = content;
2147
+ // } else if (itemValue.numeric) {
2148
+ // targetJSON[itemName] = content;
2149
+ // } else if (content.length >= 2 && [`["`, `{"`].includes(content.substr(0, 2))) {
2150
+ // targetJSON[itemName] = JSON.parse(itemValue.content);
2151
+ // } else {
2152
+ // targetJSON[itemName] = content.split(`"`).join(`\\"`);
2153
+ // }
2154
+ // targetRecord.value[targetRecord.index] = {
2155
+ // type: `constant`,
2156
+ // numeric: false,
2157
+ // content: JSON.stringify(targetJSON)
2158
+ // };
2159
+ // }
2116
2160
break ;
2117
2161
case `setPayload` :
2118
2162
program . getSymbolRecord ( command . callback ) . payload = program . getValue ( command . payload ) ;
@@ -2283,7 +2327,7 @@ const EasyCoder_Core = {
2283
2327
if ( compiler . isSymbol ( ) ) {
2284
2328
const symbol = compiler . getSymbol ( ) ;
2285
2329
const variable = compiler . getCommandAt ( symbol . pc ) ;
2286
- if ( variable . isValueHolder ) {
2330
+ if ( variable . isVHolder ) {
2287
2331
if ( compiler . peek ( ) === `giving` ) {
2288
2332
// This variable must be treated as a second value
2289
2333
const value2 = compiler . getValue ( ) ;
@@ -2343,7 +2387,7 @@ const EasyCoder_Core = {
2343
2387
const value1 = command . value1 ;
2344
2388
const value2 = command . value2 ;
2345
2389
const target = program . getSymbolRecord ( command . target ) ;
2346
- if ( target . isValueHolder ) {
2390
+ if ( target . isVHolder ) {
2347
2391
const value = target . value [ target . index ] ;
2348
2392
if ( value2 ) {
2349
2393
const result = program . getValue ( value2 ) -
@@ -2393,7 +2437,7 @@ const EasyCoder_Core = {
2393
2437
run : program => {
2394
2438
const command = program [ program . pc ] ;
2395
2439
const symbol = program [ command . symbol ] ;
2396
- if ( symbol . isValueHolder ) {
2440
+ if ( symbol . isVHolder ) {
2397
2441
const handler = program . domain [ symbol . domain ] ;
2398
2442
const content = handler . value . get ( program , symbol . value [ symbol . index ] ) . content ;
2399
2443
handler . value . put ( symbol , {
@@ -2531,6 +2575,8 @@ const EasyCoder_Core = {
2531
2575
return EasyCoder_Core . Clear ;
2532
2576
case `close` :
2533
2577
return EasyCoder_Core . Close ;
2578
+ case `continue` :
2579
+ return EasyCoder_Core . Continue ;
2534
2580
case `debug` :
2535
2581
return EasyCoder_Core . Debug ;
2536
2582
case `decode` :
@@ -3566,7 +3612,8 @@ const EasyCoder = {
3566
3612
return v . content ? `true` : `false` ;
3567
3613
}
3568
3614
if ( typeof v . content !== `undefined` && v . content . length >= 2
3569
- && ( v . content . substr ( 0 , 2 ) === `{"` || v . content [ 0 ] === `[` ) ) {
3615
+ // && (v.content.substr(0, 2) === `{"` || v.content[0] === `[`)) {
3616
+ && [ `[` , `{` ] . includes ( v . content [ 0 ] ) ) {
3570
3617
try {
3571
3618
const parsed = JSON . parse ( v . content ) ;
3572
3619
return JSON . stringify ( parsed , null , 2 ) ;
@@ -3671,6 +3718,7 @@ const EasyCoder = {
3671
3718
compiler . condition = EasyCoder_Condition ;
3672
3719
compiler . domain = this . domain ;
3673
3720
compiler . imports = imports ;
3721
+ compiler . continue = false ;
3674
3722
const program = EasyCoder_Compiler . compile ( tokens ) ;
3675
3723
// console.log('Program: ' + JSON.stringify(program, null, 2));
3676
3724
this . compiling = false ;
@@ -4215,7 +4263,7 @@ const EasyCoder_Value = {
4215
4263
return value ;
4216
4264
case `symbol` :
4217
4265
const symbol = program . getSymbolRecord ( value . name ) ;
4218
- if ( symbol . isValueHolder ) {
4266
+ if ( symbol . isVHolder ) {
4219
4267
const symbolValue = symbol . value [ symbol . index ] ;
4220
4268
if ( symbolValue ) {
4221
4269
const v = symbolValue . content ;
0 commit comments