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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2588 - (hide annotations) (download) (as text)
Sun Jun 1 14:44:38 2014 UTC (9 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4254 byte(s)
* ScriptVM: refactoring and fixes.

1 schoenebeck 2581 /*
2     * Copyright (c) 2014 Christian Schoenebeck
3     *
4     * http://www.linuxsampler.org
5     *
6     * This file is part of LinuxSampler and released under the same terms.
7     * See README file for details.
8     */
9    
10     // This header defines data types shared between the VM core implementation
11     // (inside the current source directory) and other parts of the sampler
12     // (located at other source directories).
13    
14     #ifndef LS_INSTR_SCRIPT_PARSER_COMMON_H
15     #define LS_INSTR_SCRIPT_PARSER_COMMON_H
16    
17     #include "../common/global.h"
18 schoenebeck 2588 #include <vector>
19 schoenebeck 2581
20     namespace LinuxSampler {
21    
22     enum ParserIssueType_t {
23     PARSER_ERROR,
24     PARSER_WARNING
25     };
26    
27     enum ExprType_t {
28     EMPTY_EXPR, ///< i.e. on invalid expressions or i.e. a function call that does not return a result value
29     INT_EXPR,
30     INT_ARR_EXPR,
31     STRING_EXPR,
32     STRING_ARR_EXPR,
33     };
34    
35     enum StmtFlags_t {
36     STMT_SUCCESS = 0, ///< Function / statement was executed successfully, no error occurred.
37     STMT_ABORT_SIGNALLED = 1, ///< VM should stop the current callback execution (usually because of an error, but might also be without an error reason).
38     STMT_SUSPEND_SIGNALLED = (1<<1),
39     STMT_ERROR_OCCURRED = (1<<2),
40     };
41    
42     enum VMExecStatus_t {
43     VM_EXEC_NOT_RUNNING = 0,
44     VM_EXEC_RUNNING = 1,
45     VM_EXEC_SUSPENDED = (1<<1),
46     VM_EXEC_ERROR = (1<<2),
47     };
48    
49     class VMExpr {
50     public:
51     virtual ExprType_t exprType() const = 0;
52     };
53    
54     class VMIntExpr : virtual public VMExpr {
55     public:
56     virtual int evalInt() = 0;
57     ExprType_t exprType() const { return INT_EXPR; }
58     };
59    
60     class VMStringExpr : virtual public VMExpr {
61     public:
62     virtual String evalStr() = 0;
63     ExprType_t exprType() const { return STRING_EXPR; }
64     };
65    
66     class VMFnArgs {
67     public:
68     virtual int argsCount() const = 0;
69     virtual VMExpr* arg(int i) = 0;
70     };
71    
72     class VMFnResult {
73     public:
74     virtual VMExpr* resultValue() = 0;
75     virtual StmtFlags_t resultFlags() { return STMT_SUCCESS; }
76     };
77    
78     class VMFunction {
79     public:
80     virtual ExprType_t returnType() = 0;
81     virtual int minRequiredArgs() const = 0;
82     virtual int maxAllowedArgs() const = 0;
83     virtual ExprType_t argType(int iArg) const = 0;
84     virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0;
85     virtual VMFnResult* exec(VMFnArgs* args) = 0;
86     };
87    
88     class VMFunctionProvider {
89     public:
90     virtual VMFunction* functionByName(const String& name) = 0;
91     };
92    
93     class VMExecContext {
94     public:
95     virtual ~VMExecContext() {}
96     virtual int suspensionTimeMicroseconds() const = 0;
97     };
98    
99     class VMEventHandler {
100     public:
101     virtual String eventHandlerName() const = 0;
102     };
103    
104     struct ParserIssue {
105     String txt;
106     int line;
107     ParserIssueType_t type;
108    
109     inline void dump() {
110     switch (type) {
111     case PARSER_ERROR:
112     printf("[ERROR] line %d: %s\n", line, txt.c_str());
113     break;
114     case PARSER_WARNING:
115     printf("[Warning] line %d: %s\n", line, txt.c_str());
116     break;
117     }
118     }
119    
120     inline bool isErr() const { return type == PARSER_ERROR; }
121     inline bool isWrn() const { return type == PARSER_WARNING; }
122     };
123    
124     inline String typeStr(const ExprType_t& type) {
125     switch (type) {
126     case EMPTY_EXPR: return "empty";
127     case INT_EXPR: return "integer";
128     case INT_ARR_EXPR: return "integer array";
129     case STRING_EXPR: return "string";
130     case STRING_ARR_EXPR: return "string array";
131     }
132     return "invalid";
133     }
134    
135 schoenebeck 2588 class VMParserContext {
136     public:
137     virtual ~VMParserContext() {}
138     virtual std::vector<ParserIssue> issues() const = 0;
139     virtual std::vector<ParserIssue> errors() const = 0;
140     virtual std::vector<ParserIssue> warnings() const = 0;
141     virtual VMEventHandler* eventHandler(uint index) = 0;
142     virtual VMEventHandler* eventHandlerByName(const String& name) = 0;
143     };
144    
145 schoenebeck 2581 } // namespace LinuxSampler
146    
147     #endif // LS_INSTR_SCRIPT_PARSER_COMMON_H

  ViewVC Help
Powered by ViewVC