circuitscript 0.1.8 → 0.1.10
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 +7 -6
- package/dist/cjs/antlr/CircuitScriptParser.js +141 -123
- package/dist/cjs/builtinMethods.js +15 -0
- package/dist/cjs/draw_symbols.js +3 -0
- package/dist/cjs/execute.js +90 -2
- package/dist/cjs/helpers.js +1 -0
- package/dist/cjs/layout.js +33 -44
- package/dist/cjs/objects/ClassComponent.js +1 -0
- package/dist/cjs/objects/ExecutionScope.js +5 -4
- package/dist/cjs/utils.js +57 -14
- package/dist/cjs/visitor.js +99 -39
- package/dist/esm/BaseVisitor.js +7 -6
- package/dist/esm/antlr/CircuitScriptParser.js +141 -123
- package/dist/esm/builtinMethods.js +15 -0
- package/dist/esm/draw_symbols.js +4 -1
- package/dist/esm/execute.js +91 -3
- package/dist/esm/helpers.js +2 -1
- package/dist/esm/layout.js +34 -45
- package/dist/esm/objects/ClassComponent.js +1 -0
- package/dist/esm/objects/ExecutionScope.js +5 -4
- package/dist/esm/utils.js +54 -13
- package/dist/esm/visitor.js +100 -40
- package/dist/types/BaseVisitor.d.ts +3 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +2 -1
- package/dist/types/execute.d.ts +6 -1
- package/dist/types/objects/ClassComponent.d.ts +1 -0
- package/dist/types/objects/ExecutionScope.d.ts +3 -2
- package/dist/types/utils.d.ts +9 -1
- package/dist/types/visitor.d.ts +2 -0
- package/package.json +1 -1
package/dist/esm/execute.js
CHANGED
|
@@ -2,7 +2,7 @@ import { BlockTypes, ComponentTypes, Delimiter1, GlobalNames, NoNetText, ParamKe
|
|
|
2
2
|
import { ClassComponent, ModuleComponent } from './objects/ClassComponent.js';
|
|
3
3
|
import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.js';
|
|
4
4
|
import { Net } from './objects/Net.js';
|
|
5
|
-
import { numeric } from './objects/ParamDefinition.js';
|
|
5
|
+
import { numeric, NumericValue } from './objects/ParamDefinition.js';
|
|
6
6
|
import { PortSide } from './objects/PinDefinition.js';
|
|
7
7
|
import { DeclaredReference, Direction } from './objects/types.js';
|
|
8
8
|
import { Wire } from './objects/Wire.js';
|
|
@@ -27,7 +27,8 @@ export class ExecutionContext {
|
|
|
27
27
|
__functionCache = {};
|
|
28
28
|
parentContext;
|
|
29
29
|
componentAngleFollowsWire = true;
|
|
30
|
-
|
|
30
|
+
warnings = [];
|
|
31
|
+
constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, warnings, parent) {
|
|
31
32
|
this.name = name;
|
|
32
33
|
this.namespace = namespace;
|
|
33
34
|
this.netNamespace = netNamespace;
|
|
@@ -39,6 +40,14 @@ export class ExecutionContext {
|
|
|
39
40
|
this.silent = silent;
|
|
40
41
|
this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
|
|
41
42
|
this.parentContext = parent;
|
|
43
|
+
this.warnings = warnings;
|
|
44
|
+
}
|
|
45
|
+
logWarning(message, context, fileName) {
|
|
46
|
+
this.warnings.push({
|
|
47
|
+
message,
|
|
48
|
+
ctx: context,
|
|
49
|
+
fileName,
|
|
50
|
+
});
|
|
42
51
|
}
|
|
43
52
|
log(...params) {
|
|
44
53
|
const indentOutput = ''.padStart(this.scope.indentLevel * 4, ' ');
|
|
@@ -125,7 +134,6 @@ export class ExecutionContext {
|
|
|
125
134
|
pins.forEach((pin) => {
|
|
126
135
|
component.pins.set(pin.id, pin);
|
|
127
136
|
});
|
|
128
|
-
component.arrangeProps = props.arrange ?? null;
|
|
129
137
|
component.displayProp = props.display ?? null;
|
|
130
138
|
component.widthProp = props.width ?? null;
|
|
131
139
|
component.heightProp = props.height ?? null;
|
|
@@ -138,6 +146,33 @@ export class ExecutionContext {
|
|
|
138
146
|
useAngle += 360;
|
|
139
147
|
}
|
|
140
148
|
}
|
|
149
|
+
if (props.display === null && props.arrange === null) {
|
|
150
|
+
const tmpArrangeLeft = [];
|
|
151
|
+
const tmpArrangeRight = [];
|
|
152
|
+
pins.forEach((pin, index) => {
|
|
153
|
+
const useArray = (index % 2 === 0) ? tmpArrangeLeft : tmpArrangeRight;
|
|
154
|
+
useArray.push(numeric(pin.id));
|
|
155
|
+
});
|
|
156
|
+
const arrangeProp = new Map([
|
|
157
|
+
[SymbolPinSide.Left, tmpArrangeLeft],
|
|
158
|
+
[SymbolPinSide.Right, tmpArrangeRight]
|
|
159
|
+
]);
|
|
160
|
+
props.arrange = arrangeProp;
|
|
161
|
+
}
|
|
162
|
+
if (props.arrange !== null) {
|
|
163
|
+
component.arrangeProps = this.removeArrangePropDuplicates(props.arrange);
|
|
164
|
+
const arrangePropPins = this.getArrangePropPins(component.arrangeProps).map(item => {
|
|
165
|
+
return item.toNumber();
|
|
166
|
+
});
|
|
167
|
+
pins.forEach(pin => {
|
|
168
|
+
if (arrangePropPins.indexOf(pin.id) === -1) {
|
|
169
|
+
this.logWarning(`Pin ${pin.id} is not specified in arrange property`);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
component.arrangeProps = null;
|
|
175
|
+
}
|
|
141
176
|
component.angleProp = useAngle ?? 0;
|
|
142
177
|
component.followWireOrientationProp = props.followWireOrientation;
|
|
143
178
|
const paramsMap = new Map();
|
|
@@ -181,6 +216,59 @@ export class ExecutionContext {
|
|
|
181
216
|
this.log('add symbol', instanceName, '[' + pinsOutput.join(', ') + ']');
|
|
182
217
|
return component;
|
|
183
218
|
}
|
|
219
|
+
removeArrangePropDuplicates(arrangeProp) {
|
|
220
|
+
const sides = [
|
|
221
|
+
SymbolPinSide.Left,
|
|
222
|
+
SymbolPinSide.Right,
|
|
223
|
+
SymbolPinSide.Top,
|
|
224
|
+
SymbolPinSide.Bottom
|
|
225
|
+
];
|
|
226
|
+
const result = new Map();
|
|
227
|
+
const seenIds = [];
|
|
228
|
+
sides.forEach(side => {
|
|
229
|
+
let items = arrangeProp.get(side) ?? [];
|
|
230
|
+
if (!Array.isArray(items)) {
|
|
231
|
+
items = [items];
|
|
232
|
+
}
|
|
233
|
+
const uniqueItems = [];
|
|
234
|
+
items.forEach(item => {
|
|
235
|
+
if (item instanceof NumericValue) {
|
|
236
|
+
if (seenIds.indexOf(item.toNumber()) === -1) {
|
|
237
|
+
seenIds.push(item.toNumber());
|
|
238
|
+
uniqueItems.push(item);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
this.logWarning(`Pin ${item.toNumber()} specified more than once in arrange property`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
uniqueItems.push(item);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
result.set(side, uniqueItems);
|
|
249
|
+
});
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
getArrangePropPins(arrangeProps) {
|
|
253
|
+
const pins = [];
|
|
254
|
+
const sides = [
|
|
255
|
+
SymbolPinSide.Left,
|
|
256
|
+
SymbolPinSide.Right,
|
|
257
|
+
SymbolPinSide.Top,
|
|
258
|
+
SymbolPinSide.Bottom
|
|
259
|
+
];
|
|
260
|
+
sides.forEach(side => {
|
|
261
|
+
const items = arrangeProps.get(side);
|
|
262
|
+
if (items) {
|
|
263
|
+
items.forEach(item => {
|
|
264
|
+
if (item instanceof NumericValue) {
|
|
265
|
+
pins.push(item);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
return pins;
|
|
271
|
+
}
|
|
184
272
|
printPoint(extra = '') {
|
|
185
273
|
let netString = NoNetText;
|
|
186
274
|
if (this.scope.currentComponent === null || this.scope.currentPin === null) {
|
package/dist/esm/helpers.js
CHANGED
|
@@ -5,7 +5,7 @@ import { generateKiCADNetList, printTree } from "./export.js";
|
|
|
5
5
|
import { LayoutEngine } from "./layout.js";
|
|
6
6
|
import { parseFileWithVisitor } from "./parser.js";
|
|
7
7
|
import { generatePdfOutput, generateSvgOutput, renderSheetsToSVG } from "./render.js";
|
|
8
|
-
import { generateDebugSequenceAction, ParseError, ParseSyntaxError, RenderError, resolveToNumericValue, RuntimeExecutionError, sequenceActionString, SimpleStopwatch } from "./utils.js";
|
|
8
|
+
import { generateDebugSequenceAction, ParseError, ParseSyntaxError, printWarnings, RenderError, resolveToNumericValue, RuntimeExecutionError, sequenceActionString, SimpleStopwatch } from "./utils.js";
|
|
9
9
|
import { ParserVisitor } from "./visitor.js";
|
|
10
10
|
import { SymbolValidatorVisitor } from "./validate/SymbolValidatorVisitor.js";
|
|
11
11
|
import { SymbolValidatorResolveVisitor } from "./validate/SymbolValidatorResolveVisitor.js";
|
|
@@ -185,6 +185,7 @@ export async function renderScript(scriptData, outputPath, options) {
|
|
|
185
185
|
visitor.log('reading file');
|
|
186
186
|
visitor.log('done reading file');
|
|
187
187
|
const { tree, parser, parserTimeTaken, lexerTimeTaken } = await parseFileWithVisitor(visitor, scriptData);
|
|
188
|
+
printWarnings(visitor.getWarnings());
|
|
188
189
|
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
189
190
|
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
190
191
|
if (dumpNets) {
|
package/dist/esm/layout.js
CHANGED
|
@@ -2,7 +2,7 @@ import graphlib, { Graph } from '@dagrejs/graphlib';
|
|
|
2
2
|
const { alg } = graphlib;
|
|
3
3
|
import { SymbolCustom, SymbolDrawing, SymbolCustomModule, SymbolPlaceholder, SymbolText, PlaceHolderCommands } from "./draw_symbols.js";
|
|
4
4
|
import { FrameAction, SequenceAction } from "./objects/ExecutionScope.js";
|
|
5
|
-
import { ComponentTypes, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, ParamKeys,
|
|
5
|
+
import { ComponentTypes, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, ParamKeys, WireAutoDirection } from './globals.js';
|
|
6
6
|
import { Geometry, HorizontalAlign, VerticalAlign } from './geometry.js';
|
|
7
7
|
import { Logger } from './logger.js';
|
|
8
8
|
import { FixedFrameIds, Frame, FrameParamKeys, FramePlotDirection } from './objects/Frame.js';
|
|
@@ -1058,52 +1058,39 @@ function generateLayoutPinDefinition(component) {
|
|
|
1058
1058
|
const pins = component.pins;
|
|
1059
1059
|
const symbolPinDefinitions = [];
|
|
1060
1060
|
const existingPinIds = Array.from(pins.keys());
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
pinId: existingPinIds[i],
|
|
1068
|
-
text: pin.name,
|
|
1069
|
-
position: pinPosition,
|
|
1070
|
-
pinType: pin.pinType,
|
|
1071
|
-
});
|
|
1061
|
+
const arrangeProps = component.arrangeProps ?? [];
|
|
1062
|
+
const addedPins = [];
|
|
1063
|
+
for (const [key, items] of arrangeProps) {
|
|
1064
|
+
let useItems;
|
|
1065
|
+
if (!Array.isArray(items)) {
|
|
1066
|
+
useItems = [items];
|
|
1072
1067
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
const addedPins = [];
|
|
1076
|
-
for (const [key, items] of component.arrangeProps) {
|
|
1077
|
-
let useItems;
|
|
1078
|
-
if (!Array.isArray(items)) {
|
|
1079
|
-
useItems = [items];
|
|
1080
|
-
}
|
|
1081
|
-
else {
|
|
1082
|
-
useItems = [...items];
|
|
1083
|
-
}
|
|
1084
|
-
useItems.forEach(pinId => {
|
|
1085
|
-
if (pinId instanceof NumericValue) {
|
|
1086
|
-
const pinIdValue = pinId.toNumber();
|
|
1087
|
-
if (existingPinIds.indexOf(pinIdValue) !== -1) {
|
|
1088
|
-
const pin = pins.get(pinIdValue);
|
|
1089
|
-
symbolPinDefinitions.push({
|
|
1090
|
-
side: key,
|
|
1091
|
-
pinId: pinIdValue,
|
|
1092
|
-
text: pin.name,
|
|
1093
|
-
position: pin.position,
|
|
1094
|
-
pinType: pin.pinType,
|
|
1095
|
-
});
|
|
1096
|
-
addedPins.push(pinIdValue);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
});
|
|
1068
|
+
else {
|
|
1069
|
+
useItems = [...items];
|
|
1100
1070
|
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1071
|
+
useItems.forEach(pinId => {
|
|
1072
|
+
if (pinId instanceof NumericValue) {
|
|
1073
|
+
const pinIdValue = pinId.toNumber();
|
|
1074
|
+
if (existingPinIds.indexOf(pinIdValue) !== -1) {
|
|
1075
|
+
const pin = pins.get(pinIdValue);
|
|
1076
|
+
symbolPinDefinitions.push({
|
|
1077
|
+
side: key,
|
|
1078
|
+
pinId: pinIdValue,
|
|
1079
|
+
text: pin.name,
|
|
1080
|
+
position: pin.position,
|
|
1081
|
+
pinType: pin.pinType,
|
|
1082
|
+
});
|
|
1083
|
+
addedPins.push(pinIdValue);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1103
1086
|
});
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1087
|
+
}
|
|
1088
|
+
const unplacedPins = existingPinIds.filter(pinId => {
|
|
1089
|
+
return addedPins.indexOf(pinId) === -1;
|
|
1090
|
+
});
|
|
1091
|
+
if (unplacedPins.length > 0) {
|
|
1092
|
+
component._unplacedPins = unplacedPins;
|
|
1093
|
+
console.warn("Warning: There are unplaced pins: " + unplacedPins);
|
|
1107
1094
|
}
|
|
1108
1095
|
return symbolPinDefinitions;
|
|
1109
1096
|
}
|
|
@@ -1461,7 +1448,9 @@ export function CalculatePinPositions(component) {
|
|
|
1461
1448
|
tmpSymbol.refreshDrawing();
|
|
1462
1449
|
const pins = component.pins;
|
|
1463
1450
|
pins.forEach((value, key) => {
|
|
1464
|
-
|
|
1451
|
+
if (component._unplacedPins.indexOf(key) === -1) {
|
|
1452
|
+
pinPositionMapping.set(key, tmpSymbol.pinPosition(key));
|
|
1453
|
+
}
|
|
1465
1454
|
});
|
|
1466
1455
|
return pinPositionMapping;
|
|
1467
1456
|
}
|
|
@@ -131,12 +131,13 @@ export class ExecutionScope {
|
|
|
131
131
|
exitContext() {
|
|
132
132
|
return this.contextStack.pop();
|
|
133
133
|
}
|
|
134
|
-
findPropertyKeyTree() {
|
|
134
|
+
findPropertyKeyTree(visitor) {
|
|
135
135
|
const keyNames = [];
|
|
136
136
|
for (let i = this.contextStack.length - 1; i >= 0; i--) {
|
|
137
137
|
const ctx = this.contextStack[i];
|
|
138
138
|
if (ctx instanceof Property_key_exprContext) {
|
|
139
|
-
|
|
139
|
+
const result = visitor.visitResult(ctx);
|
|
140
|
+
keyNames.push([ctx, result]);
|
|
140
141
|
}
|
|
141
142
|
else if (typeof ctx === 'number') {
|
|
142
143
|
keyNames.push(['index', ctx]);
|
|
@@ -150,9 +151,9 @@ export class ExecutionScope {
|
|
|
150
151
|
popOnPropertyHandler() {
|
|
151
152
|
return this.onPropertyHandler.pop();
|
|
152
153
|
}
|
|
153
|
-
triggerPropertyHandler(value, valueCtx) {
|
|
154
|
+
triggerPropertyHandler(visitor, value, valueCtx) {
|
|
154
155
|
const lastHandler = this.onPropertyHandler[this.onPropertyHandler.length - 1];
|
|
155
|
-
const propertyTree = this.findPropertyKeyTree();
|
|
156
|
+
const propertyTree = this.findPropertyKeyTree(visitor);
|
|
156
157
|
lastHandler && lastHandler(propertyTree, value, valueCtx);
|
|
157
158
|
}
|
|
158
159
|
}
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Big } from 'big.js';
|
|
2
|
+
import { ParserRuleContext } from "antlr4ng";
|
|
2
3
|
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
3
4
|
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
4
5
|
import { SequenceAction } from './objects/ExecutionScope.js';
|
|
@@ -243,30 +244,52 @@ export class BaseError extends Error {
|
|
|
243
244
|
startToken;
|
|
244
245
|
endToken;
|
|
245
246
|
filePath;
|
|
246
|
-
constructor(message,
|
|
247
|
+
constructor(message, startTokenOrCtx, endToken, filePath) {
|
|
247
248
|
super(message);
|
|
248
249
|
this.message = message;
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
if (startTokenOrCtx instanceof ParserRuleContext) {
|
|
251
|
+
this.startToken = startTokenOrCtx.start;
|
|
252
|
+
this.endToken = startTokenOrCtx.stop;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
this.startToken = startTokenOrCtx;
|
|
256
|
+
this.endToken = endToken;
|
|
257
|
+
}
|
|
251
258
|
this.filePath = filePath;
|
|
252
259
|
}
|
|
253
260
|
toString() {
|
|
254
261
|
const parts = [this.name];
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
parts.push(` at ${line}:${column}`);
|
|
264
|
-
}
|
|
262
|
+
const linePosition = getLinePositionAsString({
|
|
263
|
+
start: this.startToken,
|
|
264
|
+
stop: this.endToken
|
|
265
|
+
});
|
|
266
|
+
if (linePosition !== null) {
|
|
267
|
+
parts.push(linePosition);
|
|
265
268
|
}
|
|
266
269
|
parts.push(`: ${this.message}`);
|
|
267
270
|
return parts.join('');
|
|
268
271
|
}
|
|
269
272
|
}
|
|
273
|
+
export function getLinePositionAsString(ctx) {
|
|
274
|
+
if (ctx === null || ctx === undefined) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
const startToken = ctx.start;
|
|
278
|
+
const endToken = ctx.stop;
|
|
279
|
+
let result = null;
|
|
280
|
+
if (startToken) {
|
|
281
|
+
const { line, column } = startToken;
|
|
282
|
+
if (endToken && (endToken.line !== startToken.line || endToken.column !== startToken.column)) {
|
|
283
|
+
const endLine = endToken.line;
|
|
284
|
+
const endColumn = endToken.column + (endToken.stop - endToken.start);
|
|
285
|
+
result = ` at ${line}:${column}-${endLine}:${endColumn}`;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
result = ` at ${line}:${column}`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
270
293
|
export class ParseSyntaxError extends BaseError {
|
|
271
294
|
name = 'ParseSyntaxError';
|
|
272
295
|
}
|
|
@@ -284,3 +307,21 @@ export class RenderError extends Error {
|
|
|
284
307
|
this.stage = stage;
|
|
285
308
|
}
|
|
286
309
|
}
|
|
310
|
+
export function printWarnings(warnings) {
|
|
311
|
+
const warningMessages = [];
|
|
312
|
+
warnings.forEach(item => {
|
|
313
|
+
const { message } = item;
|
|
314
|
+
const linePosition = getLinePositionAsString(item.ctx);
|
|
315
|
+
const parts = [message];
|
|
316
|
+
if (linePosition !== null) {
|
|
317
|
+
parts.push(linePosition);
|
|
318
|
+
}
|
|
319
|
+
const finalMessage = parts.join('');
|
|
320
|
+
if (warningMessages.indexOf(finalMessage) === -1) {
|
|
321
|
+
warningMessages.push(finalMessage);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
warningMessages.forEach(message => {
|
|
325
|
+
console.log(`Warning: ${message}`);
|
|
326
|
+
});
|
|
327
|
+
}
|
package/dist/esm/visitor.js
CHANGED
|
@@ -47,7 +47,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
catch (err) {
|
|
50
|
-
throw new RuntimeExecutionError(err.message, ctx
|
|
50
|
+
throw new RuntimeExecutionError(err.message, ctx);
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
return this.getExecutor().getCurrentPoint();
|
|
@@ -115,6 +115,24 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
115
115
|
};
|
|
116
116
|
visitCreate_component_expr = (ctx) => {
|
|
117
117
|
const scope = this.getScope();
|
|
118
|
+
const definedPinIds = [];
|
|
119
|
+
const arrangedPinIds = [];
|
|
120
|
+
const checkPinExistsAndNotDuplicated = (pinId, ctx) => {
|
|
121
|
+
if (definedPinIds.indexOf(pinId) === -1) {
|
|
122
|
+
this.warnings.push({
|
|
123
|
+
message: `Invalid pin ${pinId}`, ctx
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (arrangedPinIds.indexOf(pinId) !== -1) {
|
|
127
|
+
this.warnings.push({
|
|
128
|
+
message: `Pin ${pinId} specified more than once`,
|
|
129
|
+
ctx,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
arrangedPinIds.push(pinId);
|
|
133
|
+
};
|
|
134
|
+
let didDefineArrangeProp = false;
|
|
135
|
+
let didDefineDisplayProp = false;
|
|
118
136
|
scope.setOnPropertyHandler((path, value, ctx) => {
|
|
119
137
|
if (path.length === 1) {
|
|
120
138
|
const [, keyName] = path[0];
|
|
@@ -127,9 +145,25 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
127
145
|
case 'height':
|
|
128
146
|
this.validateNumeric(value, ctx);
|
|
129
147
|
break;
|
|
148
|
+
case 'display':
|
|
149
|
+
if (didDefineArrangeProp) {
|
|
150
|
+
throw new RuntimeExecutionError("arrange property has already been defined", ctx);
|
|
151
|
+
}
|
|
152
|
+
didDefineDisplayProp = true;
|
|
153
|
+
break;
|
|
154
|
+
case 'arrange':
|
|
155
|
+
if (didDefineDisplayProp) {
|
|
156
|
+
throw new RuntimeExecutionError("display property already defined", ctx);
|
|
157
|
+
}
|
|
158
|
+
didDefineArrangeProp = true;
|
|
159
|
+
break;
|
|
130
160
|
case 'pins':
|
|
131
161
|
if (!(value instanceof Map)) {
|
|
132
162
|
this.validateNumeric(value, ctx);
|
|
163
|
+
const numPins = value.toNumber();
|
|
164
|
+
for (let i = 0; i < numPins; i++) {
|
|
165
|
+
definedPinIds.push(i + 1);
|
|
166
|
+
}
|
|
133
167
|
}
|
|
134
168
|
break;
|
|
135
169
|
case 'copy':
|
|
@@ -140,7 +174,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
140
174
|
this.validateBoolean(value, ctx);
|
|
141
175
|
}
|
|
142
176
|
else {
|
|
143
|
-
throw new RuntimeExecutionError("Invalid value for 'copy' property", ctx
|
|
177
|
+
throw new RuntimeExecutionError("Invalid value for 'copy' property", ctx);
|
|
144
178
|
}
|
|
145
179
|
break;
|
|
146
180
|
}
|
|
@@ -150,20 +184,26 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
150
184
|
if (keyName === 'arrange') {
|
|
151
185
|
const [sideKeyCtx, sideKeyName] = path[1];
|
|
152
186
|
if (ValidPinSides.indexOf(sideKeyName) === -1) {
|
|
153
|
-
throw new RuntimeExecutionError(`Invalid side ${sideKeyName} in arrange`, sideKeyCtx
|
|
187
|
+
throw new RuntimeExecutionError(`Invalid side ${sideKeyName} in arrange`, sideKeyCtx);
|
|
154
188
|
}
|
|
155
189
|
else {
|
|
156
|
-
if (path.length
|
|
190
|
+
if (path.length === 2 && value instanceof NumericValue) {
|
|
191
|
+
checkPinExistsAndNotDuplicated(value.toNumber(), ctx);
|
|
192
|
+
}
|
|
193
|
+
else if (path.length > 2 && path[2][0] === 'index') {
|
|
157
194
|
if (Array.isArray(value)) {
|
|
158
195
|
const goodBlank = value.length === 1 &&
|
|
159
196
|
value[0] instanceof NumericValue;
|
|
160
197
|
if (!goodBlank) {
|
|
161
|
-
throw new RuntimeExecutionError(`Invalid blank specifier`, ctx
|
|
198
|
+
throw new RuntimeExecutionError(`Invalid blank specifier`, ctx);
|
|
162
199
|
}
|
|
163
200
|
}
|
|
164
201
|
else {
|
|
165
202
|
if (!(value instanceof NumericValue)) {
|
|
166
|
-
throw new RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx
|
|
203
|
+
throw new RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
checkPinExistsAndNotDuplicated(value.toNumber(), ctx);
|
|
167
207
|
}
|
|
168
208
|
}
|
|
169
209
|
}
|
|
@@ -184,10 +224,12 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
184
224
|
}
|
|
185
225
|
else if (keyName === 'pins') {
|
|
186
226
|
if (path.length === 2) {
|
|
227
|
+
const idName = path[1][1];
|
|
228
|
+
definedPinIds.push(idName);
|
|
187
229
|
if (value.length === 2) {
|
|
188
230
|
const [pinType,] = value;
|
|
189
231
|
if (pinType instanceof UndeclaredReference) {
|
|
190
|
-
throw new RuntimeExecutionError(`Invalid pin type: ${pinType.reference.name}`, ctx
|
|
232
|
+
throw new RuntimeExecutionError(`Invalid pin type: ${pinType.reference.name}`, ctx);
|
|
191
233
|
}
|
|
192
234
|
}
|
|
193
235
|
}
|
|
@@ -416,7 +458,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
416
458
|
this.getScope().enterContext(ctxValue);
|
|
417
459
|
const keyName = this.visitResult(ctxKey);
|
|
418
460
|
const value = this.visitResult(ctxValue);
|
|
419
|
-
scope.triggerPropertyHandler(value, ctxValue);
|
|
461
|
+
scope.triggerPropertyHandler(this, value, ctxValue);
|
|
420
462
|
this.getScope().exitContext();
|
|
421
463
|
this.getScope().exitContext();
|
|
422
464
|
if (value instanceof UndeclaredReference && (value.reference.parentValue === undefined
|
|
@@ -437,7 +479,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
437
479
|
value = ctx.data_expr().map((item, index) => {
|
|
438
480
|
this.getScope().enterContext(index);
|
|
439
481
|
const result = this.visitResult(item);
|
|
440
|
-
this.getScope().triggerPropertyHandler(result, item);
|
|
482
|
+
this.getScope().triggerPropertyHandler(this, result, item);
|
|
441
483
|
this.getScope().exitContext();
|
|
442
484
|
return result;
|
|
443
485
|
});
|
|
@@ -885,7 +927,21 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
885
927
|
};
|
|
886
928
|
visitPoint_expr = (ctx) => {
|
|
887
929
|
const ID = ctx.ID();
|
|
888
|
-
|
|
930
|
+
const ctxData = ctx.data_expr();
|
|
931
|
+
let pointValue;
|
|
932
|
+
if (ctxData) {
|
|
933
|
+
const resultValue = this.visitResult(ctxData);
|
|
934
|
+
if (typeof resultValue === 'string') {
|
|
935
|
+
pointValue = resultValue;
|
|
936
|
+
}
|
|
937
|
+
else {
|
|
938
|
+
throw new RuntimeExecutionError('Invalid value for point');
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
else if (ID) {
|
|
942
|
+
pointValue = ID.getText();
|
|
943
|
+
}
|
|
944
|
+
return this.getExecutor().addPoint(pointValue);
|
|
889
945
|
};
|
|
890
946
|
visitProperty_set_expr = (ctx) => {
|
|
891
947
|
const result = this.visitResult(ctx.data_expr());
|
|
@@ -1063,45 +1119,46 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1063
1119
|
parseCreateComponentPins(pinData) {
|
|
1064
1120
|
const pins = [];
|
|
1065
1121
|
if (pinData instanceof NumericValue) {
|
|
1122
|
+
const tmpMap = new Map();
|
|
1066
1123
|
const lastPin = pinData.toNumber();
|
|
1067
1124
|
for (let i = 0; i < lastPin; i++) {
|
|
1068
1125
|
const pinId = i + 1;
|
|
1069
|
-
|
|
1126
|
+
tmpMap.set(pinId, numeric(pinId));
|
|
1070
1127
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
}
|
|
1092
|
-
else {
|
|
1093
|
-
pinName = pinDef[0];
|
|
1094
|
-
if (pinDef.length > 1) {
|
|
1095
|
-
altPinNames = pinDef.slice(1);
|
|
1096
|
-
}
|
|
1128
|
+
pinData = tmpMap;
|
|
1129
|
+
}
|
|
1130
|
+
pinData = pinData ?? [];
|
|
1131
|
+
for (const [pinId, pinDef] of pinData) {
|
|
1132
|
+
let pinIdType = PinIdType.Int;
|
|
1133
|
+
let pinType = PinTypes.Any;
|
|
1134
|
+
let pinName = null;
|
|
1135
|
+
let altPinNames = [];
|
|
1136
|
+
if (typeof pinId === 'string') {
|
|
1137
|
+
pinIdType = PinIdType.Str;
|
|
1138
|
+
}
|
|
1139
|
+
if (Array.isArray(pinDef)) {
|
|
1140
|
+
const firstValue = pinDef[0];
|
|
1141
|
+
if (firstValue.type
|
|
1142
|
+
&& firstValue.type === ReferenceTypes.pinType
|
|
1143
|
+
&& this.pinTypes.indexOf(firstValue.value) !== -1) {
|
|
1144
|
+
pinType = firstValue.value;
|
|
1145
|
+
pinName = pinDef[1];
|
|
1146
|
+
if (pinDef.length > 2) {
|
|
1147
|
+
altPinNames = pinDef.slice(2);
|
|
1097
1148
|
}
|
|
1098
1149
|
}
|
|
1099
1150
|
else {
|
|
1100
|
-
pinName = pinDef;
|
|
1151
|
+
pinName = pinDef[0];
|
|
1152
|
+
if (pinDef.length > 1) {
|
|
1153
|
+
altPinNames = pinDef.slice(1);
|
|
1154
|
+
}
|
|
1101
1155
|
}
|
|
1102
|
-
this.log('pins', pinId, pinIdType, pinName, pinType, altPinNames);
|
|
1103
|
-
pins.push(new PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
|
|
1104
1156
|
}
|
|
1157
|
+
else {
|
|
1158
|
+
pinName = pinDef;
|
|
1159
|
+
}
|
|
1160
|
+
this.log('pins', pinId, pinIdType, pinName, pinType, altPinNames);
|
|
1161
|
+
pins.push(new PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
|
|
1105
1162
|
}
|
|
1106
1163
|
return pins;
|
|
1107
1164
|
}
|
|
@@ -1310,6 +1367,9 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1310
1367
|
});
|
|
1311
1368
|
return properties;
|
|
1312
1369
|
}
|
|
1370
|
+
getWarnings() {
|
|
1371
|
+
return this.warnings;
|
|
1372
|
+
}
|
|
1313
1373
|
}
|
|
1314
1374
|
const ComponentRefDesPrefixes = {
|
|
1315
1375
|
res: 'R',
|
|
@@ -6,6 +6,7 @@ import { ClassComponent } from "./objects/ClassComponent.js";
|
|
|
6
6
|
import { Net } from "./objects/Net.js";
|
|
7
7
|
import { CallableParameter, CFunctionOptions, ComplexType, Direction, FunctionDefinedParameter, ReferenceType } from "./objects/types.js";
|
|
8
8
|
import { ParserRuleContext } from 'antlr4ng';
|
|
9
|
+
import { ExecutionWarning } from "./utils.js";
|
|
9
10
|
import { BaseError } from './utils.js';
|
|
10
11
|
import { ExecutionScope } from './objects/ExecutionScope.js';
|
|
11
12
|
import { NodeScriptEnvironment } from "./environment.js";
|
|
@@ -24,6 +25,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | Refe
|
|
|
24
25
|
onErrorHandler: OnErrorHandler | null;
|
|
25
26
|
environment: NodeScriptEnvironment;
|
|
26
27
|
protected importedFiles: ImportFile[];
|
|
28
|
+
protected warnings: ExecutionWarning[];
|
|
27
29
|
onImportFile: (visitor: BaseVisitor, filePath: string, fileData: string, onErrorHandler: OnErrorHandler) => Promise<{
|
|
28
30
|
hasError: boolean;
|
|
29
31
|
hasParseError: boolean;
|
|
@@ -60,7 +62,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | Refe
|
|
|
60
62
|
visitArrayExpr: (ctx: ArrayExprContext) => void;
|
|
61
63
|
protected setResult(ctx: ParserRuleContext, value: any): void;
|
|
62
64
|
protected getResult(ctx: ParserRuleContext): any;
|
|
63
|
-
|
|
65
|
+
visitResult(ctx: ParserRuleContext): any;
|
|
64
66
|
protected handleImportFile(name: string, throwErrors?: boolean, ctx?: ParserRuleContext | null): Promise<ImportFile>;
|
|
65
67
|
visitRoundedBracketsExpr: (ctx: RoundedBracketsExprContext) => void;
|
|
66
68
|
protected setupDefinedParameters(funcDefinedParameters: FunctionDefinedParameter[], passedInParameters: CallableParameter[], executor: ExecutionContext): void;
|
|
@@ -833,7 +833,8 @@ export declare class Array_exprContext extends antlr.ParserRuleContext {
|
|
|
833
833
|
export declare class Point_exprContext extends antlr.ParserRuleContext {
|
|
834
834
|
constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
|
|
835
835
|
Point(): antlr.TerminalNode;
|
|
836
|
-
ID(): antlr.TerminalNode;
|
|
836
|
+
ID(): antlr.TerminalNode | null;
|
|
837
|
+
data_expr(): Data_exprContext | null;
|
|
837
838
|
get ruleIndex(): number;
|
|
838
839
|
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
839
840
|
}
|