carbon-compiler 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +17 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +39 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +9 -0
- data/Vagrantfile +84 -0
- data/carbon-compiler.gemspec +28 -0
- data/lib/carbon/compiler.rb +20 -0
- data/lib/carbon/compiler/directive.rb +48 -0
- data/lib/carbon/compiler/directive/import.rb +17 -0
- data/lib/carbon/compiler/errors.rb +7 -0
- data/lib/carbon/compiler/location.rb +136 -0
- data/lib/carbon/compiler/metanostic.rb +123 -0
- data/lib/carbon/compiler/metanostic/defaults.rb +41 -0
- data/lib/carbon/compiler/metanostic/defaults.yml +138 -0
- data/lib/carbon/compiler/metanostic/diagnostic.rb +112 -0
- data/lib/carbon/compiler/metanostic/list.rb +109 -0
- data/lib/carbon/compiler/metanostic/mode.rb +162 -0
- data/lib/carbon/compiler/metanostic/state.rb +174 -0
- data/lib/carbon/compiler/metanostic/template.erb +11 -0
- data/lib/carbon/compiler/node.rb +18 -0
- data/lib/carbon/compiler/node/base.rb +213 -0
- data/lib/carbon/compiler/node/definition.rb +19 -0
- data/lib/carbon/compiler/node/definition/class.rb +24 -0
- data/lib/carbon/compiler/node/definition/class/element.rb +18 -0
- data/lib/carbon/compiler/node/definition/directive.rb +22 -0
- data/lib/carbon/compiler/node/definition/directive/function.rb +18 -0
- data/lib/carbon/compiler/node/definition/enum.rb +20 -0
- data/lib/carbon/compiler/node/definition/enum/element.rb +17 -0
- data/lib/carbon/compiler/node/definition/function.rb +44 -0
- data/lib/carbon/compiler/node/definition/function/body.rb +17 -0
- data/lib/carbon/compiler/node/definition/function/name.rb +18 -0
- data/lib/carbon/compiler/node/definition/function/parameter.rb +18 -0
- data/lib/carbon/compiler/node/definition/function/parameters.rb +17 -0
- data/lib/carbon/compiler/node/definition/module.rb +23 -0
- data/lib/carbon/compiler/node/definition/struct.rb +24 -0
- data/lib/carbon/compiler/node/definition/struct/element.rb +18 -0
- data/lib/carbon/compiler/node/etype.rb +66 -0
- data/lib/carbon/compiler/node/etype/option.rb +25 -0
- data/lib/carbon/compiler/node/etype/star.rb +13 -0
- data/lib/carbon/compiler/node/expression.rb +18 -0
- data/lib/carbon/compiler/node/expression/assignment.rb +22 -0
- data/lib/carbon/compiler/node/expression/call.rb +22 -0
- data/lib/carbon/compiler/node/expression/call/access.rb +24 -0
- data/lib/carbon/compiler/node/expression/call/attribute.rb +23 -0
- data/lib/carbon/compiler/node/expression/call/enum.rb +25 -0
- data/lib/carbon/compiler/node/expression/call/module.rb +24 -0
- data/lib/carbon/compiler/node/expression/call/parameters.rb +17 -0
- data/lib/carbon/compiler/node/expression/call/self.rb +17 -0
- data/lib/carbon/compiler/node/expression/call/unified.rb +27 -0
- data/lib/carbon/compiler/node/expression/literal.rb +83 -0
- data/lib/carbon/compiler/node/expression/operation.rb +20 -0
- data/lib/carbon/compiler/node/expression/operation/and.rb +20 -0
- data/lib/carbon/compiler/node/expression/operation/neq.rb +21 -0
- data/lib/carbon/compiler/node/expression/operation/normal.rb +20 -0
- data/lib/carbon/compiler/node/expression/operation/or.rb +20 -0
- data/lib/carbon/compiler/node/expression/unit.rb +16 -0
- data/lib/carbon/compiler/node/name.rb +27 -0
- data/lib/carbon/compiler/node/root.rb +23 -0
- data/lib/carbon/compiler/node/statement.rb +24 -0
- data/lib/carbon/compiler/node/statement/catch.rb +20 -0
- data/lib/carbon/compiler/node/statement/condition.rb +14 -0
- data/lib/carbon/compiler/node/statement/else.rb +17 -0
- data/lib/carbon/compiler/node/statement/elsif.rb +18 -0
- data/lib/carbon/compiler/node/statement/finally.rb +17 -0
- data/lib/carbon/compiler/node/statement/for.rb +18 -0
- data/lib/carbon/compiler/node/statement/if.rb +18 -0
- data/lib/carbon/compiler/node/statement/let.rb +18 -0
- data/lib/carbon/compiler/node/statement/match.rb +14 -0
- data/lib/carbon/compiler/node/statement/return.rb +17 -0
- data/lib/carbon/compiler/node/statement/try.rb +19 -0
- data/lib/carbon/compiler/node/statement/while.rb +19 -0
- data/lib/carbon/compiler/parser.rb +63 -0
- data/lib/carbon/compiler/parser/common.rb +79 -0
- data/lib/carbon/compiler/parser/expressions.rb +39 -0
- data/lib/carbon/compiler/parser/expressions/precedence.rb +134 -0
- data/lib/carbon/compiler/parser/expressions/primary.rb +120 -0
- data/lib/carbon/compiler/parser/firsts.rb +74 -0
- data/lib/carbon/compiler/parser/helpers.rb +61 -0
- data/lib/carbon/compiler/parser/root.rb +57 -0
- data/lib/carbon/compiler/parser/root/class.rb +34 -0
- data/lib/carbon/compiler/parser/root/directive.rb +87 -0
- data/lib/carbon/compiler/parser/root/enum.rb +45 -0
- data/lib/carbon/compiler/parser/root/function.rb +90 -0
- data/lib/carbon/compiler/parser/root/struct.rb +34 -0
- data/lib/carbon/compiler/parser/root/trait.rb +44 -0
- data/lib/carbon/compiler/parser/statements.rb +86 -0
- data/lib/carbon/compiler/parser/statements/if.rb +50 -0
- data/lib/carbon/compiler/parser/statements/match.rb +39 -0
- data/lib/carbon/compiler/parser/statements/try.rb +49 -0
- data/lib/carbon/compiler/project.rb +37 -0
- data/lib/carbon/compiler/project/file.rb +64 -0
- data/lib/carbon/compiler/scanner.rb +82 -0
- data/lib/carbon/compiler/scanner/main.rb +76 -0
- data/lib/carbon/compiler/scanner/token.rb +58 -0
- data/lib/carbon/compiler/version.rb +8 -0
- data/lib/carbon/compiler/visitor.rb +13 -0
- data/lib/carbon/compiler/visitor/base.rb +52 -0
- data/lib/carbon/compiler/visitor/generation.rb +45 -0
- data/lib/carbon/compiler/visitor/generation/asserts.rb +30 -0
- data/lib/carbon/compiler/visitor/generation/class.rb +93 -0
- data/lib/carbon/compiler/visitor/generation/context.rb +75 -0
- data/lib/carbon/compiler/visitor/generation/expressions.rb +82 -0
- data/lib/carbon/compiler/visitor/generation/expressions/assignment.rb +105 -0
- data/lib/carbon/compiler/visitor/generation/expressions/calls.rb +89 -0
- data/lib/carbon/compiler/visitor/generation/function.rb +68 -0
- data/lib/carbon/compiler/visitor/generation/statements.rb +131 -0
- data/lib/carbon/compiler/visitor/generation/struct.rb +115 -0
- data/lib/carbon/compiler/visitor/preparation.rb +86 -0
- data/lib/carbon/compiler/visitor/preparation/expressions.rb +26 -0
- data/lib/carbon/compiler/visitor/preparation/function.rb +55 -0
- data/lib/carbon/compiler/visitor/preparation/statements.rb +73 -0
- data/lib/carbon/compiler/visitor/preparation/struct.rb +37 -0
- data/program.ca +16 -0
- data/test.rb +21 -0
- metadata +234 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "carbon/compiler/node/expression/assignment"
|
5
|
+
require "carbon/compiler/node/expression/call"
|
6
|
+
require "carbon/compiler/node/expression/literal"
|
7
|
+
require "carbon/compiler/node/expression/operation"
|
8
|
+
require "carbon/compiler/node/expression/unit"
|
9
|
+
|
10
|
+
module Carbon
|
11
|
+
module Compiler
|
12
|
+
module Node
|
13
|
+
# An expression.
|
14
|
+
module Expression
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
# An assignment expression. This typically takes the form of
|
9
|
+
# `<Expression> = <Expression>`. There are three cases for assignments:
|
10
|
+
# a) an attribute assignment; b) an access assignment; and c) an
|
11
|
+
# identifier assignment. The first and second are turned into
|
12
|
+
# function calls using {Call::Dispatch}; the last is kept as-is,
|
13
|
+
# and turns into a store.
|
14
|
+
# This has three children: the left hand side, the operation, and
|
15
|
+
# the right hand side.
|
16
|
+
class Assignment < Base
|
17
|
+
attributes left: 0, op: 1, right: 2
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "carbon/compiler/node/expression/call/parameters"
|
5
|
+
require "carbon/compiler/node/expression/call/access"
|
6
|
+
require "carbon/compiler/node/expression/call/attribute"
|
7
|
+
require "carbon/compiler/node/expression/call/enum"
|
8
|
+
require "carbon/compiler/node/expression/call/module"
|
9
|
+
require "carbon/compiler/node/expression/call/self"
|
10
|
+
require "carbon/compiler/node/expression/call/unified"
|
11
|
+
|
12
|
+
module Carbon
|
13
|
+
module Compiler
|
14
|
+
module Node
|
15
|
+
module Expression
|
16
|
+
# Contains all of the ways a call can be made/handled.
|
17
|
+
module Call
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
module Call
|
9
|
+
# An "Access" call. An access call takes the form of
|
10
|
+
# `<Expression>[<Arguments>]`. This is used to index arrays.
|
11
|
+
# An access call has two children: an expression and the arguments
|
12
|
+
# for the access. In the example below, there is only one argument.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# # let a: Carbon::Pointer<Carbon::Integer>;
|
16
|
+
# a[0]; # => Carbon::Integer
|
17
|
+
class Access < Base
|
18
|
+
attributes expression: 0, parameters: 1, generics: 2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
module Call
|
9
|
+
# An attribute call. This is used for accessing an "attribute" of
|
10
|
+
# a module. This takes the form of `<Expression>.<Name>`. This
|
11
|
+
# has two children: an expression, and a name.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # let a: Carbon::Pointer<Carbon::Integer>;
|
15
|
+
# a.value = 1;
|
16
|
+
class Attribute < Base
|
17
|
+
attributes expression: 0, name: 1, generics: 2
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
module Call
|
9
|
+
# An Enum call. This is a call used to create an "enum" value.
|
10
|
+
# This takes the form of
|
11
|
+
# `<ModuleName>.<ModuleNamePart>.(<Arguments>)`. This has three
|
12
|
+
# children: the module name, the enum element name, and the
|
13
|
+
# arguments.
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# # let a: Some::Enum;
|
17
|
+
# a = Some::Enum.Red();
|
18
|
+
class Enum < Base
|
19
|
+
attributes module: 0, name: 1, parameters: 2, generics: 3
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
module Call
|
9
|
+
# A basic module call. This is the most basic version of a call.
|
10
|
+
# This takes the form `<ModuleName>.<Name>(<Arguments>)`.
|
11
|
+
# This has three children: the module name, the name of the
|
12
|
+
# function, and the arguments.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# let a: Carbon::Pointer<Carbon::Integer>;
|
16
|
+
# Carbon::Pointer<Carbon::Integer>.value=(a, 1);
|
17
|
+
class Module < Base
|
18
|
+
attributes module: 0, name: 1, parameters: 2, generics: 3
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
module Call
|
9
|
+
# The arguments to the call. This may be turned into a pure array
|
10
|
+
# in later versions.
|
11
|
+
class Parameters < Base
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
module Call
|
9
|
+
# Unused.
|
10
|
+
class Self < Base
|
11
|
+
attributes name: 0, parameters: 1, generics: 2
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
module Call
|
9
|
+
# A "unified" call. This is the extended version of the module
|
10
|
+
# call. This can be turned into a module call by taking the
|
11
|
+
# module type of the expression and using that as the base, and
|
12
|
+
# passing the expression as the first parameter. This takes the
|
13
|
+
# form `<Expression>.<Name>(<Arguments>)`. This has three
|
14
|
+
# children: an expression, a name, and the arguments.
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# # let a: Carbon::Pointer<Carbon::Integer>;
|
18
|
+
# a.size(); # Same as the following:
|
19
|
+
# Carbon::Pointer<Carbon::Integer>.size(a);
|
20
|
+
class Unified < Base
|
21
|
+
attributes expression: 0, name: 1, parameters: 2, generics: 3
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
# A literal expression. Contains information about how the literal
|
9
|
+
# expression should be represented.
|
10
|
+
class Literal < Base
|
11
|
+
# Replacements for strings.
|
12
|
+
#
|
13
|
+
# @return [{String => String}]
|
14
|
+
REPLACE = {
|
15
|
+
'\"' => '"',
|
16
|
+
'\\\\' => '\\',
|
17
|
+
'\/' => "/",
|
18
|
+
'\b' => "\b",
|
19
|
+
'\f' => "\f",
|
20
|
+
'\n' => "\n",
|
21
|
+
'\r' => "\r",
|
22
|
+
'\t' => "\t"
|
23
|
+
}.freeze
|
24
|
+
|
25
|
+
# Yields a LLVM value representing the literal.
|
26
|
+
#
|
27
|
+
# @return [::Numeric, ::String]
|
28
|
+
def value
|
29
|
+
case @children.first.type
|
30
|
+
when :NUMBER then number_value
|
31
|
+
# LLVM.Int(@children.first.value.to_i)
|
32
|
+
when :FLOAT
|
33
|
+
LLVM.Float(@children.first.value.to_f)
|
34
|
+
when :STRING
|
35
|
+
fail
|
36
|
+
@children.first.value[1..-2]
|
37
|
+
.gsub(%r{\\["\\/bfnrt]}, REPLACE)
|
38
|
+
else fail
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Yields the Carbon type representing the literal.
|
43
|
+
#
|
44
|
+
# @return [Carbon::Concrete::Type]
|
45
|
+
def type
|
46
|
+
case @children.first.type
|
47
|
+
# when :NUMBER then Carbon::Type("Carbon::Int32")
|
48
|
+
when :NUMBER then number_type
|
49
|
+
when :FLOAT then Carbon::Type("Carbon::Float")
|
50
|
+
when :STRING then Carbon::Type("Carbon::String")
|
51
|
+
else fail
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def raw
|
58
|
+
@children.first.value
|
59
|
+
end
|
60
|
+
|
61
|
+
def postfix
|
62
|
+
raw.match(/(?:0x[a-f0-9]+|(?:0|[1-9][0-9]*))(?:_?([ui][0-9]+))?/)[1] || "i32"
|
63
|
+
end
|
64
|
+
|
65
|
+
def number
|
66
|
+
raw.match(/(0x[a-f0-9]+|(?:0|[1-9][0-9]*))(?:_?(?:[ui][0-9]+))?/)[1]
|
67
|
+
end
|
68
|
+
|
69
|
+
def number_value
|
70
|
+
LLVM.const_get("Int#{postfix[1..-1]}").from_i(number.to_i,
|
71
|
+
postfix[0] == "i")
|
72
|
+
end
|
73
|
+
|
74
|
+
def number_type
|
75
|
+
sign = postfix[0] == "i" ? :signed : :unsigned
|
76
|
+
size = postfix[1..-1].to_i
|
77
|
+
Core::Int.find(sign: sign, size: size).name
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "carbon/compiler/node/expression/operation/and"
|
5
|
+
require "carbon/compiler/node/expression/operation/neq"
|
6
|
+
require "carbon/compiler/node/expression/operation/normal"
|
7
|
+
require "carbon/compiler/node/expression/operation/or"
|
8
|
+
|
9
|
+
module Carbon
|
10
|
+
module Compiler
|
11
|
+
module Node
|
12
|
+
module Expression
|
13
|
+
# An operation. This is just the superclass for the potential
|
14
|
+
# operations.
|
15
|
+
class Operation < Base
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
class Operation < Base
|
9
|
+
# An "And" operation. This is generated internally and cannot be
|
10
|
+
# redefined by defining an "And" function.
|
11
|
+
# This has three children: the left hand side, the operation, and
|
12
|
+
# the right hand side. This has the form `<Left> && <Right>`.
|
13
|
+
class And < Operation
|
14
|
+
attributes left: 0, op: 1, right: 2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
class Operation < Base
|
9
|
+
# A "Neq" operation. This is generated internally and cannot be
|
10
|
+
# redefined by defining a "Neq" function.
|
11
|
+
# This has three children: the left hand side, the operation, and
|
12
|
+
# the right hand side. This has the form `<Left> != <Right>`.
|
13
|
+
# This is redefined in terms of the Eq operation (`==`).
|
14
|
+
class Neq < Operation
|
15
|
+
attributes left: 0, op: 1, right: 2, func: 3
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
class Operation < Base
|
9
|
+
# A normal operation. This is redefined into a {Call::Dispatch}
|
10
|
+
# in order to turn all operations into function calls.
|
11
|
+
# This has three children: the left hand side, the operation,
|
12
|
+
# and the right hand side. This takes the form `<Left> <Op> <Right>`.
|
13
|
+
class Normal < Operation
|
14
|
+
attributes left: 0, op: 1, right: 2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
class Operation < Base
|
9
|
+
# An "Or" operation. This is generated internally and cannot be
|
10
|
+
# redefined by defining an "Or" function.
|
11
|
+
# This has three children: the left hand side, the operation, and
|
12
|
+
# the right hand side. This has the form `<Left> || <Right>`.
|
13
|
+
class Or < Operation
|
14
|
+
attributes left: 0, op: 1, right: 2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Carbon
|
5
|
+
module Compiler
|
6
|
+
module Node
|
7
|
+
module Expression
|
8
|
+
# A "unit". This takes the form of `(<Expressions>)`. This is
|
9
|
+
# used as a sort of "mini-struct". Mostly unused at the moment.
|
10
|
+
class Unit < Base
|
11
|
+
attr_reader :type
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|