DefineOp.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package gnu.q2.lang;
  2. import gnu.mapping.Symbol;
  3. import gnu.expr.*;
  4. import gnu.lists.*;
  5. import kawa.lang.*;
  6. /** Syntax handler for ($define$ VAR [TYPE-SPECIFIER]). */
  7. public class DefineOp extends Syntax {
  8. public static final DefineOp defineOp = new DefineOp();
  9. public Expression rewriteForm(Pair form, Translator tr) {
  10. Pair pair1 = (Pair) form.getCdr();
  11. Object pat = pair1.getCar();
  12. Pair typeSpecPair = null;
  13. if (pair1.getCdr() instanceof Pair)
  14. typeSpecPair = (Pair) pair1.getCdr();
  15. if (pat instanceof Symbol) {
  16. Symbol sym = (Symbol) pat;
  17. Declaration decl = tr.define(sym, tr.currentScope());
  18. PrimProcedure makeLazy = new PrimProcedure("gnu.mapping.Promise",
  19. "makeBlank", 0);
  20. BindDecls.setInitializer(decl, new ApplyExp(makeLazy),
  21. tr.currentScope(), tr);
  22. if (typeSpecPair != null)
  23. tr.exp2Type(typeSpecPair, decl, null);
  24. return new ReferenceExp(decl);
  25. }
  26. return null;
  27. }
  28. public void scanForm(Pair st, ScopeExp defs, Translator tr) {
  29. super.scanForm(st, defs, tr);
  30. }
  31. }