eleetscript 0.0.13a → 0.0.14a

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fc5d2a285f1c5be7ca29e652a4b778e75d10182
4
- data.tar.gz: c49384478e2b92eea802bcb91ea7d57bae711f5d
3
+ metadata.gz: 1e9923530119b0319ffa8ce45c74d8554dac83ec
4
+ data.tar.gz: a14bb0f0eb2f815c72d49b82526919b2e14ece5a
5
5
  SHA512:
6
- metadata.gz: 50925211b0865177514393bc13a642098177c2495cb432497c6c6d3387a6c38b0d3b61d004df9868ce476c32876c0c2d8edae84925770b55e1d6413b964bf9f4
7
- data.tar.gz: 785b7bffb8338e1eceede4b9f283202adffee20a3239f48d26be4d35a00dfb07b34b6f24e39127cebf06e993914fb65c9b8e38d8bb36dcaf8662d27a157f02b0
6
+ metadata.gz: 39efb36e6897c54457071dfb89779d247c34c7eee6c0926fc1d91bc9d25df6b691e57e48f91836fd9e9423d68f589f14c8b4f71eead668e5faa6d23581e47d71
7
+ data.tar.gz: 2dda61db2fe4268ecd9a8f58d668e3a7e44d9464cdf0b2607547e4ada1b9516fafe32e453d2fcf167d8546eab2dd6f3822ed11183af10e34b8c9754fd35e5fcf
data/lib/engine/engine.rb CHANGED
@@ -54,7 +54,7 @@ module EleetScript
54
54
  load
55
55
  var, ns = unnest(name)
56
56
  if var[0] =~ /[A-Z]/ && ns.constants.has_key?(var)
57
- memory.root_namespace["Errors"].call("<", [memory.root_namespace["String"].new_with_value("Cannot reassign constant via the Engine.")])
57
+ memory.root_namespace["Errors"].call("<", [memory.root_namespace["String"].new_with_value("Cannot reassign constant via the Engine.", memory.root_namespace)])
58
58
  return false
59
59
  else
60
60
  ns[var] = to_eleet_value(value)
data/lib/engine/values.rb CHANGED
@@ -16,23 +16,23 @@ module EleetScript
16
16
  if ruby_obj.kind_of?(EleetToRubyWrapper)
17
17
  ruby_obj.instance_variable_get("@eleet_obj")
18
18
  elsif ruby_obj.kind_of?(String)
19
- memory.root_namespace["String"].new_with_value(ruby_obj)
19
+ memory.root_namespace["String"].new_with_value(ruby_obj, memory.root_namespace)
20
20
  elsif ruby_obj.kind_of?(Symbol)
21
- memory.root_namespace["Symbol"].new_with_value(ruby_obj)
21
+ memory.root_namespace["Symbol"].new_with_value(ruby_obj, memory.root_namespace)
22
22
  elsif ruby_obj.kind_of?(Fixnum)
23
- memory.root_namespace["Integer"].new_with_value(ruby_obj)
23
+ memory.root_namespace["Integer"].new_with_value(ruby_obj, memory.root_namespace)
24
24
  elsif ruby_obj.kind_of?(Float)
25
- memory.root_namespace["Float"].new_with_value(ruby_obj)
25
+ memory.root_namespace["Float"].new_with_value(ruby_obj, memory.root_namespace)
26
26
  elsif ruby_obj.kind_of?(BigDecimal)
27
- memory.root_namespace["Integer"].new_with_value(ruby_obj.to_i)
27
+ memory.root_namespace["Integer"].new_with_value(ruby_obj.to_i, memory.root_namespace)
28
28
  elsif ruby_obj.kind_of?(Proc)
29
- memory.root_namespace["Lambda"].new_with_value(ESProc.new(ruby_obj, engine))
29
+ memory.root_namespace["Lambda"].new_with_value(ESProc.new(ruby_obj, engine), memory.root_namespace)
30
30
  elsif ruby_obj.kind_of?(RubyLambda)
31
31
  ruby_obj.es_lambda
32
32
  elsif ruby_obj.kind_of?(Regexp)
33
- memory.root_namespace["Regex"].new_with_value(ESRegex.from_regex(ruby_obj))
33
+ memory.root_namespace["Regex"].new_with_value(ESRegex.from_regex(ruby_obj), memory.root_namespace)
34
34
  elsif ruby_obj.kind_of?(ESRegex)
35
- memory.root_namespace["Regex"].new_with_value(ruby_obj)
35
+ memory.root_namespace["Regex"].new_with_value(ruby_obj, memory.root_namespace)
36
36
  elsif ruby_obj.nil?
