nodalis-compiler 1.0.4 → 1.0.6

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/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.6]
9
+
10
+ - Fixed issue with JS compile where program was not compiling exactly right.
11
+ - Integrated latest version of mticp-npm.
12
+
13
+ ## [1.0.5]
14
+
15
+ - Changed JSCompiler to avoid including the setup and run functions if we are just compiling generic ST.
16
+
8
17
  ## [1.0.4]
9
18
 
10
19
  - Added support for TypeScript types.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodalis-compiler",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Compiles IEC-61131-3/10 languages into code that can be used as a PLC on multiple platforms.",
5
5
  "icon": "nodalis.png",
6
6
  "main": "src/nodalis.js",
@@ -39,9 +39,10 @@ export const CommunicationProtocol = Object.freeze({
39
39
 
40
40
  /**
41
41
  * @typedef {Object} CompilerOptions
42
- * @property {string} source - Source file or folder path
43
- * @property {string} destination - Output destination folder path
44
- * @property {string} language - One of IECLanguage values
42
+ * @property {string} sourcePath - Source file or folder path
43
+ * @property {string} outputPath - Output destination folder path
44
+ * @property {string} target - The target type for the compiler.
45
+ * @property {string} resourceName - The name of the resource to compile, if IEC.
45
46
  * @property {string} outputType - One of OutputType values
46
47
  */
47
48
 
@@ -174,7 +174,7 @@ export class JSCompiler extends Compiler {
174
174
  `${includes}
175
175
  ${transpiledCode}
176
176
  ${target === "nodejs" ? `let opcServer = new OPCServer();`: ""}
177
- export async function setup(){
177
+ ${taskCode !== "" ? `export async function setup(){
178
178
  ${mapCode}
179
179
 
180
180
  ${target === "nodejs" ? "opcServer.setReadWriteHandlers(readAddress, writeAddress);\n" + `await opcServer.start();\n` + globals.join("\n") : ""}
@@ -186,7 +186,7 @@ export function run(){
186
186
  ${taskCode}
187
187
 
188
188
  }
189
- `;
189
+ ` : ""}`;
190
190
  if(target === "nodejs"){
191
191
  jsCode += "\nsetup();\nrun();";
192
192
  }
@@ -59,15 +59,22 @@ export class SkipCompiler extends Compiler {
59
59
  throw new Error("Invalid target. Must be IEC, ST, or XML target.");
60
60
  }
61
61
  else {
62
- const action = "to" + target;
62
+ let action = "to" + target;
63
63
  if (!fs.existsSync(outputPath)) {
64
64
  fs.mkdirSync(outputPath);
65
65
  }
66
+ let tojint = false;
67
+ if (action === "tojint") {
68
+ action = "tost";
69
+ tojint = true;
70
+ }
66
71
  runMticp([
67
72
  `action=${action}`,
68
73
  `src=${sourcePath}`,
69
74
  `dst=${outputPath}`
70
- ]).then(output => console.log(output))
75
+ ]).then(output => {
76
+ console.log(output);
77
+ })
71
78
  .catch(err => console.error(err));
72
79
  }
73
80
  }
@@ -15,6 +15,7 @@
15
15
  // limitations under the License.
16
16
 
17
17
 
18
+
18
19
  /**
19
20
  * @description Expression Converter
20
21
  * @author Nathan Skipper, MTI
@@ -72,7 +73,7 @@ export function convertExpression(expr, isjsfb = false, jsfbVars = [], isjs=fals
72
73
  results = tokens.join(' ');
73
74
  // Replace %I/Q/M references
74
75
  const parts = results.split(/\s+/);
75
- results = parts.map(e => {
76
+ results = parts.map((e, index, tks) => {
76
77
  // Don't touch raw address reads
77
78
  if (/^%[IQM][XBWDL]?\d+(\.\d+)?$/i.test(e)) return getReadAddressExpression(e);
78
79
 
@@ -84,7 +85,8 @@ export function convertExpression(expr, isjsfb = false, jsfbVars = [], isjs=fals
84
85
 
85
86
  // Don't wrap dot-bit references already processed
86
87
  if (/^&?[A-Za-z_]\w*\.\d+$/.test(e)) return e;
87
-
88
+ // token is a function call
89
+ if (tks.length > index && tks[index + 1] === "(") return e;
88
90
  // Otherwise, wrap in resolve()
89
91
  if(isjs)
90
92
  return `resolve(${e})`;
@@ -42,7 +42,7 @@ export function transpile(ast) {
42
42
 
43
43
  case 'ProgramDeclaration':
44
44
  lines.push(`export function ${block.name}() { // PROGRAM:${block.name}`);
45
- lines.push(...declareVars(block.varSections),false, block.name);
45
+ lines.push(...declareVars(block.varSections, false, block.name));
46
46
  lines.push(...transpileStatements(block.statements));
47
47
  lines.push('}');
48
48
  break;
@@ -304,12 +304,13 @@ function parseStatementsUntil(endTokens) {
304
304
  while (peek() && peek().value.toUpperCase().startsWith('VAR')) {
305
305
  vars.push(...parseVarSection());
306
306
  }
307
+
308
+ stmts.push(...parseStatements('END_PROGRAM'));
307
309
  vars.forEach((v) => {
308
- if(mapType(v.type) === "auto"){
309
- stmts.push({type: "CALL", name: v.name});
310
+ if (mapType(v.type) === "auto") {
311
+ stmts.push({ type: "CALL", name: v.name });
310
312
  }
311
313
  });
312
- stmts.push(...parseStatements('END_PROGRAM'));
313
314
  expect('END_PROGRAM');
314
315
 
315
316
  return { type: 'ProgramDeclaration', name, varSections: vars, statements: stmts };
@@ -326,12 +327,13 @@ function parseStatementsUntil(endTokens) {
326
327
  while (peek() && peek().value.toUpperCase().startsWith('VAR')) {
327
328
  vars.push(...parseVarSection());
328
329
  }
330
+
331
+ stmts.push(...parseStatements('END_FUNCTION'));
329
332
  vars.forEach((v) => {
330
- if(mapType(v.type) === "auto"){
331
- stmts.push({type: "CALL", name: v.name});
333
+ if (mapType(v.type) === "auto") {
334
+ stmts.push({ type: "CALL", name: v.name });
332
335
  }
333
336
  });
334
- stmts.push(...parseStatements('END_FUNCTION'));
335
337
  expect('END_FUNCTION');
336
338
 
337
339
  return { type: 'FunctionDeclaration', name, returnType, varSections: vars, statements: stmts };
@@ -346,12 +348,13 @@ function parseStatementsUntil(endTokens) {
346
348
  while (peek() && peek().value.toUpperCase().startsWith('VAR')) {
347
349
  vars.push(...parseVarSection());
348
350
  }
351
+
352
+ stmts.push(...parseStatements('END_FUNCTION_BLOCK'));
349
353
  vars.forEach((v) => {
350
- if(mapType(v.type) === "auto"){
351
- stmts.push({type: "CALL", name: v.name});
354
+ if (mapType(v.type) === "auto") {
355
+ stmts.push({ type: "CALL", name: v.name });
352
356
  }
353
357
  });
354
- stmts.push(...parseStatements('END_FUNCTION_BLOCK'));
355
358
  expect('END_FUNCTION_BLOCK');
356
359
 
357
360
  return { type: 'FunctionBlockDeclaration', name, varSections: vars, statements: stmts };