12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import * as Commands from './../../ast/commands';
- import { Types } from './../../typeSystem/types';
- import { toInt } from "./../../typeSystem/parsers";
- import { ArrayType } from '../../typeSystem/array_type';
- import { Modes } from '../modes';
- import { StoreValue } from '../store/value/store_value';
- /**
- * num_elements
- * matrix_lines
- * matrix_columns
- */
- export function createNumElementsFun () {
- const numElementsFun = (sto, _) => {
- const vector = sto.applyStore("vector");
- const temp = new StoreValue(Types.INTEGER, toInt(vector.lines));
- sto.mode = Modes.RETURN;
- sto.insertStore("$", temp);
- return Promise.resolve(sto);
- }
- const block = new Commands.CommandBlock([], [new Commands.SysCall(numElementsFun)]);
- const func = new Commands.Function('$numElements', Types.INTEGER,
- [new Commands.FormalParameter(new ArrayType(Types.ALL, 1), 'vector', false)],
- block);
- return func;
- }
- export function createMatrixLinesFun () {
- const matrixLinesFun = (sto, _) => {
- const matrix = sto.applyStore("matrix");
- const temp = new StoreValue(Types.INTEGER, toInt(matrix.lines));
- sto.mode = Modes.RETURN;
- sto.insertStore("$", temp);
- return Promise.resolve(sto);
- }
- const block = new Commands.CommandBlock([], [new Commands.SysCall(matrixLinesFun)]);
- const func = new Commands.Function('$matrixLines', Types.INTEGER,
- [new Commands.FormalParameter(new ArrayType(Types.ALL, 2), 'matrix', false)],
- block);
- return func;
- }
- export function createMatrixColumnsFun () {
- const matrixColumnsFun = (sto, _) => {
- const matrix = sto.applyStore("matrix");
- const temp = new StoreValue(Types.INTEGER, toInt(matrix.columns));
- sto.mode = Modes.RETURN;
- sto.insertStore("$", temp);
- return Promise.resolve(sto);
- }
- const block = new Commands.CommandBlock([], [new Commands.SysCall(matrixColumnsFun)]);
- const func = new Commands.Function('$matrixColumns', Types.INTEGER,
- [new Commands.FormalParameter(new ArrayType(Types.ALL, 2), 'matrix', false)],
- block);
- return func;
- }
-
|