summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/callable.cc
blob: 581c3af2c1c608938f227df68909c90267033ced (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*****
 * 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);
}

void nullfunc::print(ostream& out) {
  out << "nullfunc";
}

bool func::compare(callable* F)
{
  if (func* f=dynamic_cast<func*>(F))
    return (body == f->body) && (closure == f->closure);
  else return false;
}

void func::print(ostream& out) {
  out << "func with lambda";
#ifdef DEBUG_FRAME
  out << " " << body->name;
#endif
}

bool bfunc::compare(callable* F)
{
  if (bfunc* f=dynamic_cast<bfunc*>(F))
    return (func == f->func);
  else return false;
}

void bfunc::print(ostream& out) {
  out << "bltin";
#ifdef DEBUG_BLTIN
  out << " " << lookupBltin(func);
#endif
}

void thunk::call(stack *s)
{
  s->push(arg);
  func->call(s);
}

void thunk::print(ostream& out) {
  out << "thunk on " << arg << " with ";
  func->print(out);
}

nullfunc nullfunc::func;
void nullfunc::call(stack *)
{
  error("dereference of null function");
}

bool nullfunc::compare(callable* f)
{
  return f == &func;
}

} // namespace vm