|
|
1.1 paf 1: /*
1.3 ! paf 2: $Id: pa_vmframe.h,v 1.2 2001/02/25 08:12:21 paf Exp $
1.1 paf 3: */
4:
5: #ifndef PA_VMFRAME_H
6: #define PA_VMFRAME_H
7:
8: #include "pa_wcontext.h"
9: #include "pa_vunknown.h"
10: #include "pa_vjunction.h"
11:
12: class VMethodFrame : public WContext {
13: public: // Value
14:
15: // all: for error reporting after fail(), etc
16: const char *type() const { return "MethodFrame"; }
17: // frame: my or self_transparent
18: Value *get_element(const String& name) {
19: Value *result=static_cast<Value *>(my.get(name));
20: if(!result)
21: result=self->get_element(name);
22: return result;
23: }
24: // frame: my or self_transparent
25: void put_element(const String& name, Value *value){
26: if(!my.replace(name, value))
27: self->put_element(name, value);
28: }
29:
30: public: // usage
31:
32: VMethodFrame(Pool& apool, const Junction& ajunction) : WContext(apool, 0 /* empty */),
33: junction(ajunction),
34: store_param_index(0),
35: my(apool),
36: self(0) {
37: if(Method* method=junction.method) { // method junction?
38: // remember local var names
39: // those are flags that name is local == to be looked up in 'my'
40: for(int i=0; i<method->locals_names.size(); i++) {
41: my.put(
42: *static_cast<String *>(method->locals_names.get(i)),
43: NEW VUnknown(pool()));
44: }
45: }
46: }
47:
48: void set_self(Value *aself) { self=aself; }
49:
50: void store_param(Value *value) {
51: Method *method=junction.method;
52: if(store_param_index==method->params_names.size())
53: THROW(0,0,
54: name(),
55: "call: too many params (max=%d)", method->params_names.size());
56:
57: my.put(*static_cast<String *>(method->params_names.get(store_param_index++)), value);
58: }
59: void fill_unspecified_params() {
60: Method *method=junction.method;
61: for(; store_param_index<method->params_names.size(); store_param_index++)
62: my.put(
63: *static_cast<String *>(method->params_names.get(store_param_index)),
64: NEW VUnknown(pool()));
65: }
66:
67: public:
68:
69: const Junction& junction;
70:
71: private:
72: int store_param_index;
73: Hash my;
74: Value *self;
75:
76: };
77:
78: #endif