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

Contents of /linuxsampler/trunk/src/scriptvm/CoreVMFunctions.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2619 - (show annotations) (download) (as text)
Wed Jun 11 13:24:32 2014 UTC (9 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4035 byte(s)
* Implemented built-in instrument script function "abs()".
* Implemented built-in instrument script function "random()".
* Implemented built-in instrument script function "num_elements()".
* Disabled debug mode of RefPtr template class.
* Bumped version (1.0.0.svn51).

1 /*
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 #ifndef LS_COREVMFUNCTIONS_H
11 #define LS_COREVMFUNCTIONS_H
12
13 #include "../common/global.h"
14 #include "common.h"
15
16 namespace LinuxSampler {
17
18 class ScriptVM;
19
20 class VMEmptyResult : public VMFnResult, public VMExpr {
21 public:
22 StmtFlags_t flags;
23
24 VMEmptyResult() : flags(STMT_SUCCESS) {}
25 ExprType_t exprType() const { return EMPTY_EXPR; }
26 VMExpr* resultValue() { return this; }
27 StmtFlags_t resultFlags() { return flags; }
28 };
29
30 class VMIntResult : public VMFnResult, public VMIntExpr {
31 public:
32 StmtFlags_t flags;
33 int value;
34
35 VMIntResult() : flags(STMT_SUCCESS) {}
36 int evalInt() { return value; }
37 VMExpr* resultValue() { return this; }
38 StmtFlags_t resultFlags() { return flags; }
39 };
40
41 class VMStringResult : public VMFnResult, public VMStringExpr {
42 public:
43 StmtFlags_t flags;
44 String value;
45
46 VMStringResult() : flags(STMT_SUCCESS) {}
47 String evalStr() { return value; }
48 VMExpr* resultValue() { return this; }
49 StmtFlags_t resultFlags() { return flags; }
50 };
51
52 class VMEmptyResultFunction : public VMFunction {
53 protected:
54 ExprType_t returnType() { return EMPTY_EXPR; }
55 VMFnResult* errorResult();
56 VMFnResult* successResult();
57 protected:
58 VMEmptyResult result;
59 };
60
61 class VMIntResultFunction : public VMFunction {
62 protected:
63 ExprType_t returnType() { return INT_EXPR; }
64 VMFnResult* errorResult(int i = 0);
65 VMFnResult* successResult(int i = 0);
66 protected:
67 VMIntResult result;
68 };
69
70 class VMStringResultFunction : public VMFunction {
71 protected:
72 ExprType_t returnType() { return STRING_EXPR; }
73 VMFnResult* errorResult(const String& s = "");
74 VMFnResult* successResult(const String& s = "");
75 protected:
76 VMStringResult result;
77 };
78
79 class CoreVMFunction_message : public VMEmptyResultFunction {
80 public:
81 int minRequiredArgs() const { return 1; }
82 int maxAllowedArgs() const { return 1; }
83 bool acceptsArgType(int iArg, ExprType_t type) const;
84 ExprType_t argType(int iArg) const { return STRING_EXPR; }
85 VMFnResult* exec(VMFnArgs* args);
86 };
87
88 class CoreVMFunction_exit : public VMEmptyResultFunction {
89 public:
90 int minRequiredArgs() const { return 0; }
91 int maxAllowedArgs() const { return 0; }
92 bool acceptsArgType(int iArg, ExprType_t type) const { return false; }
93 ExprType_t argType(int iArg) const { return INT_EXPR; /*whatever*/ }
94 VMFnResult* exec(VMFnArgs* args);
95 };
96
97 class CoreVMFunction_wait : public VMEmptyResultFunction {
98 public:
99 CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}
100 int minRequiredArgs() const { return 1; }
101 int maxAllowedArgs() const { return 1; }
102 bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; }
103 ExprType_t argType(int iArg) const { return INT_EXPR; }
104 VMFnResult* exec(VMFnArgs* args);
105 protected:
106 ScriptVM* vm;
107 };
108
109 class CoreVMFunction_abs : public VMIntResultFunction {
110 public:
111 int minRequiredArgs() const { return 1; }
112 int maxAllowedArgs() const { return 1; }
113 bool acceptsArgType(int iArg, ExprType_t type) const;
114 ExprType_t argType(int iArg) const { return INT_EXPR; }
115 VMFnResult* exec(VMFnArgs* args);
116 };
117
118 class CoreVMFunction_random : public VMIntResultFunction {
119 public:
120 int minRequiredArgs() const { return 2; }
121 int maxAllowedArgs() const { return 2; }
122 bool acceptsArgType(int iArg, ExprType_t type) const;
123 ExprType_t argType(int iArg) const { return INT_EXPR; }
124 VMFnResult* exec(VMFnArgs* args);
125 };
126
127 class CoreVMFunction_num_elements : public VMIntResultFunction {
128 public:
129 int minRequiredArgs() const { return 1; }
130 int maxAllowedArgs() const { return 1; }
131 bool acceptsArgType(int iArg, ExprType_t type) const;
132 ExprType_t argType(int iArg) const { return INT_ARR_EXPR; }
133 VMFnResult* exec(VMFnArgs* args);
134 };
135
136 } // namespace LinuxSampler
137
138 #endif // LS_COREVMFUNCTIONS_H

  ViewVC Help
Powered by ViewVC