Commits

Tim Vernum committed 743bcca

Import from private branch (rev:f24d25dbf304)

Comments (0)

Files changed (59)

+2010-12-23
+    Support '%:-9s' as well as '%-:9s' in sprintf
+    Implement query_verb
+
+2010-12-22
+    Add unique_mapping efun
+    Fix prototype of parse_add_synonym
+    Clear the 'loadingMaster' flag even if the create method throws an exception
+    Fix calling message() efun with array as 4th arg
+    Add safeguards against NPE in call_other
+    Wildcarding (e.g. *.c) in get_dir
+    Make file_size efun() return -1 for non readable file
+
 2010-12-20
     Implement message() efun
     Avoid concurrent modification exception in input handlers

modules/lpc/source/java/compiler/us/terebi/lang/lpc/runtime/jvm/StandardEfuns.java

 
 import us.terebi.lang.lpc.runtime.jvm.context.Efuns;
 import us.terebi.lang.lpc.runtime.jvm.context.MappedEfuns;
-import us.terebi.lang.lpc.runtime.jvm.efun.AllocateEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.AllocateMappingEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.ArraypEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.BindEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.BufferpEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.EvaluateEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.FetchVariableEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.FileNameEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.FilterEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.FilterMappingEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.FindLivingEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.FindObjectEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.FindPlayerEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.InheritListEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.InheritsEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.IntpEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.KeysEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.LivingEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.LivingsEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.LoadObjectEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.MapArrayEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.MapDeleteEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.MapEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.MapMappingEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.MappEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.MasterEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.MatchPathEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.MemberArrayEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.NoOpEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.NullpEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.ObjectpEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.QuerySnoopingEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.RandomEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.ShutdownEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.SizeofEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.SnoopEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.SortArrayEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.StoreVariableEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.StringpEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.TerminalColourEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.ToFloatEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.ToIntEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.TypeofEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.UniqueArrayEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.UserpEfun;
-import us.terebi.lang.lpc.runtime.jvm.efun.ValuesEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.VariablesEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.VirtualpEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.WriteEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.callout.CallOutInfoEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.callout.FindCallOutEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.callout.RemoveCallOutEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.AllocateEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.AllocateMappingEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.FilterEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.FilterMappingEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.KeysEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.MapArrayEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.MapDeleteEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.MapEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.MapMappingEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.MemberArrayEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.SizeofEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.SortArrayEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.UniqueArrayEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.UniqueMappingEfun;
+import us.terebi.lang.lpc.runtime.jvm.efun.collection.ValuesEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.environment.EnvironmentEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.environment.InventoryEfun;
 import us.terebi.lang.lpc.runtime.jvm.efun.environment.MoveObjectEfun;
         public static final Efun sort_array = new SortArrayEfun();
         public static final Efun member_array = new MemberArrayEfun();
         public static final Efun unique_array = new UniqueArrayEfun();
+        public static final Efun unique_mapping = new UniqueMappingEfun();
         public static final Efun arrayp = new ArraypEfun();
         public static final Efun pointerp = arrayp;
         public static final Efun mapp = new MappEfun();

modules/lpc/source/java/compiler/us/terebi/lang/lpc/runtime/jvm/object/AbstractObjectDefinition.java

 import java.util.List;
 
 import org.apache.commons.io.FilenameUtils;
