Package seph.lang

Examples of seph.lang.SephMethod


                    String[] parents = ss != null ? ss.parents() : sk.parents();

                    Map<String, MethodDeclaration> methods = new LinkedHashMap<String, MethodDeclaration>();

                    for(MethodDeclaration md : cd.getMethods()) {
                        SephMethod anno = md.getAnnotation(SephMethod.class);
                        if (anno == null) {
                            continue;
                        }

                        String name = md.getSimpleName();
                        methods.put(name, md);
                    }

                    Map<String, FieldDeclaration> fields = new LinkedHashMap<String, FieldDeclaration>();

                    for(FieldDeclaration fd : cd.getFields()) {
                        SephCell anno = fd.getAnnotation(SephCell.class);
                        if (anno == null) {
                            continue;
                        }

                        String name = fd.getSimpleName();
                        fields.put(name, fd);
                    }

                    ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024);
                    out = new PrintStream(bytes);

                    out.println("/* THIS FILE IS GENERATED. DO NOT EDIT */");
                    out.println("package seph.lang.bim;");
                    out.println();
                    out.println("import java.lang.invoke.*;");
                    out.println("import seph.lang.*;");
                    out.println("import seph.lang.persistent.*;");
                    out.println("import static seph.lang.Types.*;");
                    out.println("import static seph.lang.ActivationHelpers.*;");
                    out.println();
                    out.println("public class " + cd.getSimpleName() + "Base {");
                    out.println();
                    for(String parent : parents) {
                        out.println("    public final static SephObject parent_" + parent + " = " + parent + ".instance;");
                    }
                    out.println();
                    for(String cell : methods.keySet()) {
                        out.println("    public final static SephObject cell_" + cell + " = getSephMethodHandleObject_" + cell + "();");
                    }
                    out.println();
                    for(String cell : fields.keySet()) {
                        out.println("    public final static SephObject cell_" + cell + " = " + cell + ".instance;");
                    }
                    out.println();
                    out.println("    public final static Object IDENTITY = new Object();");
                    out.println();
                    out.println("    public static SephObject get(String name) {");
                    out.println("        name = name.intern();");
                    for(Map.Entry<String,MethodDeclaration> entry : methods.entrySet()) {
                        String name = entry.getKey();
                        SephMethod anno = entry.getValue().getAnnotation(SephMethod.class);
                        if(anno.name().length > 0) {
                            name = anno.name()[0];
                        }
                        out.println("        if(name == \"" + name + "\") return cell_" + entry.getKey() + ";");
                    }
                    for(Map.Entry<String,FieldDeclaration> entry : fields.entrySet()) {
                        SephCell c = entry.getValue().getAnnotation(SephCell.class);
                        String realName = entry.getKey();
                        String cell = c.name().length > 0 ? c.name()[0] : realName;
                        out.println("        if(name == \"" + cell + "\") return cell_" + realName + ";");
                    }
                    out.println();
                    out.println("        SephObject result;");
                    for(String parent : parents) {
                        out.println("        if((result = parent_" + parent + ".get(name)) != null) return result;");
                    }
                    out.println("        return null;");
                    out.println("    }");
                    out.println();
                    for(Map.Entry<String, MethodDeclaration> entry : methods.entrySet()) {
                        String name = entry.getKey();
                        SephMethod anno = entry.getValue().getAnnotation(SephMethod.class);
                        if(anno.name().length > 0) {
                            name = anno.name()[0];
                        }

                        generateMethod(cd, entry.getKey(), entry.getValue(), name);
                    }
                    out.println();