37
37
  memory.root_namespace["nil"]
38
38
  elsif ruby_obj == true
@@ -30,7 +30,7 @@ module EleetScript
30
30
 
31
31
  module Helpers
32
32
  def self.throw_eleet_error(context, error)
33
- context.root_ns["Errors"].call("<", [context.root_ns["String"].new_with_value(error)])
33
+ context.root_ns["Errors"].call("<", [context.root_ns["String"].new_with_value(error, context.namespace_context)])
34
34
  end
35
35
  end
36
36
 
@@ -124,13 +124,13 @@ module EleetScript
124
124
  include Interpolatable
125
125
 
126
126
  def eval(context)
127
- context.root_ns["String"].new_with_value(interpolate(value, context))
127
+ context.root_ns["String"].new_with_value(interpolate(value, context), context.namespace_context)
128
128
  end
129
129
  end
130
130
 
131
131
  class SymbolNode
132
132
  def eval(context)
133
- context.root_ns["Symbol"].new_with_value(value)
133
+ context.root_ns["Symbol"].new_with_value(value, context.namespace_context)
134
134
  end
135
135
  end
136
136
 
@@ -139,19 +139,19 @@ module EleetScript
139
139
 
140
140
  def eval(context)
141
141
  f_arg = flags.length == 0 ? nil : flags
142
- context.root_ns["Regex"].new_with_value(ESRegex.new(interpolate(pattern, context), f_arg))
142
+ context.root_ns["Regex"].new_with_value(ESRegex.new(interpolate(pattern, context), f_arg), context.namespace_context)
143
143
  end
144
144
  end
145
145
 
146
146
  class IntegerNode
147
147
  def eval(context)
148
- context.root_ns["Integer"].new_with_value(value)
148
+ context.root_ns["Integer"].new_with_value(value, context.namespace_context)
149
149
  end
150
150
  end
151
151
 
152
152
  class FloatNode
153
153
  def eval(context)
154
- context.root_ns["Float"].new_with_value(value)
154
+ context.root_ns["Float"].new_with_value(value, context.namespace_context)
155
155
  end
156
156
  end
157
157
 
@@ -177,7 +177,7 @@ module EleetScript
177
177
  class SetLocalNode
178
178
  def eval(context)
179
179
  if Lexer::RESERVED_WORDS.include?(name)
180
- context.root_ns["Errors"].call("<", [context.root_ns["String"].new_with_value("Cannot assign a value to reserved word \"name\"")])
180
+ Helpers.throw_eleet_error(context, "Cannot assign a value to reserved word \"#{name}\"")
181
181
  else
182
182
  context.local_var(name, value.eval(context))
183
183
  end
@@ -291,7 +291,7 @@ module EleetScript
291
291
 
292
292
  class LambdaNode
293
293
  def eval(context)
294
- context.root_ns["Lambda"].new_with_value(EleetScriptMethod.new(params, body, context))
294
+ context.root_ns["Lambda"].new_with_value(EleetScriptMethod.new(params, body, context), context.namespace_context)
295
295
  end
296
296
  end
297
297
 
@@ -38,7 +38,7 @@ module EleetScript
38
38
  method.call(self, arguments)
39
39
  end
40
40
  else
41
- es_method_name = @context["String"].new_with_value(method_name.to_s)
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
@@ -82,12 +82,12 @@ module EleetScript
82
82
  end
83
83
  end
84
84
 
85
- def new
86
- EleetScriptClassInstance.new(@context, self)
85
+ def new(current_context)
86
+ EleetScriptClassInstance.new(@context, self, current_context.namespace_context)
87
87
  end
88
88
 
89
- def new_with_value(value)
90
- cls = EleetScriptClassInstance.new(@context, self)
89
+ def new_with_value(value, current_context)
90
+ cls = EleetScriptClassInstance.new(@context, self, current_context.namespace_context)
91
91
  cls.ruby_value = value
92
92
  cls
93
93
  end
@@ -3,14 +3,14 @@ module EleetScript
3
3
  attr_accessor :instance_vars, :runtime_class, :context, :methods
4
4
  set_is_instance
5
5
 
6
- def initialize(class_context, runtime_class)
6
+ def initialize(class_context, runtime_class, namespace_context)
7
7
  @methods = MethodHash.new
8
8
  @instance_vars = ProcessedKeyHash.new
9
9
  @instance_vars.set_key_preprocessor do |key|
10
10
  key[0] == "@" ? key[1..-1] : key
11
11
  end
12
12
  @runtime_class = runtime_class