+import org.apache.log4j.Logger;
 
 import us.terebi.lang.lpc.compiler.CompilerObjectManager;
 import us.terebi.lang.lpc.compiler.java.context.CompiledObjectDefinition;
  */
 public abstract class AbstractObjectDefinition implements CompiledObjectDefinition
 {
+    private final Logger LOG = Logger.getLogger(AbstractObjectDefinition.class);
     private static final Apply CREATE = new Apply("create");
 
     private final CompilerObjectManager _manager;
     {
         if (_loadingMaster)
         {
+            LOG.warn("The master object for " + this + " is currently being loaded - it cannot be accessed");
             return null;
         }
         if (_master == null)
         {
-            _loadingMaster = true;
-            _master = newInstance(0, InstanceType.MASTER, null, Collections.<LpcValue> emptyList());
-            _loadingMaster = false;
+            try
+            {
+                _loadingMaster = true;
+                _master = newInstance(0, InstanceType.MASTER, null, Collections.<LpcValue> emptyList());
+            }
+            finally
+            {
+                _loadingMaster = false;
+            }
         }
         return _master;
     }

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/LpcConstants.java

 import us.terebi.lang.lpc.runtime.jvm.type.Types;
 import us.terebi.lang.lpc.runtime.jvm.value.ArrayValue;
 import us.terebi.lang.lpc.runtime.jvm.value.IntValue;
+import us.terebi.lang.lpc.runtime.jvm.value.MappingValue;
 import us.terebi.lang.lpc.runtime.jvm.value.NilValue;
 import us.terebi.lang.lpc.runtime.jvm.value.StringValue;
+import us.terebi.lang.lpc.runtime.jvm.value.TypedValue;
 import us.terebi.lang.lpc.runtime.jvm.value.ZeroValue;
 
 /**
 
     public static final class STRING
     {
+        @SuppressWarnings("hiding")
+        public static final LpcValue NIL = TypedValue.type(Types.STRING, NilValue.INSTANCE);
+
         public static final StringValue BLANK = new StringValue("");
     }
 
     {
         public static final ArrayValue EMPTY = new ArrayValue(Types.MIXED_ARRAY, Collections.<LpcValue> emptyList());
     }
-    
+
+    public static final class MAPPING
+    {
+        public static final MappingValue EMPTY = new MappingValue(Collections.<LpcValue, LpcValue> emptyMap());
+    }
+
     public static final NilValue NIL = NilValue.INSTANCE;
 
 }

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/AllocateEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.Collections;
-import java.util.List;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.exception.LpcRuntimeException;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.ArrayValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-/**
- * 
- */
-public class AllocateEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    private static final int ARRAY_MAX = 0xFFFF;
-
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        return Collections.singletonList(new ArgumentSpec("size", Types.INT));
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MIXED_ARRAY;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        LpcValue arg = arguments.get(0);
-        long size = arg.asLong();
-        if (size > ARRAY_MAX)
-        {
-            throw new LpcRuntimeException("Cannot allocate an array of more than " + ARRAY_MAX + " elements");
-        }
-        return new ArrayValue(Types.MIXED_ARRAY, (int) size);
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/AllocateMappingEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.Collections;
-import java.util.List;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.exception.LpcRuntimeException;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.MappingValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-/**
- * 
- */
-public class AllocateMappingEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    private static final int MAPPING_MAX = 0xFFFF;
-
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        return Collections.singletonList(new ArgumentSpec("size", Types.INT));
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MAPPING;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        LpcValue arg = arguments.get(0);
-        long size = arg.asLong();
-        if (size > MAPPING_MAX)
-        {
-            throw new LpcRuntimeException("Cannot allocate a mapping of more than " + MAPPING_MAX + " elements");
-        }
-        return new MappingValue((int) size);
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/CallOtherEfun.java

 import us.terebi.lang.lpc.runtime.jvm.context.CallStack;
 import us.terebi.lang.lpc.runtime.jvm.context.ObjectManager;
 import us.terebi.lang.lpc.runtime.jvm.context.RuntimeContext;
+import us.terebi.lang.lpc.runtime.jvm.exception.InternalError;
 import us.terebi.lang.lpc.runtime.jvm.exception.LpcRuntimeException;
 import us.terebi.lang.lpc.runtime.jvm.support.CallableSupport;
 import us.terebi.lang.lpc.runtime.jvm.support.MiscSupport;
             }
             return ValueSupport.arrayValue(result);
         }
