Subversion Repositories HomeAutomation

Rev

Rev 1741 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1741 Rev 2107
1
/*
1
/*
2
 *
2
 *
3
 *  Copyright (C) 2010  Mattias Runge
3
 *  Copyright (C) 2010  Mattias Runge
4
 *
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
8
 *  (at your option) any later version.
9
 *
9
 *
10
 *  This program is distributed in the hope that it will be useful,
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
13
 *  GNU General Public License for more details.
14
 *
14
 *
15
 *  You should have received a copy of the GNU General Public License along
15
 *  You should have received a copy of the GNU General Public License along
16
 *  with this program; if not, write to the Free Software Foundation, Inc.,
16
 *  with this program; if not, write to the Free Software Foundation, Inc.,
17
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
18
 *
19
 */
19
 */
20
 
20
 
21
#include "Manager.h"
21
#include "Manager.h"
22
 
22
 
23
#include <fstream>
23
#include <fstream>
24
 
24
 
25
#include <boost/lexical_cast.hpp>
25
#include <boost/lexical_cast.hpp>
26
#include <boost/bind.hpp>
26
#include <boost/bind.hpp>
27
 
27
 
28
namespace atom {
28
namespace atom {
29
namespace vm {
29
namespace vm {
30
 
30
 
31
Manager::Pointer Manager::instance_;
31
Manager::Pointer Manager::instance_;
32
 
32
 
33
Manager::Manager() : LOG("vm::Manager")
33
Manager::Manager() : LOG("vm::Manager")
34
{
34
{
35
}
35
}
36
 
36
 
37
Manager::~Manager()
37
Manager::~Manager()
38
{
38
{
39
    this->io_service_.stop();
39
    this->io_service_.stop();
40
   
40
   
41
    this->plugins_.clear();
41
    this->plugins_.clear();
42
    this->context_.Dispose();
42
    this->context_.Dispose();
43
 
43
 
44
    for (ImportFunctionList::iterator it = this->functions_.begin(); it != this->functions_.end(); it++)
44
    for (ImportFunctionList::iterator it = this->functions_.begin(); it != this->functions_.end(); it++)
45
    {
45
    {
46
        it->second.Dispose();
46
        it->second.Dispose();
47
    }
47
    }
48
}
48
}
49
 
49
 
50
void Manager::Create()
50
void Manager::Create()
51
{
51
{
52
    Manager::instance_ = Manager::Pointer(new Manager());
52
    Manager::instance_ = Manager::Pointer(new Manager());
53
}
53
}
54
 
54
 
55
Manager::Pointer Manager::Instance()
55
Manager::Pointer Manager::Instance()
56
{
56
{
57
    return Manager::instance_;
57
    return Manager::instance_;
58
}
58
}
59
 
59
 
60
void Manager::Delete()
60
void Manager::Delete()
61
{
61
{
62
    Manager::instance_.reset();
62
    Manager::instance_.reset();
63
}
63
}
64
 
64
 
65
v8::Persistent<v8::Context>& Manager::GetContext()
65
v8::Persistent<v8::Context>& Manager::GetContext()
66
{
66
{
67
    return this->context_;
67
    return this->context_;
68
}
68
}
69
 
69
 
70
void Manager::AddPlugin(Plugin::Pointer plugin)
70
void Manager::AddPlugin(Plugin::Pointer plugin)
71
{
71
{
72
    this->plugins_.push_back(plugin);
72
    this->plugins_.push_back(plugin);
73
}
73
}
74
 
74
 
75
void Manager::Start(std::string script_path, std::string user_script_path)
75
void Manager::Start(std::string script_path, std::string user_script_path)
76
{
76
{
77
    this->script_path_ = script_path;
77
    this->script_path_ = script_path;
78
    this->user_script_path_ = user_script_path;
78
    this->user_script_path_ = user_script_path;
79
    this->io_service_.post(boost::bind(&Manager::StartHandler, this));
79
    this->io_service_.post(boost::bind(&Manager::StartHandler, this));
80
}
80
}
81
 
81
 
82
void Manager::CallOutput(std::string output)
82
void Manager::CallOutput(std::string output)
83
{
83
{
84
    if (this->current_plugin_name_ != "")
84
    if (this->current_plugin_name_ != "")
85
    {
85
    {
86
        for (unsigned int n = 0; n < this->plugins_.size(); n++)
86
        for (unsigned int n = 0; n < this->plugins_.size(); n++)
87
        {
87
        {
88
            if (this->plugins_[n]->GetName() == this->current_plugin_name_)
88
            if (this->plugins_[n]->GetName() == this->current_plugin_name_)
89
            {
89
            {
90
                this->plugins_[n]->CallOutput(this->current_request_id_, output);
90
                this->plugins_[n]->CallOutput(this->current_request_id_, output);
-
 
91
                return;
-
 
92
            }
-
 
93
        }
-
 
94
    }
-
 
95
    else
-
 
96
    {
-
 
97
        LOG.Info(output);
-
 
98
    }
-
 
99
}
-
 
100
 
-
 
101
void Manager::CallResult(std::string output)
-
 
102
{
-
 
103
  if (this->current_plugin_name_ != "")
-
 
104
  {
-
 
105
    for (unsigned int n = 0; n < this->plugins_.size(); n++)
-
 
106
    {
-
 
107
      if (this->plugins_[n]->GetName() == this->current_plugin_name_)
-
 
108
      {
-
 
109
        this->plugins_[n]->CallResult(this->current_request_id_, output);
91
                return;
110
        return;
92
            }
111
      }
93
        }
112
    }
94
    }
113
  }
95
    else
114
  else
96
    {
115
  {
97
        LOG.Info(output);
116
    LOG.Info(output);
98
    }
117
  }
99
}
118
}
100
 
119
 
101
Value Manager::Export_Log(const v8::Arguments& args)
120
Value Manager::Export_Log(const v8::Arguments& args)
102
{
121
{
103
    v8::Locker lock;
122
    v8::Locker lock;
104
    v8::Context::Scope context_scope(Manager::Instance()->GetContext());
123
    v8::Context::Scope context_scope(Manager::Instance()->GetContext());
105
    v8::HandleScope handle_scope;
124
    v8::HandleScope handle_scope;
106
     
125
     
107
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
126
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
108
   
127
   
109
    if (args.Length() < 1)
128
    if (args.Length() < 1)
110
    {
129
    {
111
        Manager::instance_->LOG.Error(std::string(__FUNCTION__) + ": To few arguments to log.");
130
        Manager::instance_->LOG.Error(std::string(__FUNCTION__) + ": To few arguments to log.");
112
        return v8::Undefined();
131
        return v8::Undefined();
113
    }
132
    }
114
   
133
   
115
    v8::String::AsciiValue str(args[0]);
134
    v8::String::AsciiValue str(args[0]);
116
       
135
       
117
    Manager::instance_->CallOutput(*str);
136
    Manager::instance_->CallOutput(*str);
118
   
137
   
119
    return handle_scope.Close(v8::Undefined());
138
    return handle_scope.Close(v8::Undefined());
120
}
139
}
121
 
140
 
122
void Manager::Call(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments)
141
void Manager::Call(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments)
123
{
142
{
124
    this->io_service_.post(boost::bind(&Manager::CallHandler, this, plugin_name, request_id, name, arguments));
143
    this->io_service_.post(boost::bind(&Manager::CallHandler, this, plugin_name, request_id, name, arguments));
125
}
144
}
126
 
145
 
127
void Manager::Execute(std::string plugin_name, unsigned int request_id, std::string code)
146
void Manager::Execute(std::string plugin_name, unsigned int request_id, std::string code)
128
{
147
{
129
    this->io_service_.post(boost::bind(&Manager::ExecuteHandler, this, plugin_name, request_id, code));
148
    this->io_service_.post(boost::bind(&Manager::ExecuteHandler, this, plugin_name, request_id, code));
130
}
149
}
131
 
150
 
132
bool Manager::CallHandler(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments)
151
bool Manager::CallHandler(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments)
133
{
152
{
134
    v8::Locker lock;
153
    v8::Locker lock;
135
    v8::Context::Scope context_scope(this->context_);
154
    v8::Context::Scope context_scope(this->context_);
136
    v8::TryCatch try_catch;
155
    v8::TryCatch try_catch;
137
   
156
   
138
    this->current_plugin_name_ = plugin_name;
157
    this->current_plugin_name_ = plugin_name;
139
    this->current_request_id_ = request_id;
158
    this->current_request_id_ = request_id;
140
   
159
   
141
    if (this->functions_.find(name) == this->functions_.end())
160
    if (this->functions_.find(name) == this->functions_.end())
142
    {
161
    {
143
        this->CallOutput("No such function found, " + name);
162
        this->CallOutput("No such function found, " + name);
144
       
163
       
145
        this->current_plugin_name_ = "";
164
        this->current_plugin_name_ = "";
146
        this->current_request_id_ = 0;
165
        this->current_request_id_ = 0;
147
        return false;
166
        return false;
148
    }
167
    }
149
 
168
 
150
    //LOG.Debug("Call: " + name);
169
    //LOG.Debug("Call: " + name);
151
 
170
 
152
    Value result = this->functions_[name]->Call(this->context_->Global(), arguments->size(), arguments->data());
171
    Value result = this->functions_[name]->Call(this->context_->Global(), arguments->size(), arguments->data());
153
   
172
   
154
    if (result.IsEmpty())
173
    if (result.IsEmpty())
155
    {
174
    {
156
        this->CallOutput(this->FormatException(try_catch));
175
        this->CallOutput(this->FormatException(try_catch));
157
       
176
       
158
        this->current_plugin_name_ = "";
177
        this->current_plugin_name_ = "";
159
        this->current_request_id_ = 0;
178
        this->current_request_id_ = 0;
160
        return false;
179
        return false;
161
    }
180
    }
162
   
181
   
163
    //v8::String::AsciiValue response(result->ToString());
182
    //v8::String::AsciiValue response(result->ToString());
164
    //this->CallOutput(plugin_name, request_id, std::string(*response));
183
    //this->CallOutput(plugin_name, request_id, std::string(*response));
165
   
184
   
166
    this->current_plugin_name_ = "";
185
    this->current_plugin_name_ = "";
167
    this->current_request_id_ = 0;
186
    this->current_request_id_ = 0;
168
    return true;
187
    return true;
169
}
188
}
170
 
189
 
171
void Manager::StartHandler()
190
void Manager::StartHandler()
172
{
191
{
173
    v8::Locker lock;
192
    v8::Locker lock;
174
    v8::HandleScope handle_scope;
193
    v8::HandleScope handle_scope;
175
    v8::Handle<v8::ObjectTemplate> raw_template = v8::ObjectTemplate::New();
194
    v8::Handle<v8::ObjectTemplate> raw_template = v8::ObjectTemplate::New();
176
   
195
   
177
    raw_template->Set(v8::String::New("Log"), v8::FunctionTemplate::New(Manager::Export_Log));
196
    raw_template->Set(v8::String::New("Log"), v8::FunctionTemplate::New(Manager::Export_Log));
178
   
197
   
179
    for (unsigned int c = 0; c < this->plugins_.size(); c++)
198
    for (unsigned int c = 0; c < this->plugins_.size(); c++)
180
    {
199
    {
181
        ExportFunctionList export_functions = this->plugins_[c]->GetExportFunctions();
200
        ExportFunctionList export_functions = this->plugins_[c]->GetExportFunctions();
182
       
201
       
183
        for (ExportFunctionList::iterator it = export_functions.begin(); it != export_functions.end(); it++)
202
        for (ExportFunctionList::iterator it = export_functions.begin(); it != export_functions.end(); it++)
184
        {
203
        {
185
            raw_template->Set(v8::String::New(it->first.data()), v8::FunctionTemplate::New(it->second));
204
            raw_template->Set(v8::String::New(it->first.data()), v8::FunctionTemplate::New(it->second));
186
        }
205
        }
187
    }
206
    }
188
   
207
   
189
    this->context_ = v8::Context::New(NULL, raw_template);
208
    this->context_ = v8::Context::New(NULL, raw_template);
190
   
209
   
191
   
210
   
192
    v8::Context::Scope context_scope(this->context_);
211
    v8::Context::Scope context_scope(this->context_);
193
   
212
   
194
    for (unsigned int c = 0; c < this->plugins_.size(); c++)
213
    for (unsigned int c = 0; c < this->plugins_.size(); c++)
195
    {
214
    {
196
        this->LoadScript("plugin/" + this->plugins_[c]->GetName() + ".js");
215
        this->LoadScript("plugin/" + this->plugins_[c]->GetName() + ".js");
197
    }
216
    }
198
   
217
   
199
    this->object_template_ = v8::Persistent<v8::ObjectTemplate>::New(raw_template);
218
    this->object_template_ = v8::Persistent<v8::ObjectTemplate>::New(raw_template);
200
   
219
   
201
    for (unsigned int c = 0; c < this->plugins_.size(); c++)
220
    for (unsigned int c = 0; c < this->plugins_.size(); c++)
202
    {
221
    {
203
        this->plugins_[c]->InitializeDone();
222
        this->plugins_[c]->InitializeDone();
204
    }
223
    }
205
}
224
}
206
 
225
 
207
bool Manager::ImportFunction(std::string functionname)
226
bool Manager::ImportFunction(std::string functionname)
208
{
227
{
209
    v8::Locker lock;
228
    v8::Locker lock;
210
    v8::Context::Scope context_scope(this->context_);
229
    v8::Context::Scope context_scope(this->context_);
211
   
230
   
212
    v8::TryCatch try_catch;
231
    v8::TryCatch try_catch;
213
   
232
   
214
    v8::Handle<v8::String> process_name = v8::String::New(functionname.data());
233
    v8::Handle<v8::String> process_name = v8::String::New(functionname.data());
215
    v8::Handle<v8::Value> process_val = this->context_->Global()->Get(process_name);
234
    v8::Handle<v8::Value> process_val = this->context_->Global()->Get(process_name);
216
   
235
   
217
    if (!process_val->IsFunction())
236
    if (!process_val->IsFunction())
218
    {
237
    {
219
        LOG.Error(functionname + " was not found to be a function!");
238
        LOG.Error(functionname + " was not found to be a function!");
220
        return false;
239
        return false;
221
    }
240
    }
222
   
241
   
223
    v8::Handle<v8::Function> process_fun = v8::Handle<v8::Function>::Cast(process_val);
242
    v8::Handle<v8::Function> process_fun = v8::Handle<v8::Function>::Cast(process_val);
224
   
243
   
225
    this->functions_[functionname] = v8::Persistent<v8::Function>::New(process_fun);
244
    this->functions_[functionname] = v8::Persistent<v8::Function>::New(process_fun);
226
   
245
   
227
    return true;
246
    return true;
228
}
247
}
229
 
248
 
230
bool Manager::LoadScript(std::string scriptname)
249
bool Manager::LoadScript(std::string scriptname)
231
{
250
{
232
    for (unsigned int n = 0; n < this->loaded_scripts_.size(); n++)
251
    for (unsigned int n = 0; n < this->loaded_scripts_.size(); n++)
233
    {
252
    {
234
        if (this->loaded_scripts_[n] == scriptname)
253
        if (this->loaded_scripts_[n] == scriptname)
235
        {
254
        {
236
            LOG.Debug(scriptname + " is already loaded.");
255
            LOG.Debug(scriptname + " is already loaded.");
237
            return true;
256
            return true;
238
        }
257
        }
239
    }
258
    }
240
   
259
   
241
    std::string path = this->user_script_path_ + scriptname;
260
    std::string path = this->user_script_path_ + scriptname;
242
    std::ifstream file(path.data());
261
    std::ifstream file(path.data());
243
   
262
   
244
    if (!file.is_open())
263
    if (!file.is_open())
245
    {
264
    {
246
        path = this->script_path_ + scriptname;
265
        path = this->script_path_ + scriptname;
247
        file.open(path.data());
266
        file.open(path.data());
248
       
267
       
249
        if (!file.is_open())
268
        if (!file.is_open())
250
        {
269
        {
251
            file.close();
270
            file.close();
252
            LOG.Warning("Could not load " + scriptname + ".");
271
            LOG.Warning("Could not load " + scriptname + ".");
253
            return false;
272
            return false;
254
        }
273
        }
255
    }
274
    }
256
   
275
   
257
    std::string code = "";
276
    std::string code = "";
258
    std::string line;
277
    std::string line;
259
   
278
   
260
    while (!file.eof())
279
    while (!file.eof())
261
    {
280
    {
262
        std::getline(file, line);
281
        std::getline(file, line);
263
       
282
       
264
        if (file.eof())
283
        if (file.eof())
265
        {
284
        {
266
            break;
285
            break;
267
        }
286
        }
268
       
287
       
269
        code += line + "\n";
288
        code += line + "\n";
270
    }
289
    }
271
   
290
   
272
    code += "\n";
291
    code += "\n";
273
   
292
   
274
    file.close();
293
    file.close();
275
   
294
   
276
    v8::Locker lock;
295
    v8::Locker lock;
277
    v8::Context::Scope context_scope(this->context_);
296
    v8::Context::Scope context_scope(this->context_);
278
   
297
   
279
    v8::TryCatch try_catch;
298
    v8::TryCatch try_catch;
280
   
299
   
281
    v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(code.data(), code.length()),
300
    v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(code.data(), code.length()),
282
                                                        v8::String::New(scriptname.data(), scriptname.length()));
301
                                                        v8::String::New(scriptname.data(), scriptname.length()));
283
   
302
   
284
    if (script.IsEmpty())
303
    if (script.IsEmpty())
285
    {
304
    {
286
        LOG.Error(this->FormatException(try_catch));
305
        LOG.Error(this->FormatException(try_catch));
287
        return false;
306
        return false;
288
    }
307
    }
289
    else
308
    else
290
    {
309
    {
291
        Value result = script->Run();
310
        Value result = script->Run();
292
       
311
       
293
        if (result.IsEmpty())
312
        if (result.IsEmpty())
294
        {
313
        {
295
            LOG.Error(this->FormatException(try_catch));
314
            LOG.Error(this->FormatException(try_catch));
296
            return false;
315
            return false;
297
        }
316
        }
298
    }
317
    }
299
   
318
   
300
    this->loaded_scripts_.push_back(scriptname);
319
    this->loaded_scripts_.push_back(scriptname);
301
   
320
   
302
    LOG.Info("\033[32mLoaded " + scriptname + " successfully.\033[0m");
321
    LOG.Info("\033[32mLoaded " + scriptname + " successfully.\033[0m");
303
    return true;
322
    return true;
304
}
323
}
305
 
324
 
306
void Manager::ExecuteHandler(std::string plugin_name, unsigned int request_id, std::string code)
325
void Manager::ExecuteHandler(std::string plugin_name, unsigned int request_id, std::string code)
307
{
326
{
308
    std::string scriptname = "execute_" + plugin_name + ".js";
327
    std::string scriptname = "execute_" + plugin_name + ".js";
309
   
328
   
310
    v8::Locker lock;
329
    v8::Locker lock;
311
    v8::Context::Scope context_scope(this->context_);
330
    v8::Context::Scope context_scope(this->context_);
312
   
331
   
313
    v8::TryCatch try_catch;
332
    v8::TryCatch try_catch;
314
   
333
   
315
    v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(code.data(), code.length()),
334
    v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(code.data(), code.length()),
316
                                                        v8::String::New(scriptname.data(), scriptname.length()));
335
                                                        v8::String::New(scriptname.data(), scriptname.length()));
317
   
336
   
318
    this->current_plugin_name_ = plugin_name;
337
    this->current_plugin_name_ = plugin_name;
319
    this->current_request_id_ = request_id;
338
    this->current_request_id_ = request_id;
320
   
339
   
321
    if (script.IsEmpty())
340
    if (script.IsEmpty())
322
    {
341
    {
323
        this->CallOutput(this->FormatException(try_catch));
342
        this->CallOutput(this->FormatException(try_catch));
324
    }
343
    }
325
    else
344
    else
326
    {
345
    {
327
        Value result = script->Run();
346
        Value result = script->Run();
328
       
347
       
329
        if (result.IsEmpty())
348
        if (result.IsEmpty())
330
        {
349
        {
331
            this->CallOutput(this->FormatException(try_catch));
350
            this->CallOutput(this->FormatException(try_catch));
332
        }
351
        }
333
        else
352
        else
334
        {
353
        {
335
            //v8::String::AsciiValue response(result->ToString());
354
            v8::String::AsciiValue response(result->ToString());
336
            //this->CallOutput(std::string(*response));
355
            this->CallResult(std::string(*response));
337
        }
356
        }
338
    }
357
    }
339
   
358
   
340
    this->current_plugin_name_ = "";
359
    this->current_plugin_name_ = "";
341
    this->current_request_id_ = 0;
360
    this->current_request_id_ = 0;
342
}
361
}
343
 
