rltk 2.2.1 → 3.0.0

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 (59) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +12 -12
  3. data/README.md +458 -285
  4. data/Rakefile +99 -92
  5. data/lib/rltk/ast.rb +221 -126
  6. data/lib/rltk/cfg.rb +218 -239
  7. data/lib/rltk/cg/basic_block.rb +1 -1
  8. data/lib/rltk/cg/bindings.rb +9 -26
  9. data/lib/rltk/cg/builder.rb +40 -8
  10. data/lib/rltk/cg/context.rb +1 -1
  11. data/lib/rltk/cg/contractor.rb +51 -0
  12. data/lib/rltk/cg/execution_engine.rb +45 -8
  13. data/lib/rltk/cg/function.rb +12 -2
  14. data/lib/rltk/cg/generated_bindings.rb +2541 -575
  15. data/lib/rltk/cg/generic_value.rb +2 -2
  16. data/lib/rltk/cg/instruction.rb +104 -83
  17. data/lib/rltk/cg/llvm.rb +44 -3
  18. data/lib/rltk/cg/memory_buffer.rb +22 -5
  19. data/lib/rltk/cg/module.rb +85 -36
  20. data/lib/rltk/cg/old_generated_bindings.rb +6152 -0
  21. data/lib/rltk/cg/pass_manager.rb +87 -43
  22. data/lib/rltk/cg/support.rb +2 -4
  23. data/lib/rltk/cg/target.rb +158 -28
  24. data/lib/rltk/cg/triple.rb +8 -8
  25. data/lib/rltk/cg/type.rb +69 -25
  26. data/lib/rltk/cg/value.rb +107 -66
  27. data/lib/rltk/cg.rb +16 -17
  28. data/lib/rltk/lexer.rb +21 -11
  29. data/lib/rltk/lexers/calculator.rb +1 -1
  30. data/lib/rltk/lexers/ebnf.rb +8 -7
  31. data/lib/rltk/parser.rb +300 -247
  32. data/lib/rltk/parsers/infix_calc.rb +1 -1
  33. data/lib/rltk/parsers/postfix_calc.rb +2 -2
  34. data/lib/rltk/parsers/prefix_calc.rb +2 -2
  35. data/lib/rltk/token.rb +1 -2
  36. data/lib/rltk/version.rb +3 -3
  37. data/lib/rltk.rb +6 -6
  38. data/test/cg/tc_basic_block.rb +83 -0
  39. data/test/cg/tc_control_flow.rb +191 -0
  40. data/test/cg/tc_function.rb +54 -0
  41. data/test/cg/tc_generic_value.rb +33 -0
  42. data/test/cg/tc_instruction.rb +256 -0
  43. data/test/cg/tc_llvm.rb +25 -0
  44. data/test/cg/tc_math.rb +88 -0
  45. data/test/cg/tc_module.rb +89 -0
  46. data/test/cg/tc_transforms.rb +68 -0
  47. data/test/cg/tc_type.rb +69 -0
  48. data/test/cg/tc_value.rb +151 -0
  49. data/test/cg/ts_cg.rb +23 -0
  50. data/test/tc_ast.rb +105 -8
  51. data/test/tc_cfg.rb +63 -48
  52. data/test/tc_lexer.rb +84 -96
  53. data/test/tc_parser.rb +224 -52
  54. data/test/tc_token.rb +6 -6
  55. data/test/ts_rltk.rb +12 -15
  56. metadata +149 -75
  57. data/lib/rltk/cg/generated_extended_bindings.rb +0 -287
  58. data/lib/rltk/util/abstract_class.rb +0 -25
  59. data/lib/rltk/util/monkeys.rb +0 -129