View Full Code Here


                int ix = 0;
                int result = 0;

                out.println("    public static SephObject " + name + "(SephObject receiver, SThread thread, LexicalScope scope, MethodHandle[] arguments) {");

                SephMethod sm = md.getAnnotation(SephMethod.class);

                StringBuilder sb = new StringBuilder();

                boolean eval = true;
                int arity = -1;
                if(sm.evaluateArguments()) {
                    arity = generateRegularArgumentEvaluation(md, sb);
                } else {
                    arity = generateUnevaluatedArguments(md, sb);
                    eval = false;
                }

                out.println("        return " + cd.getQualifiedName() + "." + md.getSimpleName() + "(" + sb + ");");
                out.println("    }");
                out.println();
                getters[ix++] = "                             l.findStatic(" + cd.getSimpleName() + "Base.class, \"" + name + "\", ACTIVATE_METHOD_TYPE_N)";

                tempOut = new StringBuilder();
                tempOut.append("    public static SephObject " + name + "(SephObject receiver, SThread thread, LexicalScope scope) {").append("\n");
                result = generateForArityMH(arity, 0, md, cd, eval, false);
                tempOut.append("    }").append("\n");
                if(result == 1) {
                    out.print(tempOut.toString());
                    getters[ix++] = "                             l.findStatic(" + cd.getSimpleName() + "Base.class, \"" + name + "\", ACTIVATE_METHOD_TYPE_0)";
                } else if(result == -2) {
                    getters[ix++] = "                             l.findStatic(" + cd.getQualifiedName() + ".class, \"" + md.getSimpleName() + "\", ACTIVATE_METHOD_TYPE_0)";
                } else {
                    getters[ix++] = "                             arityError(" + arity + ", 0, \"" + realName + "\", false)";
                }


                tempOut = new StringBuilder();
                tempOut.append("    public static SephObject " + name + "(SephObject receiver, SThread thread, LexicalScope scope, MethodHandle arg0) {").append("\n");
                result = generateForArityMH(arity, 1, md, cd, eval, false);
                tempOut.append("    }").append("\n");
                if(result == 1) {
                    out.print(tempOut.toString());
                    getters[ix++] = "                             l.findStatic(" + cd.getSimpleName() + "Base.class, \"" + name + "\", ACTIVATE_METHOD_TYPE_1)";
                } else if(result == -2) {
                    getters[ix++] = "                             l.findStatic(" + cd.getQualifiedName() + ".class, \"" + md.getSimpleName() + "\", ACTIVATE_METHOD_TYPE_1)";
                } else {
                    getters[ix++] = "                             arityError(" + arity + ", 1, \"" + realName + "\", false)";
                }

                tempOut = new StringBuilder();
                tempOut.append("    public static SephObject " + name + "(SephObject receiver, SThread thread, LexicalScope scope, MethodHandle arg0, MethodHandle arg1) {").append("\n");
                result = generateForArityMH(arity, 2, md, cd, eval, false);
                tempOut.append("    }").append("\n");
                if(result == 1) {
                    out.print(tempOut.toString());
                    getters[ix++] = "                             l.findStatic(" + cd.getSimpleName() + "Base.class, \"" + name + "\", ACTIVATE_METHOD_TYPE_2)";
                } else if(result == -2) {
                    getters[ix++] = "                             l.findStatic(" + cd.getQualifiedName() + ".class, \"" + md.getSimpleName() + "\", ACTIVATE_METHOD_TYPE_2)";
                } else {
                    getters[ix++] = "                             arityError(" + arity + ", 2, \"" + realName + "\", false)";
                }

                tempOut = new StringBuilder();
                tempOut.append("    public static SephObject " + name + "(SephObject receiver, SThread thread, LexicalScope scope, MethodHandle arg0, MethodHandle arg1, MethodHandle arg2) {").append("\n");
                result = generateForArityMH(arity, 3, md, cd, eval, false);
                tempOut.append("    }").append("\n");
                if(result == 1) {
                    out.print(tempOut.toString());
                    getters[ix++] = "                             l.findStatic(" + cd.getSimpleName() + "Base.class, \"" + name + "\", ACTIVATE_METHOD_TYPE_3)";
                } else if(result == -2) {
                    getters[ix++] = "                             l.findStatic(" + cd.getQualifiedName() + ".class, \"" + md.getSimpleName() + "\", ACTIVATE_METHOD_TYPE_3)";
                } else {
                    getters[ix++] = "                             arityError(" + arity + ", 3, \"" + realName + "\", false)";
                }

                tempOut = new StringBuilder();
                tempOut.append("    public static SephObject " + name + "(SephObject receiver, SThread thread, LexicalScope scope, MethodHandle arg0, MethodHandle arg1, MethodHandle arg2, MethodHandle arg3) {").append("\n");
                result = generateForArityMH(arity, 4, md, cd, eval, false);
                tempOut.append("    }").append("\n");
                if(result == 1) {
                    out.print(tempOut.toString());
                    getters[ix++] = "                             l.findStatic(" + cd.getSimpleName() + "Base.class, \"" + name + "\", ACTIVATE_METHOD_TYPE_4)";
                } else if(result == -2) {
                    getters[ix++] = "                             l.findStatic(" + cd.getQualifiedName() + ".class, \"" + md.getSimpleName() + "\", ACTIVATE_METHOD_TYPE_4)";
                } else {
                    getters[ix++] = "                             arityError(" + arity + ", 4, \"" + realName + "\", false)";
                }

                tempOut = new StringBuilder();
                tempOut.append("    public static SephObject " + name + "(SephObject receiver, SThread thread, LexicalScope scope, MethodHandle arg0, MethodHandle arg1, MethodHandle arg2, MethodHandle arg3, MethodHandle arg4) {").append("\n");
                result = generateForArityMH(arity, 5, md, cd, eval, false);
                tempOut.append("    }").append("\n");
                if(result == 1) {
                    out.print(tempOut.toString());
                    getters[ix++] = "                             l.findStatic(" + cd.getSimpleName() + "Base.class, \"" + name + "\", ACTIVATE_METHOD_TYPE_5)";
                } else if(result == -2) {
                    getters[ix++] = "                             l.findStatic(" + cd.getQualifiedName() + ".class, \"" + md.getSimpleName() + "\", ACTIVATE_METHOD_TYPE_5)";
                } else {
                    getters[ix++] = "                             arityError(" + arity + ", 5, \"" + realName + "\", false)";
                }


                out.println("    public static SephObject " + name + "(SephObject receiver, SThread thread, LexicalScope scope, MethodHandle[] arguments, String[] keywordNames, MethodHandle[] keywordArguments) {");

                sb = new StringBuilder();

                eval = true;
                arity = -1;
                if(sm.evaluateArguments()) {
                    arity = generateRegularArgumentEvaluation(md, sb);
                } else {
                    arity = generateUnevaluatedArguments(md, sb);
                    eval = false;
                }
View Full Code Here

TOP

Related Classes of seph.lang.SephMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.