summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/inst.h
blob: b1b0511f66045deb2b43ccaac3bfd25c7ed806f1 (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
76
77
78
79
80
/*****
 * inst.h
 * Andy Hammerlindl 2002/06/27
 * 
 * Descibes the items and instructions that are used by the virtual machine.
 *****/

#ifndef INST_H
#define INST_H

#include <iterator>
#include <iostream>

#include "errormsg.h"
#include "item.h"
#include "vm.h"

namespace vm {

// Forward declarations
struct inst; class stack; class program;
 
// A function "lambda," that is, the code that runs a function.
// It also needs the closure of the enclosing module or function to run.
struct lambda : public gc {
#ifdef DEBUG_FRAME
  lambda()
    : name("<unnamed>") {}
  virtual ~lambda() {}
  string name;
#endif

  // The instructions to follow.
  program *code;

  // The number of parameters of the function.  This does not include the
  // closure of the enclosing module or function.
  size_t params;

  // The total number of items that will be stored in the closure of this
  // function.  Includes the higher closure, the parameters, and the local
  // variables.
  // NOTE: In order to help garbage collection, this could be modified to
  // have one array store escaping items, and another to store non-
  // escaping items.
  size_t vars;
};

// The code run is just a string of instructions.  The ops are actual commands
// to be run, but constants, labels, and other objects can be in the code.
struct inst : public gc {
  enum opcode {
    pop, intpush, constpush,
    varpush, varsave, fieldpush, fieldsave,
    builtin, jmp, cjmp, njmp, popcall,
    pushclosure, makefunc, ret,
    alloc, pushframe, popframe,

#ifdef COMBO
    // Combo instructions:
    // varpop = varsave+pop and fieldpop = fieldsave+pop
    varpop, fieldpop,

    // gejmp = bltin greater-than-equal (for ints) + cjmp    OR
    //       = bltin less-than-equal + njmp
    gejmp
#endif
  };
  opcode op;
  position pos;
  item ref;
};
template<typename T>
inline T get(const inst& it)
{ return get<T>(it.ref); }

} // namespace vm

#endif