-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
64 lines (54 loc) · 1.31 KB
/
main.cpp
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
#include "interpreter.h"
#include "builder.h"
#include <iostream>
static Symbol* a = Symbols::intern("a");
static Symbol* b = Symbols::intern("b");
static Symbol* f = Symbols::intern("f");
void eval(Code* c) {
Interpreter i;
Value* res = i(c);
std::cout << *res << "\n";
}
void t() {
Builder f0, f1, p0;
// Function is:
//
// function() {
// f1 <- function(a) a + a
// b <- 666
// f1(b)
// }
// inner fun
f1 << BC::enter_fun << 1
// load args
<< BC::store << a
// body
<< BC::load << a << BC::force
<< BC::load << a << BC::force
<< BC::add
<< BC::leave_fun
<< BC::ret;
// the "b" promise
p0 << BC::loadenv
<< BC::load << b << BC::force
<< BC::leave_prom
<< BC::ret;
// outer function
f0 << BC::enter_fun << (int)0
<< BC::push << C(666)
<< BC::store << b
<< BC::mkclosure << f1() << L({a})
<< BC::store << f
// the call sequence
<< BC::load << f << BC::force
<< BC::mkprom << p0() // push arg
<< BC::call_generic << 1 // call
<< BC::leave_fun
<< BC::ret;
eval(f0());
}
// See tests for more examples
int main() {
t();
return 0;
}