eleetscript 0.0.17a → 0.0.18a

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.
@@ -100,10 +100,6 @@ module EleetScript
100
100
  to_s[0..-2] + " @methods(#{@methods.keys.join(", ")})>"
101
101
  end
102
102
 
103
- def is_a?(value)
104
- false
105
- end
106
-
107
103
  private
108
104
 
109
105
  def has_super_class?
@@ -40,14 +40,17 @@ module EleetScript
40
40
  to_s
41
41
  end
42
42
 
43
- def is_a?(value)
43
+ def is_a?(*values)
44
44
  names = ["Object", runtime_class.name]
45
45
  cur_class = runtime_class
46
46
  while cur_class.super_class.name != "Object"
47
47
  names << cur_class.super_class.name
48
48
  cur_class = cur_class.super_class
49
49
  end
50
- names.include?(value)
50
+ values.each do |value|
51
+ return true if names.include?(value)
52
+ end
53
+ false
51
54
  end
52
55
 
53
56
  def class_name
@@ -31,7 +31,7 @@ module EleetScript
31
31
  false
32
32
  end
33
33
 
34
- def is_a?(name)
34
+ def is_a?(*names)
35
35
  false
36
36
  end
37
37
 
@@ -6,10 +6,11 @@ module EleetScript
6
6
  attr_accessor :current_self, :current_class
7
7
 
8
8
  class << self
9
- attr_writer :init_funcs
9
+ attr_reader :init_funcs
10
10
 
11
11
  def init_with(*func_symbols)
12
- self.init_funcs += func_symbols
12
+ (@init_funcs ||= [])
13
+ @init_funcs += func_symbols
13
14
  end
14
15
 
15
16
  def init_funcs
@@ -58,6 +59,10 @@ module EleetScript
58
59
  end
59
60
  end
60
61
 
62
+ def local_constant(name)
63
+ constants[name] || es_nil
64
+ end
65
+
61
66
  def [](key)
62
67
  store = fetch_var_store(key)
63
68
  if store[key]
@@ -196,7 +201,7 @@ module EleetScript
196
201
  private
197
202
 
198
203
  def init_namespace(root = nil)
199
- if @root_ns == nil
204
+ if root.nil?
200
205
  @root_ns = self
201
206
  @global_vars = ProcessedKeyHash.new
202
207
  @global_vars.set_key_preprocessor do |key|
@@ -0,0 +1,57 @@
1
+ class Random
2
+ @@d4 do
3
+ int(1, 4)
4
+ end
5
+
6
+ @@d6 do
7
+ int(1, 6)
8
+ end
9
+
10
+ @@d8 do
11
+ int(1, 8)
12
+ end
13
+
14
+ @@d10 do
15
+ int(1, 10)
16
+ end
17
+
18
+ @@d12 do
19
+ int(1, 12)
20
+ end
21
+
22
+ @@d20 do
23
+ int(1, 20)
24
+ end
25
+
26
+ @@d100 do
27
+ int
28
+ end
29
+
30
+ d4 do
31
+ int(1, 4)
32
+ end
33
+
34
+ d6 do
35
+ int(1, 6)
36
+ end
37
+
38
+ d8 do
39
+ int(1, 8)
40
+ end
41
+
42
+ d10 do
43
+ int(1, 10)
44
+ end
45
+
46
+ d12 do
47
+ int(1, 12)
48
+ end
49
+
50
+ d20 do
51
+ int(1, 20)
52
+ end
53
+
54
+ d100 do
55
+ int
56
+ end
57
+ end
@@ -22,7 +22,8 @@ module EleetScript
22
22
  "Lambda" => nil,
23
23
  "TrueClass" => nil,
24
24
  "FalseClass" => nil,
25
- "NilClass" => nil
25
+ "NilClass" => nil,
26
+ "Random" => nil
26
27
  }
27
28
 
28
29
  class << self
