carbon-core 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.rspec +0 -0
  4. data/.rubocop.yml +0 -0
  5. data/.travis.yml +0 -0
  6. data/.yardopts +0 -0
  7. data/CODE_OF_CONDUCT.md +0 -0
  8. data/Gemfile +0 -0
  9. data/LICENSE.txt +0 -0
  10. data/README.md +0 -0
  11. data/Rakefile +0 -0
  12. data/Vagrantfile +83 -0
  13. data/carbon.gemspec +1 -1
  14. data/lib/carbon.rb +3 -2
  15. data/lib/carbon/concrete.rb +0 -0
  16. data/lib/carbon/concrete/build.rb +1 -1
  17. data/lib/carbon/concrete/index.rb +37 -13
  18. data/lib/carbon/concrete/item.rb +0 -0
  19. data/lib/carbon/concrete/item/base.rb +11 -0
  20. data/lib/carbon/concrete/item/data.rb +0 -0
  21. data/lib/carbon/concrete/item/function.rb +13 -1
  22. data/lib/carbon/concrete/item/internal.rb +0 -0
  23. data/lib/carbon/concrete/item/struct.rb +0 -0
  24. data/lib/carbon/concrete/item/struct/element.rb +0 -0
  25. data/lib/carbon/concrete/item/trait.rb +0 -0
  26. data/lib/carbon/concrete/item/trait/expectation.rb +0 -0
  27. data/lib/carbon/concrete/request.rb +0 -0
  28. data/lib/carbon/concrete/type.rb +0 -0
  29. data/lib/carbon/concrete/type/function.rb +0 -0
  30. data/lib/carbon/concrete/type/generic.rb +0 -0
  31. data/lib/carbon/concrete/type/name.rb +0 -0
  32. data/lib/carbon/concrete/type/parse.rb +0 -0
  33. data/lib/carbon/concrete/type/part.rb +0 -0
  34. data/lib/carbon/core.rb +1 -1
  35. data/lib/carbon/core/int.rb +0 -0
  36. data/lib/carbon/core/integer.rb +0 -0
  37. data/lib/carbon/core/integer/cast.rb +4 -4
  38. data/lib/carbon/core/integer/math.rb +11 -10
  39. data/lib/carbon/core/integer/misc.rb +6 -5
  40. data/lib/carbon/core/integer/pole.rb +9 -7
  41. data/lib/carbon/core/integer/ship.rb +4 -2
  42. data/lib/carbon/core/integer/sign.rb +0 -0
  43. data/lib/carbon/core/integer/type.rb +0 -0
  44. data/lib/carbon/core/integer/zero.rb +2 -2
  45. data/lib/carbon/core/pointer.rb +0 -0
  46. data/lib/carbon/core/pointer/access.rb +7 -4
  47. data/lib/carbon/core/pointer/cast.rb +1 -1
  48. data/lib/carbon/core/pointer/math.rb +12 -10
  49. data/lib/carbon/core/pointer/memory.rb +4 -4
  50. data/lib/carbon/core/pointer/type.rb +0 -0
  51. data/lib/carbon/tacky.rb +1 -0
  52. data/lib/carbon/tacky/block.rb +0 -0
  53. data/lib/carbon/tacky/builder.rb +14 -2
  54. data/lib/carbon/tacky/context.rb +12 -1
  55. data/lib/carbon/tacky/function.rb +1 -1
  56. data/lib/carbon/tacky/instruction.rb +9 -54
  57. data/lib/carbon/tacky/instruction/dependencies.rb +33 -0
  58. data/lib/carbon/tacky/instruction/generation.rb +90 -0
  59. data/lib/carbon/tacky/instruction/typeof.rb +25 -0
  60. data/lib/carbon/tacky/parameter.rb +0 -0
  61. data/lib/carbon/tacky/reference.rb +4 -0
  62. data/lib/carbon/tacky/typed.rb +25 -0
  63. data/lib/carbon/tacky/value.rb +0 -0
  64. data/lib/carbon/version.rb +1 -1
  65. data/scripts/core.rb +9 -0
  66. data/scripts/test.rb +19 -0
  67. metadata +12 -5
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Carbon
5
+ module Tacky
6
+ class Instruction < Value
7
+ # Generation logic for instructions.
8
+ module Generation
9
+
10
+ private
11
+
12
+ # Generates a "normal" instruction. It maps the parameters, then sends
13
+ # the instruction over to a builder for LLVM, before returning the
14
+ # result of the instruction.
15
+ #
16
+ # @param context [Tacky::Context] The context.
17
+ # @param block [::LLVM::BasicBlock] The block.
18
+ # @return [::LLVM::Value] The result of the llvm instruction.
19
+ def generate_normal(context, block)
20
+ params = mapped_parameters(context)
21
+ value = nil
22
+
23
+ block.build { |b| value = b.public_send(@instruction, *params) }
24
+ value
25
+ end
26
+
27
+ def generate_null(context, _block)
28
+ params = mapped_parameters(context)
29
+ context.find(params.first).null
30
+ end
31
+
32
+ def generate_sizeof(context, _block)
33
+ 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)
52
+ end
53
+
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)
67
+ end
68
+
69
+ def mapped_parameters(context)
70
+ @parameters.map { |p| mapped_parameter(p, context) }
71
+ end
72
+
73
+ # rubocop:disable Metrics/CyclomaticComplexity
74
+ def mapped_parameter(param, context)
75
+ case param
76
+ when Concrete::Type then context.find(param)
77
+ when Tacky::Reference then context.instructions.fetch(param.id)
78
+ when Tacky::Parameter then context.params.fetch(param.value)
79
+ 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
83
+ else fail ArgumentError, "Unexpected parameter #{param.class}"
84
+ end
85
+ end
86
+ # rubocop:enable Metrics/CyclomaticComplexity
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,25 @@
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
File without changes
@@ -18,6 +18,10 @@ module Carbon
18
18
  def initialize(id)
