/[svn]/linuxsampler/trunk/src/scriptvm/common.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/common.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2942 by schoenebeck, Wed Jul 13 15:51:06 2016 UTC revision 3034 by schoenebeck, Mon Oct 31 00:05:00 2016 UTC
# Line 160  namespace LinuxSampler { Line 160  namespace LinuxSampler {
160           * @see exprType()           * @see exprType()
161           */           */
162          VMIntArrayExpr* asIntArray() const;          VMIntArrayExpr* asIntArray() const;
163    
164            /**
165             * Returns true in case this expression can be considered to be a
166             * constant expression. A constant expression will retain the same
167             * value throughout the entire life time of a script and the
168             * expression's constant value may be evaluated already at script
169             * parse time, which may result in performance benefits during script
170             * runtime.
171             *
172             * @b NOTE: A constant expression is per se always also non modifyable.
173             * But a non modifyable expression may not necessarily be a constant
174             * expression!
175             *
176             * @see isModifyable()
177             */
178            virtual bool isConstExpr() const = 0;
179    
180            /**
181             * Returns true in case this expression is allowed to be modified.
182             * If this method returns @c false then this expression must be handled
183             * as read-only expression, which means that assigning a new value to it
184             * is either not possible or not allowed.
185             *
186             * @b NOTE: A constant expression is per se always also non modifyable.
187             * But a non modifyable expression may not necessarily be a constant
188             * expression!
189             *
190             * @see isConstExpr()
191             */
192            bool isModifyable() const;
193      };      };
194    
195      /** @brief Virtual machine integer expression      /** @brief Virtual machine integer expression
# Line 366  namespace LinuxSampler { Line 396  namespace LinuxSampler {
396          virtual ExprType_t argType(int iArg) const = 0;          virtual ExprType_t argType(int iArg) const = 0;
397    
398          /**          /**
399           * This function is called by the parser to check whether arguments           * This method is called by the parser to check whether arguments
400           * passed in scripts to this function are accepted by this function. If           * passed in scripts to this function are accepted by this function. If
401           * a script calls this function with an argument's data type not           * a script calls this function with an argument's data type not
402           * accepted by this function, the parser will throw a parser error. On           * accepted by this function, the parser will throw a parser error. On
# Line 384  namespace LinuxSampler { Line 414  namespace LinuxSampler {
414          virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0;          virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0;
415    
416          /**          /**
417             * This method is called by the parser to check whether some arguments
418             * (and if yes which ones) passed to this script function will be
419             * modified by this script function. Most script functions simply use
420             * their arguments as inputs, that is they only read the argument's
421             * values. However some script function may also use passed
422             * argument(s) as output variables. In this case the function
423             * implementation must return @c true for the respective argument
424             * index here.
425             *
426             * @param iArg - index of the function argument in question
427             *               (must be between 0 .. maxAllowedArgs() - 1)
428             */
429            virtual bool modifiesArg(int iArg) const = 0;
430    
431            /**
432           * Implements the actual function execution. This exec() method is           * Implements the actual function execution. This exec() method is
433           * called by the VM whenever this function implementation shall be           * called by the VM whenever this function implementation shall be
434           * executed at script runtime. This method blocks until the function           * executed at script runtime. This method blocks until the function
# Line 423  namespace LinuxSampler { Line 468  namespace LinuxSampler {
468      struct VMRelPtr {      struct VMRelPtr {
469          void** base; ///< Base pointer.          void** base; ///< Base pointer.
470          int offset;  ///< Offset (in bytes) relative to base pointer.          int offset;  ///< Offset (in bytes) relative to base pointer.
471            bool readonly; ///< Whether the pointed data may be modified or just be read.
472      };      };
473    
474      /** @brief Pointer to built-in VM integer variable (of C/C++ type int).      /** @brief Pointer to built-in VM integer variable (of C/C++ type int).
# Line 450  namespace LinuxSampler { Line 496  namespace LinuxSampler {
496          VMIntRelPtr() {          VMIntRelPtr() {
497              base   = NULL;              base   = NULL;
498              offset = 0;              offset = 0;
499                readonly = false;
500          }          }
501          VMIntRelPtr(const VMRelPtr& data) {          VMIntRelPtr(const VMRelPtr& data) {
502              base   = data.base;              base   = data.base;
503              offset = data.offset;              offset = data.offset;
504                readonly = false;
505          }          }
506          virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; }          virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; }
507          virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; }          virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; }
# Line 533  namespace LinuxSampler { Line 581  namespace LinuxSampler {
581       * complexity inside the sampler engines which provide the actual script       * complexity inside the sampler engines which provide the actual script
582       * functionalities.       * functionalities.
583       */       */
584      #define DECLARE_VMINT(basePtr, T_struct, T_member) ( \      #define DECLARE_VMINT(basePtr, T_struct, T_member) (          \
585          (VMRelPtr) {                                     \          /* Disable offsetof warning, trust us, we are cautios. */ \
586              (void**) &basePtr,                           \          _Pragma("GCC diagnostic push")                            \
587              offsetof(T_struct, T_member)                 \          _Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"")  \
588          }                                                \          (VMRelPtr) {                                              \
589      )                                                    \              (void**) &basePtr,                                    \
590                offsetof(T_struct, T_member),                         \
591                false                                                 \
592            }                                                         \
593            _Pragma("GCC diagnostic pop")                             \
594        )                                                             \
595    
596        /**
597         * Same as DECLARE_VMINT(), but this one defines the VMIntRelPtr and
598         * VMInt8RelPtr structures to be of read-only type. That means the script
599         * parser will abort any script at parser time if the script is trying to
600         * modify such a read-only built-in variable.
601         *
602         * @b NOTE: this is only intended for built-in read-only variables that
603         * may change during runtime! If your built-in variable's data is rather
604         * already available at parser time and won't change during runtime, then
605         * you should rather register a built-in constant in your VM class instead!
606         *
607         * @see ScriptVM::builtInConstIntVariables()
608         */
609        #define DECLARE_VMINT_READONLY(basePtr, T_struct, T_member) ( \
610            /* Disable offsetof warning, trust us, we are cautios. */ \
611            _Pragma("GCC diagnostic push")                            \
612            _Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"")  \
613            (VMRelPtr) {                                              \
614                (void**) &basePtr,                                    \
615                offsetof(T_struct, T_member),                         \
616                true                                                  \
617            }                                                         \
618            _Pragma("GCC diagnostic pop")                             \
619        )                                                             \
620    
621      /** @brief Built-in VM 8 bit integer array variable.      /** @brief Built-in VM 8 bit integer array variable.
622       *       *
# Line 553  namespace LinuxSampler { Line 631  namespace LinuxSampler {
631          VMInt8Array() : data(NULL), size(0) {}          VMInt8Array() : data(NULL), size(0) {}
632      };      };
633    
634        /** @brief Virtual machine script variable.
635         *
636         * Common interface for all variables accessed in scripts.
637         */
638        class VMVariable : virtual public VMExpr {
639        public:
640            /**
641             * Whether a script may modify the content of this variable by
642             * assigning a new value to it.
643             *
644             * @see isConstExpr(), assign()
645             */
646            virtual bool isAssignable() const = 0;
647    
648            /**
649             * In case this variable is assignable, this method will be called to
650             * perform the value assignment to this variable with @a expr
651             * reflecting the new value to be assigned.
652             *
653             * @param expr - new value to be assigned to this variable
654             */
655            virtual void assignExpr(VMExpr* expr) = 0;
656        };
657        
658      /** @brief Dynamically executed variable (abstract base class).      /** @brief Dynamically executed variable (abstract base class).
659       *       *
660       * Interface for the implementation of a dynamically generated content of       * Interface for the implementation of a dynamically generated content of
# Line 563  namespace LinuxSampler { Line 665  namespace LinuxSampler {
665       * to a dynamic variable some native code is executed to actually generate       * to a dynamic variable some native code is executed to actually generate
666       * and provide the content (value) of this type of variable.       * and provide the content (value) of this type of variable.
667       */       */
668      class VMDynVar : virtual public VMExpr {      class VMDynVar : public VMVariable {
669      public:      public:
670          /**          /**
          * Whether a script may modify the content of this dynamic variable by  
          * assigning a new value to it.  
          *  
          * @see isConstExpr(), assign()  
          */  
         virtual bool isAssignable() const = 0;  
   
         /**  
671           * Returns true in case this dynamic variable can be considered to be a           * Returns true in case this dynamic variable can be considered to be a
672           * constant expression. A constant expression will retain the same value           * constant expression. A constant expression will retain the same value
673           * throughout the entire life time of a script and the expression's           * throughout the entire life time of a script and the expression's
# Line 609  namespace LinuxSampler { Line 703  namespace LinuxSampler {
703           *           *
704           * @see isAssignable()           * @see isAssignable()
705           */           */
706          virtual bool isConstExpr() const { return false; }          bool isConstExpr() const OVERRIDE { return false; }
707    
708          /**          /**
709           * In case this dynamic variable is assignable, the new value (content)           * In case this dynamic variable is assignable, the new value (content)
# Line 621  namespace LinuxSampler { Line 715  namespace LinuxSampler {
715           *           *
716           * @param expr - new value to be assigned to this variable           * @param expr - new value to be assigned to this variable
717           */           */
718          virtual void assign(VMExpr* expr) {}          void assignExpr(VMExpr* expr) OVERRIDE {}
719    
720            virtual ~VMDynVar() {}
721      };      };
722    
723      /** @brief Dynamically executed variable (of integer data type).      /** @brief Dynamically executed variable (of integer data type).
# Line 762  namespace LinuxSampler { Line 858  namespace LinuxSampler {
858       * issue (either a parser error or parser warning), a human readable       * issue (either a parser error or parser warning), a human readable
859       * explanation text of the error or warning and the location of the       * explanation text of the error or warning and the location of the
860       * encountered parser issue within the script.       * encountered parser issue within the script.
861         *
862         * @see VMSourceToken for processing syntax highlighting instead.
863       */       */
864      struct ParserIssue {      struct ParserIssue {
865          String txt; ///< Human readable explanation text of the parser issue.          String txt; ///< Human readable explanation text of the parser issue.
# Line 880  namespace LinuxSampler { Line 978  namespace LinuxSampler {
978       * This class is not actually used by the sampler itself. It is rather       * This class is not actually used by the sampler itself. It is rather
979       * provided for external script editor applications. Primary purpose of       * provided for external script editor applications. Primary purpose of
980       * this class is syntax highlighting for external script editors.       * this class is syntax highlighting for external script editors.
981         *
982         * @see ParserIssue for processing compile errors and warnings instead.
983       */       */
984      class VMSourceToken {      class VMSourceToken {
985      public:      public:
# Line 892  namespace LinuxSampler { Line 992  namespace LinuxSampler {
992          String text() const;          String text() const;
993    
994          // position of token in script          // position of token in script
995          int firstLine() const; ///< First line this source token is located at in script source code (indexed with 0 being the very first line).          int firstLine() const; ///< First line this source token is located at in script source code (indexed with 0 being the very first line). Most source code tokens are not spanning over multiple lines, the only current exception are comments, in the latter case you need to process text() to get the last line and last column for the comment.
996          int firstColumn() const; ///< Last line this source token is located at in script source code.          int firstColumn() const; ///< First column on the first line this source token is located at in script source code (indexed with 0 being the very first column). To get the length of this token use text().length().
997    
998          // base types          // base types
999          bool isEOF() const;          bool isEOF() const; ///< Returns true in case this source token represents the end of the source code file.
1000          bool isNewLine() const;          bool isNewLine() const; ///< Returns true in case this source token represents a line feed character (i.e. "\n" on Unix systems).
1001          bool isKeyword() const;          bool isKeyword() const; ///< Returns true in case this source token represents a language keyword (i.e. "while", "function", "declare", "on", etc.).
1002          bool isVariableName() const;          bool isVariableName() const; ///< Returns true in case this source token represents a variable name (i.e. "$someIntVariable", "%someArrayVariable", "\@someStringVariable"). @see isIntegerVariable(), isStringVariable(), isArrayVariable() for the precise variable type.
1003          bool isIdentifier() const;          bool isIdentifier() const; ///< Returns true in case this source token represents an identifier, which currently always means a function name.
1004          bool isNumberLiteral() const;          bool isNumberLiteral() const; ///< Returns true in case this source token represents a number literal (i.e. 123).
1005          bool isStringLiteral() const;          bool isStringLiteral() const; ///< Returns true in case this source token represents a string literal (i.e. "Some text").
1006          bool isComment() const;          bool isComment() const; ///< Returns true in case this source token represents a source code comment.
1007          bool isPreprocessor() const;          bool isPreprocessor() const; ///< Returns true in case this source token represents a preprocessor statement.
1008          bool isOther() const;          bool isOther() const; ///< Returns true in case this source token represents anything else not covered by the token types mentioned above.
1009    
1010          // extended types          // extended types
1011          bool isIntegerVariable() const;          bool isIntegerVariable() const; ///< Returns true in case this source token represents an integer variable name (i.e. "$someIntVariable").
1012          bool isStringVariable() const;          bool isStringVariable() const; ///< Returns true in case this source token represents an string variable name (i.e. "\@someStringVariable").
1013          bool isArrayVariable() const;          bool isArrayVariable() const; ///< Returns true in case this source token represents an array variable name (i.e. "%someArryVariable").
1014          bool isEventHandlerName() const;          bool isEventHandlerName() const; ///< Returns true in case this source token represents an event handler name (i.e. "note", "release", "controller").
1015    
1016          VMSourceToken& operator=(const VMSourceToken& other);          VMSourceToken& operator=(const VMSourceToken& other);
1017    

Legend:
Removed from v.2942  
changed lines
  Added in v.3034

  ViewVC Help
Powered by ViewVC