#include "main.hh"
#include "input.hh"
#include "moment.hh"
+#include "ly-modules.hh"
+
static Keyword_ent the_key_tab[]={
{"alias", ALIAS},
{0,0}
};
+
My_lily_lexer::My_lily_lexer ()
{
keytable_ = new Keyword_table (the_key_tab);
- toplevel_variable_tab_ = new Scheme_hash_table ;
- scopes_.push (toplevel_variable_tab_);
+ scopes_ = SCM_EOL;
- errorlevel_ = 0;
+ add_scope(ly_make_anonymous_module());
+ errorlevel_ =0;
+
main_input_b_ = false;
}
+void
+My_lily_lexer::add_scope (SCM module)
+{
+ ly_reexport_module (scm_current_module());
+ scm_set_current_module (module);
+ for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
+ {
+ /*
+ UGH. how to do this more neatly?
+ */
+ SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
+ module, scm_list_n (ly_symbol2scm ("module-public-interface"),
+ gh_car (s), SCM_UNDEFINED),
+ SCM_UNDEFINED);
+
+ scm_primitive_eval(expr);
+ }
+
+ scopes_ = scm_cons (module, scopes_);
+}
+
+SCM
+My_lily_lexer::remove_scope ()
+{
+ SCM sc = gh_car (scopes_);
+ scopes_ = gh_cdr (scopes_);
+ scm_set_current_module (gh_car (scopes_));
+
+ return sc;
+}
+
+
int
My_lily_lexer::lookup_keyword (String s)
{
SCM
My_lily_lexer::lookup_identifier (String s)
{
- SCM sym = ly_symbol2scm (s.to_str0 ());
-
- for (int i = scopes_.size (); i--;)
+ SCM sym = ly_symbol2scm (s.to_str0());
+ for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
{
- SCM val = SCM_UNSPECIFIED;
- if (scopes_[i]->try_retrieve (sym, &val))
- return val;
+ SCM var = ly_module_lookup (gh_car (s), sym);
+ if (var != SCM_BOOL_F)
+ return scm_variable_ref(var);
}
+
return SCM_UNSPECIFIED;
}
warning (_f ("Identifier name is a keyword: `%s'", str));
free (str);
}
-
- scopes_.top ()->set (scm_string_to_symbol (name), s);
+
+ SCM sym = scm_string_to_symbol (name);
+ SCM mod = gh_car (scopes_);
+
+ scm_module_define (mod, sym, s);
}
My_lily_lexer::~My_lily_lexer ()
{
delete keytable_;
- scm_gc_unprotect_object (toplevel_variable_tab_->self_scm ());
}