Skip to content
New issue

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

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

Already on GitHub? # to your account

Add a comptime interpreter #9

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Add a comptime interpreter #9

wants to merge 18 commits into from

Conversation

mattco98
Copy link
Owner

@mattco98 mattco98 commented Oct 5, 2022

This can process most expressions and statements. The primary goal is to be able to resolve comptime calls in import statements so that the IDE can continue to provide the user with a good experience, however this also comes with the benefit of allowing the user to evaluate arbitrary comptime expression straight from their IDE:

Demo of in-IDE comptime evaluation Code:
comptime get_names() throws -> [String] {
    mut builder = StringBuilder::create()
    builder.append(b'f')
    builder.append_string("ile2")
    println("Hello.......")
    println("....world!")
    eprintln("oops, some error occurred")
    return ["file1", builder.to_string()]
}

function main() {
    let a = get_names()
}

context menu
results

TODO:

  • Struct support
  • Match expressions
  • Tracking integer/float types (instead of just always using i64/f64)
  • Styling the element in the popup that appears when the user evaluates a comptime element. This will require some architectural work in the renderer
  • IDE debugging support? It is absolutely possible, just a matter of figuring it out

The primary reason for adding this is to resolve import comptime
function calls, but it will also allow the user to see the result
of arbitrary comptime expressions.
This will interfer with scope assignments, as once assignment, a
variable would never be able to change its value.
This action will, if possible, evaluate the element and then display a
popup with the element it evaluated (to make sure the plugin didn't
make a mistake), the result of the evaluation, and any output sent to
stdout/stderr.
@mattco98 mattco98 force-pushed the comptime-evaluation branch from 50535aa to 22ddb06 Compare October 5, 2022 10:45
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant