blob: ba3fe33152c74f5112b86d808aeb612c2caa452b (
plain)
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
|
/*****
* callable.cc
* Tom Prince 2005/06/19
*
* Runtime representation of functions.
*****/
#include "stack.h"
#include "callable.h"
namespace vm {
callable::~callable()
{}
void func::call(stack *s)
{
s->run(this);
}
bool func::compare(callable* F)
{
if (func* f=dynamic_cast<func*>(F))
return (body == f->body) && (closure == f->closure);
else return false;
}
bool bfunc::compare(callable* F)
{
if (bfunc* f=dynamic_cast<bfunc*>(F))
return (func == f->func);
else return false;
}
void thunk::call(stack *s)
{
s->push(arg);
func->call(s);
}
nullfunc nullfunc::func;
void nullfunc::call(stack *)
{
error("dereference of null function");
}
bool nullfunc::compare(callable* f)
{
return f == &func;
}
} // namespace vm
|