Skip to content

Instantly share code, notes, and snippets.

@georgi
Created December 3, 2014 20:44
Show Gist options
  • Save georgi/d2c8210d76f3edd3a1a5 to your computer and use it in GitHub Desktop.
Save georgi/d2c8210d76f3edd3a1a5 to your computer and use it in GitHub Desktop.
Crystal REPL
require "./compiler/crystal/**"
while line = gets
compiler = Crystal::Compiler.new
program = Crystal::Program.new
program.target_machine = compiler.target_machine
prelude = program.normalize(Crystal::Require.new("prelude"))
parser = Crystal::Parser.new("(#{line}).inspect")
node = parser.parse
node = program.normalize(node)
node = Crystal::Expressions.new([prelude, node])
node = program.normalize(node)
node = program.infer_type(node)
# pp node.type
res = program.evaluate(node)
puts res.to_string
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment