Esempio n. 1
0
import py
from prolog.interpreter.parsing import TermBuilder
from prolog.interpreter import helper, term, error
from prolog.interpreter.signature import Signature
from prolog.interpreter.arithmetic import eval_arithmetic

from rpython.rlib.objectmodel import we_are_translated
from rpython.rlib import jit

import inspect

Signature.register_extr_attr("builtin")

jit_modules = ["control"]

class Builtin(object):
    _immutable_ = True
    def __init__(self, function, name, numargs, signature):
        self.function = function
        self.name = name
        self.numargs = numargs
        self.signature = signature

    def call(self, engine, query, rule, scont, fcont, heap):
        try:
            return self.function(engine, query, rule, scont, fcont, heap)
        except error.CatchableError as e:
            e.sig_context = self.signature
            raise

    def _freeze_(self):
Esempio n. 2
0
import py
import time
from rpython.rlib import jit
from rpython.rlib.objectmodel import we_are_translated, specialize
from prolog.interpreter import error
from prolog.interpreter import helper
from prolog.interpreter.term import Term, Atom, BindingVar, Callable, Var
from prolog.interpreter.function import Function, Rule
from prolog.interpreter.heap import Heap
from prolog.interpreter.signature import Signature
from prolog.interpreter.module import Module, ModuleWrapper
from prolog.interpreter.helper import unwrap_predicate_indicator
from prolog.interpreter.stream import StreamWrapper

Signature.register_extr_attr("function", engine=True)

# ___________________________________________________________________
# JIT stuff

def get_printable_location(rule, sconttype):
    if rule:
        s = rule.signature.string()
    else:
        s = "No rule"
    return "%s %s" % (s, sconttype)

def get_jitcell_at(where, rule):
    # XXX can be vastly simplified
    return rule.jit_cells.get(where, None)

def set_jitcell_at(newcell, where, rule):
Esempio n. 3
0
import py
import math
from prolog.interpreter.parsing import TermBuilder
from prolog.interpreter import helper, term, error
from prolog.interpreter.signature import Signature
from prolog.interpreter.error import UnificationFailed
from rpython.rlib.rarithmetic import intmask, ovfcheck_float_to_int
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib import jit, rarithmetic
from rpython.rlib.rbigint import rbigint

Signature.register_extr_attr("arithmetic")

def eval_arithmetic(engine, obj):
    result = obj.eval_arithmetic(engine)
    return make_int(result)

class CodeCollector(object):
    def __init__(self):
        self.code = []
        self.blocks = []

    def emit(self, line):
        for line in line.split("\n"):
            self.code.append(" " * (4 * len(self.blocks)) + line)

    def start_block(self, blockstarter):
        assert blockstarter.endswith(":")
        self.emit(blockstarter)
        self.blocks.append(blockstarter)
Esempio n. 4
0
from subprocess import call
from rpython.rlib import jit
from rpython.rlib.objectmodel import we_are_translated, specialize
from prolog.interpreter import error
from prolog.interpreter import helper
from prolog.interpreter.term import Term, Atom, BindingVar, Callable, Var
from prolog.interpreter.function import Function, Rule
from prolog.interpreter.heap import Heap
from prolog.interpreter.signature import Signature
from prolog.interpreter.module import Module, ModuleWrapper
from prolog.interpreter.helper import unwrap_predicate_indicator
from prolog.interpreter.stream import StreamWrapper
from prolog.interpreter.small_list import inline_small_list
from prolog.interpreter.similarity import Similarity

Signature.register_extr_attr("function", engine=True)

# ___________________________________________________________________
# JIT stuff


def get_printable_location(rule, sconttype):
    if rule:
        s = rule.signature.string()
    else:
        s = "No rule"
    return "%s %s" % (s, sconttype)


def get_jitcell_at(where, rule):
    # XXX can be vastly simplified
Esempio n. 5
0
import py
from prolog.interpreter.parsing import TermBuilder
from prolog.interpreter import helper, term, error
from prolog.interpreter.signature import Signature
from prolog.interpreter.arithmetic import eval_arithmetic

from rpython.rlib.objectmodel import we_are_translated
from rpython.rlib import jit

import inspect

Signature.register_extr_attr("builtin")

jit_modules = ["control"]


class Builtin(object):
    _immutable_ = True

    def __init__(self, function, name, numargs, signature):
        self.function = function
        self.name = name
        self.numargs = numargs
        self.signature = signature

    def call(self, engine, query, rule, scont, fcont, heap):
        try:
            return self.function(engine, query, rule, scont, fcont, heap)
        except error.CatchableError as e:
            e.sig_context = self.signature
            raise