Search in sources :

Example 6 with RuntimeArray

use of priv.bajdcc.LALR1.grammar.runtime.data.RuntimeArray in project jMiniLang by bajdcc.

the class RuntimeMachine method opArr.

@Override
public void opArr() throws RuntimeException {
    int size = current();
    next();
    RuntimeArray arr = new RuntimeArray();
    for (int i = 0; i < size; i++) {
        arr.add(load());
    }
    stack.pushData(new RuntimeObject(arr));
}
Also used : RuntimeArray(priv.bajdcc.LALR1.grammar.runtime.data.RuntimeArray)

Example 7 with RuntimeArray

use of priv.bajdcc.LALR1.grammar.runtime.data.RuntimeArray in project jMiniLang by bajdcc.

the class RuntimePipeService method stat.

@Override
public RuntimeArray stat() {
    RuntimeArray array = new RuntimeArray();
    array.add(new RuntimeObject(String.format("   %-5s   %-15s   %-15s   %-15s", "Id", "Name", "Queue", "Waiting")));
    mapPipeNames.values().stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList()).forEach((value) -> {
        array.add(new RuntimeObject(String.format("   %-5s   %-15s   %-15d   %-15d", String.valueOf(value), arrPipes[value].name, arrPipes[value].queue.size(), arrPipes[value].waiting_pids.size())));
    });
    return array;
}
Also used : RuntimeArray(priv.bajdcc.LALR1.grammar.runtime.data.RuntimeArray) RuntimeObject(priv.bajdcc.LALR1.grammar.runtime.RuntimeObject)

Example 8 with RuntimeArray

use of priv.bajdcc.LALR1.grammar.runtime.data.RuntimeArray in project jMiniLang by bajdcc.

the class RuntimeShareService method stat.

@Override
public RuntimeArray stat() {
    RuntimeArray array = new RuntimeArray();
    array.add(new RuntimeObject(String.format("   %-15s   %-15s   %-5s   %-5s", "Name", "Type", "Ref", "Locked")));
    mapShares.values().stream().sorted(Comparator.comparing(ShareStruct::getObjType).thenComparing(ShareStruct::getName)).collect(Collectors.toList()).forEach((value) -> {
        array.add(new RuntimeObject(String.format("   %-15s   %-15s   %-5s   %-5s", value.name, value.obj.getType().name(), String.valueOf(value.reference), String.valueOf(value.locked))));
    });
    return array;
}
Also used : RuntimeArray(priv.bajdcc.LALR1.grammar.runtime.data.RuntimeArray) RuntimeObject(priv.bajdcc.LALR1.grammar.runtime.RuntimeObject)

Example 9 with RuntimeArray

use of priv.bajdcc.LALR1.grammar.runtime.data.RuntimeArray in project jMiniLang by bajdcc.

the class ModuleList method buildArrayMethod.

/**
 * 数组操作
 * @param info 信息
 */
