circuitscript 0.0.38 → 0.1.0
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/cjs/BaseVisitor.js +56 -38
- package/dist/cjs/SymbolValidatorVisitor.js +1 -1
- package/dist/cjs/antlr/CircuitScriptParser.js +348 -323
- package/dist/cjs/builtinMethods.js +5 -2
- package/dist/cjs/draw_symbols.js +63 -45
- package/dist/cjs/execute.js +29 -16
- package/dist/cjs/globals.js +2 -1
- package/dist/cjs/layout.js +14 -26
- package/dist/cjs/objects/Frame.js +2 -0
- package/dist/cjs/objects/types.js +41 -0
- package/dist/cjs/render.js +1 -0
- package/dist/cjs/utils.js +25 -1
- package/dist/cjs/visitor.js +70 -35
- package/dist/esm/BaseVisitor.mjs +56 -38
- package/dist/esm/SymbolValidatorVisitor.mjs +1 -1
- package/dist/esm/antlr/CircuitScriptParser.mjs +348 -323
- package/dist/esm/builtinMethods.mjs +5 -2
- package/dist/esm/draw_symbols.mjs +67 -47
- package/dist/esm/execute.mjs +29 -16
- package/dist/esm/globals.mjs +1 -0
- package/dist/esm/layout.mjs +13 -26
- package/dist/esm/objects/Frame.mjs +2 -0
- package/dist/esm/objects/types.mjs +42 -0
- package/dist/esm/render.mjs +2 -1
- package/dist/esm/utils.mjs +22 -0
- package/dist/esm/visitor.mjs +71 -36
- package/dist/types/BaseVisitor.d.ts +2 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +3 -0
- package/dist/types/draw_symbols.d.ts +11 -5
- package/dist/types/execute.d.ts +1 -1
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/layout.d.ts +1 -0
- package/dist/types/objects/Frame.d.ts +3 -1
- package/dist/types/objects/types.d.ts +7 -2
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/visitor.d.ts +1 -0
- package/libs/lib.cst +88 -30
- package/package.json +1 -1
package/dist/cjs/BaseVisitor.js
CHANGED
|
@@ -13,6 +13,7 @@ const PinTypes_1 = require("./objects/PinTypes");
|
|
|
13
13
|
const types_1 = require("./objects/types");
|
|
14
14
|
const globals_1 = require("./globals");
|
|
15
15
|
const builtinMethods_1 = require("./builtinMethods");
|
|
16
|
+
const utils_1 = require("./utils");
|
|
16
17
|
class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
17
18
|
constructor(silent = false, onErrorHandler = null, currentDirectory, defaultLibsPath) {
|
|
18
19
|
super();
|
|
@@ -56,18 +57,21 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
56
57
|
tmpComponent.instanceName = reference.name;
|
|
57
58
|
instances.delete(oldName);
|
|
58
59
|
instances.set(reference.name, tmpComponent);
|
|
59
|
-
this.
|
|
60
|
+
this.log2(`assigned '${reference.name}' to ClassComponent`);
|
|
60
61
|
}
|
|
61
62
|
else {
|
|
62
63
|
this.getExecutor().scope.variables.set(reference.name, value);
|
|
64
|
+
this.log2(`assigned variable ${reference.name} to ${value}`);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
else {
|
|
66
|
-
if (reference.
|
|
67
|
-
this.setInstanceParam(reference.
|
|
68
|
+
if (reference.parentValue instanceof ClassComponent_1.ClassComponent) {
|
|
69
|
+
this.setInstanceParam(reference.parentValue, trailers, value);
|
|
70
|
+
this.log2(`assigned component param ${reference.parentValue} trailers: ${trailers} value: ${value}`);
|
|
68
71
|
}
|
|
69
|
-
else if (reference.
|
|
70
|
-
reference.
|
|
72
|
+
else if (reference.parentValue instanceof Object) {
|
|
73
|
+
reference.parentValue[trailers.join('.')] = value;
|
|
74
|
+
this.log2(`assigned object ${reference.parentValue} trailers: ${trailers} value: ${value}`);
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
this.setResult(ctx, value);
|
|
@@ -78,7 +82,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
78
82
|
this.visit(ctxDataExpr);
|
|
79
83
|
const value = this.getResult(ctxDataExpr);
|
|
80
84
|
if (!reference.found) {
|
|
81
|
-
|
|
85
|
+
this.throwWithContext(ctx, 'Undefined reference: ' + reference.name);
|
|
82
86
|
}
|
|
83
87
|
const trailers = reference.trailers ?? [];
|
|
84
88
|
let currentValue = null;
|
|
@@ -94,7 +98,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
if (currentValue === null) {
|
|
97
|
-
|
|
101
|
+
this.throwWithContext(ctx, 'Operator assignment failed: could not get value');
|
|
98
102
|
}
|
|
99
103
|
let newValue = 0;
|
|
100
104
|
if (ctx.AdditionAssign()) {
|
|
@@ -113,7 +117,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
113
117
|
newValue = currentValue % value;
|
|
114
118
|
}
|
|
115
119
|
else {
|
|
116
|
-
|
|
120
|
+
this.throwWithContext(ctx, 'Operator assignment failed: could not perform operator');
|
|
117
121
|
}
|
|
118
122
|
if (trailers.length === 0) {
|
|
119
123
|
this.getExecutor().scope.variables.set(reference.name, newValue);
|
|
@@ -133,6 +137,14 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
133
137
|
const firstId = ctx.ID(0);
|
|
134
138
|
const atomId = firstId.getText();
|
|
135
139
|
let currentReference;
|
|
140
|
+
const idTrailers = [];
|
|
141
|
+
if (ctx.ID().length > 1) {
|
|
142
|
+
const idLength = ctx.ID().length;
|
|
143
|
+
for (let i = 1; i < idLength; i++) {
|
|
144
|
+
const tmpCtx = ctx.ID(i);
|
|
145
|
+
idTrailers.push(tmpCtx.getText());
|
|
146
|
+
}
|
|
147
|
+
}
|
|
136
148
|
if (this.pinTypesList.indexOf(atomId) !== -1) {
|
|
137
149
|
currentReference = {
|
|
138
150
|
found: true,
|
|
@@ -141,26 +153,17 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
141
153
|
};
|
|
142
154
|
}
|
|
143
155
|
else {
|
|
144
|
-
currentReference = executor.resolveVariable(this.executionStack, atomId);
|
|
145
|
-
}
|
|
146
|
-
const idTrailers = [];
|
|
147
|
-
if (ctx.ID().length > 1) {
|
|
148
|
-
const idLength = ctx.ID().length;
|
|
149
|
-
for (let i = 1; i < idLength; i++) {
|
|
150
|
-
const tmpCtx = ctx.ID(i);
|
|
151
|
-
idTrailers.push(tmpCtx.getText());
|
|
152
|
-
}
|
|
156
|
+
currentReference = executor.resolveVariable(this.executionStack, atomId, idTrailers);
|
|
153
157
|
}
|
|
154
|
-
currentReference.
|
|
155
|
-
if (currentReference.found && currentReference.type === 'instance') {
|
|
158
|
+
if (currentReference.found && currentReference.type === 'instance' && idTrailers.length === 0) {
|
|
156
159
|
const tmpComponent = currentReference.value;
|
|
157
160
|
for (const [pinId, net] of tmpComponent.pinNets) {
|
|
158
161
|
executor.scope.setNet(tmpComponent, pinId, net);
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
|
-
this.
|
|
164
|
+
this.log2(`atomId: ${atomId} ${currentReference}`);
|
|
162
165
|
if (ctx.parent instanceof CircuitScriptParser_1.ExpressionContext && !currentReference.found) {
|
|
163
|
-
|
|
166
|
+
this.throwWithContext(ctx, "Unknown symbol: " + atomId);
|
|
164
167
|
}
|
|
165
168
|
this.setResult(ctx, currentReference);
|
|
166
169
|
};
|
|
@@ -182,7 +185,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
182
185
|
let currentReference = executor.resolveVariable(this.executionStack, atomId);
|
|
183
186
|
if (ctx.trailer_expr().length > 0) {
|
|
184
187
|
if (!currentReference.found) {
|
|
185
|
-
|
|
188
|
+
this.throwWithContext(ctx, "Unknown function name: " + atomId);
|
|
186
189
|
}
|
|
187
190
|
currentReference.trailers = [];
|
|
188
191
|
ctx.trailer_expr().forEach(item => {
|
|
@@ -195,13 +198,18 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
195
198
|
parameters = this.getResult(ctxParameters);
|
|
196
199
|
}
|
|
197
200
|
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
try {
|
|
202
|
+
const [, functionResult] = executor.callFunction(currentReference.name, parameters, this.executionStack, useNetNamespace);
|
|
203
|
+
currentReference = {
|
|
204
|
+
found: true,
|
|
205
|
+
value: functionResult,
|
|
206
|
+
type: (functionResult instanceof ClassComponent_1.ClassComponent) ?
|
|
207
|
+
'instance' : 'value',
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
this.throwWithContext(ctx, err);
|
|
212
|
+
}
|
|
205
213
|
}
|
|
206
214
|
else {
|
|
207
215
|
currentReference.trailers.push(itemValue);
|
|
@@ -233,7 +241,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
233
241
|
}
|
|
234
242
|
else {
|
|
235
243
|
if (sign === -1) {
|
|
236
|
-
|
|
244
|
+
this.throwWithContext(ctx, "Invalid value");
|
|
237
245
|
}
|
|
238
246
|
}
|
|
239
247
|
if (ctxBooleanValue) {
|
|
@@ -320,7 +328,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
320
328
|
this.visitImport_expr = (ctx) => {
|
|
321
329
|
const ID = ctx.ID().toString();
|
|
322
330
|
this.log('import', ID);
|
|
323
|
-
this.handleImportFile(ID, true);
|
|
331
|
+
this.handleImportFile(ID, true, ctx);
|
|
324
332
|
this.log('done import', ID);
|
|
325
333
|
};
|
|
326
334
|
this.visitFunction_return_expr = (ctx) => {
|
|
@@ -420,12 +428,15 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
420
428
|
getReference(ctx) {
|
|
421
429
|
const atomStr = ctx.getText();
|
|
422
430
|
if (atomStr.indexOf('(') !== -1 || atomStr.indexOf(')') !== -1) {
|
|
423
|
-
|
|
431
|
+
this.throwWithContext(ctx, "Invalid assignment expression!");
|
|
424
432
|
}
|
|
425
433
|
this.visit(ctx);
|
|
426
434
|
const reference = this.getResult(ctx);
|
|
427
|
-
|
|
428
|
-
|
|
435
|
+
const { trailers = [] } = reference;
|
|
436
|
+
const undefinedParentWithTrailers = trailers.length > 0
|
|
437
|
+
&& reference.parentValue === undefined;
|
|
438
|
+
if (undefinedParentWithTrailers) {
|
|
439
|
+
this.throwWithContext(ctx, 'Undefined reference: ' + reference.name + '.' + trailers.join('.'));
|
|
429
440
|
}
|
|
430
441
|
return reference;
|
|
431
442
|
}
|
|
@@ -435,7 +446,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
435
446
|
getResult(ctx) {
|
|
436
447
|
return this.resultData.get(ctx);
|
|
437
448
|
}
|
|
438
|
-
handleImportFile(name, throwErrors = true) {
|
|
449
|
+
handleImportFile(name, throwErrors = true, ctx = null) {
|
|
439
450
|
let hasError = false;
|
|
440
451
|
let hasParseError = false;
|
|
441
452
|
let pathExists = false;
|
|
@@ -470,14 +481,18 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
470
481
|
catch (err) {
|
|
471
482
|
this.log('Failed to import file: ', err.message);
|
|
472
483
|
}
|
|
484
|
+
let errorMessage = null;
|
|
473
485
|
if (throwErrors && (hasError || hasParseError || !pathExists)) {
|
|
474
486
|
if (!pathExists) {
|
|
475
|
-
|
|
487
|
+
errorMessage = `File does not exist: ${name}`;
|
|
476
488
|
}
|
|
477
489
|
else {
|
|
478
|
-
|
|
490
|
+
errorMessage = `Failed to import: ${name}`;
|
|
479
491
|
}
|
|
480
492
|
}
|
|
493
|
+
if (errorMessage !== null && ctx) {
|
|
494
|
+
this.throwWithContext(ctx, errorMessage);
|
|
495
|
+
}
|
|
481
496
|
return {
|
|
482
497
|
hasError,
|
|
483
498
|
hasParseError,
|
|
@@ -559,7 +574,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
559
574
|
setInstanceParam(object, trailers, value) {
|
|
560
575
|
const paramName = trailers[0];
|
|
561
576
|
object.setParam(paramName, value);
|
|
562
|
-
this.
|
|
577
|
+
this.log2(`set instance ${object.instanceName} param ${paramName} to ${value}`);
|
|
563
578
|
}
|
|
564
579
|
getInstanceParam(object, trailers) {
|
|
565
580
|
const paramName = trailers[0];
|
|
@@ -580,5 +595,8 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
580
595
|
prepareStringValue(value) {
|
|
581
596
|
return value.slice(1, value.length - 1);
|
|
582
597
|
}
|
|
598
|
+
throwWithContext(context, message) {
|
|
599
|
+
(0, utils_1.throwWithContext)(context, message);
|
|
600
|
+
}
|
|
583
601
|
}
|
|
584
602
|
exports.BaseVisitor = BaseVisitor;
|
|
@@ -9,7 +9,7 @@ class SymbolValidatorVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
9
9
|
this.symbolTable = new SymbolTable();
|
|
10
10
|
this.visitImport_expr = (ctx) => {
|
|
11
11
|
const ID = ctx.ID().toString();
|
|
12
|
-
const { pathExists } = this.handleImportFile(ID, false);
|
|
12
|
+
const { pathExists } = this.handleImportFile(ID, false, ctx);
|
|
13
13
|
if (!pathExists) {
|
|
14
14
|
this.symbolTable.addUndefined(this.getExecutor(), ID, ctx.ID());
|
|
15
15
|
}
|