definedFunctions.js 798 B

12345678910111213141516171819202122232425262728
  1. import * as Commands from './../ast/commands';
  2. import {Types} from './../ast/types';
  3. function createOutputFun () {
  4. const block = new Commands.CommandBlock([], [new Commands.SysCall('$write')]);
  5. const func = new Commands.Function('$write', Types.VOID,
  6. [new Commands.FormalParameter(Types.ALL, 'p1', 0, true)],
  7. block);
  8. return func;
  9. }
  10. function createInputFun () {
  11. const block = new Commands.CommandBlock([], [new Commands.SysCall('$read')]);
  12. const func = new Commands.Function('$read', Types.VOID,
  13. [new Commands.FormalParameter(Types.ALL, 'p1', 0, true)],
  14. block);
  15. return func;
  16. }
  17. export const LanguageDefinedFunction = Object.freeze({
  18. $write: createOutputFun(),
  19. $read: createInputFun()
  20. });
  21. export const NAMES = Object.freeze({
  22. WRITE: '$write',
  23. READ: '$read'
  24. });