rVM 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +2 -2
- data/lib/rvm.rb +1 -0
- data/lib/rvm/classes.rb +8 -5
- data/lib/rvm/classes/number.rb +12 -10
- data/lib/rvm/classes/object.rb +0 -2
- data/lib/rvm/functions.rb +6 -4
- data/lib/rvm/interpreter.rb +13 -2
- data/lib/rvm/plugin.rb +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -18,7 +18,7 @@ The following example implements a pretty easy calculator using the the math lan
|
|
18
18
|
require 'rvm' # This loads the rVM gem
|
19
19
|
require 'rvm/languages/math' #This loads the math plugin as well as the math function library
|
20
20
|
s =''
|
21
|
-
compiler = RVM::Languages[:math] #Lets get us the compiler
|
21
|
+
compiler = RVM::Languages[:math].new #Lets get us the compiler
|
22
22
|
while s!= 'QUIT'
|
23
23
|
s=gets.chomp
|
24
24
|
puts compiler.compile(s).execute(RVM::Interpreter.env) # We pass an fresh enviroment as we don't need an environment.
|
@@ -30,7 +30,7 @@ Here one example that keeps set variables due to using one enviroment for all th
|
|
30
30
|
require 'rvm' # This loads the rVM gem
|
31
31
|
require 'rvm/languages/math' #This loads the math plugin as well as the math function library
|
32
32
|
s =''
|
33
|
-
compiler = RVM::Languages[:math] #Lets get us the compiler
|
33
|
+
compiler = RVM::Languages[:math].new #Lets get us the compiler
|
34
34
|
env = RVM::Interpreter.env
|
35
35
|
while s!= 'QUIT'
|
36
36
|
s=gets.chomp
|
data/lib/rvm.rb
CHANGED
data/lib/rvm/classes.rb
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
#
|
5
5
|
# This file is published under the MIT Licenser, see LICENSE for details.
|
6
6
|
#
|
7
|
+
|
7
8
|
require File.dirname(__FILE__) + '/plugin'
|
9
|
+
require File.dirname(__FILE__) + '/functions'
|
8
10
|
module RVM
|
9
11
|
# This module is the basic class container, classes are supposed to be
|
10
12
|
# used by this as in: RVM::Classes[<class id>] this guarnatees that,
|
@@ -72,13 +74,14 @@ module RVM
|
|
72
74
|
true
|
73
75
|
end
|
74
76
|
|
75
|
-
alias
|
77
|
+
alias :method_missing_old_class :method_missing
|
76
78
|
|
77
|
-
def method_missing(m, *args)
|
78
|
-
if (RVM::Functions
|
79
|
-
RVM::Functions[m].execute args, @env
|
79
|
+
def method_missing(m, *args, &block)
|
80
|
+
if (RVM::Functions::has? m)
|
81
|
+
RVM::Functions[m].execute args, @env, &block
|
80
82
|
else
|
81
|
-
|
83
|
+
super(m, *args, &block)
|
84
|
+
#method_missing_old_class m, *args, &block
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
data/lib/rvm/classes/number.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module RVM
|
1
|
+
module RVM
|
2
2
|
module Classes
|
3
3
|
class Number < Class
|
4
4
|
register_for :number
|
@@ -14,10 +14,10 @@ module RVM
|
|
14
14
|
@value = value.to_i
|
15
15
|
else
|
16
16
|
@value = "#{value}".to_f
|
17
|
+
if @value == @value.to_i
|
18
|
+
@value = @value.to_i
|
19
|
+
end
|
17
20
|
end
|
18
|
-
#if @value.to_f == @value.to_i
|
19
|
-
# @value = @value.to_i
|
20
|
-
#end
|
21
21
|
end
|
22
22
|
|
23
23
|
def == v
|
@@ -44,13 +44,14 @@ module RVM
|
|
44
44
|
@value
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
#alias :respond_to_number :respond_to?
|
48
|
+
#def respond_to?(symbol,include_private = false)
|
49
|
+
# respond_to_number(symbol,include_private)
|
50
|
+
#end
|
50
51
|
|
52
|
+
alias :method_missing_number :method_missing
|
51
53
|
|
52
|
-
|
53
|
-
def method_missing m, *args
|
54
|
+
def method_missing m, *args, &block
|
54
55
|
if @value.respond_to? m
|
55
56
|
args.map! do |a|
|
56
57
|
if a.is_a? Number
|
@@ -63,7 +64,8 @@ module RVM
|
|
63
64
|
r = Number.new(r) if r.is_a? Numeric
|
64
65
|
r
|
65
66
|
else
|
66
|
-
|
67
|
+
#raise "beep!#{m}, #{args}, #{block}"
|
68
|
+
super(m, *args, &block)
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
data/lib/rvm/classes/object.rb
CHANGED
data/lib/rvm/functions.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/plugin'
|
2
2
|
require File.dirname(__FILE__) + '/interpreter'
|
3
3
|
module RVM
|
4
|
+
|
4
5
|
module Functions
|
5
6
|
extend RVM::PluginHost
|
6
7
|
class Function
|
@@ -12,13 +13,14 @@ module RVM
|
|
12
13
|
:any
|
13
14
|
end
|
14
15
|
|
15
|
-
alias
|
16
|
+
alias :method_missing_old_functions :method_missing
|
16
17
|
|
17
|
-
def method_missing(m, *args)
|
18
|
-
if (RVM::Functions
|
18
|
+
def method_missing(m, *args, &block)
|
19
|
+
if (RVM::Functions::has? m)
|
19
20
|
RVM::Functions[m].execute args, @env
|
20
21
|
else
|
21
|
-
|
22
|
+
raise "ook!"
|
23
|
+
#method_missing_old_functions m, *args, &block
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
data/lib/rvm/interpreter.rb
CHANGED
@@ -56,6 +56,17 @@ module RVM
|
|
56
56
|
:evaldeepth => 0,
|
57
57
|
:params => []
|
58
58
|
}.merge(init_data)
|
59
|
+
|
60
|
+
# Make sure that all locals that are passed, are actually in a variable storage.
|
61
|
+
if init_data[:locals]
|
62
|
+
locals = @data[:locals]
|
63
|
+
init_data[:locals].each do |k,v|
|
64
|
+
if not v.is_a?(VariableStorage)
|
65
|
+
locals[k] = VariableStorage.new(v)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
59
70
|
@prev = oldenv || {}
|
60
71
|
RVM::debug "data: #{data}\noldenv:#{oldenv}" if $DEBUG
|
61
72
|
RVM::debug "Creating new enviroment with: #{@data.inspect} as child of #{@prev}" if $DEBUG
|
@@ -510,11 +521,11 @@ module RVM
|
|
510
521
|
RVM::debug "Executing FunctionCall..." if $DEBUG
|
511
522
|
args = @arguments.dup
|
512
523
|
if @function.is_a? RVM::Classes[:block]
|
513
|
-
|
524
|
+
args.map! do |arg|
|
514
525
|
arg.execute env
|
515
526
|
end
|
516
527
|
@function.call(args, env, @pos)
|
517
|
-
elsif
|
528
|
+
elsif fun = env.function(@function)
|
518
529
|
args.map! do |arg|
|
519
530
|
arg.execute env
|
520
531
|
end
|
data/lib/rvm/plugin.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
module RVM
|
1
2
|
# = PluginHost
|
2
3
|
#
|
3
4
|
# $Id: plugin.rb 69 2006-07-11 06:00:20Z murphy $
|
@@ -24,7 +25,6 @@
|
|
24
25
|
#
|
25
26
|
# Thanks a lot to Murphy, this code is borrowed from coderay.
|
26
27
|
#
|
27
|
-
module RVM
|
28
28
|
module PluginHost
|
29
29
|
|
30
30
|
# Raised if Encoders::[] fails because:
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rVM
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heinz N. Gies
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-07-
|
12
|
+
date: 2008-07-16 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|