eleetscript 0.0.2a

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.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/bin/eleet +89 -0
  3. data/lib/eleetscript.rb +18 -0
  4. data/lib/engine/eleet_engine.rb +58 -0
  5. data/lib/engine/eleet_to_ruby_wrapper.rb +25 -0
  6. data/lib/engine/ruby_to_eleet_wrapper.rb +22 -0
  7. data/lib/engine/values.rb +55 -0
  8. data/lib/lang/grammar.y +350 -0
  9. data/lib/lang/interpreter.rb +400 -0
  10. data/lib/lang/lexer.rb +92 -0
  11. data/lib/lang/nodes.rb +197 -0
  12. data/lib/lang/parser.output +11953 -0
  13. data/lib/lang/parser.rb +2300 -0
  14. data/lib/lang/runtime/array.rb +23 -0
  15. data/lib/lang/runtime/base_classes.rb +31 -0
  16. data/lib/lang/runtime/bootstrap.rb +3 -0
  17. data/lib/lang/runtime/class.rb +113 -0
  18. data/lib/lang/runtime/class_instance.rb +53 -0
  19. data/lib/lang/runtime/class_skeleton.rb +57 -0
  20. data/lib/lang/runtime/context.rb +263 -0
  21. data/lib/lang/runtime/eleetscript/enumerable.es +36 -0
  22. data/lib/lang/runtime/eleetscript/falseclass.es +25 -0
  23. data/lib/lang/runtime/eleetscript/integer.es +11 -0
  24. data/lib/lang/runtime/eleetscript/list.es +44 -0
  25. data/lib/lang/runtime/eleetscript/nilclass.es +5 -0
  26. data/lib/lang/runtime/eleetscript/number.es +13 -0
  27. data/lib/lang/runtime/eleetscript/object.es +49 -0
  28. data/lib/lang/runtime/eleetscript/pair.es +12 -0
  29. data/lib/lang/runtime/eleetscript/que.es +13 -0
  30. data/lib/lang/runtime/eleetscript/stack.es +14 -0
  31. data/lib/lang/runtime/eleetscript/string.es +34 -0
  32. data/lib/lang/runtime/eleetscript/trueclass.es +25 -0
  33. data/lib/lang/runtime/memory.rb +553 -0
  34. data/lib/lang/runtime/method.rb +32 -0
  35. data/lib/lang/runtime/method_hash.rb +40 -0
  36. data/lib/util/processed_key_hash.rb +34 -0
  37. metadata +79 -0
@@ -0,0 +1,32 @@
1
+ module EleetScript
2
+ class EleetScriptMethod
3
+ def initialize(params, body, lambda_context = nil)
4
+ @params = params
5
+ @body = body
6
+ @lambda_context = lambda_context
7
+ end
8
+
9
+ def call(receiver, arguments, parent_context)
10
+ context = parent_context.new_method_context(@lambda_context)
11
+
12
+ context["lambda?"] = context["false"]
13
+ @params.each_with_index do |param, index|
14
+ arg = arguments[index]
15
+ next unless arg
16
+ context[param] = arg
17
+ end
18
+ if arguments.length > 0 && arguments.last.is_a?("Lambda")
19
+ context["lambda?"] = context["true"]
20
+ context["lambda"] = arguments.last
21
+ end
22
+
23
+ context["arguments"] = context["List"].call(:new, arguments)
24
+
25
+ @body.eval(context)
26
+ end
27
+
28
+ def arity
29
+ 3
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ module EleetScript
2
+ class MethodHash
3
+ def initialize
4
+ @instance_methods = {}
5
+ @class_methods = {}
6
+ end
7
+
8
+ def [](key)
9
+ store = fetch_method_store(key)
10
+ key = clean_key(key)
11
+ store[key]
12
+ end
13
+
14
+ def []=(key, value)
15
+ store = fetch_method_store(key)
16
+ key = clean_key(key)
17
+ store[key] = value
18
+ end
19
+
20
+ def keys
21
+ keys = @class_methods.keys.map { |k| "@@#{k}" }
22
+ keys += @instance_methods.keys
23
+ keys
24
+ end
25
+
26
+ private
27
+
28
+ def clean_key(key)
29
+ key[0..1] == "@@" ? key[2..-1] : key
30
+ end
31
+
32
+ def fetch_method_store(key)
33
+ if key[0..1] == "@@"
34
+ @class_methods
35
+ else
36
+ @instance_methods
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ module EleetScript
2
+ class ProcessedKeyHash < Hash
3
+ def initialize(*args)
4
+ super(*args)
5
+ @key_preprocessor = nil
6
+ end
7
+
8
+ def set_key_preprocessor(&block)
9
+ if block_given?
10
+ @key_preprocessor = block
11
+ end
12
+ end
13
+
14
+ def [](key)
15
+ key = adjust(key)
16
+ super(key)
17
+ end
18
+
19
+ def []=(key, value)
20
+ key = adjust(key)
21
+ super(key, value)
22
+ end
23
+
24
+ private
25
+
26
+ def adjust(key)
27
+ if @key_preprocessor && @key_preprocessor.respond_to?(:call)
28
+ @key_preprocessor.call(key)
29
+ else
30
+ key
31
+ end
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eleetscript
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2a
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Buck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: EleetScript scripting engine for use in Ruby applications
14
+ email: lordizuriel@gmail.com
15
+ executables:
16
+ - eleet
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/eleetscript.rb
21
+ - lib/engine/eleet_engine.rb
22
+ - lib/engine/eleet_to_ruby_wrapper.rb
23
+ - lib/engine/ruby_to_eleet_wrapper.rb
24
+ - lib/engine/values.rb
25
+ - lib/lang/grammar.y
26
+ - lib/lang/interpreter.rb
27
+ - lib/lang/lexer.rb
28
+ - lib/lang/nodes.rb
29
+ - lib/lang/parser.output
30
+ - lib/lang/parser.rb
31
+ - lib/lang/runtime/array.rb
32
+ - lib/lang/runtime/base_classes.rb
33
+ - lib/lang/runtime/bootstrap.rb
34
+ - lib/lang/runtime/class.rb
35
+ - lib/lang/runtime/class_instance.rb
36
+ - lib/lang/runtime/class_skeleton.rb
37
+ - lib/lang/runtime/context.rb
38
+ - lib/lang/runtime/eleetscript/enumerable.es
39
+ - lib/lang/runtime/eleetscript/falseclass.es
40
+ - lib/lang/runtime/eleetscript/integer.es
41
+ - lib/lang/runtime/eleetscript/list.es
42
+ - lib/lang/runtime/eleetscript/nilclass.es
43
+ - lib/lang/runtime/eleetscript/number.es
44
+ - lib/lang/runtime/eleetscript/object.es
45
+ - lib/lang/runtime/eleetscript/pair.es
46
+ - lib/lang/runtime/eleetscript/que.es
47
+ - lib/lang/runtime/eleetscript/stack.es
48
+ - lib/lang/runtime/eleetscript/string.es
49
+ - lib/lang/runtime/eleetscript/trueclass.es
50
+ - lib/lang/runtime/memory.rb
51
+ - lib/lang/runtime/method.rb
52
+ - lib/lang/runtime/method_hash.rb
53
+ - lib/util/processed_key_hash.rb
54
+ - bin/eleet
55
+ homepage: http://github.com/bbuck/eleetscript
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>'
71
+ - !ruby/object:Gem::Version
72
+ version: 1.3.1
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.1.9
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: EleetScript Engine
79
+ test_files: []