Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Checker + Evaluator -> Compiler + Evaluator) refactor #2

Closed
xiaq opened this issue Apr 26, 2014 · 0 comments
Closed

(Checker + Evaluator -> Compiler + Evaluator) refactor #2

xiaq opened this issue Apr 26, 2014 · 0 comments

Comments

@xiaq
Copy link
Member

xiaq commented Apr 26, 2014

Current flow of source code:

source code [parser]-> AST [checker]-> annotated AST [evaluator]-> effects

That is, the checker checks and annotates the AST with information available statically and the evaluator evaluates the annotated AST. This poses two problems:

  1. The AST is walked twice, meaning a change in the AST structs usually affect three places: the parser, the checker and the evaluator.
  2. Getting the types right is tedious. The type of the annotation is declared in the eval package, AST nodes in parse. eval imports parse; since golang forbids cyclic imports, parse cannot import eval and AST nodes cannot contain annotation types directly. To work around this, all annotations are typed interface{} and the Checker and Evaluator make type assertions everywhere.

The plan is to introduce a new component, a compiler that takes up the role of the checker and much of the evaluator. Instead of checking and annotating the AST, the compiler performs deferred evaluation of the AST. For instance, a factor is evaluated into a func(*Evaluator) []Value, where currently, the evaluator evaluates it into a []Value. Similar things apply to all levels of the AST, from terms to chunks.

This would solve the aforementioned problems, but by using closures extensively it could also make debugging a bit harder.

@xiaq xiaq added the PART-eval label Apr 26, 2014
xiaq added a commit that referenced this issue May 20, 2014
eval.Checker is now replaced by eval.Compiler which compiles the AST into a
closure operating on the Evaluator. Huge commit, sorry.
@xiaq xiaq closed this as completed Jun 6, 2014
xiaq added a commit that referenced this issue Jun 6, 2018
xiaq added a commit that referenced this issue May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant