gloss 0.0.5 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +3 -0
  3. data/.github/workflows/{crystal.yml → crystal_specs.yml} +1 -1
  4. data/.github/workflows/{ruby.yml → ruby_specs.yml} +2 -2
  5. data/.github/workflows/self_build.yml +45 -0
  6. data/.gloss.yml +1 -0
  7. data/Gemfile.lock +3 -3
  8. data/README.md +35 -5
  9. data/Rakefile +1 -1
  10. data/exe/gloss +13 -2
  11. data/ext/gloss/Makefile +8 -19
  12. data/ext/gloss/lib/cr_ruby.cr +5 -4
  13. data/ext/gloss/src/cr_ast.cr +61 -77
  14. data/ext/gloss/src/gloss.cr +7 -3
  15. data/ext/gloss/src/rb_ast.cr +37 -36
  16. data/lib/gloss.rb +11 -7
  17. data/lib/gloss/cli.rb +61 -23
  18. data/lib/gloss/config.rb +3 -1
  19. data/lib/gloss/errors.rb +1 -1
  20. data/lib/gloss/initializer.rb +2 -1
  21. data/lib/gloss/logger.rb +29 -0
  22. data/lib/gloss/parser.rb +17 -2
  23. data/lib/gloss/prog_loader.rb +141 -0
  24. data/lib/gloss/scope.rb +1 -1
  25. data/lib/gloss/source.rb +1 -1
  26. data/lib/gloss/type_checker.rb +80 -32
  27. data/lib/gloss/utils.rb +44 -0
  28. data/lib/gloss/version.rb +4 -4
  29. data/lib/gloss/{builder.rb → visitor.rb} +93 -54
  30. data/lib/gloss/watcher.rb +41 -19
  31. data/lib/gloss/writer.rb +21 -10
  32. data/sig/core.rbs +2 -0
  33. data/sig/fast_blank.rbs +4 -0
  34. data/sig/{gloss.rbs → gls.rbs} +0 -0
  35. data/sig/optparse.rbs +6 -0
  36. data/sig/rubygems.rbs +9 -0
  37. data/sig/yaml.rbs +3 -0
  38. data/src/exe/gloss +19 -0
  39. data/src/lib/gloss.gl +25 -0
  40. data/src/lib/gloss/cli.gl +40 -14
  41. data/src/lib/gloss/config.gl +2 -2
  42. data/src/lib/gloss/initializer.gl +1 -1
  43. data/src/lib/gloss/logger.gl +21 -0
  44. data/src/lib/gloss/parser.gl +17 -5
  45. data/src/lib/gloss/prog_loader.gl +133 -0
  46. data/src/lib/gloss/scope.gl +0 -2
  47. data/src/lib/gloss/type_checker.gl +85 -39
  48. data/src/lib/gloss/utils.gl +38 -0
  49. data/src/lib/gloss/version.gl +1 -1
  50. data/src/lib/gloss/{builder.gl → visitor.gl} +80 -49
  51. data/src/lib/gloss/watcher.gl +42 -24
  52. data/src/lib/gloss/writer.gl +15 -13
  53. metadata +22 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a26f64e872c2884f2fa5969d762e66ed6f1346732933f08ae7b92eb07aea5ab3
4
- data.tar.gz: 9cf39520e8dc43e6a74f9ea606a719815e2bd503d19744c7979478f746b8345f
3
+ metadata.gz: ed8cc1e615a2df1545467719ac63f8e2667a6e80c0e8fb3e05bf2e11d657779c
4
+ data.tar.gz: 59ecbb8e9f8327d8ffc86ffcb7254526b8dc2874d9c72b9fcd5f316f8c02334d
5
5
  SHA512:
6
- metadata.gz: bdb98f72e57945e9de8bbd03296d95b2cfc221f915e7e8e8fd511e8b4794ef3bb65f1830d9769486c30a004595c3a7f84e3e785bb1b1297d778cff984a0a3234
7
- data.tar.gz: 9758d730e858adf27c60f89ec9e88ffb07d3950d2a4f493b1d0ad2b00b7a10999fd76c9ae802753428fdfb0cab005adfe773456c415b504809217507ac30fbc5
6
+ metadata.gz: 91a18fc32f3a8dd27e14e9206c623fa3c608b0c6215ed8f239ae4f23a5ffa1f529b6b0cf4ddb6beeeb103b0d522c3a7bfdf5dc1d4462df0ba8a9da6598cb7c79
7
+ data.tar.gz: 8c42f4e1c6b92b5823835684d932ce686c6c517558d8e0061dc5633d7aa8eb11f8c652bf6aadca0bd5748731fdc51ae09543354de505da57640c89f5b457f5b4
data/.gitattributes ADDED
@@ -0,0 +1,3 @@
1
+ lib/gloss/**/*.rb linguist-generated
2
+ # this will basically cover 99% of the syntax anyway
3
+ **/*.gl linguist-language=Crystal
@@ -1,4 +1,4 @@
1
- name: Crystal CI
1
+ name: Crystal Specs
2
2
 
3
3
  on:
4
4
  push:
@@ -5,7 +5,7 @@
5
5
  # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
6
  # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
7
 
8
- name: Ruby
8
+ name: Ruby Specs
9
9
 
10
10
  on:
11
11
  push:
@@ -16,7 +16,7 @@ on:
16
16
  jobs:
17
17
  test:
18
18
 
19
- runs-on: ubuntu-latest
19
+ runs-on: ubuntu-20.04
20
20
 
21
21
  steps:
22
22
  - uses: actions/checkout@v2
@@ -0,0 +1,45 @@
1
+ name: Self Build
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+ env:
9
+ ImageOS: ubuntu18
10
+ jobs:
11
+ build:
12
+
13
+ runs-on: ubuntu-latest
14
+
15
+ container:
16
+ image: crystallang/crystal
17
+
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby
21
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
22
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
23
+ # uses: ruby/setup-ruby@v1
24
+ uses: ruby/setup-ruby@21351ecc0a7c196081abca5dc55b08f085efe09a
25
+ with:
26
+ ruby-version: 2.7
27
+ - name: Install ruby-dev
28
+ run: apt-get update -y && apt-get install -y ruby-dev
29
+ - uses: actions/cache@v2
30
+ id: gems-cache
31
+ with:
32
+ path: vendor/bundle
33
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
34
+ restore-keys: |
35
+ ${{ runner.os }}-gems-
36
+ - name: install Bundler
37
+ run: gem install bundler:2.2.3
38
+ - name: install gems
39
+ run: bundle install --jobs 4 --retry 3
40
+ - name: build native extensions
41
+ run: cd ext/gloss && make && cd -
42
+ - name: Build self with current state
43
+ run: ls lib/ && exe/gloss build
44
+ - name: check installation from rubygems
45
+ run: gem install gloss
data/.gloss.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  ---
2
2
  frozen_string_literals: true
3
3
  src_dir: src
4
+ entrypoint: src/exe/gloss
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gloss (0.0.5)
4
+ gloss (0.1.3)
5
5
  fast_blank
6
6
  listen
7
7
  rbs
@@ -25,7 +25,7 @@ GEM
25
25
  diff-lcs (1.4.4)
26
26
  fast_blank (1.0.0)
27
27
  ffi (1.14.2)
28
- i18n (1.8.7)
28
+ i18n (1.8.8)
29
29
  concurrent-ruby (~> 1.0)
30
30
  language_server-protocol (3.15.0.1)
31
31
  listen (3.4.1)
@@ -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,7 +1,14 @@
1
1
  # Gloss
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)
6
+ [![Current Version](http://ruby-gem-downloads-badge.herokuapp.com/gloss?color=green&label=downloads%20(current%20version)&metric=true)](https://rubygems.org/gems/gloss)
2
7
 
3
8
  [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,
4
- efficiency, and to enhance ruby's goal of developer happiness and productivity. Some of the features include:
9
+ efficiency, and to enhance ruby's goal of developer happiness and productivity.
10
+
11
+ ### Current features
5
12
 
6
13
  - Type checking, via optional type annotations
7
14
  - Compile-time macros
@@ -10,11 +17,26 @@ efficiency, and to enhance ruby's goal of developer happiness and productivity.
10
17
  - All ruby files are valid gloss files (a small exceptions for now; workarounds are mostly available)
11
18
  - Other syntactic sugar
12
19
 
13
- Coming soon:
14
- - abstract classes
20
+ ### Current Status
21
+
22
+ This project is at a stage where the core non-crystal parts are written in Gloss and compile to ruby (essentially self-hosting), albeit with the type checking being fairly loose. However the project is still in the very early stages; with (as of yet) no Linux support nor error handling (see roadmap below). Use at your own discretion!
23
+
24
+ ### Approx. roadmap:
25
+
26
+ - Improve error handling and logging (currently almost non-existant)
27
+ - Address Linux compatibility (currently more or less non-existant)
28
+ - Implement different strictnesses of type checking
29
+ - Metaprogramming helpers/safety:*
30
+ - Abstract classes and methods
31
+ - Method lookup/existence checking at compile time
32
+ - Method overloading
33
+
34
+ #### Related items:
35
+
36
+ - Rails helpers; probably some time away*
37
+ - Editor plugins/syntax highlighting/langserver; probably some time away*
15
38
 
16
- Maybe on the roadmap:
17
- - Method overloading
39
+ *__Dependent on popularity__
18
40
 
19
41
  ## Examples:
20
42
 
@@ -223,4 +245,12 @@ then
223
245
 
224
246
  then
225
247
 
248
+ `mkdir src && echo "puts 'hello world'" > src/hello_world.gl`
249
+
250
+ then
251
+
226
252
  `gloss build`
253
+
254
+ then
255
+
256
+ `ruby ./hello_world.rb`
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ RSpec::Core::RakeTask.new :spec do |spec|
18
18
  end
19
19
 
20
20
  task :build do
21
- `cd ext/gloss && make && cd -`
21
+ sh "cd", "ext/gloss", "&&", "make", "all", "&&", "cd", "-"
22
22
  end
23
23
 
24
24
  task :default => [:spec]
data/exe/gloss CHANGED
@@ -1,6 +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
- Gloss::CLI.new(ARGV).run
9
+ begin
10
+ Gloss::CLI.new(ARGV)
11
+ .run
12
+ rescue SystemExit
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")
17
+ end
data/ext/gloss/Makefile CHANGED
@@ -1,26 +1,20 @@
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
5
+ TARGET = ../../lib/gls.bundle
10
6
 
11
- shards:
12
- shards
7
+ clean:
8
+ rm -f $(TARGET) $(TARGET).dwarf
9
+ endif
13
10
 
14
- build: ./src/gloss.cr
15
- $(CRYSTAL) build --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" $< -o $(TARGET).bundle
11
+ ifeq "$(PLATFORM)" "Linux"
12
+ TARGET = ../../lib/gls.so
16
13
 
17
14
  clean:
18
- rm -f $(TARGET).bundle
19
- rm -f $(TARGET).bundle.dwarf
15
+ rm -f $(TARGET)
20
16
  endif
21
17
 
22
- ifeq "$(PLATFORM)" "Linux"
23
- LLVM_TARGET = "$(shell uname -m)-unknown-linux-gnu"
24
18
  install: all
25
19
 
26
20
  all: clean shards build
@@ -29,9 +23,4 @@ shards:
29
23
  shards
30
24
 
31
25
  build: ./src/gloss.cr
32
- $(CRYSTAL) build $< --cross-compile --target $(LLVM_TARGET) --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" -o $(TARGET)
33
-
34
- clean:
35
- rm -f $(TARGET).o
36
- rm -f $(TARGET).so
37
- endif
26
+ $(CRYSTAL) build --link-flags "-shared -dynamic -Wl,-undefined,dynamic_lookup" $< -o $(TARGET) --release
@@ -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,127 +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)
235
- end
236
- end
237
-
238
- class MacroExpression < ASTNode
239
- def to_rb
240
- Rb::AST::EmptyNode.new(self.class.name)
231
+ Rb::AST::EmptyNode.new(self.class.name, @location)
241
232
  end
242
233
  end
243
234
 
244
235
  class MacroIf < ASTNode
245
236
  def to_rb
246
- 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)
247
238
  end
248
239
  end
249
240
 
250
241
  class MacroFor < ASTNode
251
242
  def to_rb
252
- 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)
253
244
  end
254
245
  end
255
246
 
256
247
  class MacroVar < ASTNode
257
248
  def to_rb
258
- Rb::AST::EmptyNode.new(self.class.name)
249
+ Rb::AST::EmptyNode.new(self.class.name, @location)
259
250
  end
260
251
  end
261
252
 
262
253
  class MacroExpression < ASTNode
263
254
  def to_rb
264
- Rb::AST::MacroExpression.new(@exp.to_rb, @output)
255
+ Rb::AST::MacroExpression.new(@exp.to_rb, @output, @location)
265
256
  end
266
257
  end
267
258
 
268
259
  class MacroLiteral < ASTNode
269
260
  def to_rb
270
- Rb::AST::MacroLiteral.new(@value)
261
+ Rb::AST::MacroLiteral.new(@value, @location)
271
262
  end
272
263
  end
273
264
 
274
265
  class Annotation < ASTNode
275
266
  def to_rb
276
- Rb::AST::EmptyNode.new(self.class.name)
267
+ Rb::AST::EmptyNode.new(self.class.name, @location)
277
268
  end
278
269
  end
279
270
 
280
271
  class EnumDef < ASTNode
281
272
  def to_rb
282
- Rb::AST::Enum.new(@name, @members.map(&.to_rb))
273
+ Rb::AST::Enum.new(@name, @members.map(&.to_rb), @location)
283
274
  end
284
275
  end
285
276
 
286
277
  class Path < ASTNode
287
278
  def to_rb
288
- Rb::AST::Path.new(full_name)
279
+ Rb::AST::Path.new(full_name, @location)
289
280
  end
290
281
 
291
282
  def full_name
@@ -297,13 +288,13 @@ module Crystal
297
288
 
298
289
  class Require < ASTNode
299
290
  def to_rb
300
- Rb::AST::Require.new(@string)
291
+ Rb::AST::Require.new(@string, @location)
301
292
  end
302
293
  end
303
294
 
304
295
  class TypeDeclaration < ASTNode
305
296
  def to_rb
306
- 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)
307
298
  end
308
299
  end
309
300
 
@@ -313,8 +304,7 @@ module Crystal
313
304
  @cond.try(&.to_rb),
314
305
  @whens.map(&.to_rb),
315
306
  @else.try(&.to_rb),
316
- @exhaustive
317
- )
307
+ @exhaustive, @location)
318
308
  end
319
309
  end
320
310
 
@@ -328,16 +318,14 @@ module Crystal
328
318
  Def.new(
329
319
  "->",
330
320
  [Arg.new(arg_name)],
331
- c.tap { |call| call.obj = Var.new(arg_name) }
332
- )
321
+ c.tap { |call| call.obj = Var.new(arg_name) })
333
322
  ).to_rb
334
323
  else
335
324
  c.to_rb
336
325
  end
337
326
  end,
338
327
  @body.to_rb,
339
- @exhaustive
340
- )
328
+ @exhaustive, @location)
341
329
  end
342
330
  end
343
331
 
@@ -357,8 +345,7 @@ module Crystal
357
345
  Rb::AST::UnaryExpr.new(
358
346
  @exp.to_rb,
359
347
  op,
360
- requires_parentheses
361
- )
348
+ requires_parentheses ,@location)
362
349
  end
363
350
  end
364
351
  {% end %}
@@ -373,8 +360,7 @@ module Crystal
373
360
  "||",
374
361
  {% end %}
375
362
  @left.to_rb,
376
- @right.to_rb
377
- )
363
+ @right.to_rb ,@location)
378
364
  end
379
365
  end
380
366
  {% end %}
@@ -382,7 +368,7 @@ module Crystal
382
368
  {% for class_name in %w[Return Break Next] %}
383
369
  class {{class_name.id}} < ControlExpression
384
370
  def to_rb
385
- Rb::AST::{{class_name.id}}.new(@exp.try(&.to_rb))
371
+ Rb::AST::{{class_name.id}}.new(@exp.try(&.to_rb),@location)
386
372
  end
387
373
  end
388
374
  {% end %}
@@ -390,43 +376,43 @@ module Crystal
390
376
  class ExceptionHandler < ASTNode
391
377
  def to_rb
392
378
  Rb::AST::ExceptionHandler.new(@body.to_rb, @rescues.try(&.map(&.to_rb)), @else.try(&.to_rb),
393
- @ensure.try(&.to_rb))
379
+ @ensure.try(&.to_rb), @location)
394
380
  end
395
381
  end
396
382
 
397
383
  class Rescue < ASTNode
398
384
  def to_rb
399
- 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)
400
386
  end
401
387
  end
402
388
 
403
389
  class Union < ASTNode
404
390
  def to_rb
405
- Rb::AST::Union.new(@types.map(&.to_rb))
391
+ Rb::AST::Union.new(@types.map(&.to_rb), @location)
406
392
  end
407
393
  end
408
394
 
409
395
  class Generic < ASTNode
410
396
  def to_rb
411
- 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)
412
398
  end
413
399
  end
414
400
 
415
401
  class ProcLiteral < ASTNode
416
402
  def to_rb
417
- Rb::AST::Proc.new(@def.to_rb)
403
+ Rb::AST::Proc.new(@def.to_rb, @location)
418
404
  end
419
405
  end
420
406
 
421
407
  class Include < ASTNode
422
408
  def to_rb
423
- Rb::AST::Include.new(@name.to_rb)
409
+ Rb::AST::Include.new(@name.to_rb, @location)
424
410
  end
425
411
  end
426
412
 
427
413
  class Extend < ASTNode
428
414
  def to_rb
429
- Rb::AST::Extend.new(@name.to_rb)
415
+ Rb::AST::Extend.new(@name.to_rb, @location)
430
416
  end
431
417
  end
432
418
 
@@ -439,14 +425,13 @@ module Crystal
439
425
  nil,
440
426
  nil,
441
427
  nil,
442
- false
443
- )
428
+ false, @location)
444
429
  end
445
430
  end
446
431
 
447
432
  class VisibilityModifier < ASTNode
448
433
  def to_rb
449
- Rb::AST::VisibilityModifier.new(@modifier, @exp.to_rb)
434
+ Rb::AST::VisibilityModifier.new(@modifier, @exp.to_rb, @location)
450
435
  end
451
436
  end
452
437
 
@@ -459,8 +444,7 @@ module Crystal
459
444
  nil,
460
445
  nil,
461
446
  nil,
462
- !@exps.empty?
463
- )
447
+ !@exps.empty?, @location)
464
448
  end
465
449
  end
466
450
 
@@ -471,7 +455,7 @@ module Crystal
471
455
  Underscore MagicConstant Asm AsmOperand] %}
472
456
  class {{class_name.id}} < ASTNode
473
457
  def to_rb
474
- Rb::AST::EmptyNode.new(self.class.name)
458
+ Rb::AST::EmptyNode.new(self.class.name,@location)
475
459
  end
476
460
  end
477
461
  {% end %}
@@ -479,7 +463,7 @@ module Crystal
479
463
  {% for class_name in %w[PointerOf SizeOf InstanceSizeOf Out MacroVerbatim] %}
480
464
  class {{class_name.id}} < UnaryExpression
481
465
  def to_rb
482
- Rb::AST::EmptyNode.new(self.class.name)
466
+ Rb::AST::EmptyNode.new(self.class.name,@location)
483
467
  end
484
468
  end
485
469
  {% end %}