crystalruby 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/README.md +391 -195
- data/Rakefile +4 -3
- data/crystalruby.gemspec +2 -2
- data/exe/crystalruby +1 -0
- data/lib/crystalruby/adapter.rb +131 -65
- data/lib/crystalruby/arc_mutex.rb +47 -0
- data/lib/crystalruby/compilation.rb +33 -4
- data/lib/crystalruby/config.rb +41 -37
- data/lib/crystalruby/function.rb +211 -68
- data/lib/crystalruby/library.rb +153 -48
- data/lib/crystalruby/reactor.rb +40 -23
- data/lib/crystalruby/source_reader.rb +86 -0
- data/lib/crystalruby/template.rb +16 -5
- data/lib/crystalruby/templates/function.cr +11 -10
- data/lib/crystalruby/templates/index.cr +53 -66
- data/lib/crystalruby/templates/inline_chunk.cr +1 -1
- data/lib/crystalruby/templates/ruby_interface.cr +34 -0
- data/lib/crystalruby/templates/top_level_function.cr +62 -0
- data/lib/crystalruby/templates/top_level_ruby_interface.cr +33 -0
- data/lib/crystalruby/typebuilder.rb +11 -55
- data/lib/crystalruby/typemaps.rb +92 -67
- data/lib/crystalruby/types/concerns/allocator.rb +80 -0
- data/lib/crystalruby/types/fixed_width/named_tuple.cr +80 -0
- data/lib/crystalruby/types/fixed_width/named_tuple.rb +86 -0
- data/lib/crystalruby/types/fixed_width/proc.cr +45 -0
- data/lib/crystalruby/types/fixed_width/proc.rb +79 -0
- data/lib/crystalruby/types/fixed_width/tagged_union.cr +53 -0
- data/lib/crystalruby/types/fixed_width/tagged_union.rb +109 -0
- data/lib/crystalruby/types/fixed_width/tuple.cr +82 -0
- data/lib/crystalruby/types/fixed_width/tuple.rb +92 -0
- data/lib/crystalruby/types/fixed_width.cr +138 -0
- data/lib/crystalruby/types/fixed_width.rb +205 -0
- data/lib/crystalruby/types/primitive.cr +21 -0
- data/lib/crystalruby/types/primitive.rb +117 -0
- data/lib/crystalruby/types/primitive_types/bool.cr +34 -0
- data/lib/crystalruby/types/primitive_types/bool.rb +11 -0
- data/lib/crystalruby/types/primitive_types/nil.cr +35 -0
- data/lib/crystalruby/types/primitive_types/nil.rb +16 -0
- data/lib/crystalruby/types/primitive_types/numbers.cr +37 -0
- data/lib/crystalruby/types/primitive_types/numbers.rb +28 -0
- data/lib/crystalruby/types/primitive_types/symbol.cr +55 -0
- data/lib/crystalruby/types/primitive_types/symbol.rb +35 -0
- data/lib/crystalruby/types/primitive_types/time.cr +35 -0
- data/lib/crystalruby/types/primitive_types/time.rb +25 -0
- data/lib/crystalruby/types/type.cr +64 -0
- data/lib/crystalruby/types/type.rb +239 -30
- data/lib/crystalruby/types/variable_width/array.cr +74 -0
- data/lib/crystalruby/types/variable_width/array.rb +88 -0
- data/lib/crystalruby/types/variable_width/hash.cr +146 -0
- data/lib/crystalruby/types/variable_width/hash.rb +117 -0
- data/lib/crystalruby/types/variable_width/string.cr +36 -0
- data/lib/crystalruby/types/variable_width/string.rb +18 -0
- data/lib/crystalruby/types/variable_width.cr +23 -0
- data/lib/crystalruby/types/variable_width.rb +46 -0
- data/lib/crystalruby/types.rb +32 -13
- data/lib/crystalruby/version.rb +2 -2
- data/lib/crystalruby.rb +13 -6
- metadata +41 -19
- data/lib/crystalruby/types/array.rb +0 -15
- data/lib/crystalruby/types/bool.rb +0 -3
- data/lib/crystalruby/types/hash.rb +0 -17
- data/lib/crystalruby/types/named_tuple.rb +0 -28
- data/lib/crystalruby/types/nil.rb +0 -3
- data/lib/crystalruby/types/numbers.rb +0 -5
- data/lib/crystalruby/types/string.rb +0 -3
- data/lib/crystalruby/types/symbol.rb +0 -3
- data/lib/crystalruby/types/time.rb +0 -8
- data/lib/crystalruby/types/tuple.rb +0 -17
- data/lib/crystalruby/types/type_serializer/json.rb +0 -41
- data/lib/crystalruby/types/type_serializer.rb +0 -37
- data/lib/crystalruby/types/typedef.rb +0 -57
- data/lib/crystalruby/types/union_type.rb +0 -43
- 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