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;
}
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));
}
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())) };
}
});
}
});
}
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());
}
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;
}
Aggregations