eleetscript 0.0.22a → 0.0.23a
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.
- checksums.yaml +4 -4
- data/lib/eleetscript.rb +2 -0
- data/lib/engine/eleet_to_ruby_wrapper.rb +31 -4
- data/lib/engine/engine.rb +1 -10
- data/lib/engine/values.rb +28 -15
- data/lib/lang/runtime/base_classes.rb +37 -23
- data/lib/lang/runtime/class.rb +19 -15
- data/lib/lang/runtime/class_instance.rb +14 -6
- data/lib/lang/runtime/eleetscript/enumerable.es +16 -1
- data/lib/lang/runtime/eleetscript/falseclass.es +3 -3
- data/lib/lang/runtime/eleetscript/list.es +3 -1
- data/lib/lang/runtime/eleetscript/nilclass.es +5 -1
- data/lib/lang/runtime/eleetscript/object.es +5 -1
- data/lib/lang/runtime/eleetscript/stack.es +1 -1
- data/lib/lang/runtime/eleetscript/trueclass.es +3 -3
- data/lib/lang/runtime/memory.rb +31 -29
- data/lib/lang/runtime/ruby/enumerable_methods.rb +11 -0
- data/lib/lang/runtime/ruby/lambda_methods.rb +1 -1
- data/lib/lang/runtime/ruby/list_methods.rb +15 -10
- data/lib/lang/runtime/ruby/object_methods.rb +29 -1
- data/lib/lang/runtime/ruby/string_methods.rb +39 -32
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff643a94c90c05d794a559d829a94ef548ecf069
|
4
|
+
data.tar.gz: 8148f7080aa364e1ff1b04d766aaf4a272deb6d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '048c4d4c4ea2083633b4bd84926eb2c58c0e5e5c4b48c4025b504f0266b49c63066cb69bf4bf738c972f9412beb5d8fb7e617ca399045c5706ddb8852d4c3557'
|
7
|
+
data.tar.gz: 0c4a059f2b3a1b93526bfb9241790c0ab677f78f67717ce2f725eabdabeb3a6fbef796b09f6dd0d5221179804a1582b5dfbdc34d81dd556e814fddab9b628c00
|
data/lib/eleetscript.rb
CHANGED
@@ -6,9 +6,9 @@ module EleetScript
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(method, *args, &block)
|
9
|
-
eleet_args = args.map { |a|
|
10
|
-
eleet_args <<
|
11
|
-
|
9
|
+
eleet_args = args.map { |a| to_eleet_value(a) }
|
10
|
+
eleet_args << to_eleet_value(block) if block_given?
|
11
|
+
to_ruby_value(@eleet_obj.call(method, eleet_args))
|
12
12
|
end
|
13
13
|
|
14
14
|
def method_missing(name, *args, &block)
|
@@ -31,8 +31,35 @@ module EleetScript
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def to_h
|
35
|
+
if call(:responds_to?, :to_list)
|
36
|
+
list_hash = call(:to_list).raw.ruby_value.to_h
|
37
|
+
{}.tap do |hash|
|
38
|
+
list_hash.each do |key, value|
|
39
|
+
hash[to_ruby_value(key)] = to_ruby_value(value)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
else
|
43
|
+
{}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
34
47
|
def to_s
|
35
48
|
call(:to_string)
|
36
49
|
end
|
50
|
+
|
51
|
+
def inspect
|
52
|
+
"<EleetToRubyWrapper wrapping=#{call(:class_name)}>"
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
57
|
+
def to_ruby_value(eleet_val)
|
58
|
+
Values.to_ruby_value(eleet_val, @engine)
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_eleet_value(ruby_val)
|
62
|
+
Values.to_eleet_value(ruby_val, @engine)
|
63
|
+
end
|
37
64
|
end
|
38
|
-
end
|
65
|
+
end
|
data/lib/engine/engine.rb
CHANGED
@@ -55,11 +55,9 @@ module EleetScript
|
|
55
55
|
var, ns = unnest(name)
|
56
56
|
if var[0] =~ /[A-Z]/ && ns.constants.has_key?(var)
|
57
57
|
memory.root_namespace["Errors"].call("<", [memory.root_namespace["String"].new_with_value("Cannot reassign constant via the Engine.", memory.root_namespace)])
|
58
|
-
return false
|
59
58
|
else
|
60
59
|
ns[var] = to_eleet_value(value, options)
|
61
60
|
end
|
62
|
-
true
|
63
61
|
end
|
64
62
|
|
65
63
|
def get(var, raw = false)
|
@@ -154,14 +152,7 @@ module EleetScript
|
|
154
152
|
end
|
155
153
|
end
|
156
154
|
|
157
|
-
class Engine < SharedEngine
|
158
|
-
def initialize
|
159
|
-
super
|
160
|
-
puts "WARNING: EleetScript::Engine has been deprecated, please use EleetScript::SharedEngine or EleetScript::StandaloneEngine."
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
155
|
class StandaloneEngine < BaseEngine
|
165
156
|
def initialize; end
|
166
157
|
end
|
167
|
-
end
|
158
|
+
end
|
data/lib/engine/values.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require "bigdecimal"
|
2
|
+
require 'set'
|
3
|
+
|
2
4
|
require "engine/eleet_to_ruby_wrapper"
|
3
5
|
require "engine/ruby_to_eleet_wrapper"
|
4
6
|
require "engine/esproc"
|
@@ -45,26 +47,37 @@ module EleetScript
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def to_ruby_value(eleet_obj, engine)
|
48
|
-
|
49
|
-
if eleet_obj.kind_of?(RubyToEleetWrapper)
|
50
|
+
if eleet_obj.is_a?(RubyToEleetWrapper)
|
50
51
|
eleet_obj.instance_variable_get("@ruby_obj")
|
51
|
-
elsif eleet_obj.class_name
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
elsif eleet_obj.respond_to?(:class_name)
|
53
|
+
case eleet_obj.class_name
|
54
|
+
when 'Lambda'
|
55
|
+
if eleet_obj.ruby_value.is_a?(ESProc)
|
56
|
+
eleet_obj.ruby_value.proc
|
57
|
+
else
|
58
|
+
proc = RubyLambda.new do |*args|
|
59
|
+
eleet_args = args.map do |arg|
|
60
|
+
to_eleet_value(arg, engine)
|
61
|
+
end
|
62
|
+
to_ruby_value(eleet_obj.call(:call, eleet_args), engine)
|
58
63
|
end
|
59
|
-
|
64
|
+
proc.es_lambda = eleet_obj
|
65
|
+
proc
|
60
66
|
end
|
61
|
-
|
62
|
-
|
67
|
+
when 'TrueClass'
|
68
|
+
true
|
69
|
+
when 'FalseClass'
|
70
|
+
false
|
71
|
+
when 'NilClass'
|
72
|
+
nil
|
73
|
+
when 'String', 'Integer', 'Float', 'Regex', 'Symbol'
|
74
|
+
eleet_obj.ruby_value
|
75
|
+
else
|
76
|
+
EleetToRubyWrapper.new(eleet_obj, engine)
|
63
77
|
end
|
64
|
-
elsif ruby_values.include?(eleet_obj.class_name)
|
65
|
-
eleet_obj.ruby_value
|
66
78
|
else
|
67
|
-
|
79
|
+
# Probably already is a ruby value
|
80
|
+
eleet_obj
|
68
81
|
end
|
69
82
|
end
|
70
83
|
end
|
@@ -1,16 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
1
5
|
module EleetScript
|
2
6
|
class ListBase
|
3
7
|
attr_accessor :array_value, :hash_value
|
4
8
|
|
5
|
-
def initialize
|
6
|
-
@nil_val = nil_val
|
9
|
+
def initialize
|
7
10
|
@array_value = []
|
8
|
-
@hash_value =
|
11
|
+
@hash_value = {}
|
9
12
|
end
|
10
13
|
|
11
14
|
def merge!(o)
|
12
|
-
|
13
|
-
|
15
|
+
array_value.concat(o.array_value)
|
16
|
+
hash_value.merge!(o.hash_value)
|
14
17
|
end
|
15
18
|
|
16
19
|
def clone
|
@@ -18,15 +21,26 @@ module EleetScript
|
|
18
21
|
end
|
19
22
|
|
20
23
|
def dup
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
ListBase.new.tap do |lst|
|
25
|
+
lst.array_value = array_value.dup
|
26
|
+
lst.hash_value = hash_value.dup
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
{}.tap do |hash|
|
32
|
+
array_value.map.with_index do |value, index|
|
33
|
+
hash[index] = value
|
34
|
+
end
|
35
|
+
hash_value.map do |key, value|
|
36
|
+
hash[key] = value
|
37
|
+
end
|
38
|
+
end
|
25
39
|
end
|
26
40
|
|
27
41
|
def clear
|
28
|
-
|
29
|
-
|
42
|
+
array_value.clear
|
43
|
+
hash_value.clear
|
30
44
|
end
|
31
45
|
end
|
32
46
|
|
@@ -39,15 +53,15 @@ module EleetScript
|
|
39
53
|
end
|
40
54
|
end
|
41
55
|
|
42
|
-
def initialize(pattern,
|
56
|
+
def initialize(pattern, desired_flags = nil)
|
43
57
|
flag_num = 0
|
44
|
-
if
|
45
|
-
|
46
|
-
@global = true if
|
47
|
-
flag_num |= Regexp::IGNORECASE if
|
48
|
-
flag_num |= Regexp::MULTILINE if
|
58
|
+
if desired_flags.is_a?(String)
|
59
|
+
flag_set = desired_flags ? Set.new(desired_flags.chars) : []
|
60
|
+
@global = true if flag_set.include?('g')
|
61
|
+
flag_num |= Regexp::IGNORECASE if flag_set.include?('i')
|
62
|
+
flag_num |= Regexp::MULTILINE if flag_set.include?('m')
|
49
63
|
else
|
50
|
-
flag_num =
|
64
|
+
flag_num = desired_flags
|
51
65
|
end
|
52
66
|
super(pattern, flag_num)
|
53
67
|
end
|
@@ -65,11 +79,11 @@ module EleetScript
|
|
65
79
|
end
|
66
80
|
|
67
81
|
def flags
|
68
|
-
flags
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
82
|
+
@flags ||= [].tap do |flags|
|
83
|
+
flags << 'm' if multiline?
|
84
|
+
flags << 'i' if ignorecase?
|
85
|
+
flags << 'g' if global?
|
86
|
+
end.join('')
|
73
87
|
end
|
74
88
|
end
|
75
89
|
end
|
data/lib/lang/runtime/class.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'lang/runtime/class_skeleton'
|
2
|
+
require 'lang/runtime/class_instance'
|
3
|
+
require 'lang/runtime/method_hash'
|
4
|
+
require 'util/processed_key_hash'
|
5
5
|
|
6
6
|
module EleetScript
|
7
7
|
class EleetScriptClass < EleetScriptClassSkeleton
|
@@ -21,7 +21,7 @@ module EleetScript
|
|
21
21
|
@methods = MethodHash.new
|
22
22
|
@class_vars = ProcessedKeyHash.new
|
23
23
|
@class_vars.set_key_preprocessor do |key|
|
24
|
-
key[0..1] ==
|
24
|
+
key[0..1] == '@@' ? key[2..-1] : key
|
25
25
|
end
|
26
26
|
@context = namespace.new_class_context(self, self)
|
27
27
|
@super_class = super_class
|
@@ -38,13 +38,13 @@ module EleetScript
|
|
38
38
|
method.call(self, arguments)
|
39
39
|
end
|
40
40
|
else
|
41
|
-
es_method_name = @context[
|
41
|
+
es_method_name = @context['String'].new_with_value(method_name.to_s, @context.namespace_context)
|
42
42
|
call(NO_METHOD, arguments.dup.unshift(es_method_name))
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def lookup(method_name)
|
47
|
-
method_name = method_name[0..1] ==
|
47
|
+
method_name = method_name[0..1] == '@@' ? method_name : "@@#{method_name}"
|
48
48
|
method = @methods[method_name]
|
49
49
|
if method.nil? && has_super_class?
|
50
50
|
return super_class.lookup(method_name)
|
@@ -61,7 +61,7 @@ module EleetScript
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def super_class
|
64
|
-
@super_class || @context[
|
64
|
+
@super_class || @context['Object']
|
65
65
|
end
|
66
66
|
|
67
67
|
def def(method_name, es_block = nil, &block)
|
@@ -87,23 +87,27 @@ module EleetScript
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def new_with_value(value, current_context)
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
EleetScriptClassInstance.new(@context, self, current_context.namespace_context).tap do |instance|
|
91
|
+
instance.ruby_value = value
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def es_responds_to?(method_name)
|
96
|
+
!lookup(method_name.to_s).nil?
|
93
97
|
end
|
94
98
|
|
95
99
|
def to_s
|
96
|
-
"<EleetScriptClass \"#{name ||
|
100
|
+
"<EleetScriptClass \"#{name || 'Unnamed'}\">"
|
97
101
|
end
|
98
102
|
|
99
103
|
def inspect
|
100
|
-
to_s[0..-2] + " @methods(#{@methods.keys.join(
|
104
|
+
to_s[0..-2] + " @methods(#{@methods.keys.join(', ')})>"
|
101
105
|
end
|
102
106
|
|
103
107
|
private
|
104
108
|
|
105
109
|
def has_super_class?
|
106
|
-
@super_class || (@super_class.nil? && name !=
|
110
|
+
@super_class || (@super_class.nil? && name != 'Object')
|
107
111
|
end
|
108
112
|
end
|
109
|
-
end
|
113
|
+
end
|
@@ -14,12 +14,12 @@ module EleetScript
|
|
14
14
|
@ruby_value = self
|
15
15
|
end
|
16
16
|
|
17
|
+
def es_responds_to?(method_name)
|
18
|
+
!find_method(method_name).nil?
|
19
|
+
end
|
20
|
+
|
17
21
|
def call(method_name, arguments = [])
|
18
|
-
|
19
|
-
method = @methods[method_name]
|
20
|
-
if method.nil?
|
21
|
-
method = @runtime_class.instance_lookup(method_name.to_s)
|
22
|
-
end
|
22
|
+
method = find_method(method_name)
|
23
23
|
if method
|
24
24
|
if method.arity == 3
|
25
25
|
method.call(self, arguments, @context)
|
@@ -32,6 +32,14 @@ module EleetScript
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def find_method(method_name)
|
36
|
+
method = @methods[method_name]
|
37
|
+
if method.nil?
|
38
|
+
method = @runtime_class.instance_lookup(method_name.to_s)
|
39
|
+
end
|
40
|
+
method
|
41
|
+
end
|
42
|
+
|
35
43
|
def to_s
|
36
44
|
"<EleetScriptClassInstance @instance_of=\"#{runtime_class.name || "Unnamed"}\">"
|
37
45
|
end
|
@@ -57,4 +65,4 @@ module EleetScript
|
|
57
65
|
@runtime_class.name
|
58
66
|
end
|
59
67
|
end
|
60
|
-
end
|
68
|
+
end
|
@@ -14,6 +14,21 @@ class Enumerable
|
|
14
14
|
Errors < "Class %cname has not implemented length which is required for Enumerable"
|
15
15
|
end
|
16
16
|
|
17
|
+
is do |o|
|
18
|
+
if o.kind_of?(class_ref)
|
19
|
+
i = 0
|
20
|
+
while i < self.length and i < o.length
|
21
|
+
if self[i] isnt o[i]
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
i += 1
|
25
|
+
end
|
26
|
+
true
|
27
|
+
else
|
28
|
+
false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
17
32
|
each do |iter|
|
18
33
|
if lambda? and iter.kind_of?(Lambda)
|
19
34
|
i = 0
|
@@ -33,4 +48,4 @@ class Enumerable
|
|
33
48
|
end
|
34
49
|
arr
|
35
50
|
end
|
36
|
-
end
|
51
|
+
end
|
data/lib/lang/runtime/memory.rb
CHANGED
@@ -1,29 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'lang/runtime/class'
|
4
|
+
require 'lang/runtime/context'
|
5
|
+
require 'lang/runtime/method'
|
6
|
+
require 'lang/runtime/array'
|
7
|
+
require 'lang/runtime/base_classes'
|
6
8
|
|
7
9
|
module EleetScript
|
8
10
|
class Memory
|
9
11
|
attr_reader :root, :root_context, :root_namespace
|
10
12
|
|
11
13
|
ROOT_OBJECTS = {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
'Object' => nil,
|
15
|
+
'Number' => nil,
|
16
|
+
'Integer' => 'Number',
|
17
|
+
'Float' => 'Number',
|
18
|
+
'Enumerable' => nil,
|
19
|
+
'List' => 'Enumerable',
|
20
|
+
'String' => 'Enumerable',
|
21
|
+
'Symbol' => nil,
|
22
|
+
'Regex' => nil,
|
23
|
+
'IO' => nil,
|
24
|
+
'Lambda' => nil,
|
25
|
+
'TrueClass' => nil,
|
26
|
+
'FalseClass' => nil,
|
27
|
+
'NilClass' => nil,
|
28
|
+
'Random' => nil
|
27
29
|
}
|
28
30
|
|
29
31
|
class << self
|
@@ -38,7 +40,7 @@ module EleetScript
|
|
38
40
|
|
39
41
|
def initialize
|
40
42
|
@root_namespace = NamespaceContext.new(nil, nil)
|
41
|
-
@root_path = File.join(File.dirname(__FILE__),
|
43
|
+
@root_path = File.join(File.dirname(__FILE__), 'eleetscript')
|
42
44
|
end
|
43
45
|
|
44
46
|
def bootstrap(loader)
|
@@ -53,22 +55,22 @@ module EleetScript
|
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
@root = root_namespace[
|
58
|
+
@root = root_namespace['Object'].new(root_namespace)
|
57
59
|
root_namespace.current_self = @root
|
58
60
|
root_namespace.current_class = @root.runtime_class
|
59
61
|
|
60
|
-
root_namespace[
|
61
|
-
root_namespace[
|
62
|
-
root_namespace[
|
62
|
+
root_namespace['true'] = root_namespace['TrueClass'].new_with_value(true, root_namespace)
|
63
|
+
root_namespace['false'] = root_namespace['FalseClass'].new_with_value(false, root_namespace)
|
64
|
+
root_namespace['nil'] = root_namespace['NilClass'].new_with_value(nil, root_namespace)
|
63
65
|
|
64
66
|
# Global Errors Object
|
65
|
-
root_namespace[
|
67
|
+
root_namespace['Errors'] = root_namespace['List'].new_with_value(ListBase.new, root_namespace)
|
66
68
|
|
67
69
|
self.class.core_definers.each do |definer_block|
|
68
70
|
instance_eval(&definer_block)
|
69
71
|
end
|
70
72
|
|
71
|
-
files = Dir.glob(File.join(@root_path,
|
73
|
+
files = Dir.glob(File.join(@root_path, '**', '*.es'))
|
72
74
|
files.each do |file|
|
73
75
|
loader.load(file)
|
74
76
|
end
|
@@ -76,6 +78,6 @@ module EleetScript
|
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
|
-
Dir.glob(File.join(File.dirname(__FILE__),
|
81
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'ruby', '**', '*')).each do |file|
|
80
82
|
require file
|
81
|
-
end
|
83
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EleetScript
|
4
|
+
Memory.define_core_methods do
|
5
|
+
enum = root_namespace['Enumerable']
|
6
|
+
|
7
|
+
enum.def :to_list do |receiver, arguments, context|
|
8
|
+
root_namespace['List'].new_with_value(receiver.ruby_value, context)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -3,7 +3,7 @@ module EleetScript
|
|
3
3
|
list = root_namespace["List"]
|
4
4
|
|
5
5
|
list.class_def :new do |receiver, arguments, context|
|
6
|
-
new_list = receiver.new_with_value(ListBase.new
|
6
|
+
new_list = receiver.new_with_value(ListBase.new, context.namespace_context)
|
7
7
|
arguments.each do |arg|
|
8
8
|
if arg.instance? && arg.runtime_class.name == "Pair"
|
9
9
|
new_list.ruby_value.hash_value[arg.call(:key)] = arg.call(:value)
|
@@ -17,15 +17,20 @@ module EleetScript
|
|
17
17
|
list.def :[] do |receiver, arguments|
|
18
18
|
lst = receiver.ruby_value
|
19
19
|
arg = arguments.first
|
20
|
-
if arg.instance? && arg.runtime_class.name == "Integer"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
ret_val = if arg.instance? && arg.runtime_class.name == "Integer"
|
21
|
+
index = arg.ruby_value
|
22
|
+
if index < lst.array_value.length
|
23
|
+
lst.array_value[index]
|
24
|
+
else
|
25
|
+
lst.hash_value[arg.ruby_value]
|
26
|
+
end
|
27
|
+
else
|
28
|
+
lst.hash_value[arg]
|
29
|
+
end
|
30
|
+
if ret_val.nil?
|
31
|
+
root_namespace.es_nil
|
27
32
|
else
|
28
|
-
|
33
|
+
ret_val
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
@@ -174,4 +179,4 @@ module EleetScript
|
|
174
179
|
root_namespace["String"].new_with_value("[#{str}]", context.namespace_context)
|
175
180
|
end
|
176
181
|
end
|
177
|
-
end
|
182
|
+
end
|
@@ -34,6 +34,34 @@ module EleetScript
|
|
34
34
|
root_namespace["String"].new_with_value(receiver.runtime_class.name, context.namespace_context)
|
35
35
|
end
|
36
36
|
|
37
|
+
object.class_def :responds_to? do |receiver, arguments|
|
38
|
+
t, f = root_namespace["true"], root_namespace["false"]
|
39
|
+
if arguments.length == 0
|
40
|
+
f
|
41
|
+
else
|
42
|
+
method_name = arguments.first.call(:to_string).ruby_value
|
43
|
+
if receiver.es_responds_to?(method_name)
|
44
|
+
t
|
45
|
+
else
|
46
|
+
f
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
object.def :responds_to? do |receiver, arguments, context|
|
52
|
+
t, f = root_namespace["true"], root_namespace["false"]
|
53
|
+
if arguments.length == 0
|
54
|
+
f
|
55
|
+
else
|
56
|
+
method_name = arguments.first.call(:to_string).ruby_value
|
57
|
+
if receiver.es_responds_to?(method_name)
|
58
|
+
t
|
59
|
+
else
|
60
|
+
f
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
37
65
|
object.class_def :class_name do |receiver, arguments, context|
|
38
66
|
root_namespace["String"].new_with_value(receiver.name, context.namespace_context)
|
39
67
|
end
|
@@ -56,4 +84,4 @@ module EleetScript
|
|
56
84
|
end
|
57
85
|
end
|
58
86
|
end
|
59
|
-
end
|
87
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
module EleetScript
|
2
2
|
Memory.define_core_methods do
|
3
|
-
string = root_namespace[
|
3
|
+
string = root_namespace['String']
|
4
4
|
|
5
5
|
string.class_def :new do |receiver, arguments, context|
|
6
|
-
arg = arguments.length > 0 ? arguments.first.call(:to_string).ruby_value :
|
6
|
+
arg = arguments.length > 0 ? arguments.first.call(:to_string).ruby_value : ''
|
7
7
|
receiver.new_with_value(arg, context.namespace_context)
|
8
8
|
end
|
9
9
|
|
10
10
|
string.def :+ do |receiver, arguments|
|
11
11
|
arg = arguments.first
|
12
12
|
arg_str = if arg.class?
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
arg.name
|
14
|
+
elsif arg.instance? && arg.runtime_class.name == 'String'
|
15
|
+
arg.ruby_value
|
16
|
+
else
|
17
|
+
arg.call(:to_string).ruby_value
|
18
|
+
end
|
19
19
|
receiver.ruby_value += arg_str
|
20
20
|
receiver
|
21
21
|
end
|
@@ -23,32 +23,32 @@ module EleetScript
|
|
23
23
|
string.def :is do |receiver, arguments|
|
24
24
|
compare_to = arguments.first.ruby_value
|
25
25
|
if compare_to == receiver.ruby_value
|
26
|
-
root_namespace[
|
26
|
+
root_namespace['true']
|
27
27
|
else
|
28
|
-
root_namespace[
|
28
|
+
root_namespace['false']
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
string.def :substr do |receiver, arguments, context|
|
33
33
|
if arguments.length < 2
|
34
|
-
root_namespace
|
34
|
+
root_namespace.es_nil
|
35
35
|
else
|
36
36
|
s, e = arguments
|
37
|
-
if s.is_a?(
|
37
|
+
if s.is_a?('Integer') && e.is_a?('Integer')
|
38
38
|
range = if e.ruby_value < 0
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
root_namespace[
|
39
|
+
(s.ruby_value..e.ruby_value)
|
40
|
+
else
|
41
|
+
(s.ruby_value...e.ruby_value)
|
42
|
+
end
|
43
|
+
root_namespace['String'].new_with_value(receiver.ruby_value[range], context.namespace_context)
|
44
44
|
else
|
45
|
-
root_namespace
|
45
|
+
root_namespace.es_nil
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
string.def :length do |receiver, arguments, context|
|
51
|
-
root_namespace[
|
51
|
+
root_namespace['Integer'].new_with_value(receiver.ruby_value.length, context.namespace_context)
|
52
52
|
end
|
53
53
|
|
54
54
|
string.def :upper_case do |receiver, arguments, context|
|
@@ -61,7 +61,7 @@ module EleetScript
|
|
61
61
|
|
62
62
|
string.def :[] do |receiver, arguments, context|
|
63
63
|
index = arguments.first
|
64
|
-
if index.is_a?(
|
64
|
+
if index.is_a?('Integer')
|
65
65
|
index = index.ruby_value
|
66
66
|
if index < 0 || index >= receiver.ruby_value.length
|
67
67
|
root_namespace.es_nil
|
@@ -75,7 +75,7 @@ module EleetScript
|
|
75
75
|
|
76
76
|
string.def :[]= do |receiver, arguments|
|
77
77
|
index, value = arguments
|
78
|
-
if index.is_a?(
|
78
|
+
if index.is_a?('Integer')
|
79
79
|
index = index.ruby_value
|
80
80
|
if index < 0 && index >= receiver.ruby_value.length
|
81
81
|
root_namespace.es_nil
|
@@ -90,15 +90,15 @@ module EleetScript
|
|
90
90
|
end
|
91
91
|
|
92
92
|
string.def :to_symbol do |receiver, arguments, context|
|
93
|
-
root_namespace[
|
93
|
+
root_namespace['Symbol'].new_with_value(receiver.ruby_value.gsub(/\s+/, '_').to_sym, context.namespace_context)
|
94
94
|
end
|
95
95
|
|
96
96
|
string.def :to_integer do |receiver, arguments, context|
|
97
|
-
root_namespace[
|
97
|
+
root_namespace['Integer'].new_with_value(receiver.ruby_value.to_i, context.namespace_context)
|
98
98
|
end
|
99
99
|
|
100
100
|
string.def :to_float do |receiver, arguments, context|
|
101
|
-
root_namespace[
|
101
|
+
root_namespace['Float'].new_with_value(receiver.ruby_value.to_f, context.namespace_context)
|
102
102
|
end
|
103
103
|
|
104
104
|
string.def :replace do |receiver, arguments, context|
|
@@ -106,10 +106,10 @@ module EleetScript
|
|
106
106
|
string.new_with_value(receiver.ruby_value, context.namespace_context)
|
107
107
|
else
|
108
108
|
pattern, replacement = arguments
|
109
|
-
if !pattern.is_a?(
|
110
|
-
pattern = root_namespace[
|
109
|
+
if !pattern.is_a?('Regex')
|
110
|
+
pattern = root_namespace['Regex'].call(:new, [pattern.call(:to_string)])
|
111
111
|
end
|
112
|
-
if replacement.is_a?(
|
112
|
+
if replacement.is_a?('Lambda')
|
113
113
|
new_str = if pattern.ruby_value.global?
|
114
114
|
receiver.ruby_value.gsub(pattern.ruby_value) do
|
115
115
|
args = Regexp.last_match[1..-1].map { |match| string.new_with_value(match, context.namespace_context) }
|
@@ -134,10 +134,10 @@ module EleetScript
|
|
134
134
|
end
|
135
135
|
|
136
136
|
string.def :match do |receiver, arguments, context|
|
137
|
-
str_cls, list_cls = root_namespace[
|
137
|
+
str_cls, list_cls = root_namespace['String'], root_namespace['List']
|
138
138
|
rx = arguments.first
|
139
139
|
args = []
|
140
|
-
if rx.is_a?(
|
140
|
+
if rx.is_a?('Regex')
|
141
141
|
if rx.ruby_value.global?
|
142
142
|
matches = receiver.ruby_value.scan(rx.ruby_value)
|
143
143
|
list_args = matches.map do |match|
|
@@ -156,7 +156,7 @@ module EleetScript
|
|
156
156
|
if matches.names.length > 0
|
157
157
|
args += matches.names.map do |name|
|
158
158
|
n, v = str_cls.new_with_value(name, context.namespace_context), str_cls.new_with_value(matches[name], context.namespace_context)
|
159
|
-
root_namespace[
|
159
|
+
root_namespace['Pair'].call(:new, [n, v])
|
160
160
|
end
|
161
161
|
else
|
162
162
|
group_matches = matches.to_a
|
@@ -169,8 +169,15 @@ module EleetScript
|
|
169
169
|
end
|
170
170
|
end
|
171
171
|
else
|
172
|
-
root_namespace[
|
172
|
+
root_namespace['List'].call(:new)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
string.def :to_list do |receiver, arguments, context|
|
177
|
+
chars = receiver.ruby_value.chars.map do |char|
|
178
|
+
root_namespace['String'].new_with_value(char, context)
|
173
179
|
end
|
180
|
+
root_namespace['List'].call(:new, chars)
|
174
181
|
end
|
175
182
|
end
|
176
|
-
end
|
183
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eleetscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.23a
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Buck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: EleetScript scripting engine for use in Ruby applications
|
14
14
|
email: lordizuriel@gmail.com
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/lang/runtime/method.rb
|
58
58
|
- lib/lang/runtime/method_hash.rb
|
59
59
|
- lib/lang/runtime/ruby/boolean_methods.rb
|
60
|
+
- lib/lang/runtime/ruby/enumerable_methods.rb
|
60
61
|
- lib/lang/runtime/ruby/float_methods.rb
|
61
62
|
- lib/lang/runtime/ruby/integer_methods.rb
|
62
63
|
- lib/lang/runtime/ruby/io_methods.rb
|
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
91
|
version: 1.3.1
|
91
92
|
requirements: []
|
92
93
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.5.2
|
94
95
|
signing_key:
|
95
96
|
specification_version: 4
|
96
97
|
summary: EleetScript Engine
|