diff src/luan/modules/BasicLuan.java @ 1578:c922446f53aa

immutable threading
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 08 Feb 2021 14:16:19 -0700
parents 8fbcc4747091
children fa066aaa068c
line wrap: on
line diff
--- a/src/luan/modules/BasicLuan.java	Sun Jan 31 16:04:39 2021 -0700
+++ b/src/luan/modules/BasicLuan.java	Mon Feb 08 14:16:19 2021 -0700
@@ -14,9 +14,7 @@
 import luan.LuanTable;
 import luan.LuanFunction;
 import luan.LuanException;
-import luan.LuanCloner;
-import luan.LuanCloneable;
-import luan.LuanImmutabler;
+import luan.LuanMutable;
 import luan.modules.parsers.LuanToString;
 
 
@@ -51,7 +49,7 @@
 		return t.pairs(luan);
 	}
 
-	private static class Ipairs extends LuanFunction implements LuanCloneable, Cloneable {
+	private static final class Ipairs extends LuanFunction implements LuanMutable {
 		List<Object> list;
 		int i = 0;
 		final int size;
@@ -68,21 +66,12 @@
 			return new Object[]{i,val};
 		}
 
-		@Override public final Ipairs shallowClone() {
-			try {
-				return (Ipairs)clone();
-			} catch(CloneNotSupportedException e) {
-				throw new RuntimeException(e);
-			}
+		@Override public boolean isImmutable() {
+			return false;
 		}
 
-		@Override public final void deepenClone(LuanCloneable dc,LuanCloner cloner) {
-			Ipairs clone = (Ipairs)dc;
-			clone.list = (List)cloner.clone(list);
-		}
-
-		@Override public void makeImmutable(LuanImmutabler immutabler) throws LuanException {
-			throw new LuanException("ipairs cannot be made immutable");
+		@Override public void makeImmutable() {
+			throw new RuntimeException("ipairs cannot be made immutable");
 		}
 	}
 
@@ -100,9 +89,9 @@
 		return obj!=null ? obj : metatable;
 	}
 
-	public static void set_metatable(LuanTable table,LuanTable metatable) throws LuanException {
+	public static void set_metatable(Luan luan,LuanTable table,LuanTable metatable) throws LuanException {
 		Utils.checkNotNull(table);
-		if( table.getHandler("__metatable") != null )
+		if( table.getHandler(luan,"__metatable") != null )
 			throw new LuanException("cannot change a protected metatable");
 		table.setMetatable(metatable);
 	}
@@ -175,7 +164,7 @@
 		};
 	}
 
-	private static class Values extends LuanFunction implements LuanCloneable, Cloneable {
+	private static final class Values extends LuanFunction implements LuanMutable {
 		Object[] args;
 		int i = 0;
 
@@ -190,21 +179,12 @@
 			return new Object[]{i,val};
 		}
 
-		@Override public final Values shallowClone() {
-			try {
-				return (Values)clone();
-			} catch(CloneNotSupportedException e) {
-				throw new RuntimeException(e);
-			}
+		@Override public boolean isImmutable() {
+			return false;
 		}
 
-		@Override public final void deepenClone(LuanCloneable dc,LuanCloner cloner) {
-			Values clone = (Values)dc;
-			clone.args = (Object[])cloner.clone(args);
-		}
-
-		@Override public void makeImmutable(LuanImmutabler immutabler) throws LuanException {
-			throw new LuanException("values cannot be made immutable");
+		@Override public void makeImmutable() {
+			throw new RuntimeException("values cannot be made immutable");
 		}
 	}
 
@@ -248,5 +228,25 @@
 		return jts.toString(Luan.toJava(obj));
 	}
 
+	public static Object get_local_cloned(Luan luan,Object obj,Object key) {
+		return luan.getLocalCloned(obj,key);
+	}
+
+	public static void set_local_cloned(Luan luan,Object obj,Object key,Object value) {
+		luan.setLocalCloned(obj,key,value);
+	}
+
+	public static Object get_local_only(Luan luan,Object obj,Object key) {
+		return luan.getLocalOnly(obj,key);
+	}
+
+	public static void set_local_only(Luan luan,Object obj,Object key,Object value) {
+		luan.setLocalOnly(obj,key,value);
+	}
+
+	public static boolean is_immutable(LuanMutable m) {
+		return m.isImmutable();
+	}
+
 	private void BasicLuan() {}  // never
 }