Interpreter.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef _Interpreter_h_
  2. #define _Interpreter_h_
  3. /* Interpreter.h
  4. *
  5. * Copyright (C) 1993-2018 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "Collection.h"
  21. #include "Gui.h"
  22. #include "Formula.h"
  23. #include <string>
  24. #include <unordered_map>
  25. Thing_define (InterpreterVariable, SimpleString) {
  26. autostring32 stringValue;
  27. double numericValue;
  28. autoVEC numericVectorValue;
  29. autoMAT numericMatrixValue;
  30. };
  31. #define Interpreter_MAXNUM_PARAMETERS 400
  32. #define Interpreter_MAXNUM_LABELS 1000
  33. #define Interpreter_MAX_CALL_DEPTH 50
  34. #define Interpreter_MAX_DIALOG_TITLE_LENGTH 100
  35. #define Interpreter_MAX_LABEL_LENGTH 99
  36. Thing_declare (UiForm);
  37. Thing_declare (Editor);
  38. Thing_define (Interpreter, Thing) {
  39. autostring32 environmentName;
  40. ClassInfo editorClass;
  41. int numberOfParameters, numberOfLabels, callDepth;
  42. char32 parameters [1+Interpreter_MAXNUM_PARAMETERS] [100];
  43. int types [1+Interpreter_MAXNUM_PARAMETERS];
  44. autostring32 arguments [1+Interpreter_MAXNUM_PARAMETERS];
  45. char32 choiceArguments [1+Interpreter_MAXNUM_PARAMETERS] [100];
  46. char32 labelNames [1+Interpreter_MAXNUM_LABELS] [1+Interpreter_MAX_LABEL_LENGTH];
  47. integer labelLines [1+Interpreter_MAXNUM_LABELS];
  48. char32 dialogTitle [1+Interpreter_MAX_DIALOG_TITLE_LENGTH], procedureNames [1+Interpreter_MAX_CALL_DEPTH] [100];
  49. std::unordered_map <std::u32string, autoInterpreterVariable> variablesMap;
  50. bool running, stopped;
  51. };
  52. autoInterpreter Interpreter_create (conststring32 environmentName, ClassInfo editorClass);
  53. autoInterpreter Interpreter_createFromEnvironment (Editor editor);
  54. void Melder_includeIncludeFiles (autostring32 *text);
  55. integer Interpreter_readParameters (Interpreter me, mutablestring32 text);
  56. Thing_declare (UiForm);
  57. autoUiForm Interpreter_createForm (Interpreter me, GuiWindow parent, conststring32 fileName,
  58. void (*okCallback) (UiForm sendingForm, integer narg, Stackel args, conststring32 sendingString, Interpreter interpreter, conststring32 invokingButtonTitle, bool modified, void *closure), void *okClosure,
  59. bool selectionOnly);
  60. void Interpreter_getArgumentsFromDialog (Interpreter me, UiForm dialog);
  61. void Interpreter_getArgumentsFromString (Interpreter me, conststring32 arguments);
  62. void Interpreter_getArgumentsFromArgs (Interpreter me, int nargs, Stackel args);
  63. void Interpreter_run (Interpreter me, char32 *text); // destroys 'text'
  64. void Interpreter_stop (Interpreter me); // can be called from any procedure called deep-down by the interpreter; will stop before next line
  65. void Interpreter_voidExpression (Interpreter me, conststring32 expression);
  66. void Interpreter_numericExpression (Interpreter me, conststring32 expression, double *p_value);
  67. void Interpreter_numericVectorExpression (Interpreter me, conststring32 expression, VEC *p_value, bool *p_owned);
  68. void Interpreter_numericMatrixExpression (Interpreter me, conststring32 expression, MAT *p_value, bool *p_owned);
  69. autostring32 Interpreter_stringExpression (Interpreter me, conststring32 expression);
  70. void Interpreter_anyExpression (Interpreter me, conststring32 expression, Formula_Result *p_result);
  71. InterpreterVariable Interpreter_hasVariable (Interpreter me, conststring32 key);
  72. InterpreterVariable Interpreter_lookUpVariable (Interpreter me, conststring32 key);
  73. extern autoVEC theInterpreterNumvec;
  74. extern autoMAT theInterpreterNummat;
  75. /* End of file Interpreter.h */
  76. #endif