crystalruby 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -0
  3. data/README.md +391 -195
  4. data/Rakefile +4 -3
  5. data/crystalruby.gemspec +2 -2
  6. data/exe/crystalruby +1 -0
  7. data/lib/crystalruby/adapter.rb +131 -65
  8. data/lib/crystalruby/arc_mutex.rb +47 -0
  9. data/lib/crystalruby/compilation.rb +33 -4
  10. data/lib/crystalruby/config.rb +41 -37
  11. data/lib/crystalruby/function.rb +211 -68
  12. data/lib/crystalruby/library.rb +153 -48
  13. data/lib/crystalruby/reactor.rb +40 -23
  14. data/lib/crystalruby/source_reader.rb +86 -0
  15. data/lib/crystalruby/template.rb +16 -5
  16. data/lib/crystalruby/templates/function.cr +11 -10
  17. data/lib/crystalruby/templates/index.cr +53 -66
  18. data/lib/crystalruby/templates/inline_chunk.cr +1 -1
  19. data/lib/crystalruby/templates/ruby_interface.cr +34 -0
  20. data/lib/crystalruby/templates/top_level_function.cr +62 -0
  21. data/lib/crystalruby/templates/top_level_ruby_interface.cr +33 -0
  22. data/lib/crystalruby/typebuilder.rb +11 -55
  23. data/lib/crystalruby/typemaps.rb +92 -67
  24. data/lib/crystalruby/types/concerns/allocator.rb +80 -0
  25. data/lib/crystalruby/types/fixed_width/named_tuple.cr +80 -0
  26. data/lib/crystalruby/types/fixed_width/named_tuple.rb +86 -0
  27. data/lib/crystalruby/types/fixed_width/proc.cr +45 -0
  28. data/lib/crystalruby/types/fixed_width/proc.rb +79 -0
  29. data/lib/crystalruby/types/fixed_width/tagged_union.cr +53 -0
  30. data/lib/crystalruby/types/fixed_width/tagged_union.rb +109 -0
  31. data/lib/crystalruby/types/fixed_width/tuple.cr +82 -0
  32. data/lib/crystalruby/types/fixed_width/tuple.rb +92 -0
  33. data/lib/crystalruby/types/fixed_width.cr +138 -0
  34. data/lib/crystalruby/types/fixed_width.rb +205 -0
  35. data/lib/crystalruby/types/primitive.cr +21 -0
  36. data/lib/crystalruby/types/primitive.rb +117 -0
  37. data/lib/crystalruby/types/primitive_types/bool.cr +34 -0
  38. data/lib/crystalruby/types/primitive_types/bool.rb +11 -0
  39. data/lib/crystalruby/types/primitive_types/nil.cr +35 -0
  40. data/lib/crystalruby/types/primitive_types/nil.rb +16 -0
  41. data/lib/crystalruby/types/primitive_types/numbers.cr +37 -0
  42. data/lib/crystalruby/types/primitive_types/numbers.rb +28 -0
  43. data/lib/crystalruby/types/primitive_types/symbol.cr +55 -0
  44. data/lib/crystalruby/types/primitive_types/symbol.rb +35 -0
  45. data/lib/crystalruby/types/primitive_types/time.cr +35 -0
  46. data/lib/crystalruby/types/primitive_types/time.rb +25 -0
  47. data/lib/crystalruby/types/type.cr +64 -0
  48. data/lib/crystalruby/types/type.rb +239 -30
  49. data/lib/crystalruby/types/variable_width/array.cr +74 -0
  50. data/lib/crystalruby/types/variable_width/array.rb +88 -0
  51. data/lib/crystalruby/types/variable_width/hash.cr +146 -0
  52. data/lib/crystalruby/types/variable_width/hash.rb +117 -0
  53. data/lib/crystalruby/types/variable_width/string.cr +36 -0
  54. data/lib/crystalruby/types/variable_width/string.rb +18 -0
  55. data/lib/crystalruby/types/variable_width.cr +23 -0
  56. data/lib/crystalruby/types/variable_width.rb +46 -0
  57. data/lib/crystalruby/types.rb +32 -13
  58. data/lib/crystalruby/version.rb +2 -2
  59. data/lib/crystalruby.rb +13 -6
  60. metadata +41 -19
  61. data/lib/crystalruby/types/array.rb +0 -15
  62. data/lib/crystalruby/types/bool.rb +0 -3
  63. data/lib/crystalruby/types/hash.rb +0 -17
  64. data/lib/crystalruby/types/named_tuple.rb +0 -28
  65. data/lib/crystalruby/types/nil.rb +0 -3
  66. data/lib/crystalruby/types/numbers.rb +0 -5
  67. data/lib/crystalruby/types/string.rb +0 -3
  68. data/lib/crystalruby/types/symbol.rb +0 -3
  69. data/lib/crystalruby/types/time.rb +0 -8
  70. data/lib/crystalruby/types/tuple.rb +0 -17
  71. data/lib/crystalruby/types/type_serializer/json.rb +0 -41
  72. data/lib/crystalruby/types/type_serializer.rb +0 -37
  73. data/lib/crystalruby/types/typedef.rb +0 -57
  74. data/lib/crystalruby/types/union_type.rb +0 -43
  75. data/lib/module.rb +0 -3
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "type_serializer"
4
-
5
- module CrystalRuby
6
- module Types
7
- class Typedef; end
8
-
9
- def self.Typedef(type)
10
- return type if type.is_a?(Class) && type < Typedef
11
-
12
- Class.new(Typedef) do
13
- define_singleton_method(:union_types) do
14
- [self]
15
- end
16
-
17
- define_singleton_method(:anonymous?) do
18
- name.nil?
19
- end
20
-
21
- define_singleton_method(:valid?) do
22
- type.valid?
23
- end
24
-
25
- define_singleton_method(:type) do
26
- type
27
- end
28
-
29
- define_singleton_method(:type_expr) do
30
- anonymous? ? type.type_expr : name
31
- end
32
-
33
- define_singleton_method(:type_defn) do
34
- type.type_expr
35
- end
36
-
37
- define_singleton_method(:|) do |other|
38
- raise "Cannot union non-crystal type #{other}" unless other.is_a?(Type) || other.is_a?(Typedef)
39
-
40
- UnionType.new(*union_types, *other.union_types)
41
- end
42
-
43
- define_singleton_method(:inspect) do
44
- "<#{name || "AnonymousType"} #{type.inspect}>"
45
- end
46
-
47
- define_singleton_method(:serialize_as) do |format|
48
- TypeSerializer.for(format).new(self)
49
- end
50
-
51
- define_singleton_method(:interpret!) do |raw|
52
- type.interpret!(raw)
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CrystalRuby
4
- module Types
5
- class UnionType < Type
6
- attr_accessor :name, :union_types
7
-
8
- def initialize(*union_types)
9
- self.name = "UnionType"
10
- self.union_types = union_types
11
- end
12
-
13
- def valid?
14
- union_types.all?(&:valid?)
15
- end
16
-
17
- def error
18
- union_types.map(&:error).join(", ")
19
- end
20
-
21
- def inspect
22
- union_types.map(&:inspect).join(" | ")
23
- end
24
-
25
- def interprets?(raw)
26
- union_types.any? { |type| type.interprets?(raw) }
27
- end
28
-
29
- def interpret!(raw)
30
- union_types.each do |type|
31
- next unless type.interprets?(raw)
32
-
33
- begin
34
- return type.interpret!(raw)
35
- rescue StandardError
36
- # Pass
37
- end
38
- end
39
- raise "Invalid deserialized value #{raw} for type #{inspect}"
40
- end
41
- end
42
- end
43
- end
data/lib/module.rb DELETED
@@ -1,3 +0,0 @@
1
- class Module
2
- prepend CrystalRuby::Adapter
3
- end