Skip to content

Commit 5dbe663

Browse files
committed
Fix bad property name & bug in setProperty
1 parent b921f3b commit 5dbe663

File tree

22 files changed

+352
-255
lines changed

22 files changed

+352
-255
lines changed

developer/Core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ compile: compiler => {
2727
if (compiler.tokenIs(`in`)) {
2828
if (compiler.nextIsSymbol()) {
2929
const targetRecord = compiler.getSymbolRecord();
30-
if (targetRecord.isValueHolder) {
30+
if (targetRecord.isVHolder) {
3131
compiler.next();
3232
compiler.addCommand({
3333
domain: `core`,

easycoder/easycoder-min.js

Lines changed: 104 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

easycoder/easycoder.js

Lines changed: 93 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,31 @@ const EasyCoder_Compiler = {
224224
});
225225
// Add the action
226226
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+
}
227237
// 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+
}
234246
// Fixup the 'goto'
235247
this.getCommandAt(goto).goto = this.getPc();
236248
return true;
237249
},
238250

239-
compileVariable: function(domain, keyword, isValueHolder = false, extra = null) {
251+
compileVariable: function(domain, keyword, isVHolder = false, extra = null) {
240252
this.next();
241253
const lino = this.getLino();
242254
const item = this.getTokens()[this.getIndex()];
@@ -252,7 +264,7 @@ const EasyCoder_Compiler = {
252264
lino,
253265
isSymbol: true,
254266
used: false,
255-
isValueHolder,
267+
isVHolder,
256268
name: item.token,
257269
elements: 1,
258270
index: 0,
@@ -399,7 +411,7 @@ const EasyCoder_Core = {
399411
if (compiler.isSymbol()) {
400412
const symbol = compiler.getSymbol();
401413
const variable = compiler.getCommandAt(symbol.pc);
402-
if (variable.isValueHolder) {
414+
if (variable.isVHolder) {
403415
if (compiler.peek() === `giving`) {
404416
// This variable must be treated as a second value
405417
const value2 = compiler.getValue();
@@ -459,7 +471,7 @@ const EasyCoder_Core = {
459471
const value1 = command.value1;
460472
const value2 = command.value2;
461473
const target = program.getSymbolRecord(command.target);
462-
if (target.isValueHolder) {
474+
if (target.isVHolder) {
463475
const value = target.value[target.index];
464476
if (value2) {
465477
const result = program.getValue(value2) +
@@ -540,7 +552,7 @@ const EasyCoder_Core = {
540552
if (compiler.tokenIs(`to`)) {
541553
if (compiler.nextIsSymbol()) {
542554
const symbolRecord = compiler.getSymbolRecord();
543-
if (symbolRecord.isValueHolder) {
555+
if (symbolRecord.isVHolder) {
544556
compiler.next();
545557
compiler.addCommand({
546558
domain: `core`,
@@ -611,7 +623,7 @@ const EasyCoder_Core = {
611623
compiler.next();
612624
if (compiler.isSymbol()) {
613625
const symbolRecord = compiler.getSymbolRecord();
614-
if (symbolRecord.isValueHolder) {
626+
if (symbolRecord.isVHolder) {
615627
const symbol = compiler.getToken();
616628
compiler.next();
617629
compiler.addCommand({
@@ -630,7 +642,7 @@ const EasyCoder_Core = {
630642
run: program => {
631643
const command = program[program.pc];
632644
const symbol = program.getSymbolRecord(command.symbol);
633-
if (symbol.isValueHolder) {
645+
if (symbol.isVHolder) {
634646
const handler = program.domain[symbol.domain];
635647
handler.value.put(symbol, {
636648
type: `boolean`,
@@ -673,6 +685,15 @@ const EasyCoder_Core = {
673685
}
674686
},
675687

688+
Continue: {
689+
690+
compile: compiler => {
691+
compiler.next();
692+
compiler.continue = true;
693+
return true;
694+
}
695+
},
696+
676697
Debug: {
677698

678699
compile: compiler => {
@@ -780,7 +801,7 @@ const EasyCoder_Core = {
780801
run: program => {
781802
const command = program[program.pc];
782803
const target = program.getSymbolRecord(command.symbol);
783-
if (target.isValueHolder) {
804+
if (target.isVHolder) {
784805
const content = program.getValue(target.value[target.index]);
785806
target.value[target.index] = {
786807
type: `constant`,
@@ -853,7 +874,7 @@ const EasyCoder_Core = {
853874
const value1 = command.value1;
854875
const value2 = command.value2;
855876
const target = program.getSymbolRecord(command.target);
856-
if (target.isValueHolder) {
877+
if (target.isVHolder) {
857878
const value = target.value[target.index];
858879
if (value1) {
859880
const result = program.getValue(value1) / program.getValue(value2);
@@ -920,7 +941,7 @@ const EasyCoder_Core = {
920941
run: program => {
921942
const command = program[program.pc];
922943
const target = program.getSymbolRecord(command.symbol);
923-
if (target.isValueHolder) {
944+
if (target.isVHolder) {
924945
const content = program.getValue(target.value[target.index]);
925946
target.value[target.index] = {
926947
type: `constant`,
@@ -1177,7 +1198,7 @@ const EasyCoder_Core = {
11771198
newRecord.exporter = symbolRecord.exporter ? symbolRecord.exporter : caller.script;
11781199
newRecord.exportedName = symbolRecord.name;
11791200
newRecord.extra = symbolRecord.extra;
1180-
newRecord.isValueHolder = symbolRecord.isValueHolder;
1201+
newRecord.isVHolder = symbolRecord.isVHolder;
11811202
if (symbolRecord.program) {
11821203
newRecord.program = symbolRecord.program.script;
11831204
}
@@ -1355,7 +1376,7 @@ const EasyCoder_Core = {
13551376
const value1 = command.value1;
13561377
const value2 = command.value2;
13571378
const target = program.getSymbolRecord(command.target);
1358-
if (target.isValueHolder) {
1379+
if (target.isVHolder) {
13591380
const value = target.value[target.index];
13601381
if (value1) {
13611382
const result = program.getValue(value1) *
@@ -1405,7 +1426,7 @@ const EasyCoder_Core = {
14051426
run: program => {
14061427
const command = program[program.pc];
14071428
const symbol = program.getSymbolRecord(command.symbol);
1408-
if (symbol.isValueHolder) {
1429+
if (symbol.isVHolder) {
14091430
symbol.value[symbol.index] = {
14101431
type: `constant`,
14111432
numeric: true,
@@ -1530,7 +1551,7 @@ const EasyCoder_Core = {
15301551
run: program => {
15311552
const command = program[program.pc];
15321553
const target = program.getSymbolRecord(command.target);
1533-
if (!target.isValueHolder) {
1554+
if (!target.isVHolder) {
15341555
program.variableDoesNotHoldAValueError(command.lino, target.name);
15351556
}
15361557
const value = program.evaluate(command.value);
@@ -1558,7 +1579,7 @@ const EasyCoder_Core = {
15581579
if (compiler.tokenIs(`in`)) {
15591580
if (compiler.nextIsSymbol()) {
15601581
const targetRecord = compiler.getSymbolRecord();
1561-
if (targetRecord.isValueHolder) {
1582+
if (targetRecord.isVHolder) {
15621583
compiler.next();
15631584
compiler.addCommand({
15641585
domain: `core`,
@@ -1835,7 +1856,7 @@ const EasyCoder_Core = {
18351856
const lino = compiler.getLino();
18361857
if (compiler.nextIsSymbol()) {
18371858
const targetRecord = compiler.getSymbolRecord();
1838-
if (!targetRecord.isValueHolder) {
1859+
if (!targetRecord.isVHolder) {
18391860
return false;
18401861
}
18411862
if (compiler.nextTokenIs(`to`)) {
@@ -2031,7 +2052,7 @@ const EasyCoder_Core = {
20312052
switch (command.request) {
20322053
case `setBoolean`:
20332054
const target = program.getSymbolRecord(command.target);
2034-
if (target.isValueHolder) {
2055+
if (target.isVHolder) {
20352056
target.value[target.index] = {
20362057
type: `boolean`,
20372058
content: true
@@ -2085,34 +2106,57 @@ const EasyCoder_Core = {
20852106
if (!targetValue) {
20862107
targetValue = `{}`;
20872108
}
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
20952112
const itemName = program.getValue(command.name);
2113+
// This is the value of the property
20962114
const itemValue = program.evaluate(command.value);
20972115
let content = itemValue.content;
20982116
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])) {
21062118
targetJSON[itemName] = JSON.parse(itemValue.content);
2107-
} else {
2108-
targetJSON[itemName] = content.split(`"`).join(`\\"`);
2119+
content = JSON.stringify(targetJSON);
21092120
}
21102121
targetRecord.value[targetRecord.index] = {
21112122
type: `constant`,
21122123
numeric: false,
2113-
content: JSON.stringify(targetJSON)
2124+
content
21142125
};
21152126
}
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+
// }
21162160
break;
21172161
case `setPayload`:
21182162
program.getSymbolRecord(command.callback).payload = program.getValue(command.payload);
@@ -2283,7 +2327,7 @@ const EasyCoder_Core = {
22832327
if (compiler.isSymbol()) {
22842328
const symbol = compiler.getSymbol();
22852329
const variable = compiler.getCommandAt(symbol.pc);
2286-
if (variable.isValueHolder) {
2330+
if (variable.isVHolder) {
22872331
if (compiler.peek() === `giving`) {
22882332
// This variable must be treated as a second value
22892333
const value2 = compiler.getValue();
@@ -2343,7 +2387,7 @@ const EasyCoder_Core = {
23432387
const value1 = command.value1;
23442388
const value2 = command.value2;
23452389
const target = program.getSymbolRecord(command.target);
2346-
if (target.isValueHolder) {
2390+
if (target.isVHolder) {
23472391
const value = target.value[target.index];
23482392
if (value2) {
23492393
const result = program.getValue(value2) -
@@ -2393,7 +2437,7 @@ const EasyCoder_Core = {
23932437
run: program => {
23942438
const command = program[program.pc];
23952439
const symbol = program[command.symbol];
2396-
if (symbol.isValueHolder) {
2440+
if (symbol.isVHolder) {
23972441
const handler = program.domain[symbol.domain];
23982442
const content = handler.value.get(program, symbol.value[symbol.index]).content;
23992443
handler.value.put(symbol, {
@@ -2531,6 +2575,8 @@ const EasyCoder_Core = {
25312575
return EasyCoder_Core.Clear;
25322576
case `close`:
25332577
return EasyCoder_Core.Close;
2578+
case `continue`:
2579+
return EasyCoder_Core.Continue;
25342580
case `debug`:
25352581
return EasyCoder_Core.Debug;
25362582
case `decode`:
@@ -3566,7 +3612,8 @@ const EasyCoder = {
35663612
return v.content ? `true` : `false`;
35673613
}
35683614
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])) {
35703617
try {
35713618
const parsed = JSON.parse(v.content);
35723619
return JSON.stringify(parsed, null, 2);
@@ -3671,6 +3718,7 @@ const EasyCoder = {
36713718
compiler.condition = EasyCoder_Condition;
36723719
compiler.domain = this.domain;
36733720
compiler.imports = imports;
3721+
compiler.continue = false;
36743722
const program = EasyCoder_Compiler.compile(tokens);
36753723
// console.log('Program: ' + JSON.stringify(program, null, 2));
36763724
this.compiling = false;
@@ -4215,7 +4263,7 @@ const EasyCoder_Value = {
42154263
return value;
42164264
case `symbol`:
42174265
const symbol = program.getSymbolRecord(value.name);
4218-
if (symbol.isValueHolder) {
4266+
if (symbol.isVHolder) {
42194267
const symbolValue = symbol.value[symbol.index];
42204268
if (symbolValue) {
42214269
const v = symbolValue.content;

easycoder/plugins/aws.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const EasyCoder_AWS = {
4040
if (compiler.tokenIs(`giving`)) {
4141
if (compiler.nextIsSymbol()) {
4242
const targetRecord = compiler.getSymbolRecord();
43-
if (targetRecord.isValueHolder) {
43+
if (targetRecord.isVHolder) {
4444
target = targetRecord.name;
4545
compiler.next();
4646
} else {

easycoder/plugins/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ const EasyCoder_Browser = {
237237
if (compiler.nextTokenIs(`in`)) {
238238
if (compiler.nextIsSymbol()) {
239239
const symbolRecord = compiler.getSymbolRecord();
240-
if (symbolRecord.isValueHolder) {
240+
if (symbolRecord.isVHolder) {
241241
if (compiler.nextTokenIs(`to`)) {
242242
const mode = compiler.nextToken();
243243
compiler.next();

easycoder/plugins/json-rest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ const EasyCoder_Json = {
345345
if (compiler.tokenIs(`giving`)) {
346346
if (compiler.nextIsSymbol()) {
347347
const targetRecord = compiler.getSymbolRecord();
348-
if (targetRecord.isValueHolder) {
348+
if (targetRecord.isVHolder) {
349349
target = targetRecord.name;
350350
compiler.next();
351351
} else {
@@ -478,7 +478,7 @@ const EasyCoder_Json = {
478478
if (compiler.isSymbol()) {
479479
const target = compiler.getSymbolRecord();
480480
compiler.next();
481-
if (target.isValueHolder) {
481+
if (target.isVHolder) {
482482
return {
483483
domain: `json`,
484484
type,

easycoder/plugins/json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ const EasyCoder_Json = {
423423
if (compiler.isSymbol()) {
424424
const target = compiler.getSymbolRecord();
425425
compiler.next();
426-
if (target.isValueHolder) {
426+
if (target.isVHolder) {
427427
return {
428428
domain: `json`,
429429
type,

easycoder/plugins/rest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const EasyCoder_Rest = {
5454
if (compiler.tokenIs(`giving`)) {
5555
if (compiler.nextIsSymbol()) {
5656
const targetRecord = compiler.getSymbolRecord();
57-
if (targetRecord.isValueHolder) {
57+
if (targetRecord.isVHolder) {
5858
target = targetRecord.name;
5959
compiler.next();
6060
} else {

0 commit comments

Comments
 (0)