code
stringlengths
1
1.72M
language
stringclasses
1 value
class _R(int): def __repr__(self): return "r%s"%(super(_R, self).__repr__(),) __str__ = __repr__ class _F(int): def __repr__(self): return "fr%s"%(super(_F, self).__repr__(),) __str__ = __repr__ r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, \ r13, r14, r15, r16, r17, r18, r...
Python
# XXX there is much grot here. # some of this comes from trying to present a reasonably intuitive and # useful interface, which implies a certain amount of DWIMmery. # things surely still could be more transparent. class FormException(Exception): pass class Instruction(object): def __init__(self, fields): ...
Python
from pypy.tool.sourcetools import compile2 from pypy.rlib.rarithmetic import r_uint from pypy.jit.codegen.ppc.ppcgen.form import IDesc, IDupDesc ## "opcode": ( 0, 5), ## "rA": (11, 15, 'unsigned', regname._R), ## "rB": (16, 20, 'unsigned', regname._R), ## "Rc": (31, 31), ## "rD": (...
Python
from pypy.jit.codegen.ppc.ppcgen.field import Field from pypy.jit.codegen.ppc.ppcgen import regname fields = { # bit margins are *inclusive*! (and bit 0 is # most-significant, 31 least significant) "opcode": ( 0, 5), "AA": (30, 30), "BD": (16, 29, 'signed'), "BI": (11, 15), ...
Python
from pypy.jit.codegen.ppc.ppcgen.ppc_form import PPCForm as Form from pypy.jit.codegen.ppc.ppcgen.ppc_field import ppc_fields from pypy.jit.codegen.ppc.ppcgen.assembler import Assembler from pypy.jit.codegen.ppc.ppcgen.symbol_lookup import lookup A = Form("frD", "frA", "frB", "XO3", "Rc") A1 = Form("frD", "frB", "XO3"...
Python
from pypy.jit.codegen.ppc.ppcgen.ppc_assembler import MyPPCAssembler from pypy.jit.codegen.ppc.ppcgen.func_builder import make_func from regname import * def access_at(): a = MyPPCAssembler() a.lwzx(r3, r3, r4) a.blr() return make_func(a, "i", "ii") access_at = access_at() def itoO(): a = MyPP...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
class PyVarObject(object): ob_size = 8 class PyObject(object): ob_refcnt = 0 ob_type = 4 class PyTupleObject(object): ob_item = 12 class PyTypeObject(object): tp_name = 12 tp_basicsize = 16 tp_itemsize = 20 tp_dealloc = 24 class PyFloatObject(object): ob_fval = 8 class PyIntObje...
Python
from pypy.jit.codegen.ppc.ppcgen.form import Form from pypy.jit.codegen.ppc.ppcgen.ppc_field import ppc_fields class PPCForm(Form): fieldmap = ppc_fields def __init__(self, *fnames): super(PPCForm, self).__init__(*("opcode",) + fnames) def __call__(self, opcode, **specializations): specia...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
import py from pypy.jit.codegen import detect_cpu class Directory(py.test.collect.Directory): def run(self): try: processor = detect_cpu.autodetect() except detect_cpu.ProcessorAutodetectError, e: py.test.skip(str(e)) else: if processor != 'ppc': ...
Python
import pypy.rpython.rctypes.implementation # register rctypes types from pypy.rpython.rctypes.tool import ctypes_platform from pypy.rpython.rctypes.tool.libc import libc from ctypes import POINTER, cast, c_void_p, c_int, c_char class CConfig: _includes_ = ("sys/types.h", "sys/mman.h") size_t = ctypes_platform...
Python
#
Python
r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, \ r13, r14, r15, r16, r17, r18, r19, r20, r21, r22, \ r23, r24, r25, r26, r27, r28, r29, r30, r31 = range(32) rSCRATCH = r0 rSP = r1 rFP = r2 # the ABI doesn't specify a frame pointer. however, we want one class AllocationSlot(object): offset = 0 ...
Python
class CycleData: # tar2src -> map target var to source var # src2tar -> map source var to target var (!) # tar2loc -> map target var to location # src2loc -> map source var to location # loc2src -> map location to source var # srcstack -> list of source vars # freshctr -> how many fres...
Python
#
Python
""" This backend records all operations that the JIT front-end tries to do, and writes them as pseudo-Python source in /tmp/usession-<yourname>/rdumpgenop.py. """ import os from pypy.rlib.objectmodel import specialize, we_are_translated from pypy.rpython.lltypesystem import lltype, llmemory from pypy.jit.codegen.m...
Python
#
Python
class HighLevelJITInfo: """ A singleton class for the RPython-level JITed program to push information that the backend can use or log. """ sys_executable = None highleveljitinfo = HighLevelJITInfo()
Python
import ctypes import pypy.rpython.rctypes.implementation from pypy.rpython.rctypes.tool import ctypes_platform from pypy.rpython.rctypes.tool.ctypes_platform import ConstantInteger from pypy.rpython.rctypes.tool.ctypes_platform import SimpleType class CConfig: _header_ = '#include <Windows.h>' SIZE_T ...
Python
""" List of i386 instructions. This module contains the logic to set up the I386CodeBuilder multimethods. Not for direct importing. """ from ri386 import * from pypy.objspace.std.multimethod import MultiMethodTable, InstallerVersion2 from pypy.tool.sourcetools import compile2 def reg2modrm(builder, reg): return m...
Python
import pypy.rpython.rctypes.implementation # register rctypes types from pypy.rpython.rctypes.tool import ctypes_platform from pypy.rpython.rctypes.tool.libc import libc from ctypes import POINTER, c_char, c_int, cast, c_void_p class CConfig: _includes_ = ("sys/types.h", "sys/mman.h") size_t = ctypes_platform...
Python
import py from pypy.rlib.objectmodel import specialize, we_are_translated from pypy.rpython.lltypesystem import lltype, llmemory from pypy.jit.codegen.model import AbstractRGenOp, GenLabel, GenBuilder from pypy.jit.codegen.model import GenVar, GenConst, CodeGenSwitch from pypy.jit.codegen.model import ReplayBuilder, du...
Python
"""Register allocation. """ import sys from pypy.rlib.objectmodel import we_are_translated from pypy.rpython.lltypesystem import lltype from pypy.jit.codegen.i386.operation import * DEBUG_STACK = False class StackOpCache: INITIAL_STACK_EBP_OFS = -1 stack_op_cache = StackOpCache() stack_op_cache.lst = [] def s...
Python
import py from pypy.jit.codegen import detect_cpu class Directory(py.test.collect.Directory): def run(self): try: processor = detect_cpu.autodetect() except detect_cpu.ProcessorAutodetectError, e: py.test.skip(str(e)) else: if processor != 'i386': ...
Python
#! /usr/bin/env python """ Viewer for the CODE_DUMP output of compiled programs generating code. Try: ./viewcode.py dumpfile.txt or /tmp/usession-xxx/testing_1/testing_1 -var 4 2>&1 | ./viewcode.py """ import autopath import operator, sys, os, re, py, new from bisect import bisect_left # don't use pypy.to...
Python
import os from ctypes import POINTER, cast, c_char, c_void_p, CFUNCTYPE, c_int from ri386 import I386CodeBuilder # ____________________________________________________________ modname = 'pypy.jit.codegen.i386.codebuf_' + os.name memhandler = __import__(modname, globals(), locals(), ['__doc__']) PTR = memhandler.PTR...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
#! /usr/bin/env python """ Viewer for the CODE_DUMP output of compiled programs generating code. Try: ./viewcode.py dumpfile.txt or /tmp/usession-xxx/testing_1/testing_1 -var 4 2>&1 | ./viewcode.py """ import autopath import operator, sys, os, re, py, new from bisect import bisect_left # don't use pypy.to...
Python
"""Operations. In the spirit of LLVM, operations are also variables themselves: they are their own result variable. """ import sys from pypy.rlib.objectmodel import specialize from pypy.objspace.std.multimethod import FailedToImplement from pypy.jit.codegen.i386.ri386 import * from pypy.jit.codegen.i386.ri386setup im...
Python
from pypy.rlib.rarithmetic import intmask class OPERAND(object): _attrs_ = [] def __repr__(self): return '<%s %s>' % (self.__class__.__name__, self.assembler()) class REG(OPERAND): width = 4 def __repr__(self): return '<%s>' % self.__class__.__name__.lower() def assembler(self): ...
Python
""" For testing purposes. Turns *simple enough* low-level graphs into machine code by calling the rgenop interface. """ from pypy.rpython.lltypesystem import lltype from pypy.objspace.flow import model as flowmodel import random def rcompile(rgenop, entrypoint, argtypes, random_seed=0): from pypy.translator.tran...
Python
""" Awful code here. Paste your example in "lines". Change headers and footers if necessary below. The script tries to reduce it by removing lines matching 'r' and changing lines matching 'rif' to 'if True' or 'if False'. The smallest failing example found so far gets written to zsample.py. """ import autopath impo...
Python
import random from pypy.jit.codegen.demo import test_random from pypy.jit.codegen.demo import conftest as demo_conftest # each iteration of test_many_times leaks memory, so we can't run # it forever. If you want that result, use a bash command like: # # while py.test autorun.py --pdb; do echo "again"; done def...
Python
import py, random from pypy.jit.codegen.ppc import conftest Option = py.test.config.Option option = py.test.config.addoptions("demo options", Option('--seed', action="store", type="int", default=random.randrange(0, 10000), dest="randomseed", help="choose a fixed r...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
from pypy.jit.codegen.demo import test_random from pypy.jit.codegen.demo import conftest as demo_conftest def rerun(seed, *args): prevseed = demo_conftest.option.randomseed try: demo_conftest.option.randomseed = seed test_random.test_random_function(*args) finally: demo_conftest.opt...
Python
import os, sys import py from pypy.tool.udir import udir from pypy.rlib.ros import putenv from pypy.jit.codegen.graph2rgenop import rcompile from pypy.rpython.lltypesystem import lltype from pypy import conftest from pypy.jit import conftest as bench_conftest from pypy.jit.codegen.demo import conftest as demo_conftest...
Python
import random, sys from pypy.rpython.annlowlevel import MixLevelAnnotatorPolicy, llhelper from pypy.rlib.rarithmetic import intmask, r_uint from pypy.rlib.objectmodel import keepalive_until_here from pypy.rpython.lltypesystem import lltype, llmemory from pypy.translator.c.test import test_boehm from ctypes import c_voi...
Python
import py, os, sys from pypy.annotation import model as annmodel from pypy.annotation.listdef import s_list_of_strings from pypy.rlib.objectmodel import keepalive_until_here from pypy.jit.timeshifter.test import test_timeshift from pypy.translator.c.genc import CStandaloneBuilder from pypy.rlib.unroll import unrolling_...
Python
#
Python
from pypy.annotation import model as annmodel from pypy.translator.translator import TranslationContext, graphof from pypy.jit.codegen import graph2rgenop from pypy.rpython.lltypesystem import lltype from pypy.rpython.lltypesystem.lloperation import llop from pypy.rlib.rarithmetic import r_uint, intmask, ovfcheck from ...
Python
import py, time, os # Usage: py.test --benchmark # # This module provides an RPython class to use as follows: # # bench = Benchmark() # while 1: # do_something # if bench.stop(): # break Option = py.test.config.Option option = py.test.config.addoptions("pypy options", ...
Python
from pypy.annotation import model as annmodel from pypy.annotation.pairtype import pair, pairtype from pypy.jit.hintannotator.bookkeeper import getbookkeeper from pypy.rpython.lltypesystem import lltype, lloperation UNARY_OPERATIONS = """same_as hint getfield setfield getsubstruct getarraysize ca...
Python
import py from pypy.tool.tls import tlsobject from pypy.tool.ansi_print import ansi_log from pypy.rlib import jit from pypy.objspace.flow.model import copygraph, SpaceOperation, Constant from pypy.objspace.flow.model import Variable, Block, Link, FunctionGraph from pypy.annotation import model as annmodel from pypy.rpy...
Python
from pypy.annotation import policy from pypy.annotation.specialize import getuniquenondirectgraph from pypy.translator.translator import graphof class HintAnnotatorPolicy(policy.AnnotatorPolicy): novirtualcontainer = False oopspec = False entrypoint_returns_red = True def __init__(s...
Python
import weakref, itertools from pypy.annotation.listdef import ListItem from pypy.annotation import model as annmodel from pypy.jit.hintannotator import model as hintmodel from pypy.rpython.lltypesystem import lltype class AbstractContainerDef(object): __counter = itertools.count() __cache = {} def __in...
Python
from pypy.annotation import model as annmodel from pypy.annotation.annrpython import RPythonAnnotator, BlockedInference from pypy.annotation.annrpython import raise_nicer_exception from pypy.objspace.flow.model import Variable from pypy.jit.hintannotator import model as hintmodel from pypy.jit.hintannotator.bookkeeper ...
Python
from pypy.annotation.listdef import ListItem from pypy.jit.hintannotator.model import SomeLLAbstractConstant from pypy.jit.hintannotator.model import SomeLLAbstractContainer, reorigin from pypy.jit.hintannotator.bookkeeper import getbookkeeper from pypy.jit.hintannotator.container import AbstractContainerDef from pypy....
Python
from pypy.rpython.lltypesystem import lltype, llmemory, lloperation from pypy.rpython.annlowlevel import cachedtype from pypy.rpython.annlowlevel import cast_base_ptr_to_instance from pypy.rpython.annlowlevel import cast_instance_to_base_ptr from pypy.rlib.unroll import unrolling_iterable debug_print = lloperation.llo...
Python
import sys from pypy.objspace.flow.model import Variable, Constant, Block, Link from pypy.objspace.flow.model import SpaceOperation, mkentrymap from pypy.annotation import model as annmodel from pypy.jit.hintannotator import model as hintmodel from pypy.jit.hintannotator.model import originalconcretetype from py...
Python
import operator from pypy.rpython.lltypesystem import lltype from pypy.rpython.lltypesystem import rdict from pypy.jit.timeshifter.rcontainer import VirtualContainer, FrozenContainer from pypy.jit.timeshifter.rcontainer import cachedtype from pypy.jit.timeshifter import rvalue from pypy.rlib.objectmodel import r_dict ...
Python
from pypy.rpython.lltypesystem import lltype, llmemory from pypy.jit.timeshifter import rvalue, rtimeshift class ExceptionDesc: def __init__(self, hrtyper, lazy_exception_path): RGenOp = hrtyper.RGenOp self.etrafo = hrtyper.annotator.exceptiontransformer self.cexcdata = self.etrafo.cexcda...
Python
import operator, weakref from pypy.annotation import model as annmodel from pypy.rpython.lltypesystem import lltype, lloperation, llmemory from pypy.jit.hintannotator.model import originalconcretetype from pypy.jit.timeshifter import rvalue, rcontainer, rvirtualizable from pypy.rlib.unroll import unrolling_iterable fro...
Python
import types import py from pypy.tool.ansi_print import ansi_log from pypy.objspace.flow import model as flowmodel from pypy.translator.unsimplify import varoftype from pypy.translator.backendopt.ssa import SSA_to_SSI from pypy.annotation import model as annmodel from pypy.annotation import listdef from pypy.annotation...
Python
import operator from pypy.rpython.lltypesystem import lltype, llmemory from pypy.rpython.annlowlevel import cachedtype, cast_base_ptr_to_instance from pypy.rpython.annlowlevel import base_ptr_lltype, cast_instance_to_base_ptr from pypy.jit.timeshifter import rvalue from pypy.rlib.unroll import unrolling_iterable from p...
Python
from pypy.rpython.lltypesystem import lltype from pypy.rpython.extregistry import ExtRegistryEntry from pypy.jit.timeshifter.rcontainer import cachedtype from pypy.jit.timeshifter import rvalue, rtimeshift from pypy.translator.c import exceptiontransform from pypy.rlib.unroll import unrolling_iterable from pypy.tool.so...
Python
from pypy.rpython.lltypesystem import lltype, llmemory class Memo(object): _annspecialcase_ = 'specialize:ctr_location' def __init__(self): self.boxes = {} self.containers = {} def enter_block_memo(): return Memo() def freeze_memo(): return Memo() def exactmatch_memo(force_merge=Fal...
Python
from pypy.rpython.lltypesystem import lltype, llmemory from pypy.jit.timeshifter.rcontainer import VirtualContainer, FrozenContainer from pypy.jit.timeshifter.rcontainer import cachedtype from pypy.jit.timeshifter import rvalue, rvirtualizable from pypy.rpython.lltypesystem import lloperation debug_print = lloperation...
Python
import py Option = py.test.config.Option option = py.test.config.addoptions("timeshifter tests options", Option('--dump', action="store_true", default=False, dest="use_dump_backend", help="uses the dump backend, to log the backend operations"), )
Python
'''Toy Language with Cons Cells''' import py from pypy.jit.tl.opcode import * from pypy.jit.tl import opcode as tlopcode from pypy.rlib.jit import hint class Obj(object): def t(self): raise TypeError def int_o(self): raise TypeError def add(self, other): raise TypeError def sub(self, other): ra...
Python
from pypy.jit.tl import tiny2 from pypy.jit.codegen.hlinfo import highleveljitinfo def entry_point(args): """Main entry point of the stand-alone executable: takes a list of strings and returns the exit code. """ # store args[0] in a place where the JIT log can find it (used by # viewcode.py to kno...
Python
from pypy.rlib.jit import hint def ll_plus_minus(s, x, y): acc = x pc = 0 while pc < len(s): op = s[pc] hint(op, concrete=True) if op == '+': acc += y elif op == '-': acc -= y pc += 1 return acc def test_simple(): res = ll_plus_minu...
Python
from pypy.rlib.jit import hint MOV_A_R = 1 MOV_R_A = 2 JUMP_IF_A = 3 SET_A = 4 ADD_R_TO_A = 5 RETURN_A = 6 ALLOCATE = 7 NEG_A = 8 def interpret(bytecode, a): """Another Toy Language interpreter, this one register-based.""" regs = [] pc = 0 while True: hint(None, global_m...
Python
names = {} def opcode(n, opcode_name): global opcode_names names[opcode_name] = globals()[opcode_name] = n # basic tl opcodes: opcode(1, "NOP") opcode(2, "PUSH") #1 operand opcode(3, "POP") opcode(4, "SWAP") opcode(5, "ROLL") opcode(6, "PICK") #1 operand (DUP = PICK,0) opcode(7, "PUT") ...
Python
from pypy.jit.tl import tiny1 from pypy.jit.codegen.hlinfo import highleveljitinfo def entry_point(args): """Main entry point of the stand-alone executable: takes a list of strings and returns the exit code. """ # store args[0] in a place where the JIT log can find it (used by # viewcode.py to kno...
Python
class BrainInterpreter(object): def __init__(self): self.table = [0] * 30000 self.pointer = 0 def interp_char(self, code, code_pointer, input, output): char_code = code[code_pointer] if char_code == '>': self.pointer += 1 elif char_code == '<': s...
Python
""" An interpreter for a strange word-based language: the program is a list of space-separated words. Most words push themselves on a stack; some words have another action. The result is the space-separated words from the stack. Hello World => 'Hello World' 6 7 ADD => '13' ...
Python
'''Toy Language''' import py from pypy.jit.tl.opcode import * from pypy.rlib.jit import hint def char2int(c): t = ord(c) if t & 128: t = -(-ord(c) & 0xff) return t def make_interp(supports_call): def interp(code='', pc=0, inputarg=0): if not isinstance(code,str): raise Typ...
Python
import autopath import py from pypy.config import pypyoption, translationoption, config from pypy.doc.config.confrest import all_optiondescrs thisdir = py.magic.autopath().dirpath() for descr in all_optiondescrs: prefix = descr._name c = config.Config(descr) thisdir.join(prefix + ".txt").ensure() for ...
Python
from pypy.doc.confrest import * from pypy.config.makerestdoc import make_cmdline_overview from pypy.config.config import Config from pypy.config import pypyoption, translationoption all_optiondescrs = [pypyoption.pypy_optiondescription, translationoption.translation_optiondescription, ...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
import autopath import py from pypy.config import pypyoption, translationoption, config thisdir = py.magic.autopath().dirpath() if __name__ == '__main__': c = config.Config(pypyoption.pypy_optiondescription).usemodules prefix = "objspace.usemodules" thisdir.join(prefix + ".txt").ensure() for p in c.ge...
Python
import py from py.__.doc.confrest import * class PyPyPage(Page): def fill_menubar(self): self.menubar = html.div( html.a("news", href="http://codespeak.net/pypy/dist/pypy/doc/news.html", class_="menu"), " ", html.a("getting-started", ...
Python
import py from py.__.doc.conftest import Directory, DoctestText, ReSTChecker from py.__.rest.directive import register_linkrole thisdir = py.magic.autopath().dirpath() Option = py.test.config.Option option = py.test.config.addoptions("pypy-doc options", Option('--generate-redirections', action="store_true", ...
Python
#!/usr/bin/env python import log_reader def daily_date_hasher(date): return ((date.year, date.month, date.day)) def read_log(filename, path_guesser, date_hasher=daily_date_hasher, max_reads=None): assert callable(path_guesser) lr = log_reader.ApacheReader(filename) ret = {} keys = [] ...
Python
#!/usr/bin/env python import log_reader def daily_date_hasher(date): return ((date.year, date.month, date.day)) def read_log(filename, path_guesser, date_hasher=daily_date_hasher, max_reads=None): assert callable(path_guesser) lr = log_reader.ApacheReader(filename) ret = {} keys = [] ...
Python
#!/usr/bin/env python import py import string import re nonalpha = "".join([chr(i) for i in range(256) if not chr(i).isalpha()]) replacement = (string.ascii_letters * (int(len(nonalpha) / len(string.ascii_letters)) + 1))[:len(nonalpha)] transtable = string.maketrans(nonalpha, replacement) del nonalpha del replacement...
Python
#!/usr/bin/env python import py import string import re nonalpha = "".join([chr(i) for i in range(256) if not chr(i).isalpha()]) replacement = (string.ascii_letters * (int(len(nonalpha) / len(string.ascii_letters)) + 1))[:len(nonalpha)] transtable = string.maketrans(nonalpha, replacement) del nonalpha del replacement...
Python
import py py.magic.autopath() import pypy pypydir = py.path.local(pypy.__file__).dirpath() distdir = pypydir.dirpath() dist_url = 'http://codespeak.net/svn/pypy/dist/' issue_url = 'http://codespeak.net/issue/pypy-dev/' docdir = pypydir.join('doc') reffile = pypydir.join('doc', '_ref.txt') linkrex = py.std.re.co...
Python
#
Python
""" generates a contributor list """ import py try: path = py.std.sys.argv[1] except IndexError: print "usage: %s PATH" %(py.std.sys.argv[0]) raise SystemExit, 1 d = {} for logentry in py.path.svnwc(py.std.sys.argv[1]).log(): a = logentry.author if a in d: d[a] += 1 else: ...
Python
#
Python
import py from py.__.doc.confrest import * class PyPyPage(Page): def fill_menubar(self): self.menubar = html.div( html.a("news", href="../news.html", class_="menu"), " ", html.a("doc", href="../index.html", class_="menu"), " ", html.a("contact", href="../contact.html", ...
Python
import py from py.__.doc.confrest import * class PyPyPage(Page): def fill_menubar(self): self.menubar = html.div( html.a("news", href="../news.html", class_="menu"), " ", html.a("doc", href="../index.html", class_="menu"), " ", html.a("contact", href="../contact.html", ...
Python
import py import datetime import dateutil from dateutil import parser import pylab import matplotlib greyscale = False def get_data(p): data = p.readlines() title = data[0].strip() axis = data[1].strip().split(',') data = [convert_data(t) for t in zip(*[l.strip().split(',') for l in data[2:]])] r...
Python
import py chunks = 7 p = py.path.local(py.std.sys.argv[1]) data = [l.strip() for l in p.readlines()] result = data[:2] data = data[2:] acc = 0 for i, line in enumerate(data): print line line = line.split(',') acc += int(line[1]) if i % chunks == chunks - 1: line[1] = str(acc) result...
Python
import autopath from pypy.rlib.parsing.pypackrat import PackratParser from pypy.rlib.parsing.makepackrat import BacktrackException, Status from pypy.lang.scheme.object import W_Pair, W_Integer, W_String, W_Identifier, \ W_Nil, W_Boolean, W_Real, literal def unquote(s): str_lst = [] last_ch = '' for...
Python
#!/usr/bin/env python """ Interactive (untranslatable) version of the pypy scheme interpreter """ import autopath from pypy.lang.scheme.object import ExecutionContext, SchemeException, \ SchemeQuit from pypy.lang.scheme.ssparser import parse from pypy.rlib.parsing.makepackrat import BacktrackException import os...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
import py class SchemeException(Exception): pass class UnboundVariable(SchemeException): def __str__(self): return "Unbound variable %s" % (self.args[0], ) class NotCallable(SchemeException): def __str__(self): return "%s is not a callable" % (self.args[0].to_string(), ) class WrongArgsN...
Python
#!/usr/bin/env python """ Interactive (untranslatable) version of the pypy scheme interpreter """ import autopath from pypy.lang.scheme.object import ExecutionContext, SchemeException, \ SchemeQuit from pypy.lang.scheme.ssparser import parse from pypy.rlib.parsing.makepackrat import BacktrackException import os...
Python
import math from pypy.lang.js.jsparser import parse, ParseError from pypy.lang.js.astbuilder import ASTBuilder from pypy.lang.js.operations import * from pypy.lang.js.jsobj import ThrowException from pypy.rlib.objectmodel import we_are_translated from pypy.rlib.streamio import open_file_as_stream ASTBUILDER = ASTBuil...
Python
import py Option = py.test.config.Option option = py.test.config.addoptions("ecma compatibility tests", Option('', '--ecma', action="store_true", dest="ecma", default=False, help="run js interpreter ecma tests" ), )
Python
# encoding: utf-8 """ operations.py Implements the javascript operations nodes for the interpretation tree """ #XXX * imports are bad from pypy.lang.js.jsobj import * from pypy.rlib.parsing.ebnfparse import Symbol, Nonterminal from pypy.rlib.rarithmetic import r_uint, intmask from constants import unescapedict, SLASH ...
Python
escapes = [ r'\n', r'\r', r'\f', r'\v', r'\ ', r'\t', r"\'", r'\b', r'\"', r'\\', r'\u'] #don't know what to do with these codes = [ '\n', '\r', '\f', '\v', '\ ', '\t', "'", "\b", '"', '\\', 'u'] escapedict = dict(zip(codes, escap...
Python
#!/usr/bin/env python # encoding: utf-8 """ js_interactive.py """ import autopath import sys import getopt from pypy.lang.js.interpreter import load_source, Interpreter, load_file from pypy.lang.js.jsparser import parse, ParseError from pypy.lang.js.jsobj import W_Builtin, W_String, ThrowException, w_Undefined from py...
Python
#!/usr/bin/env python import autopath from py import path import py import os import sys from subprocess import * pwd = path.local(__file__) shell = pwd.dirpath('test', 'ecma', 'shell.js') exclusionlist = ['shell.js', 'browser.js'] def filter(filename): if filename.basename in exclusionlist or not filename.basena...
Python
from pypy.rlib.parsing.tree import RPythonVisitor, Symbol, Nonterminal from pypy.lang.js import operations class ASTBuilder(RPythonVisitor): BINOP_TO_CLS = { '+': operations.Plus, '-': operations.Sub, '*': operations.Mult, '/': operations.Division, '%': operations.Mod, ...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python