@@ -1,129 +0,0 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
2
- # Project: Ruby Language Toolkit
3
- # Date: 2012/03/08
4
- # Description: This file holds various monkey patches that make coding easier.
5
-
6
- ############
7
- # Requires #
8
- ############
9
-
10
- ###########
11
- # Methods #
12
- ###########
13
-
14
- # A helper method for type checking Ruby values.
15
- #
16
- # @param [Object] o Object to type check.
17
- # @param [Class] type Class the object should be an instance of.
18
- # @param [String, nil] blame Variable name to blame for failed type checks.
19
- # @param [Boolean] strict Strict or non-strict checking. Uses `instance_of?` and `is_a?` respectively.
20
- #
21
- # @raise [ArgumentError] An error is raise if the type checking fails.
22
- #
23
- # @return [Object] The object passed as parameter o.
24
- def check_type(o, type, blame = nil, strict = false)
25
- type_ok = if strict then o.instance_of?(type) else o.is_a?(type) end
26
-
27
- if type_ok
28
- o
29
- else
30
- if blame
31
- raise ArgumentError, "Parameter #{blame} must be an instance of the #{type.name} class. Received an instance of #{o.class.name}."
32
- else
33
- raise ArgumentError, "Expected an object of type #{type.name}. Received an instance of #{o.class.name}."
34
- end
35
- end
36
- end
37
-
38
- # A helper method for type checking Ruby array values.
39
- #
40
- # @param [Array<Object>] array Array of objects to type check.
41
- # @param [Class] type Class the objects should be an instance of.
42
- # @param [String, nil] blame Variable name to blame for failed type checks.
43
- # @param [Boolean] strict Strict or non-strict checking. Uses `instance_of?` and `is_a?` respectively.
44
- #
45
- # @raise [ArgumentError] An error is raise if the type checking fails.
46
- #
47
- # @return [Object] The object passed in parameter o.
48
- def check_array_type(array, type, blame = nil, strict = false)
49
- array.each do |o|
50
- type_ok = if strict then o.instance_of?(type) else o.is_a?(type) end
51
-
52
- if not type_ok
53
- if blame
54
- raise ArgumentError, "Parameter #{blame} must contain instances of the #{type.name} class."
55
- else
56
- raise ArgumentError, "Expected an object of type #{type.name}."
57
- end
58
- end
59
- end
60
- end
61
-
62
- #######################
63
- # Classes and Modules #
64
- #######################
65
-
66
- # Monkey-patched Object class.
67
- class Object
68
- # Simple implementation of the Y combinator.
69
- #
70
- # @param [Object] value Value to be returned after executing the provided block.
71
- #
72
- # @return [Object] The object passed in parameter value.
73
- def returning(value)
74
- yield(value)
75
- value
76
- end
77
- end
78
-
79
- # Monkey-patched Class class.
80
- class Class
81
- # Checks for module inclusion.
82
- #
83
- # @param [Module] mod Module to check the inclusion of.
84
- def includes_module?(mod)
85
- self.included_modules.include?(mod)
86
- end
87
-
88
- # @return [String] Name of class without the namespace.
89
- def short_name
90
- self.name.split('::').last
91
- end
92
-
93
- # Checks to see if a Class object is a subclass of the given class.
94
- #
95
- # @param [Class] klass Class we are checking if this is a subclass of.
96
- def subclass_of?(klass)
97
- raise 'The klass parameter must be an instance of Class.' if not klass.is_a?(Class)
98
-
99
- if (superklass = self.superclass)
100
- superklass == klass or superklass.subclass_of?(klass)
101
- else
102
- false
103
- end
104
- end
105
- end
106
-
107
- # Monkey-patchec Integer class.
108
- class Integer
109
- # @return [Boolean] This Integer as a Boolean value.
110
- def to_bool
111
- self != 0
112
- end
113
- end
114
-
115
- # Monkey-patched TrueClass class.
116
- class TrueClass
117
- # @return [1]
118
- def to_i
119
- 1
120
- end
121
- end
122
-
123
- # Monkey-patched FalseClass class.
124
- class FalseClass
125
- # @return [0]
126
- def to_i
127
- 0
128
- end
129
- end