Package com.stuffwithstuff.magpie.interpreter

Examples of com.stuffwithstuff.magpie.interpreter.Obj


    mClosure = closure;
  }
 
  @Override
  public Obj invoke(Context context, Obj arg) {
    Obj value = arg.getField(0).getField(mName);
    if (value == null) return context.nothing();
    return value;
  }
View Full Code Here


      List<Obj> list = left.getField(0).asList();
     
      int index = Indexable.validateIndex(context, list,
          left.getField(1).asInt());
     
      Obj value = right;
     
      list.set(index, value);
      return value;
    }
View Full Code Here

  @Def("(== List) new(fill: fill, size: size is Int)")
  @Doc("Creates a list filled with the given value.")
  public static class New_FillSize implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      Obj fill = right.getField("fill");
      int size = right.getField("size").asInt();
     
      List<Obj> elements = new ArrayList<Obj>();
      for (int i = 0; i < size; i++) {
        elements.add(fill);
View Full Code Here

  @Def("(is List) insert(item, at: index is Int)")
  @Doc("Inserts the given item at the given index in the list.")
  public static class Insert implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      List<Obj> list = left.asList();
      Obj value = right.getField(0);
     
      int index = Indexable.validateIndex(context, list.size() + 1,
          right.getField("at").asInt());

      list.add(index, value);
View Full Code Here

  }

  private static abstract class Methods implements Intrinsic {
    public Obj invoke(final Context context, Obj left, Obj right) {
    
      final Obj matchingValue = getMatchingValueFromArgs(context, left, right);

      DocBuilder docBuilder = new DocBuilder() {

        @Override
        protected boolean shouldDisplayMethod(Callable callable) {
View Full Code Here

  @Def("(== Array) new(fill: fill, size: size is Int)")
  @Doc("Creates an array filled with the given value.")
  public static class New_FillSize implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      Obj fill = right.getField("fill");
      int size = right.getField("size").asInt();
     
      List<Obj> elements = new ArrayList<Obj>();
      for (int i = 0; i < size; i++) {
        elements.add(fill);
View Full Code Here

  @Def("(is Function) call(arg)")
  @Doc("Invokes the given function.")
  public static class Call implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      FnObj function = left.asFn();
      Obj fnArg = right;
     
      // Make sure the argument matches the function's pattern.
      Callable callable = function.getCallable();
      if (!PatternTester.test(context, callable.getPattern(), fnArg,
          callable.getClosure())) {
View Full Code Here

      Map<String, Obj> fields = left.getFields();
      Set<String> compared = new HashSet<String>();
     
      // Make sure the right record has all of the left record's fields.
      for (Entry<String, Obj> entry : fields.entrySet()) {
        Obj rightField = right.getField(entry.getKey());
        if (rightField == null) return context.toObj(false);
        if (!context.getInterpreter().objectsEqual(
            entry.getValue(), rightField)) {
          return context.toObj(false);
        }
View Full Code Here

    try {
      Expr expr = parser.parseStatement();
      parser.consume(TokenType.LINE);
     
      Obj result = mInterpreter.interpret(expr);
      String resultText;
      if (result == mInterpreter.nothing()) {
        resultText = null;
      } else {
        resultText = mInterpreter.evaluateToString(result);
View Full Code Here

  @Override
  public Obj invoke(Context context, Obj arg) {
    // We don't care about the receiver.
    arg = arg.getField(1);
   
    Obj obj = context.getInterpreter().getConstructingObject();

    // Initialize the parent classes from the record.
    for (ClassObj parent : mClass.getParents()) {
      Obj value = arg.getField(parent.getName());
      if (value != null) {
        context.getInterpreter().initializeNewObject(context, parent, value);
      }
    }
   
    // Initialize the fields from the record.
    for (Entry<String, FieldObj> field : mClass.getFieldDefinitions().entrySet()) {
      // Assign it from the record.
      Obj value = arg.getField(field.getKey());
      if (value != null) {
        obj.setField(field.getKey(), arg.getField(field.getKey()));
      }
    }
   
View Full Code Here

TOP

Related Classes of com.stuffwithstuff.magpie.interpreter.Obj

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.