// Copyright (c) 1996-2002 Brian D. Carlstrom

package bdc.scheme.expression;

import bdc.scheme.Environment;
import bdc.scheme.Scheme;
import bdc.scheme.SchemeException;
import bdc.scheme.Stack;
import bdc.scheme.Variable;
import bdc.scheme.compiler.CompileTimeEnvironment;

public class LexicalAddress extends Expression
{
    public Variable variable;
    public int      frame;
    public int      displacement;

    public LexicalAddress (Variable variable,
                           int      frame,
                           int      displacement)
    {
        this.variable     = variable;
        this.frame        = frame;
        this.displacement = displacement;
    }

    public Object eval (Environment environment, Stack stack)
      throws SchemeException
    {
        try {
            return environment.lexicalAddressLookup(this);
        }
        catch (SchemeException se) {
            backTrace(se);
            return Scheme.NotReached;
        }
    }

    /**
        Fixup
    */
    public Expression fixupVariables (CompileTimeEnvironment environment)
    {
        return environment.fixupVariable(variable, this);
    }

    public String toString ()
    {
        return variable.name.toString();
    }
}
