module_static.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package kawa.standard;
  2. import kawa.lang.*;
  3. import gnu.expr.*;
  4. import gnu.lists.*;
  5. import gnu.mapping.Symbol;
  6. import gnu.mapping.SimpleSymbol;
  7. public class module_static extends Syntax
  8. {
  9. public static final module_static module_static = new module_static();
  10. static { module_static.setName("module-static"); }
  11. @Override
  12. public boolean scanForDefinitions(Pair st, ScopeExp defs, Translator tr)
  13. {
  14. Object list = st.getCdr();
  15. if (! (defs instanceof ModuleExp))
  16. {
  17. tr.error('e', "\'" + getName() + "\' not at module level");
  18. return true;
  19. }
  20. ModuleExp mexp = (ModuleExp) defs;
  21. if (list instanceof Pair
  22. && (st = (Pair) list).getCdr() == LList.Empty
  23. && st.getCar() instanceof Boolean)
  24. {
  25. if (st.getCar() == Boolean.FALSE)
  26. mexp.setFlag(ModuleExp.NONSTATIC_SPECIFIED);
  27. else
  28. mexp.setFlag(ModuleExp.STATIC_SPECIFIED);
  29. }
  30. else if (list instanceof Pair
  31. && (st = (Pair) list).getCdr() == LList.Empty
  32. && st.getCar() instanceof Pair
  33. && tr.matches((st = (Pair) st.getCar()).getCar(), Scheme.quote_str))
  34. {
  35. Object cdr = st.getCdr();
  36. if (cdr != LList.Empty
  37. && (st = (Pair) cdr).getCar() instanceof SimpleSymbol
  38. && st.getCar().toString() == "init-run")
  39. {
  40. // (module-static 'init-run) implies (module-static #t)
  41. mexp.setFlag(ModuleExp.STATIC_SPECIFIED);
  42. mexp.setFlag(ModuleExp.STATIC_RUN_SPECIFIED);
  43. if (tr.generateMainMethod())
  44. tr.error('e', "init-run option incompatible with --main");
  45. }
  46. else
  47. {
  48. tr.error('e', "invalid quoted symbol for '" + getName() + '\'');
  49. return false;
  50. }
  51. }
  52. else
  53. {
  54. mexp.setFlag(ModuleExp.NONSTATIC_SPECIFIED);
  55. while (list != LList.Empty)
  56. {
  57. if (! (list instanceof Pair)
  58. || ! ((st = (Pair) list).getCar() instanceof Symbol))
  59. {
  60. tr.error('e', "invalid syntax in '" + getName() + '\'');
  61. return false;
  62. }
  63. Symbol symbol = (Symbol) st.getCar();
  64. Declaration decl = defs.getNoDefine(symbol);
  65. if (decl.getFlag(Declaration.NOT_DEFINING))
  66. Translator.setLine(decl, st);
  67. decl.setFlag(Declaration.STATIC_SPECIFIED);
  68. list = st.getCdr();
  69. }
  70. }
  71. if (mexp.getFlag(ModuleExp.NONSTATIC_SPECIFIED)
  72. && mexp.getFlag(ModuleExp.STATIC_SPECIFIED))
  73. tr.error('e', "inconsistent module-static specifiers");
  74. return true;
  75. }
  76. public Expression rewriteForm (Pair form, Translator tr)
  77. {
  78. return null;
  79. }
  80. }