13
- @context = class_context.new_instance_context(self)
13
+ @context = class_context.new_instance_context(self, namespace_context)
14
14
  @ruby_value = self
15
15
  end
16
16
 
@@ -27,7 +27,7 @@ module EleetScript
27
27
  method.call(self, arguments)
28
28
  end
29
29
  else
30
- es_method_name = @context["String"].new_with_value(method_name.to_s)
30
+ es_method_name = @context["String"].new_with_value(method_name.to_s, @context.namespace_context)
31
31
  call(NO_METHOD, arguments.dup.unshift(es_method_name))
32
32
  end
33
33
  end
@@ -2,8 +2,6 @@ require "util/processed_key_hash"
2
2
 
3
3
  module EleetScript
4
4
  class BaseContext
5
-
6
-
7
5
  attr_reader :constants, :local_vars, :global_vars, :namespaces
8
6
  attr_accessor :current_self, :current_class
9
7
 
@@ -25,7 +23,7 @@ module EleetScript
25
23
  end
26
24
 
27
25
  def es_nil
28
- @_es_nil ||= self["nil"]
26
+ @_es_nil ||= root_ns["nil"]
29
27
  end
30
28
 
31
29
  def root_ns
@@ -48,6 +46,10 @@ module EleetScript
48
46
  @current_self.class_vars
49
47
  end
50
48
 
49
+ def namespace_context
50
+ root_ns
51
+ end
52
+
51
53
  def local_var(name, value = nil)
52
54
  if value
53
55
  local_vars[name] = value
@@ -173,6 +175,10 @@ module EleetScript
173
175
  @root_ns
174
176
  end
175
177
 
178
+ def namespace_context
179
+ self
180
+ end
181
+
176
182
  def new_class_context(current_self, current_class = nil)
177
183
  ctx = ClassContext.new(current_self, current_class)
178
184
  ctx.parent_context = self
@@ -180,9 +186,9 @@ module EleetScript
180
186
  end
181
187
 
182
188
  def new_namespace_context
183
- current_self = @root_ns["Object"].new
184
- current_class = current_self.runtime_class
185
- ctx = NamespaceContext.new(current_self, current_class, @root_ns)
189
+ ctx = NamespaceContext.new(nil, nil, @root_ns)
190
+ ctx.current_self = @root_ns["Object"].new(ctx)
191
+ ctx.current_class = current_self.runtime_class
186
192
  ctx.parent_context = self
187
193
  ctx
188
194
  end
@@ -211,8 +217,12 @@ module EleetScript
211
217
  @parent_context ? @parent_context.instance_vars : {}
212
218
  end
213
219
 
214
- def new_instance_context(instance_self)
215
- ctx = ClassInstanceContext.new(instance_self, current_class)
220
+ def namespace_context
221
+ @parent_context.namespace_context
222
+ end
223
+
224
+ def new_instance_context(instance_self, namespace)
225
+ ctx = ClassInstanceContext.new(instance_self, current_class, namespace)
216
226
  ctx.parent_context = self
217
227
  ctx
218
228
  end
@@ -225,6 +235,9 @@ module EleetScript
225
235
  end
226
236
 
227
237
  class ClassInstanceContext < BaseContext
238
+ attr_accessor :ns_context
239
+ init_with :set_ns_context
240
+
228
241
  def current_class
229
242
  @parent_context.current_class
230
243
  end
@@ -233,11 +246,30 @@ module EleetScript
233
246
  {}
234
247
  end
235
248
 
249
+ def [](key)
250
+ value = ns_context[key]
251
+ if value == es_nil
252
+ super
253
+ else
254
+ value
255
+ end
256
+ end
257
+
258
+ def namespace_context
259
+ ns_context
260
+ end
261
+
236
262
  def new_method_context(lambda_context = nil)
237
263
  ctx = MethodContext.new(current_self, current_class, lambda_context)
238
264
  ctx.parent_context = self
239
265
  ctx
240
266
  end
267
+
268
+ private
269
+
270
+ def set_ns_context(ns_context)
271
+ self.ns_context = ns_context
272
+ end
241
273
  end
242
274
 
243
275
  class MethodContext < BaseContext
@@ -262,6 +294,10 @@ module EleetScript
262
294
  end
263
295
  end
264
296
 
297
+ def namespace_context
298
+ @parent_context.namespace_context
299
+ end
300
+
265
301
  private
266
302
 
267
303
  def handle_lambda_context(lambda_context)
@@ -52,16 +52,16 @@ module EleetScript
52
52
  end
53
53
  end
54
54
 
55
- @root = root_namespace["Object"].new
55
+ @root = root_namespace["Object"].new(root_namespace)
56
56
  root_namespace.current_self = @root
57
57
  root_namespace.current_class = @root.runtime_class
58
58
 
59
- root_namespace["true"] = root_namespace["TrueClass"].new_with_value(true)
60
- root_namespace["false"] = root_namespace["FalseClass"].new_with_value(false)
61
- root_namespace["nil"] = root_namespace["NilClass"].new_with_value(nil)
59
+ root_namespace["true"] = root_namespace["TrueClass"].new_with_value(true, root_namespace)
60
+ root_namespace["false"] = root_namespace["FalseClass"].new_with_value(false, root_namespace)
61
+ root_namespace["nil"] = root_namespace["NilClass"].new_with_value(nil, root_namespace)
62
62
 
63
63
  # Global Errors Object
64
- root_namespace["Errors"] = root_namespace["List"].new_with_value(ListBase.new(root_namespace.es_nil))
64
+ root_namespace["Errors"] = root_namespace["List"].new_with_value(ListBase.new(root_namespace.es_nil), root_namespace)
65
65
 
66
66
  self.class.core_definers.each do |definer_block|
67
67
  instance_eval(&definer_block)
@@ -4,11 +4,11 @@ module EleetScript
4
4
  false_cls = root_namespace["FalseClass"]
5
5
 
6
6
  true_cls.def :clone do |receiver, arguments|
7
- true_cls.new_with_value(true)
7
+ root_namespace["true"]
8
8
  end
9
9
 
10
10
  false_cls.def :clone do |receiver, arguments|
11
- false_cls.new_with_value(false)
11
+ root_namespace["false"]
12
12
  end
13
13
  end
14
14
  end
@@ -2,8 +2,8 @@ module EleetScript
2
2
  Memory.define_core_methods do
3
3
  list = root_namespace["List"]
4
4
 
5
- list.class_def :new do |receiver, arguments|
6
- new_list = receiver.new_with_value(ListBase.new(root_namespace.es_nil))
5
+ list.class_def :new do |receiver, arguments, context|
6
+ new_list = receiver.new_with_value(ListBase.new(root_namespace.es_nil), 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)
@@ -46,7 +46,7 @@ module EleetScript
46
46
  value
47
47
  end
48
48
 
49
- list.def :merge do |receiver, arguments|
49
+ list.def :merge do |receiver, arguments, context|
50
50
  lst = receiver.ruby_value.dup
51
51
  arg = arguments.first
52
52
  if arg.is_a?("List")
@@ -58,20 +58,20 @@ module EleetScript
58
58
  new_hash = Hash.new(root_namespace.es_nil)
59
59
  keys = arg.call(:keys, [])
60
60
  keys.raw.length.times do |i|
61
- key = keys.call(:[], [root_namespace["Integer"].new_with_value(i)])
61
+ key = keys.call(:[], [root_namespace["Integer"].new_with_value(i, context.namespace_context)])
62
62
  new_hash[key] = arg.call(:[], [key])
63
63
  end
64
64
  olst.hash_value = new_hash
65
65
  elsif arg.raw.kind_of?("Array")
66
66
  new_arr = []
67
67
  arg.call(:length, []).ruby_value.times do |i|
68
- new_arr << arg.call(:[], [root_namespace["Integer"].new_with_value(i)])
68
+ new_arr << arg.call(:[], [root_namespace["Integer"].new_with_value(i, context.namespace_context)])
69
69
  end
70
70
  olst.array_value = new_arr
71
71
  end
72
72
  lst.merge!(olst)
73
73
  end
74
- root_namespace["List"].new_with_value(lst)
74
+ root_namespace["List"].new_with_value(lst, context.namespace_context)
75
75
  end
76
76
 
77
77
  list.def :merge! do |receiver, arguments|
@@ -100,9 +100,9 @@ module EleetScript
100
100
  arguments.first
101
101
  end
102
102
 
103
- list.def :keys do |receiver, arguments|
103
+ list.def :keys do |receiver, arguments, context|
104
104
  lst = receiver.ruby_value
105
- keys = (lst.array_value.length > 0 ? (0...lst.array_value.length).to_a : []).map { |v| root_namespace["Integer"].new_with_value(v) }
105
+ keys = (lst.array_value.length > 0 ? (0...lst.array_value.length).to_a : []).map { |v| root_namespace["Integer"].new_with_value(v, context.namespace_context) }
106
106
  keys.concat(lst.hash_value.keys)
107
107
  list.call(:new, keys)
108
108
  end
@@ -119,10 +119,10 @@ module EleetScript
119
119
  val.nil? ? root_namespace.es_nil : val
120
120
  end
121
121
 
122
- list.def :length do |receiver, arguments|
122
+ list.def :length do |receiver, arguments, context|
123
123
  ruby_val = receiver.ruby_value
124
124
  length = ruby_val.array_value.length + ruby_val.hash_value.length
125
- root_namespace["Integer"].new_with_value(length)
125
+ root_namespace["Integer"].new_with_value(length, context.namespace_context)
126
126
  end
127
127
 
128
128
  list.def :first do |receiver, arguments|
@@ -138,17 +138,17 @@ module EleetScript
138
138
  receiver
139
139
  end
140
140
 
141
- list.def :join do |receiver, arguments|
141
+ list.def :join do |receiver, arguments, context|
142
142
  str = if arguments.length > 0
143
143
  arguments.first.call(:to_string).ruby_value
144
144
  else
145
145
  ", "
146
146
  end
147
147
  values = receiver.call(:values).ruby_value.array_value.map { |v| v.call(:to_string).ruby_value }
148
- root_namespace["String"].new_with_value(values.join(str))
148
+ root_namespace["String"].new_with_value(values.join(str), context.namespace_context)
149
149
  end
150
150
 
151
- list.def :to_string do |receiver, arguments|
151
+ list.def :to_string do |receiver, arguments, context|
152
152
  arr_vals = receiver.ruby_value.array_value.map do |val|
153
153
  val.call(:inspect).ruby_value
154
154
  end
@@ -171,7 +171,7 @@ module EleetScript
171
171
  else
172
172
  ""
173
173
  end
174
- root_namespace["String"].new_with_value("[#{str}]")
174
+ root_namespace["String"].new_with_value("[#{str}]", context.namespace_context)
175
175
  end
176
176
  end
177
177
  end
@@ -3,7 +3,7 @@ module EleetScript
3
3
  nil_cls = root_namespace["NilClass"]
4
4
 
5
5
  nil_cls.def :clone do |receiver, arguments|
6
- nil_cls.new_with_value(nil)
6
+ root_namespace["nil"]
7
7
  end
8
8
  end
9
9
  end
@@ -4,62 +4,63 @@ module EleetScript
4
4
  int = root_namespace["Integer"]
5
5
  float = root_namespace["Float"]
6
6
 
7
- number.def :+ do |receiver, arguments|
7
+ number.def :+ do |receiver, arguments, context|
8
8
  arg = arguments.first
9
9
  if arg.is_a?("Number")
10
10
  val = receiver.ruby_value + arg.ruby_value
11
11
  if val.kind_of?(Fixnum)
12
- int.new_with_value(val)
12
+ int.new_with_value(val, context.namespace_context)
13
13
  else
14
- float.new_with_value(val)
14
+ float.new_with_value(val, context.namespace_context)
15
15
  end
16
16
  elsif arg.is_a?("String")
17
17
  str = receiver.ruby_value.to_s + arg.ruby_value
18
- root_namespace["String"].new_with_value(str)
18
+ root_namespace["String"].new_with_value(str, context.namespace_context)
19
19
  else
20
20
  receiver
21
21
  end
22
22
  end
23
23
 
24
- number.def :- do |receiver, arguments|
24
+ number.def :- do |receiver, arguments, context|
25
25
  arg = arguments.first
26
26
  if arg.is_a?("Number")
27
27
  val = receiver.ruby_value - arg.ruby_value
28
28
  if val.kind_of?(Fixnum)
29
- int.new_with_value(val)
29
+ int.new_with_value(val, context.namespace_context)
30
30
  else
31
- float.new_with_value(float)
31
+ float.new_with_value(val, context.namespace_context)
32
32
  end
33
33
  else
34
34
  receiver
35
35
  end
36
36
  end
37
37
 
38
- number.def :* do |receiver, arguments|
38
+ number.def :* do |receiver, arguments, context|
39
39
  arg = arguments.first
40
40
  if arg.is_a?("Number")
41
41
  val = receiver.ruby_value * arg.ruby_value
42
42
  if val.kind_of?(Fixnum)
43
- int.new_with_value(val)
43
+ int.new_with_value(val, context.namespace_context)
44
44
  else
45
- float.new_with_value(float)
45
+ float.new_with_value(val, context.namespace_context)
46
46
  end
47
47
  else
48
48
  receiver
49
49
  end
50
50
  end
51
51
 
52
- number.def :/ do |receiver, arguments|
52
+ number.def :/ do |receiver, arguments, context|
53
53
  arg = arguments.first
54
54
  if arg.is_a?("Number")
55
55
  if arg.ruby_value == 0
56
- int.new_with_value(0)
56
+ int.new_with_value(0, context.namespace_context)
57
+ root_namespace["Errors"].call(:<, [root_namespace["String"].new_with_value("You cannot divide by zero!", context.namespace_context)])
57
58
  else
58
59
  val = receiver.ruby_value / arg.ruby_value
59
60
  if val.kind_of?(Fixnum)
60
- int.new_with_value(val)
61
+ int.new_with_value(val, context.namespace_context)
61
62
  else
62
- float.new_with_value(float)
63
+ float.new_with_value(val, context.namespace_context)
63
64
  end
64
65
  end
65
66
  else
@@ -67,17 +68,18 @@ module EleetScript
67
68
  end
68
69
  end
69
70
 
70
- number.def :% do |receiver, arguments|
71
+ number.def :% do |receiver, arguments, context|
71
72
  arg = arguments.first
72
73
  if arg.is_a?("Number")
73
74
  if arg.ruby_value == 0
74
- int.new_with_value(0)
75
+ int.new_with_value(0, context.namespace_context)
76
+ root_namespace["Errors"].call(:<, [root_namespace["String"].new_with_value("You cannot divide by zero!", context.namespace_context)])
75
77
  else
76
78
  val = receiver.ruby_value % arg.ruby_value
77
79
  if val.kind_of?(Fixnum)
78
- int.new_with_value(val)
80
+ int.new_with_value(val, context.namespace_context)
79
81
  else
80
- float.new_with_value(float)
82
+ float.new_with_value(val, context.namespace_context)
81
83
  end
82
84
  end
83
85
  else
@@ -129,15 +131,15 @@ module EleetScript
129
131
  receiver
130
132
  end
131
133
 
132
- number.def :to_string do |receiver, arguments|
133
- root_namespace["String"].new_with_value(receiver.ruby_value.to_s)
134
+ number.def :to_string do |receiver, arguments, context|
135
+ root_namespace["String"].new_with_value(receiver.ruby_value.to_s, context.namespace_context)
134
136
  end
135
137
 
136
- number.def :clone do |receiver, arguments|
138
+ number.def :clone do |receiver, arguments, context|
137
139
  if receiver.is_a?("Integer")
138
- int.new_with_value(receiver.ruby_value)
140
+ int.new_with_value(receiver.ruby_value, context.namespace_context)
139
141
  elsif receiver.is_a?("Float")
140
- float.new_with_value(receiver.ruby_value)
142
+ float.new_with_value(receiver.ruby_value, context.namespace_context)
141
143
  else
142
144
  root_namespace.es_nil
143
145
  end
@@ -2,8 +2,8 @@ module EleetScript
2
2
  Memory.define_core_methods do
3
3
  object = root_namespace["Object"]
4
4
 
5
- object.class_def :new do |receiver, arguments|
6
- ins = receiver.new
5
+ object.class_def :new do |receiver, arguments, context|
6
+ ins = receiver.new(context.namespace_context)
7
7
  ins.call("init", arguments)
8
8
  ins
9
9
  end
@@ -30,12 +30,12 @@ module EleetScript
30
30
  receiver.runtime_class
31
31
  end
32
32
 
33
- object.def :class_name do |receiver, arguments|
34
- root_namespace["String"].new_with_value(receiver.runtime_class.name)
33
+ object.def :class_name do |receiver, arguments, context|
34
+ root_namespace["String"].new_with_value(receiver.runtime_class.name, context.namespace_context)
35
35
  end
36
36
 
37
- object.class_def :class_name do |receiver, arguments|
38
- root_namespace["String"].new_with_value(receiver.name)
37
+ object.class_def :class_name do |receiver, arguments, context|
38
+ root_namespace["String"].new_with_value(receiver.name, context.namespace_context)
39
39
  end
40
40
 
41
41
  object.def :is do |receiver, arguments|
@@ -46,10 +46,10 @@ module EleetScript
46
46
  end
47
47
  end
48
48
 
49
- object.def :clone do |receiver, arguments|
49
+ object.def :clone do |receiver, arguments, context|
50
50
  cls_name = receiver.runtime_class.name
51
51
  if ["Integer", "Float", "String", "List"].include?(cls_name)
52
- receiver.runtime_class.new_with_value(receiver.ruby_value.dup)
52
+ receiver.runtime_class.new_with_value(receiver.ruby_value.dup, context.namespace_context)
53
53
  else
