switch to sat and load code from file

This commit is contained in:
Torsten Ruger 2015-10-02 20:25:54 +03:00
parent ab55f64cdf
commit d23a9846e3
5 changed files with 78 additions and 9 deletions

View File

@ -2,7 +2,7 @@ source 'https://rubygems.org'
gem "opal" , :github => "opal/opal"
gem 'opal-browser'
gem "ast" , :github => "dancinglightning/ast" , :branch => :new_inspect
#gem "salama" , "0.2" , :path => "../salama"
gem "parslet" , github: "salama/parslet"

View File

@ -1,3 +1,10 @@
GIT
remote: git://github.com/dancinglightning/ast.git
revision: a9bc29377a94d2194e92596aceb9be7c7db4c8f8
branch: new_inspect
specs:
ast (2.1.0)
GIT
remote: git://github.com/opal/opal.git
revision: c604685071f8560d3357044683a99b80b210a99b
@ -10,9 +17,9 @@ GIT
GIT
remote: git://github.com/salama/parslet.git
revision: b8bf8db20a242eb6bd8fec88027e3b2ae19276e8
revision: 1381e3320efd0133b1d2935ef80079717ce9f245
specs:
parslet (1.7.0)
parslet (1.7.1)
GIT
remote: git://github.com/salama/salama-arm.git
@ -28,14 +35,15 @@ GIT
GIT
remote: git://github.com/salama/salama-reader.git
revision: 841592c667acea1e796f950851262e6938b231bc
revision: 34691f36d13f68d2c39cea266f26ea201bc78bb6
specs:
salama-reader (0.2.0)
ast (~> 2.1.0)
parslet (~> 1.7.0)
GIT
remote: git://github.com/salama/salama.git
revision: df95b8b54de103523743cbfd5c46d87af84c6b09
revision: 501da4d922c9d13a8c2c9bd19c3e5ebc65833b39
specs:
salama (0.2.0)
salama-object-file (~> 0.2)
@ -115,6 +123,7 @@ PLATFORMS
ruby
DEPENDENCIES
ast!
capybara (~> 2.4.2)
chromedriver2-helper (~> 0.0.8)
minitest
@ -133,4 +142,4 @@ DEPENDENCIES
susy
BUNDLED WITH
1.10.5
1.10.6

View File

@ -8,6 +8,7 @@ require "opal"
require 'opal-browser'
Opal.use_gem("salama")
Opal.use_gem("ast")
Opal.use_gem("salama-arm")
class DebugServer < Opal::Server
@ -23,7 +24,6 @@ run DebugServer.new { |s|
s.main = 'debugger'
s.append_path 'lib'
s.append_path 'assets'
# s.source_map = true
s.debug = !ENV["DEBUG"].nil?
s.index_path = "index.html.erb"

58
lib/code.rb Normal file
View File

@ -0,0 +1,58 @@
include AST::Sexp
CODE = s(:expressions,
s(:class, :Integer,
s(:derives, :Object),
s(:expressions,
s(:function, :ref,
s(:name, :add_string),
s(:parameters,
s(:parameter, :ref, :str)),
s(:expressions,
s(:field_def, :int, :div),
s(:assign,
s(:name, :div),
s(:operator, "/",
s(:name, :self),
s(:int, 10))),
s(:field_def, :int, :rest),
s(:assign,
s(:name, :rest),
s(:operator, "-",
s(:name, :self),
s(:name, :div))),
s(:if,
s(:condition,
s(:operator, "<",
s(:name, :rest),
s(:int, 0))),
s(:if_true,
s(:assign,
s(:name, :str),
s(:operator, "+",
s(:name, :str),
s(:call,
s(:name, :digit),
s(:arguments,
s(:name, :rest)))))),
s(:if_false,
s(:assign,
s(:name, :str),
s(:call,
s(:name, :add_string),
s(:arguments,
s(:name, :str)),
s(:receiver,
s(:name, :div)))))),
s(:return,
s(:name, :str)))),
s(:function, :ref,
s(:name, :to_string),
s(:parameters),
s(:expressions,
s(:field_def, :ref, :start,
s(:string, " ")),
s(:return,
s(:call,
s(:name, :add_string),
s(:arguments,
s(:name, :start)))))))))

View File

@ -6,6 +6,8 @@ require "opal-parser"
require 'browser'
require 'native'
require "salama"
require "salama-reader"
require "ast"
require "interpreter/interpreter"
require "base/list_view"
require_relative "classes_view"
@ -14,6 +16,7 @@ require_relative "file_view"
require_relative "blocks_view"
require_relative "instruction_view"
require_relative "registers_view"
require_relative "code"
class MainView < ListView
@ -27,8 +30,7 @@ class MainView < ListView
# so the code above is functionally equivalent to the one below, minus the parse
# When the ast expression is given all works, so pretty sure it is the parse that fails
code = Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(2),Ast::IntegerExpression.new(5))
Virtual::Compiler.compile( code , machine.space.get_main )
Bosl::Compiler.compile( CODE , machine.space.get_main )
machine.run_before "Register::CallImplementation"
@interpreter = Interpreter::Interpreter.new