Search in sources :

Example 16 with Environment

use of php.runtime.env.Environment in project jphp by jphp-compiler.

the class WrapFlow method __construct.

@Signature({ @Arg(value = "collection", type = HintType.TRAVERSABLE) })
public Memory __construct(Environment env, Memory... args) {
    ForeachIterator iterator = args[0].toImmutable().getNewIterator(env);
    this.iterator = iterator;
    this.worker = new Worker() {

        @Override
        public boolean next(Environment env) {
            return WrapFlow.this.iterator.next();
        }
    };
    this.worker.setIterator(iterator);
    return Memory.NULL;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Environment(php.runtime.env.Environment)

Example 17 with Environment

use of php.runtime.env.Environment in project jphp by jphp-compiler.

the class WebServerController method get.

@RequestMapping
public void get(OutputStream stream, HttpServletRequest request, HttpServletResponse response) throws Throwable {
    PWebServer webServer = webServerMap.get(serverId);
    Environment environment = webServer.getEnvironment();
    CompileScope scope = environment.getScope();
    Environment requestEnvironment;
    if (!webServer.isIsolated()) {
        requestEnvironment = new Environment(environment);
    } else {
        if (webServer.isHotReload()) {
            scope = new CompileScope(scope);
        }
        requestEnvironment = new Environment(scope);
    }
    requestEnvironment.getDefaultBuffer().setOutput(stream);
    if (webServer.isImportAutoloaders()) {
        for (SplClassLoader loader : environment.getClassLoaders()) {
            requestEnvironment.registerAutoloader(loader.forEnvironment(requestEnvironment), false);
        }
    }
    Invoker onRequest = webServer.getOnRequest().forEnvironment(requestEnvironment);
    PWebRequest webRequest = new PWebRequest(requestEnvironment, request);
    PWebResponse webResponse = new PWebResponse(requestEnvironment, response);
    requestEnvironment.setUserValue(webServer);
    requestEnvironment.setUserValue(webRequest);
    requestEnvironment.setUserValue(webResponse);
    try {
        onRequest.call(ObjectMemory.valueOf(webRequest), ObjectMemory.valueOf(webResponse));
    } catch (Throwable throwable) {
        Environment.catchThrowable(throwable, requestEnvironment);
    } finally {
        requestEnvironment.doFinal();
    }
}
Also used : PWebServer(org.develnext.jphp.ext.webserver.classes.PWebServer) CompileScope(php.runtime.env.CompileScope) SplClassLoader(php.runtime.env.SplClassLoader) Invoker(php.runtime.invoke.Invoker) Environment(php.runtime.env.Environment) PWebRequest(org.develnext.jphp.ext.webserver.classes.PWebRequest) PWebResponse(org.develnext.jphp.ext.webserver.classes.PWebResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with Environment

use of php.runtime.env.Environment in project jphp by jphp-compiler.

the class ObjectMemory method refOfIndex.

@Override
public Memory refOfIndex(final TraceInfo trace, final Memory index) {
    if (value instanceof ArrayAccess) {
        return new ReferenceMemory() {

            @Override
            public Memory assign(Memory memory) {
                Environment env = ObjectMemory.this.value.getEnvironment();
                if (env != null && trace != null) {
                    ArrayAccess array = (ArrayAccess) ObjectMemory.this.value;
                    Memory[] args = new Memory[] { index, memory };
                    env.pushCall(ObjectMemory.this.value, "offsetSet", args);
                    try {
                        array.offsetSet(env, args);
                    } finally {
                        env.popCall();
                    }
                } else
                    invalidUseAsArray(trace);
                return memory;
            }

            @Override
            public Memory assignRef(Memory reference) {
                return assign(reference);
            }

            @Override
            public Memory assign(long memory) {
                return assign(LongMemory.valueOf(memory));
            }

            @Override
            public Memory assign(String memory) {
                return assign(StringMemory.valueOf(memory));
            }

            @Override
            public Memory assign(boolean memory) {
                return assign(TrueMemory.valueOf(memory));
            }

            @Override
            public Memory assign(double memory) {
                return assign(DoubleMemory.valueOf(memory));
            }

            @Override
            public Memory assignConcat(Memory memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignConcat(long memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignConcat(double memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignConcat(boolean memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignConcat(String memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignPlus(Memory memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlus(long memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlus(double memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlus(boolean memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlus(String memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlusRight(Memory memory) {
                value = toValue();
                return super.assignPlusRight(memory);
            }

            @Override
            public Memory assignMinus(Memory memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinus(long memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinus(double memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinus(boolean memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinus(String memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinusRight(Memory memory) {
                value = toValue();
                return super.assignMinusRight(memory);
            }

            @Override
            public Memory assignMul(Memory memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMul(long memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMul(double memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMul(boolean memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMul(String memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMulRight(Memory memory) {
                value = toValue();
                return super.assignMulRight(memory);
            }

            @Override
            public Memory assignDiv(Memory memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDiv(long memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDiv(double memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDiv(boolean memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDiv(String memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDivRight(Memory memory) {
                value = toValue();
                return super.assignDivRight(memory);
            }

            @Override
            public Memory assignMod(Memory memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignMod(long memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignMod(double memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignMod(boolean memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignMod(String memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignModRight(Memory memory) {
                value = toValue();
                return super.assignModRight(memory);
            }

            @Override
            public Memory assignBitShr(Memory memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShr(long memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShr(double memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShr(boolean memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShr(String memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShrRight(Memory memory) {
                value = toValue();
                return super.assignBitShrRight(memory);
            }

            @Override
            public Memory assignBitShl(Memory memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShl(long memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShl(double memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShl(boolean memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShl(String memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShlRight(Memory memory) {
                value = toValue();
                return super.assignBitShlRight(memory);
            }

            @Override
            public Memory assignBitAnd(Memory memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAnd(long memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAnd(double memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAnd(boolean memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAnd(String memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAndRight(Memory memory) {
                value = toValue();
                return super.assignBitAndRight(memory);
            }

            @Override
            public Memory assignBitOr(Memory memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOr(long memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOr(double memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOr(boolean memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOr(String memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOrRight(Memory memory) {
                value = toValue();
                return super.assignBitOrRight(memory);
            }

            @Override
            public Memory assignBitXor(Memory memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXor(long memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXor(double memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXor(boolean memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXor(String memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXorRight(Memory memory) {
                value = toValue();
                return super.assignBitXorRight(memory);
            }

            @Override
            public Memory toValue() {
                return ObjectMemory.this.valueOfIndex(trace, index);
            }

            @Override
            public ReferenceMemory getReference() {
                Memory ret = toValue();
                if (ret instanceof ReferenceMemory)
                    return (ReferenceMemory) ret;
                else
                    return new ReferenceMemory();
            }

            @Override
            public Memory toImmutable() {
                return toValue().toImmutable();
            }

            @Override
            public Memory inc() {
                return toValue().inc();
            }

            @Override
            public Memory dec() {
                return toValue().dec();
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, Memory index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, long index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, double index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, String index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, boolean index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory refOfPush(TraceInfo trace) {
                return toValue().refOfPush(trace);
            }

            @Override
            public Memory refOfIndexAsShortcut(TraceInfo trace, Memory index) {
                return toValue().refOfIndexAsShortcut(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, Memory index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, long index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, double index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, String index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, boolean index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public void unsetOfIndex(TraceInfo trace, Memory index) {
                toValue().unsetOfIndex(trace, index);
            }

            @Override
            public Memory issetOfIndex(TraceInfo trace, Memory index) {
                return toValue().issetOfIndex(trace, index);
            }

            @Override
            public Memory emptyOfIndex(TraceInfo trace, Memory index) {
                return toValue().emptyOfIndex(trace, index);
            }
        };
    } else {
        invalidUseAsArray(trace);
        return new ReferenceMemory();
    }
}
Also used : ArrayAccess(php.runtime.lang.spl.ArrayAccess) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment) TraceInfo(php.runtime.env.TraceInfo)

Example 19 with Environment

use of php.runtime.env.Environment in project jphp by jphp-compiler.

the class ObjectMemory method issetOfIndex.

private Memory issetOfIndex(TraceInfo trace, Memory index, boolean asEmpty) {
    if (value instanceof ArrayAccess) {
        Environment env = value.getEnvironment();
        if (env != null && trace != null) {
            Memory[] args = new Memory[] { index };
            env.pushCall(value, "offsetExists", args);
            try {
                if (((ArrayAccess) value).offsetExists(env, args).toBoolean())
                    return asEmpty ? valueOfIndex(trace, index) : TRUE;
                else
                    return NULL;
            } finally {
                env.popCall();
            }
        } else {
            invalidUseAsArray(trace);
            return NULL;
        }
    } else {
        invalidUseAsArray(trace);
        return NULL;
    }
}
Also used : ArrayAccess(php.runtime.lang.spl.ArrayAccess) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment)

Example 20 with Environment

use of php.runtime.env.Environment in project jphp by jphp-compiler.

the class ObjectMemory method valueOfIndex.

@Override
public Memory valueOfIndex(TraceInfo trace, Memory index) {
    if (value instanceof ArrayAccess) {
        Environment env = value.getEnvironment();
        if (env != null && trace != null) {
            Memory[] args = new Memory[] { index };
            env.pushCall(value, "offsetGet", args);
            try {
                return ((ArrayAccess) value).offsetGet(env, args);
            } finally {
                env.popCall();
            }
        } else {
            invalidUseAsArray(trace);
            return NULL;
        }
    } else {
        invalidUseAsArray(trace);
        return NULL;
    }
}
Also used : ArrayAccess(php.runtime.lang.spl.ArrayAccess) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment)

Aggregations

Environment (php.runtime.env.Environment)23 Memory (php.runtime.Memory)13 Invoker (php.runtime.invoke.Invoker)6 ObjectMemory (php.runtime.memory.ObjectMemory)5 ArrayAccess (php.runtime.lang.spl.ArrayAccess)4 CompileScope (php.runtime.env.CompileScope)3 TraceInfo (php.runtime.env.TraceInfo)3 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 FulledNameToken (org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken)2 MemorySerializer (org.develnext.jphp.json.gson.MemorySerializer)2 Context (php.runtime.env.Context)2 Closure (php.runtime.lang.Closure)2 IObject (php.runtime.lang.IObject)2 Launcher (php.runtime.launcher.Launcher)2 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)2 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 ArrayList (java.util.ArrayList)1