I've been working on getting the pypy vm built with emterpreter enabled to get synchronous functions to work. I've added a function to the js
module to synchronously await a promise.
But now I'm running into a compile error that I can't figure out.
This is the error: (I'll add the stacktrace to the end)
[translation:ERROR] ValueError: argument to ll function pointer call: should return a low-level type,
[translation:ERROR] got instead SomeInstance(can_be_None=True, classdef=pypy.interpreter.baseobjspace.W_Root)
I added this to emjs.h
//Synchronously await a promise
emjs_handle emjs_await(emjs_handle promise);
and then this to library_emjs.js
emjs_await__deps: ['emjs_deref', '$EmterpreterAsync'],
emjs_await: function(promise_h) {
var promise = _emjs_deref(promise_h);
EmterpreterAsync.handle(function(resume) {
promise.then(function(val) {
if (ABORT) return;
resume(val);
}, function(err) {
if (ABORT) return;
EMJS.last_error = err;
resume(EMJS.ERROR);
});
});
},
And this to support.py (what does random_effects_on_gcobjs
mean?)
@jsexternal([EMJS_HANDLE_TP], EMJS_HANDLE_TP,
random_effects_on_gcobjs=True)
def emjs_await(h_prom):
raise NotImplementedError
I added this to interp_js.py
def await(space, w_promise):
"""Await a javascript promise."""
h = support.emjs_await(w_promise)
return _wrap_handle(space, h)
And this to init.py: 'await': 'interp_js.await'
stacktrace:
[translation:info] Error:
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/translator/goal/translate.py", line 318, in main
[translation:info] drv.proceed(goals)
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/translator/driver.py", line 559, in proceed
[translation:info] return self._execute(goals, task_skip = self._maybe_skip())
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/translator/tool/taskengine.py", line 114, in _execute
[translation:info] res = self._do(goal, taskcallable, *args, **kwds)
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/translator/driver.py", line 277, in _do
[translation:info] res = func()
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/translator/driver.py", line 314, in task_annotate
[translation:info] s = annotator.build_types(self.entry_point, self.inputtypes)
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/annotator/annrpython.py", line 89, in build_types
[translation:info] return self.build_graph_types(flowgraph, inputcells, complete_now=complete_now)
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/annotator/annrpython.py", line 135, in build_graph_types
[translation:info] self.complete()
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/annotator/annrpython.py", line 189, in complete
[translation:info] self.complete_pending_blocks()
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/annotator/annrpython.py", line 184, in complete_pending_blocks
[translation:info] self.processblock(graph, block)
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/annotator/annrpython.py", line 336, in processblock
[translation:info] self.flowin(graph, block)
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/annotator/annrpython.py", line 408, in flowin
[translation:info] self.consider_op(op)
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/annotator/annrpython.py", line 582, in consider_op
[translation:info] resultcell = op.consider(self)
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/flowspace/operation.py", line 104, in consider
[translation:info] return spec(annotator, *self.args)
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/annotator/unaryop.py", line 52, in simple_call_SomeObject
[translation:info] simple_args([annotator.annotation(arg) for arg in args]))
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/rtyper/lltypesystem/lltype.py", line 1575, in call
[translation:info] for s_arg in args_s]
[translation:info] File "/home/albertjan/pypyjs/deps/pypy/rpython/rtyper/llannotation.py", line 168, in annotation_to_lltype
[translation:info] info, s_val))
[translation:ERROR] ValueError: argument to ll function pointer call: should return a low-level type,
[translation:ERROR] got instead SomeInstance(can_be_None=True, classdef=pypy.interpreter.baseobjspace.W_Root)
[translation:ERROR] Processing block:
[translation:ERROR] block@9 is a <class 'rpython.flowspace.flowcontext.SpamBlock'>
[translation:ERROR] in (pypy.module.js.interp_js:953)await
[translation:ERROR] containing the following operations:
[translation:ERROR] h_0 = simple_call((<* fn emjs_await>), w_promise_0)
[translation:ERROR] v557 = simple_call((function _wrap_handle), space_92, h_0)
[translation:ERROR] --end--