Search in sources :

Example 1 with PyLexicalScopeProxyObject

use of org.cafebabepy.runtime.object.proxy.PyLexicalScopeProxyObject in project cafebabepy by cafebabepy.

the class PyInterpretFunctionObject method call.

@Override
public PyObject call(PyObject... args) {
    PyObject lexicalContext = new PyLexicalScopeProxyObject(this.context);
    PyObjectScope scope = lexicalContext.getScope();
    this.runtime.getattrOptional(this.args, "args").ifPresent(argslist -> this.runtime.iterIndex(argslist, (a, i) -> {
        PyObject arg = this.runtime.getattr(a, "arg");
        scope.put(arg.toJava(String.class), args[i]);
    }));
    return evaluator.eval(lexicalContext, body);
}
Also used : PyObject(org.cafebabepy.runtime.PyObject) Python(org.cafebabepy.runtime.Python) AbstractPyObjectObject(org.cafebabepy.runtime.object.AbstractPyObjectObject) PyLexicalScopeProxyObject(org.cafebabepy.runtime.object.proxy.PyLexicalScopeProxyObject) ProtocolNames.__call__(org.cafebabepy.util.ProtocolNames.__call__) PyObjectScope(org.cafebabepy.runtime.PyObjectScope) PyLexicalScopeProxyObject(org.cafebabepy.runtime.object.proxy.PyLexicalScopeProxyObject) PyObject(org.cafebabepy.runtime.PyObject) PyObjectScope(org.cafebabepy.runtime.PyObjectScope)

Example 2 with PyLexicalScopeProxyObject

use of org.cafebabepy.runtime.object.proxy.PyLexicalScopeProxyObject in project cafebabepy by cafebabepy.

the class InterpretEvaluator method evalListComp.

private PyObject evalListComp(PyObject context, PyObject node) {
    PyObject elt = this.runtime.getattr(node, "elt");
    PyObject generators = this.runtime.getattr(node, "generators");
    List<PyObject> generatorList = this.runtime.toList(generators);
    List<PyObject> resultList = new ArrayList<>();
    PyLexicalScopeProxyObject lexicalContext = new PyLexicalScopeProxyObject(context);
    evalGenerators(lexicalContext, elt, generatorList, resultList);
    return this.runtime.list(resultList);
}
Also used : PyLexicalScopeProxyObject(org.cafebabepy.runtime.object.proxy.PyLexicalScopeProxyObject) PyObject(org.cafebabepy.runtime.PyObject)

Aggregations

PyObject (org.cafebabepy.runtime.PyObject)2 PyLexicalScopeProxyObject (org.cafebabepy.runtime.object.proxy.PyLexicalScopeProxyObject)2 PyObjectScope (org.cafebabepy.runtime.PyObjectScope)1 Python (org.cafebabepy.runtime.Python)1 AbstractPyObjectObject (org.cafebabepy.runtime.object.AbstractPyObjectObject)1 ProtocolNames.__call__ (org.cafebabepy.util.ProtocolNames.__call__)1