perlang-org / perlang

The Perlang Programming Language (GitHub Mirror)
https://gitlab.perlang.org/perlang/perlang
MIT License
16 stars 1 forks source link

Make all Stmt and Expr subclasses have a good ToString() implementation #411

Closed perlun closed 2 months ago

perlun commented 1 year ago

Moved to GitLab

Please continue to the new version of this issue here: https://gitlab.perlang.org/perlang/perlang/-/issues/411. The GitHub page you are currently reading will not contain the latest information on this issue.


The objective here is easy: improve the debugging experience of the Perlang compiler by making all Stmt and Expr subclasses have a good (preferably, excellent) ToString() implementation. This method is typically called by debuggers when viewing the contents of local variables and parameters.

Here's what it looks like right now:

image

The screenshot above illustrates this well. Stmt.Var has a good implementation, where it virtually reconstructs the Perlang source code (var i = 12). Stmt.ExpressionStmt and Stmt.Print are much harder to debug; you more or less have to manually inspect these variables to get a glimpse of what's going on.

This should be pretty straightforward for most expression types, and we should clearly call other ToString() methods recursively in this.