01: package jsint;
02:
03: /** A LocalVariable is denoted by its position in the environment, in terms
04: * of the number of levels "up" we have to go (number of nested environments),
05: * the number of variables "in" we have to go (ordinal position of variable),
06: * and whether the variable is a "rest" (or "dotted") variable.
07: * Example of variables in <tt>(list x y z a b)</tt>:
08: * <fmt>
09: * (lambda (x y) x.up=2, x.in=0 y.up=2, y.in=1
10: * (lambda (z . a) z.up=1, z.in=0 a.up=1, a.in=1
11: * (lambda b b.up=0, b.in=0
12: * (list x y z a b))))
13: * </fmt>
14: * @author Peter Norvig, Copyright 1998, peter@norvig.com, <a href="license.txt">license</a>
15: * subsequently modified by Jscheme project members
16: * licensed under zlib licence (see license.txt)
17: **/
18: public class LocalVariable implements java.io.Serializable {
19:
20: /** The number of levels up in the parent chain where the variable is. **/
21: public int up;
22: /** The ordinal position in the environment where the variable is. **/
23: public int in;
24: /** The name of the variable (for debugging purposes only). **/
25: Symbol name;
26:
27: /** Create a new variable. **/
28: public LocalVariable(int up, int in, Symbol name) {
29: this .up = up;
30: this .in = in;
31: this .name = name;
32: }
33:
34: /** Use the name, up and in of the variable as its String
35: representation so they distinguish themselves from a Global
36: variable. **/
37: public String toString() {
38: return name.toString() + "^" + up + in;
39: }
40: }
|