362
 
344
std::string Manager::FormatException(v8::TryCatch& try_catch)
363
std::string Manager::FormatException(v8::TryCatch& try_catch)
345
{
364
{
346
    v8::Locker lock;
365
    v8::Locker lock;
347
    v8::Context::Scope context_scope(this->context_);
366
    v8::Context::Scope context_scope(this->context_);
348
   
367
   
349
    std::string result;
368
    std::string result;
350
   
369
   
351
    v8::HandleScope handle_scope;
370
    v8::HandleScope handle_scope;
352
    v8::String::Utf8Value exception(try_catch.Exception());
371
    v8::String::Utf8Value exception(try_catch.Exception());
353
    v8::Handle<v8::Message> message = try_catch.Message();
372
    v8::Handle<v8::Message> message = try_catch.Message();
354
   
373
   
355
    if (message.IsEmpty())
374
    if (message.IsEmpty())
356
    {
375
    {
357
        result = *exception;
376
        result = *exception;
358
    }
377
    }
359
    else
378
    else
360
    {
379
    {
361
        v8::String::Utf8Value filename(message->GetScriptResourceName());
380
        v8::String::Utf8Value filename(message->GetScriptResourceName());
362
       
381
       
363
        result = std::string(*filename) + ":" + boost::lexical_cast<std::string>(message->GetLineNumber()) + ": " + std::string(*exception);
382
        result = std::string(*filename) + ":" + boost::lexical_cast<std::string>(message->GetLineNumber()) + ": " + std::string(*exception);
364
       
383
       
365
        /*v8::String::Utf8Value sourceline(message->GetSourceLine());
384
        /*v8::String::Utf8Value sourceline(message->GetSourceLine());
366
        string strSourceline = *sourceline;
385
        string strSourceline = *sourceline;
367
       
386
       
368
        result += strSourceline + "\n";
387
        result += strSourceline + "\n";
369
       
388
       
370
        string underline = rpad("", message->GetStartColumn(), ' ');
389
        string underline = rpad("", message->GetStartColumn(), ' ');
371
        underline = rpad(underline, message->GetEndColumn(), '^');
390
        underline = rpad(underline, message->GetEndColumn(), '^');
372
       
391
       
373
        result += underline + "\n";*/
392
        result += underline + "\n";*/
374
    }
393
    }
375
   
394
   
376
    return result;
395
    return result;
377
}
396
}
378
   
397
   
379
}; // namespace vm
398
}; // namespace vm
380
}; // namespace atom
399
}; // namespace atom
381
 
400