carbon-core 0.1.1 → 0.2.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +17 -0
  3. data/.gitignore +0 -0
  4. data/.rspec +0 -0
  5. data/.rubocop.yml +0 -0
  6. data/.travis.yml +0 -0
  7. data/.yardopts +0 -0
  8. data/CODE_OF_CONDUCT.md +0 -0
  9. data/Gemfile +0 -0
  10. data/LICENSE.txt +0 -0
  11. data/README.md +0 -0
  12. data/Rakefile +0 -0
  13. data/Vagrantfile +0 -0
  14. data/carbon.gemspec +0 -0
  15. data/lib/carbon.rb +25 -1
  16. data/lib/carbon/concrete.rb +4 -2
  17. data/lib/carbon/concrete/build.rb +21 -13
  18. data/lib/carbon/concrete/index.rb +53 -159
  19. data/lib/carbon/concrete/item.rb +0 -0
  20. data/lib/carbon/concrete/item/base.rb +14 -27
  21. data/lib/carbon/concrete/item/class.rb +71 -0
  22. data/lib/carbon/concrete/item/class/element.rb +42 -0
  23. data/lib/carbon/concrete/item/data.rb +0 -0
  24. data/lib/carbon/concrete/item/function.rb +35 -39
  25. data/lib/carbon/concrete/item/internal.rb +17 -19
  26. data/lib/carbon/concrete/item/struct.rb +12 -7
  27. data/lib/carbon/concrete/item/struct/element.rb +0 -0
  28. data/lib/carbon/concrete/item/trait.rb +9 -10
  29. data/lib/carbon/concrete/item/trait/expectation.rb +0 -0
  30. data/lib/carbon/concrete/request.rb +137 -136
  31. data/lib/carbon/concrete/type.rb +126 -21
  32. data/lib/carbon/concrete/type/function.rb +26 -10
  33. data/lib/carbon/concrete/type/generic.rb +19 -3
  34. data/lib/carbon/concrete/type/name.rb +0 -0
  35. data/lib/carbon/concrete/type/parse.rb +1 -0
  36. data/lib/carbon/concrete/type/part.rb +9 -1
  37. data/lib/carbon/core.rb +6 -1
  38. data/lib/carbon/core/int.rb +0 -0
  39. data/lib/carbon/core/integer.rb +0 -0
  40. data/lib/carbon/core/integer/cast.rb +0 -0
  41. data/lib/carbon/core/integer/math.rb +0 -0
  42. data/lib/carbon/core/integer/misc.rb +17 -1
  43. data/lib/carbon/core/integer/pole.rb +0 -0
  44. data/lib/carbon/core/integer/ship.rb +8 -4
  45. data/lib/carbon/core/integer/sign.rb +0 -0
  46. data/lib/carbon/core/integer/type.rb +0 -0
  47. data/lib/carbon/core/integer/zero.rb +0 -0
  48. data/lib/carbon/core/main.rb +50 -0
  49. data/lib/carbon/core/pointer.rb +0 -0
  50. data/lib/carbon/core/pointer/access.rb +1 -1
  51. data/lib/carbon/core/pointer/cast.rb +0 -0
  52. data/lib/carbon/core/pointer/math.rb +14 -0
  53. data/lib/carbon/core/pointer/memory.rb +2 -4
  54. data/lib/carbon/core/pointer/type.rb +0 -0
  55. data/lib/carbon/core/void.rb +20 -0
  56. data/lib/carbon/counter.rb +27 -0
  57. data/lib/carbon/errors.rb +13 -0
  58. data/lib/carbon/tacky.rb +0 -0
  59. data/lib/carbon/tacky/block.rb +0 -0
  60. data/lib/carbon/tacky/builder.rb +3 -6
  61. data/lib/carbon/tacky/context.rb +4 -10
  62. data/lib/carbon/tacky/function.rb +0 -24
  63. data/lib/carbon/tacky/instruction.rb +2 -5
  64. data/lib/carbon/tacky/instruction/generation.rb +19 -41
  65. data/lib/carbon/tacky/parameter.rb +0 -0
  66. data/lib/carbon/tacky/reference.rb +0 -0
  67. data/lib/carbon/tacky/typed.rb +0 -0
  68. data/lib/carbon/tacky/value.rb +0 -2
  69. data/lib/carbon/version.rb +1 -1
  70. data/scripts/core.rb +0 -0
  71. data/scripts/test.rb +5 -7
  72. metadata +9 -4
  73. data/lib/carbon/tacky/instruction/dependencies.rb +0 -33
  74. data/lib/carbon/tacky/instruction/typeof.rb +0 -25
data/lib/carbon/tacky.rb CHANGED
File without changes
File without changes
@@ -288,12 +288,9 @@ module Carbon
288
288
  _call(:_null, type)
289
289
  end
290
290
 
291
- def typeof(value)
292
- _call(:_typeof, value)
293
- end
294
-
295
- def mcall(mod, name, *params)
296
- _call(:_mcall, mod, name, *params)
291
+ def deref(type)
292
+ fail
293
+ _call(:_deref, type)
297
294
  end
298
295
 
299
296
  # Creates an instruction, and returns a reference to that instruction.
@@ -41,13 +41,11 @@ module Carbon
41
41
  # @return [Concrete::Build]
42
42
  attr_reader :build
43
43
 
44
- # (see Concrete::Build#types)
45
- attr_reader :types
46
- def_delegator :@build, :types
44
+ # (see Concrete::Build#items)
45
+ attr_reader :items
46
+ def_delegator :@build, :items
47
47
 
48
- # (see Concrete::Build#functions)
49
- attr_reader :functions
50
- def_delegator :@build, :functions
48
+ def_delegator :@build, :fetch
51
49
 
52
50
  # Returns the function that this is being built for.
53
51
  #
@@ -68,10 +66,6 @@ module Carbon
68
66
  @params = []
69
67
  freeze
70
68
  end
71
-
72
- def find(name)
73
- name.function? ? functions.fetch(name).last : types.fetch(name).last
74
- end
75
69
  end
76
70
  end
77
71
  end
@@ -10,30 +10,6 @@ module Carbon
10
10
  #
11
11
  # @api semiprivate
12
12
  class Function
13
- # A mutable counter for giving out instruction ids. This makes it so
14
- # that _all_ instruction ids are unique for every function.
15
- #
16
- # @api private
17
- class Counter
18
- # The value.
19
- # @return [::Numeric]
20
- attr_reader :value
21
-
22
- # Initialize the counter.
23
- #
24
- # @param value [::Numeric] The initial value of the counter.
25
- def initialize(value = 0)
26
- @value = value
27
- end
28
-
29
- # Increments the counter by one, and returns the new value.
30
- #
31
- # @return [::Numeric]
32
- def increment
33
- @value += 1
34
- end
35
- end
36
-
37
13
  # The basic blocks of the function. The first block is expected to be
38
14
  # the entry block; the rest can be in any order.
39
15
  #
@@ -1,8 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
- #
3
+
4
4
  require "carbon/tacky/instruction/generation"
5
- require "carbon/tacky/instruction/typeof"
6
5
 
7
6
  module Carbon
8
7
  module Tacky
@@ -10,7 +9,6 @@ module Carbon
10
9
  # structures. Each instruction performs some sort of action.
11
10
  class Instruction < Value
12
11
  include Instruction::Generation
13
- include Instruction::Typeof
14
12
  # Instructions that can be represented by this class that can have a
15
13
  # name parameter.
16
14
  #
@@ -66,9 +64,8 @@ module Carbon
66
64
  def call(context, block)
67
65
  case @instruction
68
66
  when "_null" then generate_null(context, block)
69
- when "_mcall" then generate_mcall(context, block)
70
67
  when "_sizeof" then generate_sizeof(context, block)
71
- when "_typeof" then generate_typeof(context, block)
68
+ when "_deref" then generate_deref(context, block)
72
69
  else generate_normal(context, block)
73
70
  end
74
71
  end
@@ -3,10 +3,9 @@
3
3
 
4
4
  module Carbon
5
5
  module Tacky
6
- class Instruction < Value
6
+ class Instruction < Value
7
7
  # Generation logic for instructions.
8
8
  module Generation
9
-
10
9
  private
11
10
 
12
11
  # Generates a "normal" instruction. It maps the parameters, then sends
@@ -18,7 +17,7 @@ module Carbon
18
17
  # @return [::LLVM::Value] The result of the llvm instruction.
19
18
  def generate_normal(context, block)
20
19
  params = mapped_parameters(context)
21
- value = nil
20
+ value = :_
22
21
 
23
22
  block.build { |b| value = b.public_send(@instruction, *params) }
24
23
  value
@@ -26,64 +25,43 @@ module Carbon
26
25
 
27
26
  def generate_null(context, _block)
28
27
  params = mapped_parameters(context)
29
- context.find(params.first).null
28
+ params.first.null
30
29
  end
31
30
 
32
31
  def generate_sizeof(context, _block)
33
32
  params = mapped_parameters(context)
34
- context.find(params.first).size
35
- end
36
-
37
- def generate_typeof(context, block)
38
- context.find(typeof_value(@parameters.first, context))
39
- end
40
-
41
- # [Concrete::Type, String | Symbol, *Value]
42
- def generate_mcall(context, block)
43
- mod, name = @parameters[0..1]
44
- types = @parameters[2..-1].map { |p| typeof_value(p, context) }
45
- fname = mod.call(name, types)
46
- item, func = context.functions.fetch(fname)
47
- params = @parameters[2..-1].map { |p| mapped_parameter(p, context) }
48
- result = nil
49
-
50
- block.build { |b| result = b.call(func, *params) }
51
- context.type(result, item.return)
33
+ params.first.size
52
34
  end
53
35
 
54
- # [Value, String | Symbol, *Value]
55
- def generate_ucall(context, block)
56
- mod = typeof_value(@parameters[0], context, block)
57
- name = @parameters[1]
58
- types = @parameters[2..-1].map { |p| typeof_value(p, context) }
59
- fname = mod.call(name, [mod, *types])
60
- item, func = context.functions.fetch(fname)
61
- params = [@parameters[0], *@parameters[2..-1]]
62
- .map { |p| mapped_parameter(p, context) }
63
- result = nil
64
-
65
- block.build { |b| result = b.call(func, params) }
66
- concrete.type(result, item.return)
36
+ def generate_deref(context, _block)
37
+ mapped_parameter(@parameters.first, context).element_type
67
38
  end
68
39
 
69
40
  def mapped_parameters(context)
70
41
  @parameters.map { |p| mapped_parameter(p, context) }
71
42
  end
72
43
 
73
- # rubocop:disable Metrics/CyclomaticComplexity
44
+ def typeof_value(value, context)
45
+ case value
46
+ when Concrete::Type
47
+ value.sub(context.generics)
48
+ when Tacky::Typed, Tacky::Parameter
49
+ value.type.sub(context.generics)
50
+ else fail ArgumentError, "Cannot typeof #{value.class}"
51
+ end
52
+ end
53
+
74
54
  def mapped_parameter(param, context)
75
55
  case param
76
- when Concrete::Type then context.find(param)
56
+ when Concrete::Type
57
+ context.fetch(param.sub(context.generics)).last
77
58
  when Tacky::Reference then context.instructions.fetch(param.id)
78
59
  when Tacky::Parameter then context.params.fetch(param.value)
79
60
  when Tacky::Typed then mapped_parameter(param.value, context)
80
- when ::Integer then LLVM.Int(param)
81
- when ::Float then LLVM.Float(param)
82
- when ::String then param
61
+ when ::Integer, ::Float, ::String, ::LLVM::Value then param
83
62
  else fail ArgumentError, "Unexpected parameter #{param.class}"
84
63
  end
85
64
  end
86
- # rubocop:enable Metrics/CyclomaticComplexity
87
65
  end
88
66
  end
89
67
  end
File without changes
File without changes
File without changes
@@ -4,8 +4,6 @@
4
4
  module Carbon
5
5
  module Tacky
6
6
  # A "value." A value can be a parameter, a reference, or a number.
7
- #
8
- # @todo TODO: Figure out if I still need this.
9
7
  class Value
10
8
  # The name of the value. This can be set in order to make the resulting
11
9
  # LLVM IR pretty.
@@ -5,5 +5,5 @@ module Carbon
5
5
  # The version of Carbon.
6
6
  #
7
7
  # @return [::String]
8
- VERSION = "0.1.1".freeze
8
+ VERSION = "0.2.0".freeze
9
9
  end
data/scripts/core.rb CHANGED
File without changes
data/scripts/test.rb CHANGED
@@ -9,11 +9,9 @@ require "pry"
9
9
  require "pry/rescue"
10
10
  require "carbon"
11
11
 
12
- Pry.rescue do
13
- index = Carbon::Core.finalize
14
- add = index.fetch("Carbon::UInt32.+(Carbon::UInt32, Carbon::Int32)")
15
- build = Carbon::Concrete::Build.new(index.build(add), index)
12
+ index = Carbon::Core.finalize
13
+ add = index.fetch("Carbon::UInt32.+(Carbon::UInt32, Carbon::Int32)")
14
+ build = Carbon::Concrete::Build.new(index.build(add), index)
16
15
 
17
- build.call
18
- puts build.module
19
- end
16
+ build.call
17
+ puts build.module
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carbon-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-03 00:00:00.000000000 Z
11
+ date: 2016-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -101,6 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".gitattributes"
104
105
  - ".gitignore"
105
106
  - ".rspec"
106
107
  - ".rubocop.yml"
@@ -119,6 +120,8 @@ files:
119
120
  - lib/carbon/concrete/index.rb
120
121
  - lib/carbon/concrete/item.rb
121
122
  - lib/carbon/concrete/item/base.rb
123
+ - lib/carbon/concrete/item/class.rb
124
+ - lib/carbon/concrete/item/class/element.rb
122
125
  - lib/carbon/concrete/item/data.rb
123
126
  - lib/carbon/concrete/item/function.rb
124
127
  - lib/carbon/concrete/item/internal.rb
@@ -144,21 +147,23 @@ files:
144
147
  - lib/carbon/core/integer/sign.rb
145
148
  - lib/carbon/core/integer/type.rb
146
149
  - lib/carbon/core/integer/zero.rb
150
+ - lib/carbon/core/main.rb
147
151
  - lib/carbon/core/pointer.rb
148
152
  - lib/carbon/core/pointer/access.rb
149
153
  - lib/carbon/core/pointer/cast.rb
150
154
  - lib/carbon/core/pointer/math.rb
151
155
  - lib/carbon/core/pointer/memory.rb
152
156
  - lib/carbon/core/pointer/type.rb
157
+ - lib/carbon/core/void.rb
158
+ - lib/carbon/counter.rb
159
+ - lib/carbon/errors.rb
153
160
  - lib/carbon/tacky.rb
154
161
  - lib/carbon/tacky/block.rb
155
162
  - lib/carbon/tacky/builder.rb
156
163
  - lib/carbon/tacky/context.rb
157
164
  - lib/carbon/tacky/function.rb
158
165
  - lib/carbon/tacky/instruction.rb
159
- - lib/carbon/tacky/instruction/dependencies.rb
160
166
  - lib/carbon/tacky/instruction/generation.rb
161
- - lib/carbon/tacky/instruction/typeof.rb
162
167
  - lib/carbon/tacky/parameter.rb
163
168
  - lib/carbon/tacky/reference.rb
164
169
  - lib/carbon/tacky/typed.rb
@@ -1,33 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module Carbon
5
- module Tacky
6
- class Instruction < Value
7
- module Dependencies
8
- def dependencies
9
- case @instruction
10
- when "_mcall" then dependencies_mcall
11
- when "_ucall" then dependencies_ucall
12
- when "_typeof" then dependencies_typeof
13
- else dependencies_normal
14
- end
15
- end
16
-
17
- private
18
-
19
- def dependencies_mcall
20
- deps = Set.new
21
- mod = @parameters[0]
22
- types = @parameters[2..-1].map { }
23
- @function = mod.call(@parameters[1])
24
- deps << @parameters[0]
25
- end
26
-
27
- def dependencies_normal
28
- @parameters.select { |p| p.is_a?(Concrete::Type) }.inject(Set.new, :<<)
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module Carbon
5
- module Tacky
6
- class Instruction < Value
7
- module Typeof
8
- # rubocop:disable Metrics/CyclomaticComplexity
9
- def typeof_value(value, context)
10
- case value
11
- when Concrete::Type then value
12
- when Tacky::Reference then fail NotImplementedError
13
- when Tacky::Parameter then context.function.params[value.value].type
14
- when Tacky::Typed then value.type
15
- when ::Integer then Carbon::Type("Carbon::Int32")
16
- when ::Float then Carbon::Type("Carbon::Float")
17
- when ::String then Carbon::Type("Carbon::String")
18
- else fail ArgumentError, "Cannot typeof #{value.class}"
19
- end
20
- end
21
- # rubocop:enable Metrics/CyclomaticComplexity
22
- end
23
- end
24
- end
25
- end