1
1
mirror of https://github.com/tweag/asterius.git synced 2024-10-05 21:30:49 +03:00

Automatically call hs_init() before newAsteriusInstance() resolves (#524)

This commit is contained in:
Shao Cheng 2020-03-30 15:54:02 +02:00 committed by GitHub
parent 681497e934
commit c40ad926d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 4 additions and 16 deletions

View File

@ -198,10 +198,11 @@ export async function newAsteriusInstance(req) {
);
}
Object.assign(__asterius_exports, __asterius_wasm_instance.exports);
__asterius_exports.hs_init();
return Object.assign(__asterius_jsffi_instance, {
exports: Object.freeze(
Object.assign(__asterius_exports, __asterius_wasm_instance.exports)
),
exports: __asterius_exports,
symbolTable: req.symbolTable,
persistentState: __asterius_persistent_state
});

View File

@ -20,7 +20,6 @@ import Asterius.CodeGen
import Asterius.Internals ((!))
import Asterius.Internals.Name
import Asterius.Internals.Temp
import Asterius.JSRun.Main
import Asterius.JSRun.NonMain
import Asterius.Ld
import Asterius.Resolve
@ -332,7 +331,6 @@ asteriusRunTH hsc_env _ _ q ty _ s ahc_dist_input =
<> ",{module:"
<> takeJSVal mod_val
<> "}))"
hsInit s i
let runner_closure =
deRefJSVal i <> ".symbolTable."
<> coerce

View File

@ -2,7 +2,6 @@
module Asterius.JSRun.Main
( newAsteriusInstance,
hsInit,
hsMain,
hsStdOut,
hsStdErr,
@ -31,9 +30,6 @@ newAsteriusInstance s req_path mod_buf = do
<> takeJSVal mod_val
<> "}))"
hsInit :: JSSession -> JSVal -> IO ()
hsInit s i = eval s $ deRefJSVal i <> ".exports.hs_init()"
hsMain :: String -> JSSession -> JSVal -> IO ()
hsMain prog_name s i =
eval s $

View File

@ -209,7 +209,6 @@ genDefEntry task =
".req.mjs\";\n",
mconcat
[ "module.then(m => rts.newAsteriusInstance(Object.assign(req, {module: m}))).then(i => {\n",
"i.exports.hs_init();\n",
"i.exports.main().catch(err => {if (!(err.startsWith('ExitSuccess') || err.startsWith('ExitFailure '))) i.fs.writeSync(2, `",
string7 $ takeBaseName $ inputHS task,
": ${err}\n`)});\n",

View File

@ -7,7 +7,6 @@ const asteriusInstance = new Promise((resolve, reject) => {
// It gets hardcoded to 'wasm' when using the Wrangler CLI (as of v1.6.0).
rts.newAsteriusInstance(Object.assign(cloudflare, { module: wasm }))
.then(i => {
i.exports.hs_init();
resolve(i);
})
.catch(e => reject(e));

View File

@ -143,7 +143,6 @@ runTestCase l_opts tlref TestCase {..} = catch m h
}
$ \s -> do
i <- newAsteriusInstance s (tmp_case_path -<.> "req.mjs") mod_buf
hsInit s i
hsMain (takeBaseName tmp_case_path) s i
hs_stdout <- hsStdOut s i
hs_stderr <- hsStdErr s i

View File

@ -9,7 +9,6 @@ process.on("unhandledRejection", err => {
module
.then(m => rts.newAsteriusInstance(Object.assign(jsffi, { module: m })))
.then(async i => {
i.exports.hs_init();
await i.exports.main();
console.log(await i.exports.mult_hs_int(9, 9));
console.log(await i.exports.mult_hs_double(9, 9));

View File

@ -1,6 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
import Asterius.JSRun.Main
import Asterius.JSRun.NonMain
import Data.Binary
import qualified Data.ByteString.Lazy as LBS
@ -33,7 +32,6 @@ main = do
"test/nomain/NoMain"
["base_AsteriusziTopHandler_runNonIO_closure", "NoMain_x_closure"]
m
hsInit s i
let x_closure =
deRefJSVal i
<> ".exports.rts_apply("

View File

@ -9,7 +9,6 @@ process.on("unhandledRejection", err => {
module
.then(m => rts.newAsteriusInstance(Object.assign(rtsapi, { module: m })))
.then(async i => {
i.exports.hs_init();
await i.exports.main();
await i.exports.rts_evalLazyIO(
i.exports.rts_apply(