porffor 0.2.0-fde989a → 0.14.0-4057a18e9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +256 -0
- package/LICENSE +20 -20
- package/README.md +131 -86
- package/asur/README.md +2 -0
- package/asur/index.js +1262 -0
- package/byg/index.js +216 -0
- package/compiler/2c.js +2 -53
- package/compiler/{sections.js → assemble.js} +84 -21
- package/compiler/builtins/annexb_string.js +72 -0
- package/compiler/builtins/annexb_string.ts +18 -0
- package/compiler/builtins/array.ts +145 -0
- package/compiler/builtins/base64.ts +76 -0
- package/compiler/builtins/boolean.ts +18 -0
- package/compiler/builtins/crypto.ts +120 -0
- package/compiler/builtins/date.ts +2067 -0
- package/compiler/builtins/escape.ts +141 -0
- package/compiler/builtins/function.ts +5 -0
- package/compiler/builtins/int.ts +145 -0
- package/compiler/builtins/number.ts +529 -0
- package/compiler/builtins/object.ts +4 -0
- package/compiler/builtins/porffor.d.ts +60 -0
- package/compiler/builtins/set.ts +187 -0
- package/compiler/builtins/string.ts +1080 -0
- package/compiler/builtins.js +436 -283
- package/compiler/{codeGen.js → codegen.js} +1027 -482
- package/compiler/decompile.js +2 -3
- package/compiler/embedding.js +22 -22
- package/compiler/encoding.js +94 -10
- package/compiler/expression.js +1 -1
- package/compiler/generated_builtins.js +1625 -0
- package/compiler/index.js +25 -36
- package/compiler/log.js +6 -3
- package/compiler/opt.js +55 -41
- package/compiler/parse.js +38 -30
- package/compiler/precompile.js +120 -0
- package/compiler/prefs.js +27 -0
- package/compiler/prototype.js +31 -46
- package/compiler/types.js +38 -0
- package/compiler/wasmSpec.js +33 -8
- package/compiler/wrap.js +88 -70
- package/package.json +9 -5
- package/porf +2 -0
- package/rhemyn/compile.js +46 -27
- package/rhemyn/parse.js +322 -320
- package/rhemyn/test/parse.js +58 -58
- package/runner/compare.js +33 -34
- package/runner/debug.js +117 -0
- package/runner/index.js +78 -11
- package/runner/profiler.js +75 -0
- package/runner/repl.js +40 -13
- package/runner/sizes.js +37 -37
- package/runner/version.js +10 -8
- package/compiler/builtins/base64.js +0 -92
- package/filesize.cmd +0 -2
- package/runner/info.js +0 -89
- package/runner/profile.js +0 -46
- package/runner/results.json +0 -1
- package/runner/transform.js +0 -15
- package/tmp.c +0 -661
- package/util/enum.js +0 -20
@@ -0,0 +1,187 @@
|
|
1
|
+
// dark wasm magic for dealing with memory, sorry.
|
2
|
+
export const __Porffor_allocate = (): number => {
|
3
|
+
Porffor.wasm`i32.const 1
|
4
|
+
memory.grow 0
|
5
|
+
drop
|
6
|
+
memory.size 0
|
7
|
+
i32.const 1
|
8
|
+
i32.sub
|
9
|
+
i32.const 65536
|
10
|
+
i32.mul
|
11
|
+
i32.from_u
|
12
|
+
return`;
|
13
|
+
};
|
14
|
+
|
15
|
+
export const __Porffor_set_read = (_this: Set, index: number): any => {
|
16
|
+
Porffor.wasm`
|
17
|
+
local offset i32
|
18
|
+
local.get ${index}
|
19
|
+
i32.to_u
|
20
|
+
i32.const 9
|
21
|
+
i32.mul
|
22
|
+
local.get ${_this}
|
23
|
+
i32.to_u
|
24
|
+
i32.add
|
25
|
+
local.set offset
|
26
|
+
|
27
|
+
local.get offset
|
28
|
+
f64.load 0 4
|
29
|
+
|
30
|
+
local.get offset
|
31
|
+
i32.load8_u 0 12
|
32
|
+
return`;
|
33
|
+
};
|
34
|
+
|
35
|
+
export const __Porffor_set_write = (_this: Set, index: number, value: any): boolean => {
|
36
|
+
Porffor.wasm`
|
37
|
+
local offset i32
|
38
|
+
local.get ${index}
|
39
|
+
i32.to_u
|
40
|
+
i32.const 9
|
41
|
+
i32.mul
|
42
|
+
local.get ${_this}
|
43
|
+
i32.to_u
|
44
|
+
i32.add
|
45
|
+
local.set offset
|
46
|
+
|
47
|
+
local.get offset
|
48
|
+
local.get ${value}
|
49
|
+
f64.store 0 4
|
50
|
+
|
51
|
+
local.get offset
|
52
|
+
local.get ${value+1}
|
53
|
+
i32.store8 0 12`;
|
54
|
+
|
55
|
+
return true;
|
56
|
+
};
|
57
|
+
|
58
|
+
|
59
|
+
// todo: this should be a getter somehow not a method
|
60
|
+
export const __Set_prototype_size = (_this: Set) => {
|
61
|
+
return Porffor.wasm.i32.load(_this, 0, 0);
|
62
|
+
};
|
63
|
+
|
64
|
+
export const __Set_prototype_values = (_this: Set) => {
|
65
|
+
// todo: this should return an iterator not array
|
66
|
+
const size: number = __Set_prototype_size(_this);
|
67
|
+
|
68
|
+
const out: any[] = __Porffor_allocate();
|
69
|
+
for (let i: number = 0; i < size; i++) {
|
70
|
+
const val: any = __Porffor_set_read(_this, i);
|
71
|
+
out.push(val);
|
72
|
+
}
|
73
|
+
|
74
|
+
return out;
|
75
|
+
};
|
76
|
+
|
77
|
+
export const __Set_prototype_keys = (_this: Set) => {
|
78
|
+
return __Set_prototype_values(_this);
|
79
|
+
};
|
80
|
+
|
81
|
+
export const __Set_prototype_has = (_this: Set, value: any) => {
|
82
|
+
const size: number = __Set_prototype_size(_this);
|
83
|
+
|
84
|
+
for (let i: number = 0; i < size; i++) {
|
85
|
+
if (__Porffor_set_read(_this, i) === value) return true;
|
86
|
+
}
|
87
|
+
|
88
|
+
return false;
|
89
|
+
};
|
90
|
+
|
91
|
+
export const __Set_prototype_add = (_this: Set, value: any) => {
|
92
|
+
const size: number = __Set_prototype_size(_this);
|
93
|
+
|
94
|
+
// check if already in set
|
95
|
+
for (let i: number = 0; i < size; i++) {
|
96
|
+
if (__Porffor_set_read(_this, i) === value) return _this;
|
97
|
+
}
|
98
|
+
|
99
|
+
// not, add it
|
100
|
+
// increment size by 1
|
101
|
+
Porffor.wasm.i32.store(_this, size + 1, 0, 0);
|
102
|
+
|
103
|
+
// write new value at end
|
104
|
+
__Porffor_set_write(_this, size, value);
|
105
|
+
|
106
|
+
return _this;
|
107
|
+
};
|
108
|
+
|
109
|
+
export const __Set_prototype_delete = (_this: Set, value: any) => {
|
110
|
+
const size: number = __Set_prototype_size(_this);
|
111
|
+
|
112
|
+
// check if already in set
|
113
|
+
for (let i: number = 0; i < size; i++) {
|
114
|
+
if (__Porffor_set_read(_this, i) === value) {
|
115
|
+
// found, delete
|
116
|
+
// decrement size by 1
|
117
|
+
Porffor.wasm.i32.store(_this, size - 1, 0, 0);
|
118
|
+
|
119
|
+
// offset all elements after by -1 ind
|
120
|
+
Porffor.wasm`
|
121
|
+
local offset i32
|
122
|
+
local.get ${i}
|
123
|
+
i32.to_u
|
124
|
+
i32.const 9
|
125
|
+
i32.mul
|
126
|
+
local.get ${_this}
|
127
|
+
i32.to_u
|
128
|
+
i32.add
|
129
|
+
i32.const 4
|
130
|
+
i32.add
|
131
|
+
local.set offset
|
132
|
+
|
133
|
+
;; dst = offset (this element)
|
134
|
+
local.get offset
|
135
|
+
|
136
|
+
;; src = offset + 9 (this element + 1 element)
|
137
|
+
local.get offset
|
138
|
+
i32.const 9
|
139
|
+
i32.add
|
140
|
+
|
141
|
+
;; size = (size - i - 1) * 9
|
142
|
+
local.get ${size}
|
143
|
+
local.get ${i}
|
144
|
+
f64.sub
|
145
|
+
i32.to_u
|
146
|
+
i32.const 1
|
147
|
+
i32.sub
|
148
|
+
i32.const 9
|
149
|
+
i32.mul
|
150
|
+
|
151
|
+
memory.copy 0 0`;
|
152
|
+
|
153
|
+
return true;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
// not, return false
|
158
|
+
return false;
|
159
|
+
};
|
160
|
+
|
161
|
+
export const __Set_prototype_clear = (_this: Set) => {
|
162
|
+
// just set size to 0
|
163
|
+
// do not need to delete any as will not be accessed anymore,
|
164
|
+
// and will be overwritten with new add
|
165
|
+
Porffor.wasm.i32.store(_this, 0, 0, 0);
|
166
|
+
};
|
167
|
+
|
168
|
+
export const Set = () => {
|
169
|
+
throw new TypeError("Constructor Set requires 'new'");
|
170
|
+
};
|
171
|
+
|
172
|
+
export const Set$constructor = (iterable: any): Set => {
|
173
|
+
const out: Set = __Porffor_allocate();
|
174
|
+
|
175
|
+
const type: number = Porffor.rawType(iterable);
|
176
|
+
if (Porffor.fastOr(
|
177
|
+
type == Porffor.TYPES.array,
|
178
|
+
type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
|
179
|
+
type == Porffor.TYPES.set
|
180
|
+
)) {
|
181
|
+
for (const x of iterable) {
|
182
|
+
__Set_prototype_add(out, x);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
return out;
|
187
|
+
};
|