bahasa-simpl 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/simpl-interpreter.js +11 -9
- package/package.json +1 -1
|
@@ -109,9 +109,7 @@ class PetikTipe extends Stipe {
|
|
|
109
109
|
if (!thing?.type) return `nihil`;
|
|
110
110
|
let type = v.environment.get(thing.type.description);
|
|
111
111
|
if (type?.member.has("kePetik")) {
|
|
112
|
-
v.stack.push(v.line);
|
|
113
112
|
let res = v.callFunc(type.member.get("kePetik").data, [thing]).data;
|
|
114
|
-
v.stack.pop();
|
|
115
113
|
return res;
|
|
116
114
|
}
|
|
117
115
|
return `${thing.type.description}<>`;
|
|
@@ -241,7 +239,10 @@ class AngkaTipe extends Stipe {
|
|
|
241
239
|
class LogisTipe extends Stipe {
|
|
242
240
|
constructor() {
|
|
243
241
|
super(logisSymbol, new Callable(null, (_, args) => {
|
|
244
|
-
|
|
242
|
+
if (args[0].type === barisSymbol && args[0].data.length === 0) {
|
|
243
|
+
return new Value(logisSymbol, false);
|
|
244
|
+
}
|
|
245
|
+
return new Value(logisSymbol, Boolean(args[0].data) || Boolean(args[0].data?.member?.size));
|
|
245
246
|
}, [[null]], logisSymbol, true)
|
|
246
247
|
);
|
|
247
248
|
this.init();
|
|
@@ -411,6 +412,10 @@ let Jenis$1 = class Jenis extends Stipe {
|
|
|
411
412
|
enums.forEach((thing, idx) => {
|
|
412
413
|
this.member.define(thing.lexeme, new Value(sym, idx));
|
|
413
414
|
});
|
|
415
|
+
this.member.define("kePetik", makeBuiltInFunc([sym], petikSymbol, (_, [j]) => {
|
|
416
|
+
let enumName = enums.map(thing=>thing.lexeme)[j.data];
|
|
417
|
+
return new Value(petikSymbol, `${name}.${enumName}`);
|
|
418
|
+
}));
|
|
414
419
|
this.init(sym);
|
|
415
420
|
}
|
|
416
421
|
|
|
@@ -922,8 +927,9 @@ class Interpreter {
|
|
|
922
927
|
if (type.member?.has(name)) {
|
|
923
928
|
if (willBeCalled) {
|
|
924
929
|
this.objectStack = main;
|
|
930
|
+
return type.member.get(name);
|
|
925
931
|
}
|
|
926
|
-
|
|
932
|
+
this.error(`akses titik . dari objek ke model harus berupa panggilan/penggunaaan mesin.`);
|
|
927
933
|
}
|
|
928
934
|
this.error(`nama .${name} tidak ditemukan dalam tipe ${main.type.description}`);
|
|
929
935
|
} else {
|
|
@@ -964,12 +970,7 @@ class Interpreter {
|
|
|
964
970
|
if (!thing?.type) return `nihil`;
|
|
965
971
|
let type = this.environment.get(thing.type.description);
|
|
966
972
|
if (type?.member?.has("kePetik")) {
|
|
967
|
-
let prevState = this.state;
|
|
968
|
-
this.state = location.MESIN;
|
|
969
|
-
this.stack.push(this.line);
|
|
970
973
|
let res = this.callFunc(type.member.get("kePetik").data, [thing]).data;
|
|
971
|
-
this.stack.pop();
|
|
972
|
-
this.state = prevState;
|
|
973
974
|
return res;
|
|
974
975
|
}
|
|
975
976
|
return `${thing.type.description}<>`;
|
|
@@ -2295,6 +2296,7 @@ class Simpl {
|
|
|
2295
2296
|
let output = this.interpreter.interpret(pohon);
|
|
2296
2297
|
return output.join("\n");
|
|
2297
2298
|
} catch (err) {
|
|
2299
|
+
// throw err
|
|
2298
2300
|
if (err instanceof SimplError) {
|
|
2299
2301
|
const errorCode = textLines[err.line - 1];
|
|
2300
2302
|
let errorText = (errorCode ? `ERROR! Pada baris ke-${err.line}\n>> ` + errorCode + '\n' : "") + err.message;
|