File: _rffi_stacklet.py

package info (click to toggle)
pypy 5.6.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 97,040 kB
  • ctags: 185,069
  • sloc: python: 1,147,862; ansic: 49,642; cpp: 5,245; asm: 5,169; makefile: 529; sh: 481; xml: 232; lisp: 45
file content (56 lines) | stat: -rw-r--r-- 2,028 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import py
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rtyper.tool import rffi_platform
from rpython.rlib.rarithmetic import is_emulated_long
from rpython.translator import cdir


cdir = py.path.local(cdir)

eci = ExternalCompilationInfo(
    include_dirs = [cdir],
    includes = ['src/stacklet/stacklet.h'],
    separate_module_files = [cdir / 'src' / 'stacklet' / 'stacklet.c'],
)
if 'masm' in dir(eci.platform): # Microsoft compiler
    if is_emulated_long:
        asmsrc = 'switch_x64_msvc.asm'
    else:
        asmsrc = 'switch_x86_msvc.asm'
    eci.separate_module_files += (cdir / 'src' / 'stacklet' / asmsrc, )

rffi_platform.verify_eci(eci.convert_sources_to_files())

def llexternal(name, args, result, **kwds):
    return rffi.llexternal(name, args, result, compilation_info=eci,
                           _nowrapper=True, **kwds)

# ----- types -----

handle = rffi.COpaquePtr(typedef='stacklet_handle', compilation_info=eci)
thread_handle = rffi.COpaquePtr(typedef='stacklet_thread_handle',
                                compilation_info=eci)
run_fn = lltype.Ptr(lltype.FuncType([handle, llmemory.Address], handle))

# ----- constants -----

null_handle = lltype.nullptr(handle.TO)

def is_empty_handle(h):
    return rffi.cast(lltype.Signed, h) == -1

# ----- functions -----

newthread = llexternal('stacklet_newthread', [], thread_handle)
deletethread = llexternal('stacklet_deletethread',[thread_handle], lltype.Void)

new = llexternal('stacklet_new', [thread_handle, run_fn, llmemory.Address],
                 handle, random_effects_on_gcobjs=True)
switch = llexternal('stacklet_switch', [handle], handle,
                    random_effects_on_gcobjs=True)
destroy = llexternal('stacklet_destroy', [handle], lltype.Void)

_translate_pointer = llexternal("_stacklet_translate_pointer",
                                [llmemory.Address, llmemory.Address],
                                llmemory.Address)