Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Eliminate Capability parameter in all exported RTS API #44
Browse files Browse the repository at this point in the history
  • Loading branch information
TerrorJack committed Dec 14, 2018
1 parent fd40f38 commit ddfcf70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 2 additions & 10 deletions asterius/rts/rts.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,8 @@
__asterius_bigint_decode(i0) ** __asterius_bigint_decode(i1)
),
integerToString: (_i, _s) => {
const bi_str = __asterius_bigint_decode(_i).toString(),
cap = req.staticsSymbolMap.MainCapability;
const bi_str = __asterius_bigint_decode(_i).toString();
const rp = __asterius_wasm_instance.exports.allocate(
cap,
bi_str.length * 5
);
const buf = new BigUint64Array(
Expand Down Expand Up @@ -454,10 +452,8 @@
return 0;
},
__asterius_fromJSArrayBuffer: _i => {
const buf = __asterius_jsffi_JSRefs[_i],
cap = req.staticsSymbolMap.MainCapability;
const buf = __asterius_jsffi_JSRefs[_i];
let p = __asterius_wasm_instance.exports.allocate(
cap,
Math.ceil((buf.byteLength + 31) / 8)
);
p = Math.ceil(p / 16) * 16;
Expand Down Expand Up @@ -487,10 +483,8 @@
__asterius_fromJSString: _i => {
const s = __asterius_jsffi_JSRefs[_i];
if (s) {
const cap = req.staticsSymbolMap.MainCapability;
const s_utf32 = __asterius_encodeUTF32(s);
const rp = __asterius_wasm_instance.exports.allocate(
cap,
s_utf32.length * 5
);
const buf = new BigUint64Array(
Expand Down Expand Up @@ -519,9 +513,7 @@
__asterius_fromJSArray: _i => {
const arr = __asterius_jsffi_JSRefs[_i];
if (arr.length) {
const cap = req.staticsSymbolMap.MainCapability;
const rp = __asterius_wasm_instance.exports.allocate(
cap,
arr.length * 5
);
const buf = new BigUint64Array(
Expand Down
14 changes: 11 additions & 3 deletions asterius/src/Asterius/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ rtsAsteriusModule opts =
, ("createIOThread", createIOThreadFunction opts)
, ("createStrictIOThread", createStrictIOThreadFunction opts)
, ("allocate", allocateFunction opts)
, ( "allocate_wrapper"
, generateWrapperFunction "allocate" $ allocateFunction opts)
, ("allocate_wrapper", allocateWrapperFunction opts)
, ("allocateMightFail", allocateProxyFunction opts)
, ("allocatePinned", allocateProxyFunction opts)
, ("allocGroup", allocGroupFunction opts)
Expand Down Expand Up @@ -637,7 +636,7 @@ generateWrapperFunction func_sym AsteriusFunction {functionType = FunctionType {
[I64] -> ([F64], Unary ConvertSInt64ToFloat64)
_ -> (returnTypes, id)

mainFunction, hsInitFunction, rtsApplyFunction, rtsEvalFunction, rtsEvalIOFunction, rtsEvalLazyIOFunction, rtsEvalStableIOFunction, rtsGetSchedStatusFunction, rtsCheckSchedStatusFunction, scheduleWaitThreadFunction, createThreadFunction, createGenThreadFunction, createIOThreadFunction, createStrictIOThreadFunction, allocateFunction, allocateProxyFunction, allocGroupFunction, newCAFFunction, stgReturnFunction, getStablePtrWrapperFunction, deRefStablePtrWrapperFunction, freeStablePtrWrapperFunction, rtsMkBoolFunction, rtsMkDoubleFunction, rtsMkCharFunction, rtsMkIntFunction, rtsMkWordFunction, rtsMkPtrFunction, rtsMkStablePtrFunction, rtsGetBoolFunction, rtsGetDoubleFunction, rtsGetCharFunction, rtsGetIntFunction, loadI64Function, printI64Function, printF32Function, printF64Function, strlenFunction, memchrFunction, memcpyFunction, memsetFunction, memcmpFunction, fromJSArrayBufferFunction, toJSArrayBufferFunction, fromJSStringFunction, fromJSArrayFunction ::
mainFunction, hsInitFunction, rtsApplyFunction, rtsEvalFunction, rtsEvalIOFunction, rtsEvalLazyIOFunction, rtsEvalStableIOFunction, rtsGetSchedStatusFunction, rtsCheckSchedStatusFunction, scheduleWaitThreadFunction, createThreadFunction, createGenThreadFunction, createIOThreadFunction, createStrictIOThreadFunction, allocateFunction, allocateWrapperFunction, allocateProxyFunction, allocGroupFunction, newCAFFunction, stgReturnFunction, getStablePtrWrapperFunction, deRefStablePtrWrapperFunction, freeStablePtrWrapperFunction, rtsMkBoolFunction, rtsMkDoubleFunction, rtsMkCharFunction, rtsMkIntFunction, rtsMkWordFunction, rtsMkPtrFunction, rtsMkStablePtrFunction, rtsGetBoolFunction, rtsGetDoubleFunction, rtsGetCharFunction, rtsGetIntFunction, loadI64Function, printI64Function, printF32Function, printF64Function, strlenFunction, memchrFunction, memcpyFunction, memsetFunction, memcmpFunction, fromJSArrayBufferFunction, toJSArrayBufferFunction, fromJSStringFunction, fromJSArrayFunction ::
BuiltinsOptions -> AsteriusFunction
mainFunction BuiltinsOptions {..} =
runEDSL [] $ do
Expand Down Expand Up @@ -941,6 +940,15 @@ allocateFunction BuiltinsOptions {..} =
storeI64 bd_object_pool offset_bdescr_free new_free
emit old_free

allocateWrapperFunction _ =
runEDSL [F64] $ do
setReturnTypes [F64]
n <- param F64
r <-
Unary ConvertUInt64ToFloat64 <$>
call' "allocate" [mainCapability, Unary TruncUFloat64ToInt64 n] I64
emit r

allocateProxyFunction _ =
runEDSL [I64] $ do
setReturnTypes [I64]
Expand Down

0 comments on commit ddfcf70

Please sign in to comment.