19
19
  @id = id
20
20
  end
21
+
22
+ def as(type)
23
+ Tacky::Typed.new(self, type)
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Carbon
5
+ module Tacky
6
+ Typed = Struct.new(:value, :type) do
7
+ INT32 = Carbon::Type("Carbon::Int32")
8
+ STRING = Carbon::Type("Carbon::String")
9
+ FLOAT = Carbon::Type("Carbon::Float")
10
+
11
+ def self.from(value)
12
+ case value
13
+ when Concrete::Type, Tacky::Typed then value
14
+ when Tacky::Parameter then new(value, value.type)
15
+ when Tacky::Reference then fail NotImplementedError
16
+ when Tacky::Block then nil
17
+ when ::Integer then new(value, INT32)
18
+ when ::Float then new(value, FLOAT)
19
+ when ::String, ::Symbol then new(value, STRING)
20
+ else fail ArgumentError, "Cannot guess type for #{value.class}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
File without changes
@@ -5,5 +5,5 @@ module Carbon
5
5
  # The version of Carbon.
6
6
  #
7
7
  # @return [::String]
8
- VERSION = "0.1.0".freeze
8
+ VERSION = "0.1.1".freeze
9
9
  end
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path("../../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "pry"
6
+ require "pry/rescue"
7
+ require "carbon"
8
+
9
+ index = Carbon::Core.index
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ # frozen_string_literal: true
4
+
5
+ lib = File.expand_path("../../lib", __FILE__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require "ruby-prof"
8
+ require "pry"
9
+ require "pry/rescue"
10
+ require "carbon"
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)
16
+
17
+ build.call
18
+ puts build.module
19
+ end
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.0
4
+ version: 0.1.1
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-07-25 00:00:00.000000000 Z
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.1'
69
69
  - !ruby/object:Gem::Dependency
70
- name: msgpack
70
+ name: oj
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.0'
75
+ version: '2.17'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.0'
82
+ version: '2.17'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: ice_nine
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -111,6 +111,7 @@ files:
111
111
  - LICENSE.txt
112
112
  - README.md
113
113
  - Rakefile
114
+ - Vagrantfile
114
115
  - carbon.gemspec
115
116
  - lib/carbon.rb
116
117
  - lib/carbon/concrete.rb
@@ -155,10 +156,16 @@ files:
155
156
  - lib/carbon/tacky/context.rb
156
157
  - lib/carbon/tacky/function.rb
157
158
  - lib/carbon/tacky/instruction.rb
159
+ - lib/carbon/tacky/instruction/dependencies.rb
160
+ - lib/carbon/tacky/instruction/generation.rb
161
+ - lib/carbon/tacky/instruction/typeof.rb
158
162
  - lib/carbon/tacky/parameter.rb
159
163
  - lib/carbon/tacky/reference.rb
164
+ - lib/carbon/tacky/typed.rb
160
165
  - lib/carbon/tacky/value.rb
161
166
  - lib/carbon/version.rb
167
+ - scripts/core.rb
168
+ - scripts/test.rb
162
169
  homepage: https://github.com/carbon-lang/core
163
170
  licenses:
164
171
  - MIT