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

Annotation of /linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2581 - (hide annotations) (download)
Fri May 30 12:48:05 2014 UTC (9 years, 10 months ago) by schoenebeck
File size: 2032 byte(s)
* (WIP) Implemented parser and VM for upcoming new real-time instrument
  script support. It needs yet to be integrated into the sampler's
  sampler engines. You can toy around for now with the command line tool
  "ls_instr_script" and i.e. examples showing the core language features
  under src/scriptvm/examples/.
* Bumped version (1.0.0.svn41).

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     #include "CoreVMFunctions.h"
11    
12     #include <iostream>
13     #include "tree.h"
14     #include "ScriptVM.h"
15    
16     namespace LinuxSampler {
17    
18     VMFnResult* VMEmptyResultFunction::errorResult() {
19     result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED);
20     return &result;
21     }
22    
23     VMFnResult* VMEmptyResultFunction::successResult() {
24     result.flags = STMT_SUCCESS;
25     return &result;
26     }
27    
28     VMFnResult* VMStringResultFunction::errorResult(const String& s) {
29     result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED);
30     result.value = s;
31     return &result;
32     }
33    
34     VMFnResult* VMStringResultFunction::successResult(const String& s) {
35     result.flags = STMT_SUCCESS;
36     result.value = s;
37     return &result;
38     }
39    
40     bool CoreVMFunction_message::acceptsArgType(int iArg, ExprType_t type) const {
41     return type == INT_EXPR || type == STRING_EXPR;
42     }
43    
44     VMFnResult* CoreVMFunction_message::exec(VMFnArgs* args) {
45     if (!args->argsCount()) return errorResult();
46    
47     VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(args->arg(0));
48     if (strExpr) {
49     std::cout << "[ScriptVM] " << strExpr->evalStr() << "\n";
50     return successResult();
51     }
52    
53     VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(args->arg(0));
54     if (intExpr) {
55     std::cout << "[ScriptVM] " << intExpr->evalInt() << "\n";
56     return successResult();
57     }
58    
59     return errorResult();
60     }
61    
62     VMFnResult* CoreVMFunction_exit::exec(VMFnArgs* args) {
63     this->result.flags = STMT_ABORT_SIGNALLED;
64     return &result;
65     }
66    
67     VMFnResult* CoreVMFunction_wait::exec(VMFnArgs* args) {
68     ExecContext* ctx = dynamic_cast<ExecContext*>(vm->currentVMExecContext());
69     VMIntExpr* expr = dynamic_cast<VMIntExpr*>(args->arg(0));
70     ctx->suspendMicroseconds = expr->evalInt();
71     this->result.flags = STMT_SUSPEND_SIGNALLED;
72     return &result;
73     }
74    
75     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC