Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e9a73cba3b90
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 008d17bb3669
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on May 6, 2016

  1. Cleanup: removed a few extra spaces

    Ary Borenszweig committed May 6, 2016
    Copy the full SHA
    c5ce133 View commit details
  2. Copy the full SHA
    9441b4c View commit details
  3. std: made a few macro methods regular methods.

    Ary Borenszweig committed May 6, 2016
    Copy the full SHA
    008d17b View commit details
Showing with 17 additions and 4 deletions.
  1. +4 −0 spec/compiler/macro/macro_methods_spec.cr
  2. +1 −1 src/class.cr
  3. +4 −0 src/compiler/crystal/macros.cr
  4. +7 −0 src/compiler/crystal/macros/methods.cr
  5. +1 −1 src/enum.cr
  6. +0 −2 src/primitives.cr
4 changes: 4 additions & 0 deletions spec/compiler/macro/macro_methods_spec.cr
Original file line number Diff line number Diff line change
@@ -510,6 +510,10 @@ describe "macro methods" do
assert_macro "", %({{ [1, 2, 3].includes?(1) }}), [] of ASTNode, %(true)
assert_macro "", %({{ [1, 2, 3].includes?(4) }}), [] of ASTNode, %(false)
end

it "executes +" do
assert_macro "", %({{ [1, 2] + [3, 4, 5] }}), [] of ASTNode, %([1, 2, 3, 4, 5])
end
end

describe "hash methods" do
2 changes: 1 addition & 1 deletion src/class.cr
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ class Class
# typeof(number) # => (String | Int32)
# typeof(klass.cast(number)) # => Int32
#
macro def cast(other) : self
def cast(other) : self
other as self
end

4 changes: 4 additions & 0 deletions src/compiler/crystal/macros.cr
Original file line number Diff line number Diff line change
@@ -498,6 +498,10 @@ module Crystal::Macros
# Similar to `Array#[]`, but returns `NilLiteral` on out of bounds.
def [](index : NumberLiteral) : ASTNode
end

# Similar to `Array#+`.
def +(other : ArrayLiteral) : ArrayLiteral
end
end

# A hash literal.
7 changes: 7 additions & 0 deletions src/compiler/crystal/macros/methods.cr
Original file line number Diff line number Diff line change
@@ -508,6 +508,13 @@ module Crystal
else
wrong_number_of_arguments "ArrayLiteral##{method}", args.size, 1
end
when "+"
interpret_one_arg_method(method, args) do |arg|
unless arg.is_a?(ArrayLiteral)
arg.raise "argument to `ArrayLiteral#+` must be an array, not #{arg.class_desc}:\n\n#{arg}"
end
ArrayLiteral.new(elements + arg.elements)
end
else
super
end
2 changes: 1 addition & 1 deletion src/enum.cr
Original file line number Diff line number Diff line change
@@ -325,7 +325,7 @@ struct Enum
# Color.from_value(2) # => Color::Blue
# Color.from_value(3) # => Exception
# ```
macro def self.from_value(value) : self
def self.from_value(value) : self
from_value?(value) || raise "Unknown enum #{self} value: #{value}"
end

2 changes: 0 additions & 2 deletions src/primitives.cr
Original file line number Diff line number Diff line change
@@ -284,7 +284,6 @@ end
end
{% end %}


{% for int in ints %}
struct {{int.id}}
# Returns a `Char` that has the unicode codepoint of *self*.
@@ -340,7 +339,6 @@ end
@[Primitive(:binary)]
def unsafe_mod(other : {{int2.id}}) : self
end

{% end %}

{% for float in floats %}