celtic / rubyex

a Ruby VM/interpreter

This URL has Read+Write access

rubyex / vm / context.h
100644 45 lines (34 sloc) 1.105 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
#ifndef CONTEXT_H
#define CONTEXT_H
 
// A context for local variables, etc.
// Experimental concept; not sure if this is the correct way of representing it.
//
// Relationship to `Binding'?
 
#include <string>
#include <memory>
#include <exception>
#include "linked_ptr.h"
#include "stack.h"
#include "rvalue.h"
#include "renvironment.h"
#include "binding.h"
 
class Context
{
  public:
    Context(RubyEnvironment &);
    Context(RubyEnvironment &, RubyValue, RubyModule *, Context *);
    Context(linked_ptr<Binding> &);
 
    const linked_ptr<RubyMethod> &get_method(const std::string &);
 
    RubyValue entry_to_value(const Stack::StackEntry &);
    RubyValue resolve_local(const std::string &);
    RubyValue resolve_identifier(const std::string &);
    RubyValue resolve_constant(const std::string &);
    // these three not const - could result in method call.
 
    void assign(const std::string &, RubyValue);
    bool assign_if_exists(const std::string &, RubyValue);
 
    linked_ptr<Binding> binding;
    Context *outer_context;
};
 
class CannotFindLocalError : public std::exception
{ };
 
#endif