@@ -0,0 +1,23 @@
1
+ module EleetScript
2
+ Memory.define_core_methods do
3
+ float = root_namespace["Float"]
4
+
5
+ float.def :to_float do |receiver, _|
6
+ receiver
7
+ end
8
+
9
+ float.def :to_integer do |receiver, _, context|
10
+ root_namespace["Integer"].new_with_value(receiver.ruby_value.to_i, context.namespace_context)
11
+ end
12
+
13
+ float.def :round do |receiver, arguments, context|
14
+ if arguments.length == 0
15
+ root_namespace["Integer"].new_with_value(receiver.ruby_value.round, context.namespace_context)
16
+ elsif arguments.length >= 1 && arguments.first.is_a?("String", "Number")
17
+ root_namespace["Float"].new_with_value(receiver.ruby_value.round(arguments.first.calL(:to_integer).ruby_value), context.namespace_context)
18
+ else
19
+ root_namespace["nil"]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module EleetScript
2
+ Memory.define_core_methods do
3
+ integer = root_namespace["Integer"]
4
+
5
+ integer.def :to_float do |receiver, _, context|
6
+ root_namespace["Float"].new_with_value(receiver.ruby_value.to_f, context.namespace_context)
7
+ end
8
+
9
+ integer.def :to_integer do |receiver, _, context|
10
+ receiver
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,57 @@
1
+ module EleetScript
2
+ Memory.define_core_methods do
3
+ random = root_namespace["Random"]
4
+
5
+ random.class_def :int do |_, arguments, context|
6
+ min, max = 1, 100
7
+ if arguments.length == 1 && arguments.first.is_a?("String", "Number")
8
+ min, max = 0, arguments.first.call(:to_integer).ruby_value
9
+ elsif arguments.length >= 2 && arguments.first.is_a?("String", "Number") && arguments[1].is_a?("String", "Number")
10
+ min, max = arguments.first.call(:to_integer).ruby_value, arguments[1].call(:to_integer).ruby_value
11
+ end
12
+ root_namespace["Integer"].new_with_value(rand(max - min) + min, context.namespace_context)
13
+ end
14
+
15
+ random.class_def :float do |_, _, context|
16
+ root_namespace["Float"].new_with_value(rand, context.namespace_context)
17
+ end
18
+
19
+ random.class_def :bool do |_, _, context|
20
+ t, f = root_namespace["True"], root_namespace["False"]
21
+ if rand > 0.5
22
+ t
23
+ else
24
+ f
25
+ end
26
+ end
27
+
28
+ random.class_def :new do |receiver, arguments, context|
29
+ first_arg = arguments.first
30
+ seed = first_arg.is_a?("String", "Number") ? first_arg.call(:to_integer).ruby_value : nil
31
+ random.new_with_value(Random.new(seed), context.namespace_context)
32
+ end
33
+
34
+ random.def :int do |receiver, arguments, context|
35
+ min, max = 1, 100
36
+ if arguments.length == 1 && arguments.first.is_a?("String", "Number")
37
+ min, max = 0, arguments.first.call(:to_integer).ruby_value
38
+ elsif arguments.length >= 2 && arguments.first.is_a?("String", "Number") && arguments[1].is_a?("String", "Number")
39
+ min, max = arguments.first.call(:to_integer).ruby_value, arguments[1].call(:to_integer).ruby_value
40
+ end
41
+ root_namespace["Integer"].new_with_value(receiver.ruby_value.rand(max - min) + min, context.namespace_context)
42
+ end
43
+
44
+ random.def :float do |receiver, _, context|
45
+ root_namespace["Float"].new_with_value(receiver.ruby_value.rand, context.namespace_context)
46
+ end
47
+
48
+ random.def :bool do |receiver, _, context|
49
+ t, f = root_namespace["True"], root_namespace["False"]
50
+ if receiver.ruby_value.rand > 0.5
51
+ t
52
+ else
53
+ f
54
+ end
55
+ end
56
+ end
57
+ end
@@ -90,7 +90,15 @@ module EleetScript
90
90
  end
91
91
 
92
92
  string.def :to_symbol do |receiver, arguments, context|
93
- root_namespace["Symbol"].new_with_value(receiver.ruby_value.to_sym, context.namespace_context)
93
+ root_namespace["Symbol"].new_with_value(receiver.ruby_value.gsub(/\s+/, "_").to_sym, context.namespace_context)
94
+ end
95
+
96
+ string.def :to_integer do |receiver, arguments, context|
97
+ root_namespace["Integer"].new_with_value(receiver.ruby_value.to_i, context.namespace_context)
98
+ end
99
+
100
+ string.def :to_float do |receiver, arguments, context|
101
+ root_namespace["Float"].new_with_value(receiver.ruby_value.to_f, context.namespace_context)
94
102
  end
95
103
 
96
104
  string.def :replace do |receiver, arguments, context|
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.17a
4
+ version: 0.0.18a
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Buck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-15 00:00:00.000000000 Z
11
+ date: 2014-03-05 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
@@ -47,6 +47,7 @@ files:
47
47
  - lib/lang/runtime/eleetscript/object.es
48
48
  - lib/lang/runtime/eleetscript/pair.es
49
49
  - lib/lang/runtime/eleetscript/que.es
50
+ - lib/lang/runtime/eleetscript/random.es
50
51
  - lib/lang/runtime/eleetscript/regex.es
51
52
  - lib/lang/runtime/eleetscript/stack.es
52
53
  - lib/lang/runtime/eleetscript/string.es
@@ -56,12 +57,15 @@ files:
56
57
  - lib/lang/runtime/method.rb
57
58
  - lib/lang/runtime/method_hash.rb
58
59
  - lib/lang/runtime/ruby/boolean_methods.rb
60
+ - lib/lang/runtime/ruby/float_methods.rb
61
+ - lib/lang/runtime/ruby/integer_methods.rb
59
62
  - lib/lang/runtime/ruby/io_methods.rb
60
63
  - lib/lang/runtime/ruby/lambda_methods.rb
61
64
  - lib/lang/runtime/ruby/list_methods.rb
62
65
  - lib/lang/runtime/ruby/nil_methods.rb
63
66
  - lib/lang/runtime/ruby/number_methods.rb
64
67
  - lib/lang/runtime/ruby/object_methods.rb
68
+ - lib/lang/runtime/ruby/random_methods.rb
65
69
  - lib/lang/runtime/ruby/regex_methods.rb
66
70
  - lib/lang/runtime/ruby/string_methods.rb
67
71
  - lib/lang/runtime/ruby/symbol_methods.rb