-        else if (MiscSupport.isString(arg1))
+
+        if (MiscSupport.isString(arg1))
         {
             ObjectManager objectManager = RuntimeContext.obtain().system().objectManager();
             String objectName = arg1.asString();
                 throw new LpcRuntimeException("No such object " + objectName);
             }
             target = objectDefinition.getMasterInstance();
+            if (target == null)
+            {
+                throw new InternalError("Cannot get master instance for object " + objectDefinition);
+            }
         }
         else if (MiscSupport.isObject(arg1))
         {
             target = arg1.asObject();
+            if (target == null)
+            {
+                throw new LpcRuntimeException("Object " + arg1 + " is nil");
+            }
         }
         else
         {

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/FilterArrayEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.ArgumentSemantics;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.StandardEfuns;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-/**
- * 
- */
-public class FilterArrayEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("array", Types.MIXED_ARRAY));
-        list.add(new ArgumentSpec("func", Types.MIXED));
-        list.add(new ArgumentSpec("args", Types.MIXED_ARRAY, true, ArgumentSemantics.BY_VALUE));
-        return list;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MIXED_ARRAY;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        return StandardEfuns.COLLECTION.filter.execute(arguments);
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/FilterEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.ArgumentSemantics;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.exception.LpcRuntimeException;
-import us.terebi.lang.lpc.runtime.jvm.support.MiscSupport;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.ArrayValue;
-import us.terebi.lang.lpc.runtime.jvm.value.MappingValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isArray;
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isMapping;
-
-/**
- * 
- */
-public class FilterEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    //    mixed filter(mixed x, string fun, object ob, mixed extra, ...);
-    //    mixed filter(mixed x, function f, mixed extra, ...);
-
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("collection", Types.MIXED));
-        list.add(new ArgumentSpec("func", Types.MIXED));
-        list.add(new ArgumentSpec("args", Types.MIXED_ARRAY, true, ArgumentSemantics.BY_VALUE));
-        return list;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MIXED;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        LpcValue collection = arguments.get(0);
-        if (isMapping(collection))
-        {
-            return filter_mapping(arguments);
-        }
-        if (isArray(collection))
-        {
-            return filter_array(arguments);
-        }
-        throw new UnsupportedOperationException(getName() + "(" + collection.getActualType() + ", ..) - Not implemented");
-    }
-
-    private LpcValue filter_array(List< ? extends LpcValue> arguments)
-    {
-        LpcValue array = arguments.get(0);
-        List<LpcValue> list = array.asList();
-
-        LpcValue func = arguments.get(1);
-
-        List< ? extends LpcValue> args = arguments.get(2).asList();
-        LpcValue object = null;
-        if (MiscSupport.isString(func) && !args.isEmpty())
-        {
-            object = args.get(0);
-            args = args.subList(1, args.size());
-        }
-
-        Callable callable = getFunctionReference(func, object);
-        List< ? extends LpcValue> result = filter(list, callable, args);
-        return new ArrayValue(array.getActualType(), result);
-    }
-
-    private List< ? extends LpcValue> filter(List<LpcValue> list, Callable function, List< ? extends LpcValue> additionalArguments)
-    {
-        List<LpcValue> result = new ArrayList<LpcValue>();
-
-        List<LpcValue> arguments = new ArrayList<LpcValue>(1 + additionalArguments.size());
-        arguments.add(null);
-        arguments.addAll(additionalArguments);
-
-        for (LpcValue value : list)
-        {
-            arguments.set(0, value);
-
-            LpcValue predicate = function.execute(arguments);
-            if (predicate.asBoolean())
-            {
-                result.add(value);
-            }
-        }
-        return result;
-    }
-
-    private LpcValue filter_mapping(List< ? extends LpcValue> arguments)
-    {
-        LpcValue mapping = arguments.get(0);
-        Map<LpcValue, LpcValue> map = mapping.asMap();
-
-        LpcValue func = arguments.get(1);
-        List< ? extends LpcValue> args = arguments.get(2).asList();
-
-        LpcValue object = null;
-        if (MiscSupport.isString(func) && !args.isEmpty())
-        {
-            object = args.get(0);
-            args = args.subList(1, args.size());
-        }
-
-        Callable callable = getFunctionReference(func, object);
-        Map<LpcValue, LpcValue> result = filter(map, callable, args);
-        return new MappingValue(result);
-    }
-
-    private Map<LpcValue, LpcValue> filter(Map<LpcValue, LpcValue> map, Callable function, List< ? extends LpcValue> additionalArguments)
-    {
-        HashMap<LpcValue, LpcValue> result = new HashMap<LpcValue, LpcValue>(map.size());
-
-        List<LpcValue> arguments = new ArrayList<LpcValue>(2 + additionalArguments.size());
-        arguments.add(null);
-        arguments.add(null);
-        arguments.addAll(additionalArguments);
-
-        for (Entry<LpcValue, LpcValue> entry : map.entrySet())
-        {
-            LpcValue key = entry.getKey();
-            LpcValue value = entry.getValue();
-
-            arguments.set(0, key);
-            arguments.set(1, value);
-
-            LpcValue predicate = function.execute(arguments);
-            if (predicate.asBoolean())
-            {
-                result.put(key, value);
-            }
-        }
-        return result;
-    }
-
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/FilterMappingEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.ArgumentSemantics;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.StandardEfuns;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-/**
- * 
- */
-public class FilterMappingEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    //    mapping filter(mapping x, string fun, object ob, mixed extra, ...);
-    //    mapping filter(mapping x, function f, mixed extra, ...);
-
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("m", Types.MAPPING));
-        list.add(new ArgumentSpec("func", Types.MIXED));
-        list.add(new ArgumentSpec("args", Types.MIXED_ARRAY, true, ArgumentSemantics.BY_VALUE));
-        return list;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MAPPING;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        return StandardEfuns.COLLECTION.filter.execute(arguments);
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/KeysEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.ArrayValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-/**
- * 
- */
-public class KeysEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        return Collections.singletonList(new ArgumentSpec("map", Types.MAPPING));
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MIXED_ARRAY;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        LpcValue arg = arguments.get(0);
-        Set<LpcValue> keys = arg.asMap().keySet();
-        return new ArrayValue(Types.MIXED_ARRAY, keys);
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/MapArrayEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.ArgumentSemantics;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.support.MiscSupport;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.ArrayValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isFunction;
-
-/**
- * 
- */
-public class MapArrayEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    //    array map_array( array arr, string fun, object ob, mixed extra, ... );
-    //    array map_array( array arr, function f, mixed extra, ... );;
-
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("arr", Types.MIXED_ARRAY));
-        list.add(new ArgumentSpec("func", Types.MIXED));
-        list.add(new ArgumentSpec("args", Types.MIXED_ARRAY, true, ArgumentSemantics.BY_VALUE));
-        return list;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MIXED_ARRAY;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-
-        LpcValue array = arguments.get(0);
-        List<LpcValue> list = array.asList();
-
-        LpcValue func = arguments.get(1);
-
-        List< ? extends LpcValue> args = arguments.get(2).asList();
-
-        Callable callable;
-        if (isFunction(func))
-        {
-            callable = func.asCallable();
-        }
-        else if (MiscSupport.isString(func))
-        {
-            callable = this.getFunctionReference(func.asString(), getArgument(args, 0).asObject());
-            args = args.subList(1, args.size());
-        }
-        else
-        {
-            throw new UnsupportedOperationException(getName() + "(array," + func.getActualType() + ", ..) - Not implemented");
-        }
-        List<LpcValue> result = map_array(list, callable, args);
-        return new ArrayValue(Types.arrayOf(MiscSupport.commonType(result)), result);
-    }
-
-    private List<LpcValue> map_array(List<LpcValue> list, Callable function, List< ? extends LpcValue> additionalArguments)
-    {
-        List<LpcValue> result = new ArrayList<LpcValue>(list.size());
-
-        List<LpcValue> arguments = new ArrayList<LpcValue>(1 + additionalArguments.size());
-        arguments.add(null);
-        arguments.addAll(additionalArguments);
-
-        for (LpcValue value : list)
-        {
-            arguments.set(0, value);
-            value = function.execute(arguments);
-            result.add(value);
-        }
-        return result;
-    }
-
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/MapDeleteEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.VoidValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-/**
- * 
- */
-public class MapDeleteEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("m", Types.MAPPING));
-        list.add(new ArgumentSpec("element", Types.MIXED));
-        return list;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.VOID;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        LpcValue mapping = arguments.get(0);
-        LpcValue element = arguments.get(1);
-        mapping.asMap().remove(element);
-        return VoidValue.INSTANCE;
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/MapEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.ArgumentSemantics;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.StandardEfuns;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isArray;
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isMapping;
-
-/**
- * 
- */
-public class MapEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    //    mixed map( mixed x, string fun, object ob, mixed extra, ... );
-    //    mixed map( mixed x, function f, mixed extra, ... );
-
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("collection", Types.MIXED));
-        list.add(new ArgumentSpec("func", Types.MIXED));
-        list.add(new ArgumentSpec("args", Types.MIXED_ARRAY, true, ArgumentSemantics.BY_VALUE));
-        return list;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MIXED;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        LpcValue collection = arguments.get(0);
-        if (isMapping(collection))
-        {
-            return StandardEfuns.COLLECTION.map_mapping.execute(arguments);
-        }
-        if (isArray(collection))
-        {
-            return StandardEfuns.COLLECTION.map_array.execute(arguments);
-        }
-        throw new UnsupportedOperationException(getName() + "(" + collection.getActualType() + ", ..) - Not implemented");
-    }
-
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/MapMappingEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.ArgumentSemantics;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.ObjectInstance;
-import us.terebi.lang.lpc.runtime.jvm.support.MiscSupport;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.MappingValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isFunction;
-
-/**
- * 
- */
-public class MapMappingEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    //    mapping map_mapping( mapping map, string fun, object ob, ... );
-    //    mapping map_mapping( mapping map, function f, ... );
-
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("map", Types.MAPPING));
-        list.add(new ArgumentSpec("func", Types.MIXED));
-        list.add(new ArgumentSpec("args", Types.MIXED_ARRAY, true, ArgumentSemantics.BY_VALUE));
-        return list;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MAPPING;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-
-        LpcValue mapping = arguments.get(0);
-        Map<LpcValue, LpcValue> map = mapping.asMap();
-
-        LpcValue func = arguments.get(1);
-        List< ? extends LpcValue> args = arguments.get(2).asList();
-
-        Callable callable;
-        if (isFunction(func))
-        {
-            callable = func.asCallable();
-        }
-        else if (MiscSupport.isString(func))
-        {
-            ObjectInstance object;
-            if (args.isEmpty())
-            {
-                object = ThisObjectEfun.this_object();
-            }
-            else
-            {
-                object = args.get(0).asObject();
-            }
-            callable = super.getFunctionReference(func.asString(), object);
-            args = args.subList(1, args.size());
-        }
-        else
-        {
-            throw new UnsupportedOperationException(getName() + "(mapping," + func.getActualType() + ", ..) - Not implemented");
-        }
-        Map<LpcValue, LpcValue> result = map_function(map, callable, args);
-        return new MappingValue(result);
-    }
-
-    private Map<LpcValue, LpcValue> map_function(Map<LpcValue, LpcValue> map, Callable function, List< ? extends LpcValue> additionalArguments)
-    {
-        HashMap<LpcValue, LpcValue> result = new HashMap<LpcValue, LpcValue>(map.size());
-
-        List<LpcValue> arguments = new ArrayList<LpcValue>(2 + additionalArguments.size());
-        arguments.add(null);
-        arguments.add(null);
-        arguments.addAll(additionalArguments);
-
-        for (Entry<LpcValue, LpcValue> entry : map.entrySet())
-        {
-            LpcValue key = entry.getKey();
-            arguments.set(0, key);
-            arguments.set(1, entry.getValue());
-            LpcValue value = function.execute(arguments);
-            result.put(key, value);
-        }
-        return result;
-    }
-
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/MemberArrayEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.LpcConstants;
-import us.terebi.lang.lpc.runtime.jvm.support.ValueSupport;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isArray;
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isInt;
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isString;
-import static us.terebi.lang.lpc.runtime.jvm.support.ValueSupport.intValue;
-
-/**
- * 
- */
-public class MemberArrayEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    //    int member_array(mixed item, mixed arr);
-    //    int member_array(mixed item, mixed arr, int start);
-
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("item", Types.MIXED));
-        list.add(new ArgumentSpec("array", Types.MIXED));
-        list.add(new ArgumentSpec("start", Types.INT));
-        return list;
-    }
-
-    public boolean acceptsLessArguments()
-    {
-        return true;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MIXED;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments, 2);
-        LpcValue item = arguments.get(0);
-        LpcValue array = arguments.get(1);
-        LpcValue arg3 = arguments.get(2);
-        long start = isInt(arg3) ? arg3.asLong() : 0;
-
-        if (item == null)
-        {
-            throw new NullPointerException("Internal Error - Cannot search for null member");
-        }
-
-        if (isString(array))
-        {
-            if (isInt(item))
-            {
-                return ValueSupport.intValue(searchString(array.asString(), item.asLong(), start));
-            }
-        }
-        else if (isArray(array))
-        {
-            return intValue(searchList(array.asList(), item, start));
-        }
-        return LpcConstants.INT.MINUS_ONE;
-    }
-
-    private long searchString(String str, long charValue, long start)
-    {
-        if (charValue > Character.MAX_VALUE)
-        {
-            return -1;
-        }
-        if (start > str.length())
-        {
-            return -1;
-        }
-        for (int i = (int) start; i < str.length(); i++)
-        {
-            if (str.charAt(i) == charValue)
-            {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    private long searchList(List<LpcValue> list, LpcValue item, long start)
-    {
-        if (start > list.size())
-        {
-            return -1;
-        }
-
-        ListIterator<LpcValue> iterator = list.listIterator((int) start);
-        while (iterator.hasNext())
-        {
-            if (item.equals(iterator.next()))
-            {
-                return iterator.previousIndex();
-            }
-        }
-        return -1;
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/SizeofEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.Collections;
-import java.util.List;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-import static us.terebi.lang.lpc.runtime.jvm.support.ValueSupport.intValue;
-
-/**
- * 
- */
-public class SizeofEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        return Collections.singletonList(new ArgumentSpec("collection", Types.MIXED));
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.INT;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        LpcValue arg = arguments.get(0);
-        int size = getSize(arg);
-        return intValue(size);
-    }
-
-    private int getSize(LpcValue arg)
-    {
-        if (arg.getActualType().getArrayDepth() > 0)
-        {
-            return arg.asList().size();
-        }
-        switch (arg.getActualType().getKind())
-        {
-            case STRING:
-                return arg.asString().length();
-            case MAPPING:
-                return arg.asMap().size();
-            case CLASS:
-                return arg.asClass().getDefinition().getFields().size();
-            default:
-                return 0;
-        }
-    }
-
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/SortArrayEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import org.apache.commons.collections.comparators.ReverseComparator;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.ArgumentSemantics;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.ObjectInstance;
-import us.terebi.lang.lpc.runtime.jvm.exception.LpcRuntimeException;
-import us.terebi.lang.lpc.runtime.jvm.support.CallOtherComparator;
-import us.terebi.lang.lpc.runtime.jvm.support.CallableComparator;
-import us.terebi.lang.lpc.runtime.jvm.support.LpcValueComparator;
-import us.terebi.lang.lpc.runtime.jvm.support.MiscSupport;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.ArrayValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isFunction;
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isInteger;
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isString;
-
-/**
- * 
- */
-public class SortArrayEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    //  array sort_array( array arr, string fun, object ob, ... );
-    //  array sort_array( array arr, function f, ... );
-    //  array sort_array( array arr, int direction );    
-    //  
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("array", Types.MIXED_ARRAY));
-        list.add(new ArgumentSpec("func", Types.MIXED));
-        list.add(new ArgumentSpec("args", Types.MIXED_ARRAY, true, ArgumentSemantics.BY_VALUE));
-        return list;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MIXED_ARRAY;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        LpcValue array = arguments.get(0);
-        LpcValue arg = arguments.get(1);
-
-        LpcValue otherArgs = arguments.get(2);
-        List<LpcValue> argList = MiscSupport.isArray(otherArgs) ? arguments.get(2).asList() : Collections.<LpcValue> emptyList();
-        List<LpcValue> sorted = sort(array.asList(), arg, argList);
-
-        return new ArrayValue(array.getActualType(), sorted);
-    }
-
-    private List<LpcValue> sort(List<LpcValue> list, LpcValue arg0, List<LpcValue> args)
-    {
-        if (isInteger(arg0))
-        {
-            return sort(list, arg0.asLong());
-        }
-        if (isFunction(arg0))
-        {
-            return sort(list, arg0.asCallable(), args);
-        }
-        if (isString(arg0))
-        {
-            if (args.isEmpty())
-            {
-                return sort(list, arg0.asString());
-            }
-            else
-            {
-                return sort(list, arg0.asString(), args.get(0).asObject(), args.subList(1, args.size()));
-            }
-        }
-        throw new LpcRuntimeException("Argument 1 to " + getName() + " must be one of int|function|string");
-    }
-
-    private List<LpcValue> sort(@SuppressWarnings("unused")
-    List<LpcValue> list, @SuppressWarnings("unused")
-    String func)
-    {
-        throw new UnsupportedOperationException("sort by name on this_object() - Not implemented");
-    }
-
-    private List<LpcValue> sort(List<LpcValue> list, String func, ObjectInstance object, List<LpcValue> args)
-    {
-        return sortList(list, new CallOtherComparator(object, func, args));
-    }
-
-    private List<LpcValue> sort(List<LpcValue> list, Callable callable, List<LpcValue> args)
-    {
-        return sortList(list, new CallableComparator(callable, args));
-    }
-
-    @SuppressWarnings("unchecked")
-    private List<LpcValue> sort(List<LpcValue> list, long direction)
-    {
-        Comparator<LpcValue> comparator = new LpcValueComparator();
-        if (direction == -1)
-        {
-            comparator = new ReverseComparator(comparator);
-        }
-        return sortList(list, comparator);
-    }
-
-    private List<LpcValue> sortList(List<LpcValue> list, Comparator<LpcValue> comparator)
-    {
-        List<LpcValue> sorted = new ArrayList<LpcValue>(list);
-        Collections.sort(sorted, comparator);
-        return sorted;
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/UniqueArrayEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.ArrayValue;
-import us.terebi.lang.lpc.runtime.jvm.value.VoidValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-import static us.terebi.lang.lpc.runtime.jvm.support.MiscSupport.isFunction;
-
-/**
- * 
- */
-public class UniqueArrayEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    //    array unique_array(object array obarr, string separator);
-    //    array unique_array(object array obarr, string separator, mixed skip);
-    //
-    //    array unique_array(array arr, function f);
-    //    array unique_array(array arr, function f, mixed skip);
-
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        ArrayList<ArgumentDefinition> list = new ArrayList<ArgumentDefinition>();
-        list.add(new ArgumentSpec("array", Types.MIXED_ARRAY));
-        list.add(new ArgumentSpec("func", Types.MIXED));
-        list.add(new ArgumentSpec("skip", Types.MIXED));
-        return list;
-    }
-
-    public boolean acceptsLessArguments()
-    {
-        return true;
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.arrayOf(Types.MIXED_ARRAY);
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments, 2);
-        LpcValue array = arguments.get(0);
-        LpcValue func = arguments.get(1);
-        LpcValue skip = VoidValue.INSTANCE;
-        if (hasArgument(arguments, 2))
-        {
-            skip = arguments.get(2);
-        }
-
-        if (isFunction(func))
-        {
-            return new ArrayValue(Types.arrayOf(array.getActualType()), unique(array, func.asCallable(), skip));
-        }
-        throw new UnsupportedOperationException(getName() + "(array, " + func.getActualType() + ",..) - Not implemented");
-
-    }
-
-    private Collection< ? extends LpcValue> unique(LpcValue array, Callable function, LpcValue skip)
-    {
-        Map<LpcValue, ArrayValue> buckets = new HashMap<LpcValue, ArrayValue>();
-        for (LpcValue value : array.asList())
-        {
-            LpcValue token = function.execute(value);
-            if (skip.equals(token))
-            {
-                continue;
-            }
-
-            ArrayValue bucket = buckets.get(token);
-            if (bucket == null)
-            {
-                bucket = new ArrayValue(array.getActualType(), new ArrayList<LpcValue>());
-                buckets.put(token, bucket);
-            }
-            
-            bucket.asList().add(value);
-        }
-        return buckets.values();
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/ValuesEfun.java

-/* ------------------------------------------------------------------------
- * $Id$
- * Copyright 2009 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-
-package us.terebi.lang.lpc.runtime.jvm.efun;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import us.terebi.lang.lpc.runtime.ArgumentDefinition;
-import us.terebi.lang.lpc.runtime.Callable;
-import us.terebi.lang.lpc.runtime.FunctionSignature;
-import us.terebi.lang.lpc.runtime.LpcType;
-import us.terebi.lang.lpc.runtime.LpcValue;
-import us.terebi.lang.lpc.runtime.jvm.type.Types;
-import us.terebi.lang.lpc.runtime.jvm.value.ArrayValue;
-import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
-
-/**
- * 
- */
-public class ValuesEfun extends AbstractEfun implements FunctionSignature, Callable
-{
-    protected List< ? extends ArgumentDefinition> defineArguments()
-    {
-        return Collections.singletonList(new ArgumentSpec("map", Types.MAPPING));
-    }
-
-    public LpcType getReturnType()
-    {
-        return Types.MIXED_ARRAY;
-    }
-
-    public LpcValue execute(List< ? extends LpcValue> arguments)
-    {
-        checkArguments(arguments);
-        LpcValue arg = arguments.get(0);
-        Collection<LpcValue> values = arg.asMap().values();
-        return new ArrayValue(Types.MIXED_ARRAY, values);
-    }
-}

modules/lpc/source/java/runtime/us/terebi/lang/lpc/runtime/jvm/efun/collection/AllocateEfun.java

+/* ------------------------------------------------------------------------
+ * $Id$
+ * Copyright 2009 Tim Vernum
+ * ------------------------------------------------------------------------
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ------------------------------------------------------------------------
+ */
+
+package us.terebi.lang.lpc.runtime.jvm.efun.collection;
+
+import java.util.Collections;
+import java.util.List;
+
+import us.terebi.lang.lpc.runtime.ArgumentDefinition;
+import us.terebi.lang.lpc.runtime.Callable;
+import us.terebi.lang.lpc.runtime.FunctionSignature;
+import us.terebi.lang.lpc.runtime.LpcType;
+import us.terebi.lang.lpc.runtime.LpcValue;
+import us.terebi.lang.lpc.runtime.jvm.efun.AbstractEfun;
+import us.terebi.lang.lpc.runtime.jvm.exception.LpcRuntimeException;
+import us.terebi.lang.lpc.runtime.jvm.type.Types;
+import us.terebi.lang.lpc.runtime.jvm.value.ArrayValue;
+import us.terebi.lang.lpc.runtime.util.ArgumentSpec;
+
+/**
+ *