[pypy-commit] lang-smalltalk emscripten: more changes for emscripten
timfel
noreply at buildbot.pypy.org
Fri Aug 8 17:54:35 CEST 2014
Author: Tim Felgentreff <timfelgentreff at gmail.com>
Branch: emscripten
Changeset: r1032:2a78caaf3e0f
Date: 2014-08-08 11:48 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/2a78caaf3e0f/
Log: more changes for emscripten
diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -47,7 +47,7 @@
assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
RSDL.WM_SetCaption(title, "RSqueakVM")
RSDL.EnableUNICODE(1)
- SDLCursor.has_display = True
+ # SDLCursor.has_display = True
self.has_surface = False
self.mouse_position = [0, 0]
self.interrupt_key = 15 << 8 # pushing all four meta keys, of which we support three...
@@ -270,45 +270,45 @@
self.interrupt_key = encoded_key
-class SDLCursorClass(object):
- _attrs_ = ["cursor", "has_cursor", "has_display"]
+# class SDLCursorClass(object):
+# _attrs_ = ["cursor", "has_cursor", "has_display"]
- instance = None
+# instance = None
- def __init__(self):
- self.cursor = lltype.nullptr(RSDL.CursorPtr.TO)
- self.has_cursor = False
- self.has_display = False
+# def __init__(self):
+# self.cursor = lltype.nullptr(RSDL.CursorPtr.TO)
+# self.has_cursor = False
+# self.has_display = False
- def set(self, data_words, w, h, x, y, mask_words=None):
- if not self.has_display:
- return
- if self.has_cursor:
- RSDL.FreeCursor(self.cursor)
- data = self.words_to_bytes(len(data_words) * 4, data_words)
- try:
- mask = self.words_to_bytes(len(data_words) * 4, mask_words)
- try:
- self.cursor = RSDL.CreateCursor(data, mask, w * 2, h, x, y)
- self.has_cursor = True
- RSDL.SetCursor(self.cursor)
- finally:
- lltype.free(mask, flavor="raw")
- finally:
- lltype.free(data, flavor="raw")
+# def set(self, data_words, w, h, x, y, mask_words=None):
+# if not self.has_display:
+# return
+# if self.has_cursor:
+# RSDL.FreeCursor(self.cursor)
+# data = self.words_to_bytes(len(data_words) * 4, data_words)
+# try:
+# mask = self.words_to_bytes(len(data_words) * 4, mask_words)
+# try:
+# self.cursor = RSDL.CreateCursor(data, mask, w * 2, h, x, y)
+# self.has_cursor = True
+# RSDL.SetCursor(self.cursor)
+# finally:
+# lltype.free(mask, flavor="raw")
+# finally:
+# lltype.free(data, flavor="raw")
- def words_to_bytes(self, bytenum, words):
- bytes = lltype.malloc(RSDL.Uint8P.TO, bytenum, flavor="raw")
- if words:
- for pos in range(bytenum / 4):
- word = words[pos]
- bytes[pos * 4] = rffi.r_uchar((word >> 24) & 0xff)
- bytes[pos * 4 + 1] = rffi.r_uchar((word >> 16) & 0xff)
- bytes[pos * 4 + 2] = rffi.r_uchar((word >> 8) & 0xff)
- bytes[pos * 4 + 3] = rffi.r_uchar(word & 0xff)
- else:
- for idx in range(bytenum):
- bytes[idx] = rffi.r_uchar(0)
- return bytes
+# def words_to_bytes(self, bytenum, words):
+# bytes = lltype.malloc(RSDL.Uint8P.TO, bytenum, flavor="raw")
+# if words:
+# for pos in range(bytenum / 4):
+# word = words[pos]
+# bytes[pos * 4] = rffi.r_uchar((word >> 24) & 0xff)
+# bytes[pos * 4 + 1] = rffi.r_uchar((word >> 16) & 0xff)
+# bytes[pos * 4 + 2] = rffi.r_uchar((word >> 8) & 0xff)
+# bytes[pos * 4 + 3] = rffi.r_uchar(word & 0xff)
+# else:
+# for idx in range(bytenum):
+# bytes[idx] = rffi.r_uchar(0)
+# return bytes
-SDLCursor = SDLCursorClass()
+# SDLCursor = SDLCursorClass()
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -3,12 +3,14 @@
import os
from rpython.rlib.streamio import open_file_as_stream
-from rpython.rlib import jit, rpath, objectmodel
+from rpython.rlib import jit, rpath, objectmodel, rgc
+from rpython.rlib.entrypoint import entrypoint
+from rpython.rtyper.lltypesystem import rffi, llmemory, lltype
from spyvm import model, interpreter, squeakimage, objspace, wrapper,\
error, shadow, storage_logger, constants
from spyvm.tool.analyseimage import create_image
-from spyvm.interpreter_proxy import VirtualMachine
+# from spyvm.interpreter_proxy import VirtualMachine
def _usage(argv):
print """
@@ -200,6 +202,61 @@
storage_logger.print_aggregated_log()
return 0
+
+ at entrypoint('main', [rffi.INT], c_name='load_image')
+def load_image(bitflags):
+ trace = (bitflags & 0b1) != 0
+ trace_important = (bitflags & 0b10) != 0
+ safe_trace = (bitflags & 0b100) != 0
+
+ space = prebuilt_space
+ if safe_trace:
+ space.omit_printing_raw_bytes.activate()
+ path = rpath.rabspath("/Squeak.image")
+ try:
+ f = open_file_as_stream(path, mode="rb", buffering=0)
+ try:
+ imagedata = f.readall()
+ finally:
+ f.close()
+ except OSError as e:
+ print_error("%s -- %s (LoadError)" % (os.strerror(e.errno), path))
+ return 1
+ # Load & prepare image and environment
+ image_reader = squeakimage.reader_for_image(space, squeakimage.Stream(data=imagedata))
+ image = create_image(space, image_reader)
+ interp = interpreter.Interpreter(space, image,
+ trace=trace, trace_important=trace_important,
+ evented=False, is_async=True)
+ space.runtime_setup("./rsqueak.vm.js", path)
+ print_error("") # Line break after image-loading characters
+ return rffi.cast(rffi.INT, interp)
+
+ at entrypoint('main', [rffi.INT], c_name='load_active_context')
+def load_active_context(i_interp):
+ gcref = rffi.cast(llmemory.GCREF, i_interp)
+ interp = rgc.try_cast_gcref_to_instance(interpreter.Interpreter, gcref)
+ space = interp.space
+ context = active_context(space)
+ return rffi.cast(rffi.INT, context.w_self())
+
+ at entrypoint('main', [rffi.INT, rffi.INT], c_name='execute_async')
+def execute_async(i_interp, i_w_frame):
+ i_gcref = rffi.cast(llmemory.GCREF, i_interp)
+ interp = rgc.try_cast_gcref_to_instance(interpreter.Interpreter, i_gcref)
+ f_gcref = rffi.cast(llmemory.GCREF, i_w_frame)
+ w_frame = rgc.try_cast_gcref_to_instance(model.W_PointersObject, f_gcref)
+ try:
+ w_context = interp.loop(w_frame)
+ print result_string(w_context)
+ # print w_context.as_context_get_shadow(interp.space).print_stack()
+ return rffi.cast(rffi.INT, w_context)
+ except interpreter.ReturnFromTopLevel, e:
+ print "returned from toplevel"
+ print result_string(e.object)
+ return 0
+
+
def result_string(w_result):
# This will also print contents of strings/symbols/numbers
if not w_result:
@@ -279,7 +336,17 @@
if hasattr(rgc, "stm_is_enabled"):
driver.config.translation.stm = True
driver.config.translation.thread = True
+
driver.exe_name = "rsqueak"
+
+ from rpython.translator import platform
+ if hasattr(platform, "emscripten_platform"):
+ # platform.emscripten_platform.EmscriptenPlatform.exe_ext = "js"
+ platform.emscripten_platform.EmscriptenPlatform.link_flags += [
+ "--embed-file", "/home/tim/Dev/lang-smalltalk/images/minibluebookdebug.image@/Squeak.image"
+ ]
+ driver.exe_name = "rsqueak.js"
+
return safe_entry_point, None
def jitpolicy(self):
More information about the pypy-commit
mailing list