carbon-core 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/.rspec +0 -0
- data/.rubocop.yml +0 -0
- data/.travis.yml +0 -0
- data/.yardopts +0 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/Vagrantfile +83 -0
- data/carbon.gemspec +1 -1
- data/lib/carbon.rb +3 -2
- data/lib/carbon/concrete.rb +0 -0
- data/lib/carbon/concrete/build.rb +1 -1
- data/lib/carbon/concrete/index.rb +37 -13
- data/lib/carbon/concrete/item.rb +0 -0
- data/lib/carbon/concrete/item/base.rb +11 -0
- data/lib/carbon/concrete/item/data.rb +0 -0
- data/lib/carbon/concrete/item/function.rb +13 -1
- data/lib/carbon/concrete/item/internal.rb +0 -0
- data/lib/carbon/concrete/item/struct.rb +0 -0
- data/lib/carbon/concrete/item/struct/element.rb +0 -0
- data/lib/carbon/concrete/item/trait.rb +0 -0
- data/lib/carbon/concrete/item/trait/expectation.rb +0 -0
- data/lib/carbon/concrete/request.rb +0 -0
- data/lib/carbon/concrete/type.rb +0 -0
- data/lib/carbon/concrete/type/function.rb +0 -0
- data/lib/carbon/concrete/type/generic.rb +0 -0
- data/lib/carbon/concrete/type/name.rb +0 -0
- data/lib/carbon/concrete/type/parse.rb +0 -0
- data/lib/carbon/concrete/type/part.rb +0 -0
- data/lib/carbon/core.rb +1 -1
- data/lib/carbon/core/int.rb +0 -0
- data/lib/carbon/core/integer.rb +0 -0
- data/lib/carbon/core/integer/cast.rb +4 -4
- data/lib/carbon/core/integer/math.rb +11 -10
- data/lib/carbon/core/integer/misc.rb +6 -5
- data/lib/carbon/core/integer/pole.rb +9 -7
- data/lib/carbon/core/integer/ship.rb +4 -2
- data/lib/carbon/core/integer/sign.rb +0 -0
- data/lib/carbon/core/integer/type.rb +0 -0
- data/lib/carbon/core/integer/zero.rb +2 -2
- data/lib/carbon/core/pointer.rb +0 -0
- data/lib/carbon/core/pointer/access.rb +7 -4
- data/lib/carbon/core/pointer/cast.rb +1 -1
- data/lib/carbon/core/pointer/math.rb +12 -10
- data/lib/carbon/core/pointer/memory.rb +4 -4
- data/lib/carbon/core/pointer/type.rb +0 -0
- data/lib/carbon/tacky.rb +1 -0
- data/lib/carbon/tacky/block.rb +0 -0
- data/lib/carbon/tacky/builder.rb +14 -2
- data/lib/carbon/tacky/context.rb +12 -1
- data/lib/carbon/tacky/function.rb +1 -1
- data/lib/carbon/tacky/instruction.rb +9 -54
- data/lib/carbon/tacky/instruction/dependencies.rb +33 -0
- data/lib/carbon/tacky/instruction/generation.rb +90 -0
- data/lib/carbon/tacky/instruction/typeof.rb +25 -0
- data/lib/carbon/tacky/parameter.rb +0 -0
- data/lib/carbon/tacky/reference.rb +4 -0
- data/lib/carbon/tacky/typed.rb +25 -0
- data/lib/carbon/tacky/value.rb +0 -0
- data/lib/carbon/version.rb +1 -1
- data/scripts/core.rb +9 -0
- data/scripts/test.rb +19 -0
- 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
|
@@ -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
|
data/lib/carbon/tacky/value.rb
CHANGED
File without changes
|
data/lib/carbon/version.rb
CHANGED
data/scripts/core.rb
ADDED
data/scripts/test.rb
ADDED
@@ -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.
|
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-
|
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:
|
70
|
+
name: oj
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
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: '
|
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
|