private void buildArrayMethod(IRuntimeDebugInfo info) {
    info.addExternalFunc("g_array_add", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组添加元素";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kObject };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            args.get(1).setReadonly(false);
            array.add(args.get(1));
            return args.get(0);
        }
    });
    info.addExternalFunc("g_array_contains", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组查找元素";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kObject };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            args.get(1).setReadonly(false);
            return new RuntimeObject(array.contains(args.get(1)));
        }
    });
    info.addExternalFunc("g_array_append", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组添加数组";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kArray };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            RuntimeArray array2 = (RuntimeArray) args.get(1).getObj();
            array.add(array2);
            args.get(1).setReadonly(false);
            return args.get(0);
        }
    });
    info.addExternalFunc("g_array_insert", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组添加元素";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kInt, RuntimeObjectType.kObject };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            BigInteger n = (BigInteger) args.get(1).getObj();
            args.get(2).setReadonly(false);
            array.insert(n.intValue(), args.get(2));
            return args.get(0);
        }
    });
    info.addExternalFunc("g_array_set", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组设置元素";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kInt, RuntimeObjectType.kObject };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            BigInteger index = (BigInteger) args.get(1).getObj();
            args.get(2).setReadonly(false);
            if (!array.set(index.intValue(), args.get(2))) {
                status.err(RuntimeException.RuntimeError.INVALID_INDEX, "array.set");
            }
            return null;
        }
    });
    info.addExternalFunc("g_array_pop", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组弹出元素";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            return new RuntimeObject(array.pop());
        }
    });
    info.addExternalFunc("g_array_clear", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组清除元素";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            array.clear();
            return new RuntimeObject(array);
        }
    });
    info.addExternalFunc("g_array_reverse", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组反转";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            array.reverse();
            return new RuntimeObject(array);
        }
    });
    info.addExternalFunc("g_array_get", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组查询";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kInt };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            BigInteger index = (BigInteger) args.get(1).getObj();
            return new RuntimeObject(array.get(index.intValue()));
        }
    });
    info.addExternalFunc("g_array_get_ex", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组查询";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kInt };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            BigInteger index = (BigInteger) args.get(1).getObj();
            return new RuntimeObject(array.get(index.intValue(), status));
        }
    });
    info.addExternalFunc("g_array_size", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组长度";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            return array.size();
        }
    });
    info.addExternalFunc("g_array_remove", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组移除";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kInt };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            BigInteger index = (BigInteger) args.get(1).getObj();
            return new RuntimeObject(array.remove(index.intValue()));
        }
    });
    info.addExternalFunc("g_array_delete", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组移除";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kObject };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            RuntimeObject obj = args.get(1);
            return new RuntimeObject(array.delete(obj));
        }
    });
    info.addExternalFunc("g_array_empty", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "数组为空";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            return new RuntimeObject(array.isEmpty());
        }
    });
    info.addExternalFunc("g_array_range", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "产生连续整数数组";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kInt, RuntimeObjectType.kInt };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = new RuntimeArray();
            int a = ((BigInteger) args.get(0).getObj()).intValue();
            int b = ((BigInteger) args.get(1).getObj()).intValue();
            for (int i = a; i <= b; i++) {
                array.add(new RuntimeObject(BigInteger.valueOf(i)));
            }
            return new RuntimeObject(array);
        }
    });
    info.addExternalFunc("g_array_fill", new IRuntimeDebugExec() {

        @Override
        public String getDoc() {
            return "填充数组";
        }

        @Override
        public RuntimeObjectType[] getArgsType() {
            return new RuntimeObjectType[] { RuntimeObjectType.kArray, RuntimeObjectType.kObject };
        }

        @Override
        public RuntimeObject ExternalProcCall(List<RuntimeObject> args, IRuntimeStatus status) throws Exception {
            RuntimeArray array = (RuntimeArray) args.get(0).getObj();
            RuntimeObject obj = args.get(1);
            for (int i = 0; i <= array.length(); i++) {
                array.set(i, obj);
            }
            return new RuntimeObject(array);
        }
    });
}
Also used : RuntimeArray(priv.bajdcc.LALR1.grammar.runtime.data.RuntimeArray) BigInteger(java.math.BigInteger) RuntimeException(priv.bajdcc.LALR1.grammar.runtime.RuntimeException)

Aggregations

RuntimeArray (priv.bajdcc.LALR1.grammar.runtime.data.RuntimeArray)9 BigInteger (java.math.BigInteger)4 List (java.util.List)3 Matcher (java.util.regex.Matcher)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 Pattern (java.util.regex.Pattern)2 Document (org.dom4j.Document)2 Node (org.dom4j.Node)2 SAXReader (org.dom4j.io.SAXReader)2 Grammar (priv.bajdcc.LALR1.grammar.Grammar)2 RuntimeException (priv.bajdcc.LALR1.grammar.runtime.RuntimeException)2 RuntimeObject (priv.bajdcc.LALR1.grammar.runtime.RuntimeObject)2 RuntimeMap (priv.bajdcc.LALR1.grammar.runtime.data.RuntimeMap)2 ModuleNetClient (priv.bajdcc.LALR1.interpret.module.net.ModuleNetClient)2 ModuleNetServer (priv.bajdcc.LALR1.interpret.module.net.ModuleNetServer)2 JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1