package org.jruby.ir.instructions.defined;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.FixedArityInstr;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.instructions.ResultInstr;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class GetErrorInfoInstr extends Instr implements ResultInstr, FixedArityInstr {
    private Variable result;

    public GetErrorInfoInstr(Variable result) {
        super(Operation.GET_ERROR_INFO);

        this.result = result;
    }

    @Override
    public Operand[] getOperands() {
        return EMPTY_OPERANDS;
    }

    @Override
    public Variable getResult() {
        return result;
    }

    @Override
    public void updateResult(Variable v) {
        result = v;
    }

    @Override
    public Instr clone(CloneInfo info) {
        return new GetErrorInfoInstr((Variable) getResult().cloneForInlining(info));
    }

    @Override
    public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
        return context.getErrorInfo();
    }

    @Override
    public void visit(IRVisitor visitor) {
        visitor.GetErrorInfoInstr(this);
    }
}
