gloss 0.0.6 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +41 -0
  3. data/.gloss.yml +2 -0
  4. data/Gemfile.lock +10 -10
  5. data/README.md +5 -7
  6. data/Rakefile +5 -3
  7. data/exe/gloss +10 -13
  8. data/ext/gloss/Makefile +6 -21
  9. data/ext/gloss/lib/cr_ruby.cr +5 -4
  10. data/ext/gloss/src/cr_ast.cr +61 -71
  11. data/ext/gloss/src/gloss.cr +7 -2
  12. data/ext/gloss/src/rb_ast.cr +37 -36
  13. data/gloss.gemspec +3 -3
  14. data/lib/gloss.rb +10 -7
  15. data/lib/gloss/cli.rb +61 -40
  16. data/lib/gloss/config.rb +14 -8
  17. data/lib/gloss/errors.rb +1 -1
  18. data/lib/gloss/logger.rb +6 -6
  19. data/lib/gloss/prog_loader.rb +144 -0
  20. data/lib/gloss/scope.rb +1 -1
  21. data/lib/gloss/source.rb +1 -1
  22. data/lib/gloss/type_checker.rb +60 -32
  23. data/lib/gloss/utils.rb +38 -0
  24. data/lib/gloss/version.rb +1 -1
  25. data/lib/gloss/{builder.rb → visitor.rb} +88 -53
  26. data/lib/gloss/watcher.rb +14 -7
  27. data/lib/gloss/writer.rb +21 -10
  28. data/logo.svg +6 -0
  29. data/sig/core.rbs +2 -0
  30. data/sig/fast_blank.rbs +4 -0
  31. data/sig/{gloss.rbs → gls.rbs} +0 -0
  32. data/sig/optparse.rbs +6 -0
  33. data/sig/rubygems.rbs +9 -0
  34. data/sig/yaml.rbs +3 -0
  35. data/src/exe/gloss +19 -0
  36. data/src/lib/gloss.gl +25 -0
  37. data/src/lib/gloss/cli.gl +41 -26
  38. data/src/lib/gloss/config.gl +13 -8
  39. data/src/lib/gloss/logger.gl +2 -5
  40. data/src/lib/gloss/prog_loader.gl +138 -0
  41. data/src/lib/gloss/scope.gl +0 -2
  42. data/src/lib/gloss/type_checker.gl +57 -28
  43. data/src/lib/gloss/utils.gl +35 -0
  44. data/src/lib/gloss/version.gl +1 -1
  45. data/src/lib/gloss/{builder.gl → visitor.gl} +82 -45
  46. data/src/lib/gloss/watcher.gl +13 -8
  47. data/src/lib/gloss/writer.gl +15 -13
  48. metadata +29 -18
  49. data/.github/workflows/crystal_specs.yml +0 -26
  50. data/.github/workflows/ruby_specs.yml +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9315ca2d8d487ca5729f7665abcba9e922ec4e0ee85ac54787248d07b54b7ed5
4
- data.tar.gz: 78928faa1a7e77e0184594a31786c0befdc796a4a9b46c5f509adb95c39d37c3
3
+ metadata.gz: 0cb01614c6e4395edaf5600dd39e958b2ca86ae6c2650c2028519659c813ff64
4
+ data.tar.gz: a1ee0171851a7463113c4e12dff9dd81bb2c003e080896171060dfc439a18499
5
5
  SHA512:
6
- metadata.gz: c3178c5cf74e3946e327cbe97b5c5f421090e7b678d331c34ce5c8a45aea137cdc9628f91481425e18f66cf3245983d1e5bf965feaae211d619d8d9f5ed55647
7
- data.tar.gz: 9d9b5ef709cffe8efb6b0124762bbe025948caa51772cf33a38143862003048f15ee83198c2fd0f6a05128f14da65a9feb22b45205563b686bacb70d51dd5741
6
+ metadata.gz: 781f7dc53f12231f843947aa619521fbd99deca1bf15a7a5263a279e7a030683c4da2d72722beb30d4a35beba8e98e86085eabd3046d1567be1c37c7d577c6d7
7
+ data.tar.gz: b3a63fbcb5c81a8c0d4336dcfdb64d46a2ebf624fd804942ba8243c04b43fab05a881ba6386e6f6a5c7fb76b416ca8677212e7993ea8ea22cdca981bff2645fd
@@ -0,0 +1,41 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+ env:
9
+ ImageOS: ubuntu18
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ container:
14
+ image: johansenja/gloss:latest
15
+ steps:
16
+ - name: Checkout
17
+ uses: actions/checkout@v2
18
+ - uses: actions/cache@v2
19
+ id: gems-cache
20
+ with:
21
+ path: vendor/bundle
22
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
23
+ restore-keys: |
24
+ ${{ runner.os }}-gems-
25
+ - name: install Bundler
26
+ run: gem install bundler:2.2.3
27
+ - name: install gems
28
+ run: bundle install --jobs 4 --retry 3
29
+ - name: Compile extension
30
+ run: make
31
+ working-directory: ext/gloss
32
+ - name: Run tests
33
+ run: rake
34
+ - name: Install dependencies
35
+ run: shards install
36
+ working-directory: ext/gloss
37
+ - name: Run tests
38
+ run: crystal spec
39
+ working-directory: ext/gloss
40
+ - name: Build self with current state
41
+ run: exe/gloss build
data/.gloss.yml CHANGED
@@ -1,3 +1,5 @@
1
1
  ---
2
2
  frozen_string_literals: true
3
3
  src_dir: src
4
+ entrypoint: src/exe/gloss
5
+ type_checking_strictness: lenient
data/Gemfile.lock CHANGED
@@ -1,22 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gloss (0.0.6)
4
+ gloss (0.1.4)
5
5
  fast_blank
6
6
  listen
7
- rbs
8
- steep
7
+ rbs (~> 1.0.4)
8
+ steep (~> 0.41.0)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (6.1.1)
13
+ activesupport (6.1.3)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 1.6, < 2)
16
16
  minitest (>= 5.1)
17
17
  tzinfo (~> 2.0)
18
18
  zeitwerk (~> 2.3)
19
- ast (2.4.1)
19
+ ast (2.4.2)
20
20
  ast_utils (0.4.0)
21
21
  parser (>= 2.7.0)
22
22
  byebug (11.1.3)
@@ -24,15 +24,15 @@ GEM
24
24
  concurrent-ruby (1.1.8)
25
25
  diff-lcs (1.4.4)
26
26
  fast_blank (1.0.0)
27
- ffi (1.14.2)
28
- i18n (1.8.7)
27
+ ffi (1.15.0)
28
+ i18n (1.8.9)
29
29
  concurrent-ruby (~> 1.0)
30
30
  language_server-protocol (3.15.0.1)
31
31
  listen (3.4.1)
32
32
  rb-fsevent (~> 0.10, >= 0.10.3)
33
33
  rb-inotify (~> 0.9, >= 0.9.10)
34
34
  method_source (1.0.0)
35
- minitest (5.14.3)
35
+ minitest (5.14.4)
36
36
  parallel (1.20.1)
37
37
  parser (2.7.2.0)
38
38
  ast (~> 2.4.1)
@@ -49,7 +49,7 @@ GEM
49
49
  rb-fsevent (0.10.4)
50
50
  rb-inotify (0.10.1)
51
51
  ffi (~> 1.0)
52
- rbs (1.0.4)
52
+ rbs (1.0.6)
53
53
  regexp_parser (2.0.3)
54
54
  rexml (3.2.4)
55
55
  rspec (3.10.0)
@@ -77,7 +77,7 @@ GEM
77
77
  rubocop-ast (1.4.0)
78
78
  parser (>= 2.7.1.5)
79
79
  ruby-progressbar (1.11.0)
80
- steep (0.40.0)
80
+ steep (0.41.0)
81
81
  activesupport (>= 5.1)
82
82
  ast_utils (>= 0.4.0)
83
83
  language_server-protocol (~> 3.15.0.1)
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
- # Gloss
1
+ # ![Gloss](./logo.svg "Gloss")
2
2
  [![Gem Version](https://badge.fury.io/rb/gloss.svg)](https://rubygems.org/gems/gloss)
3
- [![Ruby Specs](https://github.com/johansenja/gloss/workflows/Ruby%20Specs/badge.svg)](https://github.com/johansenja/gloss/actions?query=workflow%3A%22Ruby+Specs%22)
4
- [![Crystal Specs](https://github.com/johansenja/gloss/workflows/Crystal%20Specs/badge.svg)](https://github.com/johansenja/gloss/actions?query=workflow%3A%22Crystal+Specs%22)
5
- [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/gloss?type=total&color=green&metric=true&label=downloads%20(total)&total_label=)](https://rubygems.org/gems/gloss)
3
+ [![Tests](https://github.com/johansenja/gloss/workflows/Tests/badge.svg)](https://github.com/johansenja/gloss/actions?query=workflow%3ATests)
4
+ [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/gloss?type=total&color=green&label=downloads%20(total)&total_label=)](https://rubygems.org/gems/gloss)
6
5
  [![Current Version](http://ruby-gem-downloads-badge.herokuapp.com/gloss?color=green&label=downloads%20(current%20version)&metric=true)](https://rubygems.org/gems/gloss)
7
- [![Total Views](https://counter.gofiber.io/badge/johansenja/gloss)](https://rubygems.org/gems/gloss)
8
6
 
9
7
  [Gloss](https://en.wikipedia.org/wiki/Gloss_(annotation)) is a high-level programming language based on [Ruby](https://github.com/ruby/ruby) and [Crystal](https://github.com/crystal-lang/crystal), which compiles to ruby; its aims are on transparency,
10
8
  efficiency, and to enhance ruby's goal of developer happiness and productivity.
@@ -137,7 +135,7 @@ class Language
137
135
  TS = "TypeScript"
138
136
  P = "Python"
139
137
  end
140
-
138
+
141
139
  def favourite_language(language : Lang)
142
140
  puts "my favourite language is #{language}"
143
141
  end
@@ -213,7 +211,7 @@ end
213
211
  ```crystal
214
212
  abstract class BaseClass
215
213
  attr_reader :var
216
-
214
+
217
215
  def initialize(@var); end
218
216
  end
219
217
 
data/Rakefile CHANGED
@@ -17,8 +17,10 @@ RSpec::Core::RakeTask.new :spec do |spec|
17
17
  spec.pattern = 'spec/**/*_spec.rb'
18
18
  end
19
19
 
20
- task :build do
21
- `cd ext/gloss && make && cd -`
20
+ task :build_gem do
21
+ sh "cd", "ext/gloss", "&&", "make", "all", "&&", "cd", "-"
22
22
  end
23
23
 
24
- task :default => [:spec]
24
+ task build: [:build_gem]
25
+
26
+ task default: [:spec]
data/exe/gloss CHANGED
@@ -1,20 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ ##### This file was generated by Gloss; any changes made here will be overwritten.
5
+ ##### See src/ to make changes
2
6
 
3
7
  require "bundler/setup"
4
8
  require "gloss"
5
-
6
9
  begin
7
- Gloss::CLI.new(ARGV).run
10
+ Gloss::CLI.new(ARGV)
11
+ .run
8
12
  rescue SystemExit
9
- # raised by `abort` or `exit`; no op
10
- rescue => e
11
- Gloss.logger.fatal <<~MSG
12
- Unexpected error: #{e.class.name}
13
- Message: #{e.message}
14
- Trace:
15
- #{e.backtrace.join("\n")}
16
-
17
- This is probably a bug and may warrant a bug report at https://github.com/johansenja/gloss/issues
18
- MSG
19
- exit 1
13
+ rescue => e
14
+ abort(" Unexpected error: #{e.class
15
+ .name}\n Message: #{e.message}\n Trace:\n #{e.backtrace
16
+ .join("\n")}\n\n This is probably a bug and may warrant a bug report at https://github.com/johansenja/gloss/issues")
20
17
  end
data/ext/gloss/Makefile CHANGED
@@ -1,26 +1,12 @@
1
1
  CRYSTAL = crystal
2
- TARGET = ../../lib/gls
3
-
4
2
  PLATFORM = $(shell uname -s)
5
3
 
6
4
  ifeq "$(PLATFORM)" "Darwin"
7
- install: all
8
-
9
- all: clean shards build
10
-
11
- shards:
12
- shards
13
-
14
- build: ./src/gloss.cr
15
- $(CRYSTAL) build --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" $< -o $(TARGET).bundle
16
-
17
- clean:
18
- rm -f $(TARGET).bundle
19
- rm -f $(TARGET).bundle.dwarf
5
+ TARGET = ../../lib/gls.bundle
6
+ else
7
+ TARGET = ../../lib/gls.so
20
8
  endif
21
9
 
22
- ifeq "$(PLATFORM)" "Linux"
23
- LLVM_TARGET = "$(shell uname -m)-unknown-linux-gnu"
24
10
  install: all
25
11
 
26
12
  all: clean shards build
@@ -29,9 +15,8 @@ shards:
29
15
  shards
30
16
 
31
17
  build: ./src/gloss.cr
32
- $(CRYSTAL) build $< --cross-compile --target $(LLVM_TARGET) --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" -o $(TARGET)
18
+ $(CRYSTAL) build --link-flags "-shared -Wl,-undefined,dynamic_lookup" $< -o $(TARGET) --release
33
19
 
34
20
  clean:
35
- rm -f $(TARGET).o
36
- rm -f $(TARGET).so
37
- endif
21
+ rm -f $(TARGET)
22
+ rm -f $(TARGET).dwarf
@@ -1,8 +1,6 @@
1
1
  lib CrRuby
2
2
  # every ruby Object is a VALUE
3
3
  type VALUE = Void*
4
- # ruby method typing
5
- type METHOD_FUNC = VALUE, VALUE -> VALUE
6
4
 
7
5
  # a ruby Class is a VALUE
8
6
  $rb_cObject : VALUE
@@ -28,8 +26,11 @@ lib CrRuby
28
26
  fun rb_define_module(name: UInt8*) : VALUE
29
27
 
30
28
  # define ruby method in C
31
- fun rb_define_method(klass: VALUE, name: UInt8*, func: METHOD_FUNC, argc: Int32)
29
+ fun rb_define_method(klass: VALUE, name: UInt8*, func: Proc(CrRuby::VALUE, CrRuby::VALUE,
30
+ CrRuby::VALUE), argc: Int32)
32
31
 
33
32
  # define singleton ruby method in C
34
- fun rb_define_singleton_method(klass: VALUE, name: UInt8*, func: METHOD_FUNC, argc: Int32)
33
+ fun rb_define_singleton_method(klass: VALUE, name: UInt8*, func: Proc(CrRuby::VALUE,
34
+ CrRuby::VALUE,
35
+ CrRuby::VALUE), argc: Int32)
35
36
  end
@@ -5,7 +5,7 @@ require "./rb_ast"
5
5
  module Crystal
6
6
  abstract class ASTNode
7
7
  def to_rb
8
- Rb::AST::EmptyNode.new(self.class.name)
8
+ Rb::AST::EmptyNode.new(self.class.name, @location)
9
9
  end
10
10
  end
11
11
 
@@ -17,13 +17,13 @@ module Crystal
17
17
 
18
18
  class Expressions < ASTNode
19
19
  def to_rb
20
- Rb::AST::CollectionNode.new(@expressions.map(&.to_rb))
20
+ Rb::AST::CollectionNode.new(@expressions.map(&.to_rb), @location)
21
21
  end
22
22
  end
23
23
 
24
24
  class NilLiteral < ASTNode
25
25
  def to_rb
26
- Rb::AST::LiteralNode.new("nil", Rb::AST::RbLiteral::NilClass)
26
+ Rb::AST::LiteralNode.new("nil", Rb::AST::RbLiteral::NilClass, @location)
27
27
  end
28
28
  end
29
29
 
@@ -31,74 +31,73 @@ module Crystal
31
31
  def to_rb
32
32
  Rb::AST::LiteralNode.new(
33
33
  @value.inspect,
34
- @value ? Rb::AST::RbLiteral::TrueClass : Rb::AST::RbLiteral::FalseClass
35
- )
34
+ @value ? Rb::AST::RbLiteral::TrueClass : Rb::AST::RbLiteral::FalseClass, @location)
36
35
  end
37
36
  end
38
37
 
39
38
  class NumberLiteral < ASTNode
40
39
  def to_rb
41
- Rb::AST::LiteralNode.new(@value, Rb::AST::RbLiteral::Integer)
40
+ Rb::AST::LiteralNode.new(@value, Rb::AST::RbLiteral::Integer, @location)
42
41
  end
43
42
  end
44
43
 
45
44
  class CharLiteral < ASTNode
46
45
  def to_rb
47
- Rb::AST::LiteralNode.new(@value.inspect, Rb::AST::RbLiteral::String)
46
+ Rb::AST::LiteralNode.new(@value.inspect, Rb::AST::RbLiteral::String, @location)
48
47
  end
49
48
  end
50
49
 
51
50
  class StringLiteral < ASTNode
52
51
  def to_rb
53
- Rb::AST::LiteralNode.new(@value.inspect, Rb::AST::RbLiteral::String)
52
+ Rb::AST::LiteralNode.new(@value.inspect, Rb::AST::RbLiteral::String, @location)
54
53
  end
55
54
  end
56
55
 
57
56
  class StringInterpolation < ASTNode
58
57
  def to_rb
59
- Rb::AST::StringInterpolation.new(@expressions.map &.to_rb)
58
+ Rb::AST::StringInterpolation.new(@expressions.map &.to_rb, @location)
60
59
  end
61
60
  end
62
61
 
63
62
  class SymbolLiteral < ASTNode
64
63
  def to_rb
65
- Rb::AST::LiteralNode.new(%{:"#{@value.to_s}"}, Rb::AST::RbLiteral::Symbol)
64
+ Rb::AST::LiteralNode.new(%{:"#{@value.to_s}"}, Rb::AST::RbLiteral::Symbol, @location)
66
65
  end
67
66
  end
68
67
 
69
68
  class ArrayLiteral < ASTNode
70
69
  def to_rb
71
- Rb::AST::ArrayLiteral.new(@elements.map(&.to_rb))
70
+ Rb::AST::ArrayLiteral.new(@elements.map(&.to_rb), @location)
72
71
  end
73
72
  end
74
73
 
75
74
  class HashLiteral < ASTNode
76
75
  def to_rb
77
- Rb::AST::HashLiteral.new(@entries.map { |e| {e.key.to_rb, e.value.to_rb} })
76
+ Rb::AST::HashLiteral.new(@entries.map { |e| {e.key.to_rb, e.value.to_rb} }, @location)
78
77
  end
79
78
  end
80
79
 
81
80
  class NamedTupleLiteral < ASTNode
82
81
  def to_rb
83
- Rb::AST::HashLiteral.new(@entries.map { |e| {e.key, e.value.to_rb} }, frozen: true)
82
+ Rb::AST::HashLiteral.new(@entries.map { |e| {e.key, e.value.to_rb} }, @location, frozen: true)
84
83
  end
85
84
  end
86
85
 
87
86
  class RangeLiteral < ASTNode
88
87
  def to_rb
89
- Rb::AST::RangeLiteral.new(@from.to_rb, @to.to_rb, @exclusive)
88
+ Rb::AST::RangeLiteral.new(@from.to_rb, @to.to_rb, @exclusive, @location)
90
89
  end
91
90
  end
92
91
 
93
92
  class RegexLiteral < ASTNode
94
93
  def to_rb
95
- Rb::AST::RegexLiteral.new(@value.to_rb)
94
+ Rb::AST::RegexLiteral.new(@value.to_rb, @location)
96
95
  end
97
96
  end
98
97
 
99
98
  class TupleLiteral < ASTNode
100
99
  def to_rb
101
- Rb::AST::ArrayLiteral.new(@elements.map(&.to_rb), frozen: true)
100
+ Rb::AST::ArrayLiteral.new(@elements.map(&.to_rb), @location, frozen: true)
102
101
  end
103
102
  end
104
103
 
@@ -115,26 +114,25 @@ module Crystal
115
114
  @body.to_rb,
116
115
  return_type.try(&.to_rb),
117
116
  @yields,
118
- @block_arg.try &.to_rb
119
- )
117
+ @block_arg.try &.to_rb, @location)
120
118
  end
121
119
  end
122
120
 
123
121
  class ClassDef < ASTNode
124
122
  def to_rb
125
- Rb::AST::ClassNode.new(@name.to_rb, @body.to_rb, @superclass.try(&.to_rb), @type_vars, @abstract)
123
+ Rb::AST::ClassNode.new(@name.to_rb, @body.to_rb, @superclass.try(&.to_rb), @type_vars, @abstract, @location)
126
124
  end
127
125
  end
128
126
 
129
127
  class ModuleDef < ASTNode
130
128
  def to_rb
131
- Rb::AST::ModuleNode.new(@name.to_rb, @body.to_rb, @type_vars)
129
+ Rb::AST::ModuleNode.new(@name.to_rb, @body.to_rb, @type_vars, @location)
132
130
  end
133
131
  end
134
132
 
135
133
  class Var < ASTNode
136
134
  def to_rb
137
- Rb::AST::Var.new(@name)
135
+ Rb::AST::Var.new(@name, @location)
138
136
  end
139
137
  end
140
138
 
@@ -142,7 +140,7 @@ module Crystal
142
140
  def to_rb
143
141
  positional_args = args.dup
144
142
  splat = @splat_index ? positional_args.delete_at(@splat_index.as(Int32)) : nil
145
- Rb::AST::Block.new(positional_args.map(&.to_rb), splat.try &.to_rb, @body.to_rb)
143
+ Rb::AST::Block.new(positional_args.map(&.to_rb), splat.try &.to_rb, @body.to_rb, @location)
146
144
  end
147
145
  end
148
146
 
@@ -155,8 +153,7 @@ module Crystal
155
153
  @named_args.try(&.map(&.to_rb.as(Rb::AST::Arg))),
156
154
  @block.try(&.to_rb),
157
155
  @block_arg.try(&.to_rb),
158
- @has_parentheses
159
- )
156
+ @has_parentheses, @location)
160
157
  end
161
158
  end
162
159
 
@@ -165,121 +162,121 @@ module Crystal
165
162
 
166
163
  def to_rb
167
164
  Rb::AST::Arg.new(@name, @external_name, @restriction.try(&.to_rb),
168
- @default_value.try(&.to_rb), @keyword_arg)
165
+ @default_value.try(&.to_rb), @keyword_arg, @location)
169
166
  end
170
167
  end
171
168
 
172
169
  class NamedArgument < ASTNode
173
170
  def to_rb
174
- Rb::AST::Arg.new(@name, @name, nil, @value.to_rb, true)
171
+ Rb::AST::Arg.new(@name, @name, nil, @value.to_rb, true, @location)
175
172
  end
176
173
  end
177
174
 
178
175
  class If < ASTNode
179
176
  def to_rb
180
- Rb::AST::If.new(@cond.to_rb, @then.to_rb, @else.to_rb)
177
+ Rb::AST::If.new(@cond.to_rb, @then.to_rb, @else.to_rb, @location)
181
178
  end
182
179
  end
183
180
 
184
181
  class Unless < ASTNode
185
182
  def to_rb
186
- Rb::AST::Unless.new(@cond.to_rb, @then.to_rb, @else.to_rb)
183
+ Rb::AST::Unless.new(@cond.to_rb, @then.to_rb, @else.to_rb, @location)
187
184
  end
188
185
  end
189
186
 
190
187
  class Assign < ASTNode
191
188
  def to_rb
192
- Rb::AST::Assign.new(@target.to_rb, @value.to_rb)
189
+ Rb::AST::Assign.new(@target.to_rb, @value.to_rb, nil, @location)
193
190
  end
194
191
  end
195
192
 
196
193
  class OpAssign < ASTNode
197
194
  def to_rb
198
- Rb::AST::Assign.new(@target.to_rb, @value.to_rb, @op)
195
+ Rb::AST::Assign.new(@target.to_rb, @value.to_rb, @op, @location)
199
196
  end
200
197
  end
201
198
 
202
199
  class MultiAssign < ASTNode
203
200
  def to_rb
204
- Rb::AST::MultiAssign.new(@targets.map(&.to_rb), @values.map(&.to_rb))
201
+ Rb::AST::MultiAssign.new(@targets.map(&.to_rb), @values.map(&.to_rb), @location)
205
202
  end
206
203
  end
207
204
 
208
205
  class InstanceVar < ASTNode
209
206
  def to_rb
210
- Rb::AST::InstanceVar.new(@name)
207
+ Rb::AST::InstanceVar.new(@name, @location)
211
208
  end
212
209
  end
213
210
 
214
211
  class ReadInstanceVar < ASTNode
215
212
  def to_rb
216
- Rb::AST::EmptyNode.new(self.class.name)
213
+ Rb::AST::EmptyNode.new(self.class.name, @location)
217
214
  end
218
215
  end
219
216
 
220
217
  class ClassVar < ASTNode
221
218
  def to_rb
222
- Rb::AST::EmptyNode.new(self.class.name)
219
+ Rb::AST::EmptyNode.new(self.class.name, @location)
223
220
  end
224
221
  end
225
222
 
226
223
  class Global < ASTNode
227
224
  def to_rb
228
- Rb::AST::GlobalVar.new(@name)
225
+ Rb::AST::GlobalVar.new(@name, @location)
229
226
  end
230
227
  end
231
228
 
232
229
  class Annotation < ASTNode
233
230
  def to_rb
234
- Rb::AST::EmptyNode.new(self.class.name)
231
+ Rb::AST::EmptyNode.new(self.class.name, @location)
235
232
  end
236
233
  end
237
234
 
238
235
  class MacroIf < ASTNode
239
236
  def to_rb
240
- Rb::AST::MacroIf.new(@cond.to_rb, @then.to_rb, @else.to_rb)
237
+ Rb::AST::MacroIf.new(@cond.to_rb, @then.to_rb, @else.to_rb, @location)
241
238
  end
242
239
  end
243
240
 
244
241
  class MacroFor < ASTNode
245
242
  def to_rb
246
- Rb::AST::MacroFor.new(@vars.map(&.to_rb), @exp.to_rb, @body.to_rb)
243
+ Rb::AST::MacroFor.new(@vars.map(&.to_rb), @exp.to_rb, @body.to_rb, @location)
247
244
  end
248
245
  end
249
246
 
250
247
  class MacroVar < ASTNode
251
248
  def to_rb
252
- Rb::AST::EmptyNode.new(self.class.name)
249
+ Rb::AST::EmptyNode.new(self.class.name, @location)
253
250
  end
254
251
  end
255
252
 
256
253
  class MacroExpression < ASTNode
257
254
  def to_rb
258
- Rb::AST::MacroExpression.new(@exp.to_rb, @output)
255
+ Rb::AST::MacroExpression.new(@exp.to_rb, @output, @location)
259
256
  end
260
257
  end
261
258
 
262
259
  class MacroLiteral < ASTNode
263
260
  def to_rb
264
- Rb::AST::MacroLiteral.new(@value)
261
+ Rb::AST::MacroLiteral.new(@value, @location)
265
262
  end
266
263
  end
267
264
 
268
265
  class Annotation < ASTNode
269
266
  def to_rb
270
- Rb::AST::EmptyNode.new(self.class.name)
267
+ Rb::AST::EmptyNode.new(self.class.name, @location)
271
268
  end
272
269
  end
273
270
 
274
271
  class EnumDef < ASTNode
275
272
  def to_rb
276
- Rb::AST::Enum.new(@name, @members.map(&.to_rb))
273
+ Rb::AST::Enum.new(@name, @members.map(&.to_rb), @location)
277
274
  end
278
275
  end
279
276
 
280
277
  class Path < ASTNode
281
278
  def to_rb
282
- Rb::AST::Path.new(full_name)
279
+ Rb::AST::Path.new(full_name, @location)
283
280
  end
284
281
 
285
282
  def full_name
@@ -291,13 +288,13 @@ module Crystal
291
288
 
292
289
  class Require < ASTNode
293
290
  def to_rb
294
- Rb::AST::Require.new(@string)
291
+ Rb::AST::Require.new(@string, @location)
295
292
  end
296
293
  end
297
294
 
298
295
  class TypeDeclaration < ASTNode
299
296
  def to_rb
300
- Rb::AST::TypeDeclaration.new(@var.to_rb, @declared_type.to_rb, @value.try(&.to_rb))
297
+ Rb::AST::TypeDeclaration.new(@var.to_rb, @declared_type.to_rb, @value.try(&.to_rb), @location)
301
298
  end
302
299
  end
303
300
 
@@ -307,8 +304,7 @@ module Crystal
307
304
  @cond.try(&.to_rb),
308
305
  @whens.map(&.to_rb),
309
306
  @else.try(&.to_rb),
310
- @exhaustive
311
- )
307
+ @exhaustive, @location)
312
308
  end
313
309
  end
314
310
 
@@ -322,16 +318,14 @@ module Crystal
322
318
  Def.new(
323
319
  "->",
324
320
  [Arg.new(arg_name)],
325
- c.tap { |call| call.obj = Var.new(arg_name) }
326
- )
321
+ c.tap { |call| call.obj = Var.new(arg_name) })
327
322
  ).to_rb
328
323
  else
329
324
  c.to_rb
330
325
  end
331
326
  end,
332
327
  @body.to_rb,
333
- @exhaustive
334
- )
328
+ @exhaustive, @location)
335
329
  end
336
330
  end
337
331
 
@@ -351,8 +345,7 @@ module Crystal
351
345
  Rb::AST::UnaryExpr.new(
352
346
  @exp.to_rb,
353
347
  op,
354
- requires_parentheses
355
- )
348
+ requires_parentheses ,@location)
356
349
  end
357
350
  end
358
351
  {% end %}
@@ -367,8 +360,7 @@ module Crystal
367
360
  "||",
368
361
  {% end %}
369
362
  @left.to_rb,
370
- @right.to_rb
371
- )
363
+ @right.to_rb ,@location)
372
364
  end
373
365
  end
374
366
  {% end %}
@@ -376,7 +368,7 @@ module Crystal
376
368
  {% for class_name in %w[Return Break Next] %}
377
369
  class {{class_name.id}} < ControlExpression
378
370
  def to_rb
379
- Rb::AST::{{class_name.id}}.new(@exp.try(&.to_rb))
371
+ Rb::AST::{{class_name.id}}.new(@exp.try(&.to_rb),@location)
380
372
  end
381
373
  end
382
374
  {% end %}
@@ -384,43 +376,43 @@ module Crystal
384
376
  class ExceptionHandler < ASTNode
385
377
  def to_rb
386
378
  Rb::AST::ExceptionHandler.new(@body.to_rb, @rescues.try(&.map(&.to_rb)), @else.try(&.to_rb),
387
- @ensure.try(&.to_rb))
379
+ @ensure.try(&.to_rb), @location)
388
380
  end
389
381
  end
390
382
 
391
383
  class Rescue < ASTNode
392
384
  def to_rb
393
- Rb::AST::Rescue.new(@body.to_rb, @types.try(&.map(&.to_rb)), @name)
385
+ Rb::AST::Rescue.new(@body.to_rb, @types.try(&.map(&.to_rb)), @name, @location)
394
386
  end
395
387
  end
396
388
 
397
389
  class Union < ASTNode
398
390
  def to_rb
399
- Rb::AST::Union.new(@types.map(&.to_rb))
391
+ Rb::AST::Union.new(@types.map(&.to_rb), @location)
400
392
  end
401
393
  end
402
394
 
403
395
  class Generic < ASTNode
404
396
  def to_rb
405
- Rb::AST::Generic.new(@name.to_rb, @type_vars.map(&.to_rb))
397
+ Rb::AST::Generic.new(@name.to_rb, @type_vars.map(&.to_rb), @location)
406
398
  end
407
399
  end
408
400
 
409
401
  class ProcLiteral < ASTNode
410
402
  def to_rb
411
- Rb::AST::Proc.new(@def.to_rb)
403
+ Rb::AST::Proc.new(@def.to_rb, @location)
412
404
  end
413
405
  end
414
406
 
415
407
  class Include < ASTNode
416
408
  def to_rb
417
- Rb::AST::Include.new(@name.to_rb)
409
+ Rb::AST::Include.new(@name.to_rb, @location)
418
410
  end
419
411
  end
420
412
 
421
413
  class Extend < ASTNode
422
414
  def to_rb
423
- Rb::AST::Extend.new(@name.to_rb)
415
+ Rb::AST::Extend.new(@name.to_rb, @location)
424
416
  end
425
417
  end
426
418
 
@@ -433,14 +425,13 @@ module Crystal
433
425
  nil,
434
426
  nil,
435
427
  nil,
436
- false
437
- )
428
+ false, @location)
438
429
  end
439
430
  end
440
431
 
441
432
  class VisibilityModifier < ASTNode
442
433
  def to_rb
443
- Rb::AST::VisibilityModifier.new(@modifier, @exp.to_rb)
434
+ Rb::AST::VisibilityModifier.new(@modifier, @exp.to_rb, @location)
444
435
  end
445
436
  end
446
437
 
@@ -453,8 +444,7 @@ module Crystal
453
444
  nil,
454
445
  nil,
455
446
  nil,
456
- !@exps.empty?
457
- )
447
+ !@exps.empty?, @location)
458
448
  end
459
449
  end
460
450
 
@@ -465,7 +455,7 @@ module Crystal
465
455
  Underscore MagicConstant Asm AsmOperand] %}
466
456
  class {{class_name.id}} < ASTNode
467
457
  def to_rb
468
- Rb::AST::EmptyNode.new(self.class.name)
458
+ Rb::AST::EmptyNode.new(self.class.name,@location)
469
459
  end
470
460
  end
471
461
  {% end %}
@@ -473,7 +463,7 @@ module Crystal
473
463
  {% for class_name in %w[PointerOf SizeOf InstanceSizeOf Out MacroVerbatim] %}
474
464
  class {{class_name.id}} < UnaryExpression
475
465
  def to_rb
476
- Rb::AST::EmptyNode.new(self.class.name)
466
+ Rb::AST::EmptyNode.new(self.class.name,@location)
477
467
  end
478
468
  end
479
469
  {% end %}