Package anvil.script

Examples of anvil.script.CompilableFunction


  public void compile(ByteCompiler context, int operation)
  {
    ClassType base = _classtype.getBaseClass();
    if (base != null) {
      Code code = context.getCode();
      CompilableFunction ctor = base.getConstructor();
      code.self();
      context.compileArgumentList(ctor, getChilds(0));
      code.invokespecial(ctor.getTypeRef(code.getPool()));
    }
  }
View Full Code Here


  }


  protected CompilableFunction onFunction(Method method, String name, Object[] parameters, Doc doc)
  {
    CompilableFunction function = new FunctionBase(this, method, name, parameters, doc);
    putstatic(_class, "f_" + name, function);
    putstatic(_class, "F_" + name, new AnyFunction(function));
    declare(function);
    return function;
  }
View Full Code Here

      return new TypeNode((CompilableFunction)type);
      //functioname[.field...]
    } else {
      if (hasArgs()) {
        //functioname(...)
        CompilableFunction function = (CompilableFunction)type;
        checkArguments(listener, function);
        return new CallNode(function, consumeArgs());
      } else {
        //functioname
        return new TypeNode((CompilableFunction)type);
View Full Code Here

        context.error(_location, "Superclass constructor invoke must appear as first statement in the body of constructor");
        return null;
      }
    
      ClassType base = classtype.getBaseClass();
      CompilableFunction constructor = base.getConstructor();
      if (constructor == null) {
        context.error(_location, "Base class '"+base+"' does not have constructor");
        return null;
      }
      checkArguments(context, constructor);
      return new ConstructorInvokeNode(classtype, consumeArgs());
    }
   
    if (symbolsLeft() < 1) {
      context.error(_location, "Invalid use of 'super'.");
      return null;
    }
   
    String symbol = consumeSymbol();
    Type type = classtype.lookupInheritedDeclaration(symbol);
    if (type == null) {
      context.error(_location, "Undefined entity '"+_name+"'");
      return null;
    }
   
    switch(type.getType()) {
    case Type.INTERFACE_METHOD:
      {
        context.error(_location, "Illegal access to interface method with 'super'");
        return null;
      }
     
    case Type.METHOD:
      if (!hasArgs()) {
        return new TypeNode(type);
      }
      if (_statement.isStaticRegion()) {
        context.error(_location, "Attempting to invoke '"+type+"' from static region");
      }
      MethodType ctor = (MethodType)type;
      checkArguments(context, ctor);
      return new SuperInvokeNode(ctor, consumeArgs());

    case Type.FUNCTION:
      if (!hasArgs()) {
        return new TypeNode(type);
      }
      CompilableFunction function = (CompilableFunction)type;
      checkArguments(context, function);
      return new CallNode(function, consumeArgs());

    case Type.CONSTANT_VARIABLE:
      return new ConstantVariableNode((ConstantVariableType)type);
View Full Code Here

          }
          if (!hasArgs()) {
            listener.error(_location, "Syntax error: argument list expected after '"+_name.toString(1)+"'");
            return null;
          }
          CompilableFunction constructor = clazz.getConstructor();
          if (constructor == null) {
            listener.error(_location, "Class '" + clazz + "' does not have constructor");
            return null;
          }
          ClassType context = _statement.getClassStatement();