54
54
  ins = receiver.runtime_class.call(:new)
55
55
  ins.ruby_value = receiver.ruby_value.dup
@@ -2,19 +2,19 @@ module EleetScript
2
2
  Memory.define_core_methods do
3
3
  regex = root_namespace["Regex"]
4
4
 
5
- regex.class_def :new do |receiver, arguments|
5
+ regex.class_def :new do |receiver, arguments, context|
6
6
  pattern, flags = arguments
7
7
  pattern = (pattern ? pattern.ruby_value : "")
8
8
  flags = (flags ? flags.ruby_value : nil)
9
- receiver.new_with_value(ESRegex.new(pattern, flags))
9
+ receiver.new_with_value(ESRegex.new(pattern, flags), context.namespace_context)
10
10
  end
11
11
 
12
- regex.def :pattern do |receiver, arguments|
13
- root_namespace["String"].new_with_value(receiver.ruby_value.source)
12
+ regex.def :pattern do |receiver, arguments, context|
13
+ root_namespace["String"].new_with_value(receiver.ruby_value.source, context.namespace_context)
14
14
  end
15
15
 
16
- regex.def :flags do |receiver, arguments|
17
- root_namespace["String"].new_with_value(receiver.ruby_value.flags)
16
+ regex.def :flags do |receiver, arguments, context|
17
+ root_namespace["String"].new_with_value(receiver.ruby_value.flags, context.namespace_context)
18
18
  end
19
19
 
20
20
  regex.def :global= do |receiver, arguments|
@@ -24,7 +24,7 @@ module EleetScript
24
24
  end
25
25
  end
26
26
 
27
- string.def :substr do |receiver, arguments|
27
+ string.def :substr do |receiver, arguments, context|
28
28
  if arguments.length < 2
29
29
  root_namespace["nil"]
30
30
  else
@@ -35,33 +35,33 @@ module EleetScript
35
35
  else
36
36
  (s.ruby_value...e.ruby_value)
37
37
  end
38
- root_namespace["String"].new_with_value(receiver.ruby_value[range])
38
+ root_namespace["String"].new_with_value(receiver.ruby_value[range], context.namespace_context)
39
39
  else
40
40
  root_namespace["nil"]
41
41
  end
42
42
  end
43
43
  end
44
44
 
45
- string.def :length do |receiver, arguments|
46
- root_namespace["Integer"].new_with_value(receiver.ruby_value.length)
45
+ string.def :length do |receiver, arguments, context|
46
+ root_namespace["Integer"].new_with_value(receiver.ruby_value.length, context.namespace_context)
47
47
  end
48
48
 
49
- string.def :upper_case do |receiver, arguments|
50
- string.new_with_value(receiver.ruby_value.upcase)
49
+ string.def :upper_case do |receiver, arguments, context|
50
+ string.new_with_value(receiver.ruby_value.upcase, context.namespace_context)
51
51
  end
52
52
 
53
- string.def :lower_case do |receiver, arguments|
54
- string.new_with_value(receiver.ruby_value.downcase)
53
+ string.def :lower_case do |receiver, arguments, context|
54
+ string.new_with_value(receiver.ruby_value.downcase, context.namespace_context)
55
55
  end
56
56
 
57
- string.def :[] do |receiver, arguments|
57
+ string.def :[] do |receiver, arguments, context|
58
58
  index = arguments.first
59
59
  if index.is_a?("Integer")
60
60
  index = index.ruby_value
61
61
  if index < 0 || index >= receiver.ruby_value.length
62
62
  root_namespace.es_nil
63
63
  else
64
- string.new_with_value(receiver.ruby_value[index])
64
+ string.new_with_value(receiver.ruby_value[index], context.namespace_context)
65
65
  end
66
66
  else
67
67
  root_namespace.es_nil
@@ -84,13 +84,13 @@ module EleetScript
84
84
  end
85
85
  end
86
86
 
87
- string.def :to_symbol do |receiver, arguments|
88
- root_namespace["Symbol"].new_with_value(receiver.ruby_value.to_sym)
87
+ string.def :to_symbol do |receiver, arguments, context|
88
+ root_namespace["Symbol"].new_with_value(receiver.ruby_value.to_sym, context.namespace_context)
89
89
  end
90
90
 
91
- string.def :replace do |receiver, arguments|
91
+ string.def :replace do |receiver, arguments, context|
92
92
  if arguments.length < 2
93
- string.new_with_value(receiver.ruby_value)
93
+ string.new_with_value(receiver.ruby_value, context.namespace_context)
94
94
  else
95
95
  pattern, replacement = arguments
