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 |
|
|
|
19 |
|
|
namespace LinuxSampler { |
20 |
|
|
|
21 |
|
|
enum ParserIssueType_t { |
22 |
|
|
PARSER_ERROR, |
23 |
|
|
PARSER_WARNING |
24 |
|
|
}; |
25 |
|
|
|
26 |
|
|
enum ExprType_t { |
27 |
|
|
EMPTY_EXPR, ///< i.e. on invalid expressions or i.e. a function call that does not return a result value |
28 |
|
|
INT_EXPR, |
29 |
|
|
INT_ARR_EXPR, |
30 |
|
|
STRING_EXPR, |
31 |
|
|
STRING_ARR_EXPR, |
32 |
|
|
}; |
33 |
|
|
|
34 |
|
|
enum StmtFlags_t { |
35 |
|
|
STMT_SUCCESS = 0, ///< Function / statement was executed successfully, no error occurred. |
36 |
|
|
STMT_ABORT_SIGNALLED = 1, ///< VM should stop the current callback execution (usually because of an error, but might also be without an error reason). |
37 |
|
|
STMT_SUSPEND_SIGNALLED = (1<<1), |
38 |
|
|
STMT_ERROR_OCCURRED = (1<<2), |
39 |
|
|
}; |
40 |
|
|
|
41 |
|
|
enum VMExecStatus_t { |
42 |
|
|
VM_EXEC_NOT_RUNNING = 0, |
43 |
|
|
VM_EXEC_RUNNING = 1, |
44 |
|
|
VM_EXEC_SUSPENDED = (1<<1), |
45 |
|
|
VM_EXEC_ERROR = (1<<2), |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
class VMExpr { |
49 |
|
|
public: |
50 |
|
|
virtual ExprType_t exprType() const = 0; |
51 |
|
|
}; |
52 |
|
|
|
53 |
|
|
class VMIntExpr : virtual public VMExpr { |
54 |
|
|
public: |
55 |
|
|
virtual int evalInt() = 0; |
56 |
|
|
ExprType_t exprType() const { return INT_EXPR; } |
57 |
|
|
}; |
58 |
|
|
|
59 |
|
|
class VMStringExpr : virtual public VMExpr { |
60 |
|
|
public: |
61 |
|
|
virtual String evalStr() = 0; |
62 |
|
|
ExprType_t exprType() const { return STRING_EXPR; } |
63 |
|
|
}; |
64 |
|
|
|
65 |
|
|
class VMFnArgs { |
66 |
|
|
public: |
67 |
|
|
virtual int argsCount() const = 0; |
68 |
|
|
virtual VMExpr* arg(int i) = 0; |
69 |
|
|
}; |
70 |
|
|
|
71 |
|
|
class VMFnResult { |
72 |
|
|
public: |
73 |
|
|
virtual VMExpr* resultValue() = 0; |
74 |
|
|
virtual StmtFlags_t resultFlags() { return STMT_SUCCESS; } |
75 |
|
|
}; |
76 |
|
|
|
77 |
|
|
class VMFunction { |
78 |
|
|
public: |
79 |
|
|
virtual ExprType_t returnType() = 0; |
80 |
|
|
virtual int minRequiredArgs() const = 0; |
81 |
|
|
virtual int maxAllowedArgs() const = 0; |
82 |
|
|
virtual ExprType_t argType(int iArg) const = 0; |
83 |
|
|
virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0; |
84 |
|
|
virtual VMFnResult* exec(VMFnArgs* args) = 0; |
85 |
|
|
}; |
86 |
|
|
|
87 |
|
|
class VMFunctionProvider { |
88 |
|
|
public: |
89 |
|
|
virtual VMFunction* functionByName(const String& name) = 0; |
90 |
|
|
}; |
91 |
|
|
|
92 |
|
|
class VMParserContext { |
93 |
|
|
public: |
94 |
|
|
virtual ~VMParserContext() {} |
95 |
|
|
}; |
96 |
|
|
|
97 |
|
|
class VMExecContext { |
98 |
|
|
public: |
99 |
|
|
virtual ~VMExecContext() {} |
100 |
|
|
virtual int suspensionTimeMicroseconds() const = 0; |
101 |
|
|
}; |
102 |
|
|
|
103 |
|
|
class VMEventHandler { |
104 |
|
|
public: |
105 |
|
|
virtual String eventHandlerName() const = 0; |
106 |
|
|
}; |
107 |
|
|
|
108 |
|
|
struct ParserIssue { |
109 |
|
|
String txt; |
110 |
|
|
int line; |
111 |
|
|
ParserIssueType_t type; |
112 |
|
|
|
113 |
|
|
inline void dump() { |
114 |
|
|
switch (type) { |
115 |
|
|
case PARSER_ERROR: |
116 |
|
|
printf("[ERROR] line %d: %s\n", line, txt.c_str()); |
117 |
|
|
break; |
118 |
|
|
case PARSER_WARNING: |
119 |
|
|
printf("[Warning] line %d: %s\n", line, txt.c_str()); |
120 |
|
|
break; |
121 |
|
|
} |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
inline bool isErr() const { return type == PARSER_ERROR; } |
125 |
|
|
inline bool isWrn() const { return type == PARSER_WARNING; } |
126 |
|
|
}; |
127 |
|
|
|
128 |
|
|
inline String typeStr(const ExprType_t& type) { |
129 |
|
|
switch (type) { |
130 |
|
|
case EMPTY_EXPR: return "empty"; |
131 |
|
|
case INT_EXPR: return "integer"; |
132 |
|
|
case INT_ARR_EXPR: return "integer array"; |
133 |
|
|
case STRING_EXPR: return "string"; |
134 |
|
|
case STRING_ARR_EXPR: return "string array"; |
135 |
|
|
} |
136 |
|
|
return "invalid"; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
} // namespace LinuxSampler |
140 |
|
|
|
141 |
|
|
#endif // LS_INSTR_SCRIPT_PARSER_COMMON_H |