Exemplo n.º 1
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 2;
   final A_Atom propertyKey = args.get(0);
   final A_Atom atom = args.get(1);
   if (atom.isAtomSpecial()) {
     return interpreter.primitiveFailure(E_SPECIAL_ATOM);
   }
   final A_BasicObject propertyValue = atom.getAtomProperty(propertyKey);
   return interpreter.primitiveSuccess(
       AtomDescriptor.objectFromBoolean(!propertyValue.equalsNil()));
 }
Exemplo n.º 2
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 1;
   final A_BasicObject value = args.get(0);
   final ByteArrayOutputStream out = new ByteArrayOutputStream(100);
   final Serializer serializer = new Serializer(out);
   try {
     serializer.serialize(value);
   } catch (final Exception e) {
     return interpreter.primitiveFailure(E_SERIALIZATION_FAILED);
   }
   return interpreter.primitiveSuccess(ByteArrayTupleDescriptor.forByteArray(out.toByteArray()));
 }
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 1;
   final A_Token token = args.get(0);
   return interpreter.primitiveSuccess(LiteralNodeDescriptor.fromToken(token));
 }
Exemplo n.º 4
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 1;
   final AvailObject map = args.get(0);
   return interpreter.primitiveSuccess(ObjectTypeDescriptor.objectTypeFromMap(map));
 }
Exemplo n.º 5
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 2;
   final A_Type type1 = args.get(0);
   final A_Type type2 = args.get(1);
   return interpreter.primitiveSuccess(type1.typeIntersection(type2).makeImmutable());
 }
Exemplo n.º 6
0
  @Override
  public Result attempt(
      final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
    assert args.size() == 2;
    final A_Set set1 = args.get(0);
    final A_Set set2 = args.get(1);

    return interpreter.primitiveSuccess(set1.setIntersectionCanDestroy(set2, true));
  }
Exemplo n.º 7
0
  @Override
  public Result attempt(
      final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
    assert args.size() == 1;
    final A_Bundle bundle = args.get(0);

    final MessageSplitter splitter = bundle.messageSplitter();
    return interpreter.primitiveSuccess(IntegerDescriptor.fromInt(splitter.numberOfArguments()));
  }
Exemplo n.º 8
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 4;
   final A_BasicObject methodPojo = args.get(0);
   final A_Tuple methodArgs = args.get(1);
   final A_Tuple marshaledTypePojos = args.get(2);
   final A_Type expectedType = args.get(3);
   // Marshal the arguments and invoke the method.
   final Method method = (Method) methodPojo.javaObject();
   assert method != null;
   final Object[] marshaledArgs = new Object[methodArgs.tupleSize()];
   try {
     for (int i = 0; i < marshaledArgs.length; i++) {
       final Class<?> marshaledType = (Class<?>) marshaledTypePojos.tupleAt(i + 1).javaObject();
       marshaledArgs[i] = methodArgs.tupleAt(i + 1).marshalToJava(marshaledType);
     }
   } catch (final MarshalingException e) {
     return interpreter.primitiveFailure(
         PojoDescriptor.newPojo(
             RawPojoDescriptor.identityWrap(e), PojoTypeDescriptor.forClass(e.getClass())));
   }
   final Object result;
   try {
     result = method.invoke(null, marshaledArgs);
   } catch (final InvocationTargetException e) {
     final Throwable cause = e.getCause();
     return interpreter.primitiveFailure(
         PojoDescriptor.newPojo(
             RawPojoDescriptor.identityWrap(cause),
             PojoTypeDescriptor.forClass(cause.getClass())));
   } catch (final Throwable e) {
     // This is an unexpected failure.
     error("reflected method call unexpectedly failed");
     throw new Error();
   }
   if (result == null) {
     return interpreter.primitiveSuccess(PojoDescriptor.nullObject());
   }
   final AvailObject unmarshaled = PojoTypeDescriptor.unmarshal(result, expectedType);
   return interpreter.primitiveSuccess(unmarshaled);
 }
Exemplo n.º 9
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 2;
   final AvailObject handle = args.get(0);
   final AvailObject options = args.get(1);
   final AvailObject pojo = handle.getAtomProperty(AtomDescriptor.socketKey());
   if (pojo.equalsNil()) {
     return interpreter.primitiveFailure(
         handle.isAtomSpecial() ? E_SPECIAL_ATOM : E_INVALID_HANDLE);
   }
   final AsynchronousSocketChannel socket = (AsynchronousSocketChannel) pojo.javaObjectNotNull();
   try {
     for (final MapDescriptor.Entry entry : options.mapIterable()) {
       final AvailObject key = entry.key();
       final AvailObject entryValue = entry.value();
       assert key != null;
       @SuppressWarnings("rawtypes")
       final SocketOption option = socketOptions[key.extractInt()];
       final Class<?> type = option.type();
       if (type.equals(Boolean.class) && entryValue.isBoolean()) {
         final SocketOption<Boolean> booleanOption = option;
         socket.setOption(booleanOption, entryValue.extractBoolean());
       } else if (type.equals(Integer.class) && entryValue.isInt()) {
         final Integer value = entryValue.extractInt();
         socket.<Integer>setOption(option, value);
       } else {
         return interpreter.primitiveFailure(E_INCORRECT_ARGUMENT_TYPE);
       }
     }
     return interpreter.primitiveSuccess(NilDescriptor.nil());
   } catch (final IllegalArgumentException e) {
     return interpreter.primitiveFailure(E_INCORRECT_ARGUMENT_TYPE);
   } catch (final IOException e) {
     return interpreter.primitiveFailure(E_IO_ERROR);
   }
 }