irust 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a8680765ab2d6bbe030ce43b0dd47ce13c60989
4
- data.tar.gz: ec059eae0484d928fe6c91a0e75c57a87e7d618d
3
+ metadata.gz: d71c1afd38f1f48fc58a4705783bd9de7f058f20
4
+ data.tar.gz: ae752373a7856bd1cb5b9fc2c81feee7e12ed0fb
5
5
  SHA512:
6
- metadata.gz: 4a7d90d96f88aa46f29bbe17bc246d909f23f0a1c1e90f93dc4719482dc2757d26345a476f05e2213e27b9b773419c61c7e2a5bda3402ddee7c26334cc45d5a2
7
- data.tar.gz: 520b0149be9f72c76c34d29dd45ba6c8e9bd0798e7acd8051677615dec7967f5abd11869b7a36b680e8669f335d4b069fc2f1cb7df7e2fefd97c0e15f0515fce
6
+ metadata.gz: 9a90fcd4505d163b5f28ac2e496dfb14251386519039d35e9e41a7a57d24112763d8e98b879d0f873268cbd7078f740439edac06b4223dd33771ee0c225c714c
7
+ data.tar.gz: 1157872356efef33da734d5be8be7c9a344723463cbddba868138f2ef2b2d43b5a0135f7fac5ba4619438ce02b477afc0e3284b8cbd2428dcbedc78a4a2810bd
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ 1.1.0 (2014-01-05)
2
+ ------------------
3
+ * Keep a basic history
4
+ * Show the type of the return value
5
+ * Display the type and value of let and fn statements
6
+ * Rewrite internals around an ERB template
7
+
1
8
  1.0.1 (2013-12-22)
2
9
  ------------------
3
10
  * Exit properly when ^D is pressed
data/README.md CHANGED
@@ -47,7 +47,7 @@ Now type some fancy Rust expressions and watch them get magically evaluated
47
47
  before your eyes!
48
48
 
49
49
  irust> 2+2
50
- 4
50
+ 4 : int
51
51
  irust>
52
52
 
53
53
  Technology!
@@ -60,5 +60,5 @@ Technology!
60
60
 
61
61
  ## License
62
62
 
63
- Copyright (c) 2013 Tony Arcieri. Distributed under the MIT License. See
63
+ Copyright (c) 2014 Tony Arcieri. Distributed under the MIT License. See
64
64
  LICENSE.txt for further details.
@@ -2,6 +2,8 @@ require "readline"
2
2
  require "tmpdir"
3
3
  require "open3"
4
4
 
5
+ require "irust/template_renderer"
6
+
5
7
  module IRust
6
8
  module_function
7
9
 
@@ -9,21 +11,8 @@ module IRust
9
11
  Readline.readline("irust> ", true)
10
12
  end
11
13
 
12
- def rust_program(line)
13
- <<-RUST
14
- #[feature(globs, macro_rules, struct_variant)];
15
- extern mod extra;
16
-
17
- fn main() {
18
- let r = {
19
- fn type_of<T>(_: &T) -> &'static str { unsafe {
20
- (*std::unstable::intrinsics::get_tydesc::<T>()).name } } struct
21
- Foo<T>(T);
22
- #{line}
23
- };
24
- println!("{:?}", r)
25
- }
26
- RUST
14
+ def rust_program(line, history)
15
+ IRust::TemplateRenderer.new(line, history).render
27
16
  end
28
17
 
29
18
  def compile(tmpdir)
@@ -39,20 +28,25 @@ RUST
39
28
  end
40
29
  end
41
30
 
42
- def eval(line)
31
+ def eval(line, history = nil)
43
32
  exit 0 if line.nil?
44
33
 
45
34
  Dir.mktmpdir do |tmpdir|
46
35
  input_src = File.join(tmpdir, "irust.rs")
47
- File.write input_src, rust_program(line)
36
+ File.write input_src, rust_program(line, history)
48
37
 
49
38
  if compile(tmpdir)
50
39
  system input_src.sub(/\.rs$/, '')
40
+ history + ";\n" + line
41
+ else
42
+ history
51
43
  end
52
44
  end
53
45
  end
54
46
 
55
47
  def run
56
- loop { eval read }
48
+ history = ""
49
+ loop { history = eval read, history }
57
50
  end
58
51
  end
52
+
@@ -0,0 +1,20 @@
1
+ #[feature(globs, macro_rules, struct_variant)];
2
+ extern mod extra;
3
+
4
+ fn main() {
5
+ fn type_of<T>(_: &T) -> &'static str {
6
+ unsafe {
7
+ (*std::unstable::intrinsics::get_tydesc::<T>()).name
8
+ }
9
+ } struct Foo<T>(T);
10
+
11
+ <%= history %>;
12
+
13
+ <% if let_var %>
14
+ <%= rust_code %>;
15
+ println!("<%= let_var%> = {:?} : {:s}", <%= let_var %>, type_of(&<%= let_var %>));
16
+ <% else %>
17
+ let _result = { <%= rust_code %> };
18
+ println!("{:?} : {:s}", _result, type_of(&_result));
19
+ <% end %>
20
+ }
@@ -0,0 +1,22 @@
1
+ require 'erb'
2
+
3
+ module IRust
4
+ class TemplateRenderer
5
+ RUST_TEMPLATE = File.expand_path("../template.rs.erb", __FILE__)
6
+
7
+ attr_reader :rust_code, :history
8
+
9
+ def initialize(rust_code, history = nil)
10
+ @rust_code, @history = rust_code, history
11
+ end
12
+
13
+ def render
14
+ template = File.read(RUST_TEMPLATE)
15
+ ERB.new(template).result(binding)
16
+ end
17
+
18
+ def let_var
19
+ rust_code[/^\s*(let|fn)\s+(mut\s+)?(\w+)/, 3]
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module IRust
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irust
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-22 00:00:00.000000000 Z
11
+ date: 2014-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: iRust is an interactive REPL for Rust
@@ -46,7 +46,7 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
49
+ - ".gitignore"
50
50
  - CHANGES.md
51
51
  - Gemfile
52
52
  - LICENSE.txt
@@ -55,6 +55,8 @@ files:
55
55
  - bin/irust
56
56
  - irust.gemspec
57
57
  - lib/irust.rb
58
+ - lib/irust/template.rs.erb
59
+ - lib/irust/template_renderer.rb
58
60
  - lib/irust/version.rb
59
61
  homepage: https://github.com/tarcieri/irust
60
62
  licenses:
@@ -66,17 +68,17 @@ require_paths:
66
68
  - lib
67
69
  required_ruby_version: !ruby/object:Gem::Requirement
68
70
  requirements:
69
- - - '>='
71
+ - - ">="
70
72
  - !ruby/object:Gem::Version
71
73
  version: '0'
72
74
  required_rubygems_version: !ruby/object:Gem::Requirement
73
75
  requirements:
74
- - - '>='
76
+ - - ">="
75
77
  - !ruby/object:Gem::Version
76
78
  version: '0'
77
79
  requirements: []
78
80
  rubyforge_project:
79
- rubygems_version: 2.0.6
81
+ rubygems_version: 2.2.0
80
82
  signing_key:
81
83
  specification_version: 4
82
84
  summary: Read, Eval, and Print Rust code to your heart's desire!