Example #1
0
 @Override
 public Value binary(Term.BinaryOperator operator, Term left, Term right) {
   Value leftValue = left.accept(this);
   Value rightValue = right.accept(this);
   double l = leftValue.accept(extractNumber);
   double r = rightValue.accept(extractNumber);
   switch (operator) {
     case add:
       return values.number(l + r);
     case sub:
       return values.number(l - r);
     case mult:
       return values.number(l * r);
     case div:
       return values.number(l / r);
     default:
       throw new RuntimeException("Unknown operator: " + operator);
   }
 }
Example #2
0
 @Override
 public Value record(String typeName, Map<String, Term> fields) {
   Record record = actor.records.get(typeName);
   if (record == null) {
     throw new RuntimeException("Unknown record type: " + typeName);
   }
   if (fields.size() != record.fields.size()) {
     throw new RuntimeException("Wrong number of fields");
   }
   Map<String, Value> fieldValues = new HashMap<String, Value>();
   for (Map.Entry<String, Term> entry : fields.entrySet()) {
     fieldValues.put(entry.getKey(), entry.getValue().accept(this));
     boolean found = false;
     for (Record.Field field : record.fields) {
       found |= field.name.equals(entry.getKey());
     }
     if (!found) {
       throw new RuntimeException("Unknown label: " + entry.getKey());
     }
   }
   return values.record(typeName, fieldValues);
 }
Example #3
0
 @Override
 public Value number(double value) {
   return values.number(value);
 }
Example #4
0
 @Override
 public Value constructor(String typeName, String constructorName, Term term) {
   return values.constructor(typeName, constructorName, term.accept(this));
 }