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

org.snapscript.tree.closure.ClosureStatement Maven / Gradle / Ivy

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

import org.snapscript.core.Evaluation;
import org.snapscript.core.Result;
import org.snapscript.core.Scope;
import org.snapscript.core.Statement;
import org.snapscript.core.Value;

public class ClosureStatement extends Statement {
   
   private final Evaluation evaluation;
   private final Statement statement;
   
   public ClosureStatement(Statement statement, Evaluation evaluation) {
      this.evaluation = evaluation;
      this.statement = statement;
   }
   
   @Override
   public Result compile(Scope scope) throws Exception {   
      if(evaluation != null){
         evaluation.compile(scope);
      }
      if(statement != null) {
         statement.compile(scope);
      }
      return Result.getNormal();
   }

   @Override
   public Result execute(Scope scope) throws Exception {
      if(evaluation != null) {
         Value value = evaluation.evaluate(scope, null);
         Object object = value.getValue();
         
         return Result.getNormal(object);
      }
      return statement.execute(scope);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy