-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
runtime.js
151 lines (113 loc) Β· 3.39 KB
/
runtime.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
var nqp = require('nqp-runtime');
var CodeRef = require('nqp-runtime/code-ref');
var op = {};
var Scalar, True, False, Int, Num, Str, Code;
op.p6settypes = function(types) {
Scalar = types.content.get('Scalar');
True = types.content.get('True');
False = types.content.get('False');
Int = types.content.get('Int');
Num = types.content.get('Num');
Str = types.content.get('Str');
Code = types.content.get('Code');
return types;
};
op.p6bool = function(value) {
return value ? True : False;
};
op.p6definite = function(obj) {
return obj.typeObject_ ? False : True;
};
op.p6typecheckrv = function(rv, routine, bypassType) {
// STUB
return rv;
};
op.p6decontrv = function(rountine, cont) {
// STUB
return cont;
};
op.p6box_i = function(int) {
var repr = Int._STable.REPR;
var boxed = repr.allocate(Int._STable);
boxed.$$setInt(int.value);
return boxed;
};
op.p6box_n = function(num) {
var repr = Num._STable.REPR;
var boxed = repr.allocate(Num._STable);
boxed.$$setNum(num);
return boxed;
};
op.p6box_s = function(str) {
var repr = Str._STable.REPR;
var boxed = repr.allocate(Str._STable);
boxed.$$setStr(str);
return boxed;
};
op.p6captureouters2 = function(ctx, capList, target) {
var cf = (target.outerCtx || closure.forcedOuter);
if (cf === null) {
return capList;
}
var elems = capList.$$elems();
for (var i = 0; i < elems; i++) {
var codeObj = capList.$$atpos(i);
var closure = codeObj.$$getattr(Code, "$!do");
var ctxToDiddle = (closure.outerCtx || closure.forcedOuter);
ctxToDiddle.$$outer = cf;
}
return capList;
};
op.p6captureouters = function(ctx, capList) {
var elems = capList.$$elems();
for (var i = 0; i < elems; i++) {
var codeObj = capList.$$atpos(i);
var closure = codeObj.$$getattr(Code, "$!do");
var ctxToDiddle = (closure.outerCtx || closure.forcedOuter);
ctxToDiddle.$$outer = ctx;
}
return capList;
};
op.p6capturelex = function(ctx, codeObj) {
var closure = codeObj.$$getattr(Code, "$!do");
var wantedStaticInfo = closure.staticCode.outerCodeRef;
if (ctx.codeRef().staticCode === wantedStaticInfo) {
closure.forcedOuter = ctx;
} else if (ctx.$$outer.codeRef().staticCode === wantedStaticInfo) {
closure.forcedOuter = ctx.$$outer;
}
return codeObj;
};
var containerSpecs = require('nqp-runtime/container-specs.js');
function RakudoScalar(STable) {
this.STable = STable;
}
RakudoScalar.prototype.configure = function(conf) {
this.setupSTable();
};
RakudoScalar.prototype.setupSTable = function() {
this.STable.addInternalMethod('$$assignunchecked', function(ctx, value) {
console.log('storing into rakudo_scalar unchecked');
process.exit();
});
this.STable.addInternalMethod('$$assign', function(ctx, value) {
console.log('storing into rakudo_scalar');
process.exit();
});
this.STable.addInternalMethod('$$decont', function(ctx) {
return this.$$getattr(Scalar, '$!value');
});
this.STable.addInternalMethod('$$getInt', function(ctx) {
return this.$$decont().$$getInt();
});
};
RakudoScalar.prototype.serialize = function(cursor) {
console.log('serializing rakudo_scalar');
};
RakudoScalar.prototype.deserialize = function(cursor) {
console.log('* deserializing rakudo_scalar');
};
RakudoScalar.prototype.name = 'rakudo_scalar';
containerSpecs.rakudo_scalar = RakudoScalar;
nqp.loadOps({op: op});
module.exports = null;