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

Refactor the way the prelude is loaded. #154

Open
KCreate opened this issue Jan 18, 2017 · 1 comment
Open

Refactor the way the prelude is loaded. #154

KCreate opened this issue Jan 18, 2017 · 1 comment

Comments

@KCreate
Copy link
Collaborator

KCreate commented Jan 18, 2017

Currently the prelude is being passed via the require call and added to the new visitor.

The prelude should be the top-most layer in the hierarchy, appending program execution scopes to it. It should be passed as an initialization argument to the Visitor. This would allow us to reuse the same Visitor instance for each file that's executed.

Instead of passing the prelude to the require call, the active visitor instance would be passed.

Also, there should be an easier way of getting code executed.

Idea

source = <<-SOURCE
  let a = 25
  let b = 25
  a + b
SOURCE

vm = Charly::VM.new
result = vm.run source, "input"
puts result.value # => 50

Charly::VM should be the top-level interface to the interpreter. Config options would added to the initialize call. Charly::VM#run takes two arguments:

  1. The source code of the program
  2. An optional filename

If no filename is passed, VM-#{current_timestamp} will be used

Charly::VM should also keep track of the scope hierarchy, making sure each file is run in it's own scope, with the prelude being at the top.

The class PreludeLoader would be incorporated into the initialize call of Charly::VM and can then be removed. Configuration options would need a new class Charly::Config. This class would contain the values used for STDOUT, STDIN, STDERR, ARGV, IFLAGS, ENV, etc.

The internal methods api needs access to these config values as it contains the bindings to stdout etc.

@ghost
Copy link

ghost commented Apr 22, 2017

@KCreate So this will be similar to the eval option in crystal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant