import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import static x30_pkg.x30_util.DynamicObject;
class main {
static ICachedJavaXExpr javaExpr(Object expr) {
if (expr instanceof ICachedJavaXExpr) return ((ICachedJavaXExpr) expr);
return new LiteralJavaXExpr(expr);
}
static ICachedJavaXExpr javaExpr(Object expr, IF0 quickEval) {
LiteralJavaXExpr < A > e = new LiteralJavaXExpr<>(expr);
e.quickEval = quickEval;
return e;
}
static interface IF0 {
A get();
}
static class LiteralJavaXExpr extends Meta implements ICachedJavaXExpr , IFieldsToList{
Object expr;
LiteralJavaXExpr() {}
LiteralJavaXExpr(Object expr) {
this.expr = expr;}
public boolean equals(Object o) {
if (!(o instanceof LiteralJavaXExpr)) return false;
LiteralJavaXExpr __1 = (LiteralJavaXExpr) o;
return eq(expr, __1.expr);
}
public int hashCode() {
int h = 1878341052;
h = boostHashCombine(h, _hashCode(expr));
return h;
}
public Object[] _fieldsToList() { return new Object[] {expr}; }
public String toString() { return str(expr); }
public transient IF0 quickEval;
public A quickEval() { return quickEval != null ? quickEval.get() : quickEval_base(); }
final public A quickEval_fallback(IF0 _f) { return _f != null ? _f.get() : quickEval_base(); }
public A quickEval_base() { return ICachedJavaXExpr.super.quickEval(); }
}
// Meta - a "minimal" approach to adding meta-level to Java objects
static class Meta implements IMeta {
// We allocate one extra field for each Java object to make it
// reasoning-compatible. We couldn't go for 0 extra fields and
// there are no half fields in Java... so there you go.
// Also, if you don't use any meta data, you are probably not
// reasoning about anything. The point of reasoning in JavaX is
// to attach information to objects directly used in the program.
// Possible information contained in the meta field:
// Origin, destination, security level, sender, cost center,
// purpose, list of reifications, ...
// So here it is. THE FIELD YOU HAVE BEEN WAITING FOR
// We also have IMeta to retrofit foreign classes (rare but
// probably useful)
////////////
// "meta" //
////////////
// Generic meta value of any kind, but the typical case is it's a
// Map with extra field values for the object etc.
// "meta" is volatile to avoid synchronization; but you can also synchronize on
// _tempMetaMutex() which is usually the object itself. Collections
// and maps are exempt from using the collections's monitor as the meta
// mutex because their monitor tends to be held for long operations
// (e.g. cloneList). For those we use a substantially more complex
// algorithm using a weakMap. Probably overkill. I may reconsider.
volatile Object meta;
// The meta field is not transient, thus by default it will be
// persisted like anything else unless you customize your object
// to suppress or modulate this.
// ...and the interface methods
public void _setMeta(Object meta) { this.meta = meta; }
public Object _getMeta() { return meta; }
// MOST functions are implemented in IMeta (default implementations)
}
static interface IFieldsToList {
Object[] _fieldsToList();
}
static interface IMeta {
// see class "Meta" for the bla bla
public void _setMeta(Object meta);
public Object _getMeta();
default public IAutoCloseableF0 _tempMetaMutex() {
return new IAutoCloseableF0() {
public Object get() { return IMeta.this; }
public void close() {}
};
}
// actually query another object
default public Object getMeta(Object obj, Object key){ return metaGet(obj, key); }
default public Object metaGet(Object obj, Object key) {
return main.metaGet(obj, key);
}
default public Object getMeta(Object key){ return metaGet(key); }
default public Object metaGet(Object key) {
if (key == null) return null;
Object meta = _getMeta();
if (meta instanceof Map) return ((Map) meta).get(key);
return null;
}
default public void metaSet(Object key, Object value){ metaPut(key, value); }
default public void metaPut(Object key, Object value) {
if (key == null) return;
Map map = convertObjectMetaToMap(this);
syncMapPutOrRemove(map, key, value);
}
}
// represents the (hopefully structured) source code of a Java(X) expression
// call str() to get JavaX expression
// call quickEval() to try to evaluate right now
//
// A is return type of expression
static interface ICachedJavaXExpr extends IMeta {
// override to provide an evaluation result
public default A quickEval() { throw fail("Can't quick eval: " + toStringWithClassName(this)); }
}
static interface IAutoCloseableF0 extends IF0, AutoCloseable {}
static boolean eq(Object a, Object b) {
return a == b || a != null && b != null && a.equals(b);
}
// a little kludge for stuff like eq(symbol, "$X")
static boolean eq(Symbol a, String b) {
return eq(str(a), b);
}
static int boostHashCombine(int a, int b) {
return a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2));
}
static int _hashCode(Object a) {
return a == null ? 0 : a.hashCode();
}
static String str(Object o) {
return o == null ? "null" : o.toString();
}
static String str(char[] c) {
return new String(c);
}
static Object metaGet(IMeta o, Object key) {
return metaMapGet(o, key);
}
static Object metaGet(Object o, Object key) {
return metaMapGet(o, key);
}
static Map convertObjectMetaToMap(IMeta o) { return convertObjectMetaToMap(o, () -> synchroLinkedHashMap()); }
static Map convertObjectMetaToMap(IMeta o, IF0