96
96
  if !pattern.is_a?("Regex")
@@ -99,28 +99,28 @@ module EleetScript
99
99
  if replacement.is_a?("Lambda")
100
100
  new_str = if pattern.ruby_value.global?
101
101
  receiver.ruby_value.gsub(pattern.ruby_value) do
102
- args = Regexp.last_match[1..-1].map { |match| string.new_with_value(match) }
102
+ args = Regexp.last_match[1..-1].map { |match| string.new_with_value(match, context.namespace_context) }
103
103
  replacement.call(:call, args).call(:to_string).ruby_value
104
104
  end
105
105
  else
106
106
  receiver.ruby_value.sub(pattern.ruby_value) do
107
- args = Regexp.last_match[1..-1].map { |match| string.new_with_value(match) }
107
+ args = Regexp.last_match[1..-1].map { |match| string.new_with_value(match, context.namespace_context) }
108
108
  replacement.call(:call, args).call(:to_string).ruby_value
109
109
  end
110
110
  end
111
- string.new_with_value(new_str)
111
+ string.new_with_value(new_str, context.namespace_context)
112
112
  else
113
113
  new_str = if pattern.ruby_value.global?
114
114
  receiver.ruby_value.gsub(pattern.ruby_value, replacement.call(:to_string).ruby_value)
115
115
  else
116
116
  receiver.ruby_value.sub(pattern.ruby_value, replacement.call(:to_string).ruby_value)
117
117
  end
118
- string.new_with_value(new_str)
118
+ string.new_with_value(new_str, context.namespace_context)
119
119
  end
120
120
  end
121
121
  end
122
122
 
123
- string.def :match do |receiver, arguments|
123
+ string.def :match do |receiver, arguments, context|
124
124
  str_cls, list_cls = root_namespace["String"], root_namespace["List"]
125
125
  rx = arguments.first
126
126
  args = []
@@ -129,7 +129,7 @@ module EleetScript
129
129
  matches = receiver.ruby_value.scan(rx.ruby_value)
130
130
  list_args = matches.map do |match|
131
131
  args = match.map do |a|
132
- str_cls.new_with_value(a)
132
+ str_cls.new_with_value(a, context.namespace_context)
133
133
  end
134
134
  list_cls.call(:new, args)
135
135
  end
@@ -139,17 +139,17 @@ module EleetScript
139
139
  if matches.nil?
140
140
  list_cls.call(:new)
141
141
  else
142
- args = [str_cls.new_with_value(matches[0])]
142
+ args = [str_cls.new_with_value(matches[0], context.namespace_context)]
143
143
  if matches.names.length > 0
144
144
  args += matches.names.map do |name|
145
- n, v = str_cls.new_with_value(name), str_cls.new_with_value(matches[name])
145
+ n, v = str_cls.new_with_value(name, context.namespace_context), str_cls.new_with_value(matches[name], context.namespace_context)
146
146
  root_namespace["Pair"].call(:new, [n, v])
147
147
  end
148
148
  else
149
149
  group_matches = matches.to_a
150
150
  group_matches.shift # Remove full match
151
151
  args += group_matches.map do |res|
152
- str_cls.new_with_value(res)
152
+ str_cls.new_with_value(res, context.namespace_context)
153
153
  end
154
154
  end
155
155
  list_cls.call(:new, args)
@@ -2,11 +2,11 @@ module EleetScript
2
2
  Memory.define_core_methods do
3
3
  symbol = root_namespace["Symbol"]
4
4
 
5
- symbol.class_def :new do |receiver, arguments|
5
+ symbol.class_def :new do |receiver, arguments, context|
6
6
  if arguments.length > 0
7
- receiver.new_with_value(arguments.first.call(:to_string).ruby_value.intern)
7
+ receiver.new_with_value(arguments.first.call(:to_string).ruby_value.intern, context.namespace_context)
8
8
  else
9
- reciever.new_with_value(:nil)
9
+ reciever.new_with_value(:nil, context.namespace_context)
10
10
  end
11
11
  end
12
12
 
@@ -19,8 +19,8 @@ module EleetScript
19
19
  end
20
20
  end
21
21
 
22
- symbol.def :to_string do |receiver, arguments|
23
- root_namespace["String"].new_with_value("#{receiver.ruby_value.to_s}")
22
+ symbol.def :to_string do |receiver, arguments, context|
23
+ root_namespace["String"].new_with_value("#{receiver.ruby_value.to_s}", context.namespace_context)
24
24
  end
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eleetscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13a
4
+ version: 0.0.14a
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Buck