View Full Code Here

  }


  protected void addConstructorCall(ErrorListener context)
  {
    CompilableFunction ctor = getBaseClassConstructor();
    if (ctor != null) {
      if (ctor.getMinimumParameterCount() > 0) {
        context.error(getLocation(), "Cannot create implicit constructor call in class '" + getName() +
          "' since superclass '" + getBase().getReference() + "' does not have constructor with empty parameter list");
      } else {
        BlockStatement block = _constructor.getBlockStatement();
        block.insert(new EvalStatement(block, getLocation(),
View Full Code Here

     

    case Type.FUNCTION:
    case Type.CONSTRUCTOR:
      {
        CompilableFunction function = (CompilableFunction)_type;
        if (function.isInnerFunction()) {
          throw context.CallError("Cannot call inner function: " + _type.toString());
        }
        return function.execute(context, parameters);
      }
     
    case Type.INTERFACE_METHOD:
      {
        throw context.CallError("Cannot call interface method: " + _type.toString());
      }

    case Type.METHOD:
      {
        CompilableFunction function = (CompilableFunction)_type;
        if (function.isInnerFunction()) {
          throw context.CallError("Cannot call inner method: " + _type.toString());
        }
        int length = parameters.length;
        if (length == 0) {
          throw context.NoInstance(_type.toString());
        }
        Any self = parameters[0];
        Type target = function.getParent();
        if (!self.isInstanceOf(target)) {
          throw context.BadParameter("Instance of '"+target+"' expected");
        }
        Any[] params = Any.ARRAY0;
        if (length > 1) {
          params = new Any[--length];
          System.arraycopy(parameters, 1, params, 0, length);
        }
        return function.execute(context, self, params);
      }
     
    default:
      return Any.UNDEFINED;
    }
View Full Code Here

  /// contains <code>(restName, docText, docTypeText)</code>.
  /// @synopsis array getParameterList()
  public Any m_getParameterList()
  {
    if (_type instanceof CompilableFunction) {
      CompilableFunction function = (CompilableFunction)_type;
      int max = function.getParameterCount();
      int min = function.getMinimumParameterCount();
      Array list = new Array();
      Any value;
      int count = 0;
      boolean required;
      Doc doc;
      for(int i=0; i<max; i++) {
        switch(function.getParameterType(i)) {
        case CompilableFunction.PARAMETER_CONTEXT:
          break;
        case CompilableFunction.PARAMETER_ANY:
        case CompilableFunction.PARAMETER_STRING:
        case CompilableFunction.PARAMETER_OBJECT:
        case CompilableFunction.PARAMETER_DOUBLE:
        case CompilableFunction.PARAMETER_INT:
        case CompilableFunction.PARAMETER_LONG:
        case CompilableFunction.PARAMETER_BOOLEAN:
          required = (count < min);
          if (count >= min) {
            value = function.getParameterDefault(i);
            if (value == null) {
              value = UNDEFINED;
            }
          } else {
            value = UNDEFINED;
          }
          doc = function.getParameterDoc(i);
          list.append(new AnyString(function.getParameterName(i)),
            new AnyTuple(new Any[] {
              required ? Any.TRUE : Any.FALSE,
              value,
              Any.create((doc != null) ? doc.getText() : null),
              Any.create((doc != null) ? doc.getChildText(doc.T_TYPE, null) : null)
            }));
          count++;
          break;
         
        case CompilableFunction.PARAMETER_ARRAY:
        case CompilableFunction.PARAMETER_ANYLIST:
        case CompilableFunction.PARAMETER_LIST:
          doc = function.getParameterDoc(i);
          list.append(DOTDOT, new AnyTuple(new Any[] {
              new AnyString(function.getParameterName(i)),
              Any.create((doc != null) ? doc.getText() : null),
              Any.create((doc != null) ? doc.getChildText(doc.T_TYPE, null) : null)
            }));
          break;
        }
View Full Code Here

      }

      /* methods */ {
        Method[] methods = module.getDeclaredMethods();
        Object[] parameters;
        CompilableFunction function;
        int n = methods.length;
        for(int i=0; i<n; i++) {
          Method method = methods[i];
          String name = method.getName();
          int mod = method.getModifiers();
          if (Modifier.isPublic(mod) && Modifier.isStatic(mod)) {
            if (method.getReturnType().equals(Any.class)) {
              Doc doc = _document.findFirst(Doc.T_FUNCTION, name);
              parameters = (Object[])Compiled.getstatic(module, "p_"+name);
              function = new NativeFunction(this, method, name, parameters, doc);
              _types.put(function.getName(), function);
            }
          }
        }
      }

View Full Code Here

TOP

Related Classes of anvil.script.CompilableFunction

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.