xo-interpreter: implement variable lookup

This commit is contained in:
Roland Conybeare 2025-11-25 12:43:57 -05:00
commit d91a2ae08e
10 changed files with 140 additions and 13 deletions

View file

@ -24,6 +24,11 @@ namespace xo {
/** true iff @p vname is present in Symtab for innermost environment **/
virtual bool local_contains_var(const std::string & vname) const = 0;
/** Fetch storage location for innermost binding of variable with name @p vname.
* nullptr if not found
**/
virtual gp<Object> * lookup_slot(const std::string & vname) = 0;
/** require storage for variable @p v.
* will also establish binding path.
*
@ -31,8 +36,10 @@ namespace xo {
* replacing any previous variable with the same name.
*
* Beware of invalidating type correctness
*
* @return slot address for runtime value of @p v
**/
virtual void establish_var(bp<Variable> v) = 0;
virtual gp<Object> * establish_var(bp<Variable> v) = 0;
//gp<Object> lookup_symbol(const std::string & name) const;
};

View file

@ -21,6 +21,11 @@ namespace xo {
static gp<ExpressionBoxed> make(gc::IAlloc * mm,
bp<Expression> c);
/** runtime downcast **/
static gp<ExpressionBoxed> from(gp<Object> x) {
return gp<ExpressionBoxed>::from(x);
}
const rp<Expression> & contents() const { return contents_; }
// inherited from Object

View file

@ -28,7 +28,8 @@ namespace xo {
// inherited from Env..
virtual bool local_contains_var(const std::string & vname) const final override;
virtual void establish_var(bp<Variable> var) final override;
virtual gp<Object> * lookup_slot(const std::string & vname) final override;
virtual gp<Object> * establish_var(bp<Variable> var) final override;
// inherited from Object..
virtual TaggedPtr self_tp() const final override;

View file

@ -64,10 +64,12 @@ namespace xo {
virtual bool local_contains_var(const std::string & vname) const final override;
virtual gp<Object> * lookup_slot(const std::string & vname) final override;
/** LocalEnv policy is that variable can be established once only.
* For example function arguments must all have distinct names
* For example function arguments must all have distinct names.
**/
virtual void establish_var(bp<Variable> v) final override;
virtual gp<Object> * establish_var(bp<Variable> v) final override;
// inherited from Object..
virtual TaggedPtr self_tp() const final override;

View file

@ -83,10 +83,12 @@ namespace xo {
/** interpret define expression **/
void eval_define_op();
/** continue after establishing value fo rhs of define exprsssion **/
void do_defexpr_assign_op();
/** interpret variable expression **/
void eval_variable_op();
/** goto error state with message @p err **/
void report_error(const std::string & err);