01: package gnu.expr;
02:
03: import gnu.mapping.*;
04: import gnu.bytecode.Type;
05:
06: /**
07: * An Expression that evaluates to a constant value.
08: * @author Per Bothner
09: */
10:
11: public class QuoteExp extends Expression {
12: Object value;
13: Type type = null;
14:
15: public final Object getValue() {
16: return value;
17: }
18:
19: public final gnu.bytecode.Type getType() {
20: if (type != null)
21: return type;
22: if (value == Values.empty)
23: return gnu.bytecode.Type.void_type;
24: if (value == null)
25: return gnu.bytecode.Type.nullType;
26: return gnu.bytecode.Type.make(value.getClass());
27: }
28:
29: static public QuoteExp undefined_exp = new QuoteExp(Undefined
30: .getInstance());
31: static public QuoteExp voidExp = new QuoteExp(Values.empty);
32: static public QuoteExp trueExp = new QuoteExp(Boolean.TRUE);
33: static public QuoteExp falseExp = new QuoteExp(Boolean.FALSE);
34: static public QuoteExp nullExp = new QuoteExp(null);
35:
36: public QuoteExp(Object val) {
37: value = val;
38: }
39:
40: public QuoteExp(Object val, Type type) {
41: this (val);
42: this .type = type;
43: }
44:
45: public Object eval(Environment env) {
46: return value;
47: }
48:
49: public void compile(Compilation comp, Target target) {
50: comp.compileConstant(value, target);
51: }
52:
53: protected Expression walk(ExpWalker walker) {
54: return walker.walkQuoteExp(this );
55: }
56:
57: public void print(OutPort out) {
58: out.startLogicalBlock("(Quote", ")", 2);
59: out.writeSpaceLinear();
60: gnu.lists.FormatToConsumer saveFormat = out.objectFormat;
61: try {
62: out.objectFormat = Interpreter.getInterpreter().getFormat(
63: true);
64: out.print(value);
65: } finally {
66: out.objectFormat = saveFormat;
67: }
68: out.endLogicalBlock(")");
69: }
70: }
|