// Copyright (c) 1996-2002 Brian D. Carlstrom

package bdc.scheme.procedure;

import bdc.scheme.Scheme;
import bdc.scheme.Stack;
import bdc.scheme.exception.ArgumentTypeException;
import bdc.scheme.expression.Procedure2;
import bdc.util.ClassUtil;
import bdc.util.Constants;

/**
    Primitive for instanceof

    The Java instanceof operator can't take a Class object as an arugment
    so we have to implement it ourselves
*/
public class InstanceOf extends Procedure2
{
    public Object apply2 (Stack stack) throws ArgumentTypeException
    {
        Object o1 = stack.array[stack.inUse-1];
        Object o2 = stack.array[stack.inUse-2];
        Class clazz = Scheme.clazz(o2, this);
        return Constants.getBoolean(ClassUtil.instanceOf(o1.getClass(), clazz));
    }
}
