Search in sources :

Example 16 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class WrapTimeZone method UTC.

@FastMethod
@Signature
public static Memory UTC(final Environment env, Memory... args) {
    Memory r = env.getUserValue(WrapTimeZone.class.getName() + "#UTC", Memory.class);
    if (r == null) {
        r = new ObjectMemory(new WrapTimeZone(env, UTC));
        env.setUserValue(WrapTimeZone.class.getName() + "#UTC", r);
    }
    return r;
}
Also used : ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) FastMethod(php.runtime.annotation.Runtime.FastMethod)

Example 17 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class WrapThreadPool method submit.

@Signature({ @Arg(value = "runnable", type = HintType.CALLABLE), @Arg(value = "env", typeClass = "php\\lang\\Environment", optional = @Optional("NULL")) })
public Memory submit(Environment env, Memory... args) {
    final Environment _env = args[1].isNull() ? env : args[1].toObject(WrapEnvironment.class).getWrapEnvironment();
    final Invoker invoker = Invoker.valueOf(_env, null, args[0]);
    Future<Memory> future = service.submit(new Callable<Memory>() {

        @Override
        public Memory call() throws Exception {
            return invoker.callNoThrow();
        }
    });
    return new ObjectMemory(new WrapFuture(env, future));
}
Also used : Invoker(php.runtime.invoke.Invoker) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) Environment(php.runtime.env.Environment)

Example 18 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class JTreeXEventProvider method register.

@Override
public void register(final Environment env, final JTreeX component, final ComponentProperties properties) {
    final ObjectMemory self = new ObjectMemory(new UITree(env, component));
    component.getContent().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final TreeSelectionEvent e) {
            trigger(env, properties, "selected", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    Memory oldNode = Memory.NULL;
                    if (e.getOldLeadSelectionPath() != null) {
                        oldNode = new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) e.getOldLeadSelectionPath().getLastPathComponent()));
                    }
                    Memory node = Memory.NULL;
                    if (e.getNewLeadSelectionPath() != null) {
                        node = new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) e.getNewLeadSelectionPath().getLastPathComponent()));
                    }
                    return new Memory[] { self, node, oldNode, TrueMemory.valueOf(e.isAddedPath()) };
                }
            });
        }
    });
    component.getContent().addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillExpand(final TreeExpansionEvent event) {
            trigger(env, properties, "willExpand", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
                }
            });
        }

        @Override
        public void treeWillCollapse(final TreeExpansionEvent event) {
            trigger(env, properties, "willCollapse", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
                }
            });
        }
    });
    component.getContent().addTreeExpansionListener(new TreeExpansionListener() {

        @Override
        public void treeExpanded(final TreeExpansionEvent event) {
            trigger(env, properties, "expanded", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
                }
            });
        }

        @Override
        public void treeCollapsed(final TreeExpansionEvent event) {
            trigger(env, properties, "collapsed", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
                }
            });
        }
    });
}
Also used : Function(php.runtime.common.Function) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ObjectMemory(php.runtime.memory.ObjectMemory) TrueMemory(php.runtime.memory.TrueMemory) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) WrapTreeNode(org.develnext.jphp.swing.classes.components.tree.WrapTreeNode) UITree(org.develnext.jphp.swing.classes.components.tree.UITree)

Example 19 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class ClassesTest method testDefine.

@Test
public void testDefine() {
    Memory memory;
    memory = runDynamic("class A { } return new A();", false);
    Assert.assertTrue(memory.isObject());
    IObject object = ((ObjectMemory) memory).value;
    Assert.assertEquals("A", object.getReflection().getName());
}
Also used : IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) Test(org.junit.Test)

Example 20 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class MemoryDeserializer method convert.

protected Memory convert(JsonElement json, int depth) {
    if (depth > maxDepth)
        throw new MaxDepthException();
    if (json.isJsonNull())
        return Memory.NULL;
    if (json.isJsonPrimitive()) {
        JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive();
        if (jsonPrimitive.isString())
            return StringMemory.valueOf(jsonPrimitive.getAsString());
        else if (jsonPrimitive.isBoolean())
            return jsonPrimitive.getAsBoolean() ? Memory.TRUE : Memory.FALSE;
        else if (jsonPrimitive.isNumber()) {
            Memory l = StringMemory.toLong(jsonPrimitive.getAsString());
            if (l != null)
                return l;
            else
                return new DoubleMemory(json.getAsDouble());
        }
        return Memory.NULL;
    } else if (json.isJsonArray()) {
        ArrayMemory array = new ArrayMemory();
        for (JsonElement el : json.getAsJsonArray()) array.add(convert(el, depth + 1).toImmutable());
        return array.toConstant();
    } else if (json.isJsonObject()) {
        JsonObject jsonObject = json.getAsJsonObject();
        StdClass stdClass = assoc ? null : new StdClass(env.get());
        ArrayMemory array = assoc ? new ArrayMemory() : stdClass.getProperties();
        for (Map.Entry<String, JsonElement> el : jsonObject.entrySet()) {
            String key = el.getKey();
            if (!key.startsWith("\0"))
                array.put(key, convert(el.getValue(), depth + 1).toImmutable());
        }
        return assoc ? array : new ObjectMemory(stdClass);
    } else
        return Memory.NULL;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ObjectMemory(php.runtime.memory.ObjectMemory) DoubleMemory(php.runtime.memory.DoubleMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) StringMemory(php.runtime.memory.StringMemory) ObjectMemory(php.runtime.memory.ObjectMemory) DoubleMemory(php.runtime.memory.DoubleMemory) Map(java.util.Map) StdClass(php.runtime.lang.StdClass)

Aggregations

ObjectMemory (php.runtime.memory.ObjectMemory)55 ArrayMemory (php.runtime.memory.ArrayMemory)24 Memory (php.runtime.Memory)19 ClassEntity (php.runtime.reflection.ClassEntity)17 StringMemory (php.runtime.memory.StringMemory)14 IObject (php.runtime.lang.IObject)11 Invoker (php.runtime.invoke.Invoker)6 LongMemory (php.runtime.memory.LongMemory)6 Environment (php.runtime.env.Environment)5 MethodEntity (php.runtime.reflection.MethodEntity)5 Calendar (java.util.Calendar)4 Closure (php.runtime.lang.Closure)4 Locale (java.util.Locale)3 Test (org.junit.Test)3 WrapLocale (php.runtime.ext.core.classes.util.WrapLocale)3 PropertyEntity (php.runtime.reflection.PropertyEntity)3 AbstractFunctionEntity (php.runtime.reflection.support.AbstractFunctionEntity)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Date (java.util.Date)2 TimeZone (java.util.TimeZone)2