| 1 |
import py |
| 2 |
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi |
| 3 |
from rpython.translator.tool.cbuild import ExternalCompilationInfo |
| 4 |
from rpython.rtyper.tool import rffi_platform |
| 5 |
from rpython.rlib.rarithmetic import is_emulated_long |
| 6 |
from rpython.translator import cdir |
| 7 |
|
| 8 |
|
| 9 |
cdir = py.path.local(cdir) |
| 10 |
|
| 11 |
eci = ExternalCompilationInfo( |
| 12 |
include_dirs = [cdir], |
| 13 |
includes = ['src/stacklet/stacklet.h'], |
| 14 |
separate_module_files = [cdir / 'src' / 'stacklet' / 'stacklet.c'], |
| 15 |
) |
| 16 |
if 'masm' in dir(eci.platform): |
| 17 |
if is_emulated_long: |
| 18 |
asmsrc = 'switch_x64_msvc.asm' |
| 19 |
else: |
| 20 |
asmsrc = 'switch_x86_msvc.asm' |
| 21 |
eci.separate_module_files += (cdir / 'src' / 'stacklet' / asmsrc, ) |
| 22 |
|
| 23 |
rffi_platform.verify_eci(eci.convert_sources_to_files()) |
| 24 |
|
| 25 |
def llexternal(name, args, result, **kwds): |
| 26 |
return rffi.llexternal(name, args, result, compilation_info=eci, |
| 27 |
_nowrapper=True, **kwds) |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
handle = rffi.COpaquePtr(typedef='stacklet_handle', compilation_info=eci) |
| 32 |
thread_handle = rffi.COpaquePtr(typedef='stacklet_thread_handle', |
| 33 |
compilation_info=eci) |
| 34 |
run_fn = lltype.Ptr(lltype.FuncType([handle, llmemory.Address], handle)) |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
null_handle = lltype.nullptr(handle.TO) |
| 39 |
|
| 40 |
def is_empty_handle(h): |
| 41 |
return rffi.cast(lltype.Signed, h) == -1 |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
newthread = llexternal('stacklet_newthread', [], thread_handle) |
| 46 |
deletethread = llexternal('stacklet_deletethread',[thread_handle], lltype.Void) |
| 47 |
|
| 48 |
new = llexternal('stacklet_new', [thread_handle, run_fn, llmemory.Address], |
| 49 |
handle, random_effects_on_gcobjs=True) |
| 50 |
switch = llexternal('stacklet_switch', [handle], handle, |
| 51 |
random_effects_on_gcobjs=True) |
| 52 |
destroy = llexternal('stacklet_destroy', [handle], lltype.Void) |
| 53 |
|
| 54 |
_translate_pointer = llexternal("_stacklet_translate_pointer", |
| 55 |
[llmemory.Address, llmemory.Address], |
| 56 |
llmemory.Address) |