All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.tree.ArgumentList Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.tree;

import org.snapscript.core.Scope;
import org.snapscript.core.Value;

public class ArgumentList {
   
   private final Argument[] list;
   private final Object[] empty;
   
   public ArgumentList(Argument... list) {
      this.empty = new Object[]{};
      this.list = list;
   }
   
   public void compile(Scope scope) throws Exception{
      for(int i = 0; i < list.length; i++){
         list[i].compile(scope);
      }
   }
   
   public Value create(Scope scope) throws Exception{
      if(list.length > 0) {
         return create(scope, empty);
      }
      return Value.getTransient(empty);
   }
   
   public Value create(Scope scope, Object... prefix) throws Exception{
      Object[] values = new Object[list.length + prefix.length];
      
      for(int i = 0; i < list.length; i++){
         Value reference = list[i].evaluate(scope, null);
         Object result = reference.getValue();
         
         values[i + prefix.length] = result;
      }
      for(int i = 0; i < prefix.length; i++) {
         values[i] = prefix[i];
      }
      return Value.getTransient(values);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy