porffor 0.18.9 → 0.18.11
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/.editorconfig +12 -0
- package/compiler/builtins.js +45 -0
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/.editorconfig
ADDED
package/compiler/builtins.js
CHANGED
@@ -1140,5 +1140,50 @@ export const BuiltinFuncs = function() {
|
|
1140
1140
|
]
|
1141
1141
|
};
|
1142
1142
|
|
1143
|
+
this.__Porffor_allocateBytes = {
|
1144
|
+
params: [ Valtype.i32 ],
|
1145
|
+
locals: [],
|
1146
|
+
globals: [ Valtype.i32, Valtype.i32 ],
|
1147
|
+
globalNames: [ 'currentPtr', 'bytesWritten' ],
|
1148
|
+
globalInits: [ 0, pageSize ], // init to pageSize so we always allocate on first call
|
1149
|
+
returns: [ Valtype.i32 ],
|
1150
|
+
returnType: TYPES.number,
|
1151
|
+
wasm: [
|
1152
|
+
// bytesWritten += bytesToAllocate
|
1153
|
+
[ Opcodes.local_get, 0 ],
|
1154
|
+
[ Opcodes.global_get, 1 ],
|
1155
|
+
[ Opcodes.i32_add ],
|
1156
|
+
[ Opcodes.global_set, 1 ],
|
1157
|
+
|
1158
|
+
// if bytesWritten >= pageSize:
|
1159
|
+
[ Opcodes.global_get, 1 ],
|
1160
|
+
...number(pageSize, Valtype.i32),
|
1161
|
+
[ Opcodes.i32_ge_s ],
|
1162
|
+
[ Opcodes.if, Valtype.i32 ],
|
1163
|
+
// bytesWritten = 0
|
1164
|
+
[ Opcodes.local_get, 0 ],
|
1165
|
+
[ Opcodes.global_set, 1 ],
|
1166
|
+
|
1167
|
+
// grow memory by 1 page
|
1168
|
+
...number(1, Valtype.i32),
|
1169
|
+
[ Opcodes.memory_grow, 0x00 ],
|
1170
|
+
|
1171
|
+
// currentPtr = old page count * pageSize
|
1172
|
+
...number(pageSize, Valtype.i32),
|
1173
|
+
[ Opcodes.i32_mul ],
|
1174
|
+
[ Opcodes.global_set, 0 ],
|
1175
|
+
[ Opcodes.else ],
|
1176
|
+
// else, currentPtr += bytesToAllocate
|
1177
|
+
[ Opcodes.global_get, 0 ],
|
1178
|
+
[ Opcodes.local_get, 0 ],
|
1179
|
+
[ Opcodes.i32_add ],
|
1180
|
+
[ Opcodes.global_set, 0 ]
|
1181
|
+
[ Opcodes.end ],
|
1182
|
+
|
1183
|
+
// return currentPtr
|
1184
|
+
[ Opcodes.global_get, 0 ]
|
1185
|
+
]
|
1186
|
+
};
|
1187
|
+
|
1143
1188
|
GeneratedBuiltins.BuiltinFuncs.call(this);
|
1144
1189
|
};
|
package/package.json
CHANGED