public
Description: a Ruby VM/interpreter
Homepage: http://rubyex.sairyx.org/
Clone URL: git://github.com/celtic/rubyex.git
rubyex / vm / renvironment.h
100644 90 lines (70 sloc) 2.289 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef RENVIRONMENT_H
#define RENVIRONMENT_H
 
#include <string>
#include <map>
#include <exception>
#include "rclass.h"
#include "rarray.h"
#include "rmodule.h"
#include "rstring.h"
#include "rexception.h"
#include "gc.h"
 
class RubyEnvironment
{
  public:
    RubyEnvironment();
    ~RubyEnvironment();
 
    bool global_exists(const std::string &) const;
    RubyValue get_global_by_name(const std::string &) const;
    void set_global_by_name(const std::string &, RubyValue);
    void set_global_by_name(const std::string &, RubyObject *);
    void set_readonly_global_by_name(const std::string &, RubyValue);
    void set_readonly_global_by_name(const std::string &, RubyObject *);
 
    const std::string &get_name_by_global(RubyValue) const;
    inline RubyValue get_truth(bool _t) const { return _t ? TRUE : FALSE; }
    inline RubyValue get_string(const std::string &_s) {
      /* String interning here. Maybe. Or in RubyString's ctor. */
      return O2V(gc.track(new RubyString(*this, _s)));
    }
 
    RubyObject *errno_exception(linked_ptr<Binding> &, int, const char *);
 
    RubySymbol *get_symbol(const std::string &);
 
    RubyClass *Object, *Module, *Class;
    RubyClass *_Binding, *Symbol, *Fixnum, *Float, *String;
    RubyClass *Array, *Hash, *Range, *IO, *File;
    RubyClass *Regexp, *MatchData;
 
    RubyClass *Exception;
      RubyClass *ScriptError;
RubyClass *LoadError;
RubyClass *NotImplementedError;
RubyClass *SyntaxError;
      RubyClass *StandardError;
RubyClass *ArgumentError;
RubyClass *IOError;
RubyClass *IndexError;
RubyClass *LocalJumpError;
RubyClass *NameError;
RubyClass *NoMethodError;
RubyClass *RuntimeError;
RubyClass *SystemCallError;
RubyClass *TypeError;
 
    RubyModule *Kernel, *Comparable;
 
    RubyArray *RubyPath, *RubyLoaded;
 
    RubyObject *main;
    RubyValue TRUE, FALSE, NIL;
 
    GarbageCollector gc;
 
  protected:
    class _GlobalSettings {
      public:
_GlobalSettings();
_GlobalSettings(bool);
 
bool readonly;
    };
 
    std::map<std::string, RubyValue> globals;
    std::map<std::string, _GlobalSettings> global_settings;
    std::map<std::string, RubySymbol *> symbols;
};
 
class CannotFindGlobalError : public std::exception
{ };
 
class CannotChangeReadonlyError : public std::exception
{ };
 
#endif