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: 33af503eebd7
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: 9634fc4d35ec
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Dec 13, 2016

  1. Macros: forward magic constant location

    Ary Borenszweig committed Dec 13, 2016
    2
    Copy the full SHA
    7a0a677 View commit details
  2. Debug: add missing debug location. Fixes #3584

    Ary Borenszweig committed Dec 13, 2016
    Copy the full SHA
    9634fc4 View commit details
42 changes: 42 additions & 0 deletions spec/compiler/codegen/macro_spec.cr
Original file line number Diff line number Diff line change
@@ -1575,4 +1575,46 @@ describe "Code gen: macro" do
x
)).to_b.should be_false
end

it "forwards file location" do
run(%(
macro foo
bar
end
macro bar(file = __FILE__)
{{file}}
end
foo
), filename: "bar.cr").to_string.should eq("bar.cr")
end

it "forwards dir location" do
run(%(
macro foo
bar
end
macro bar(dir = __DIR__)
{{dir}}
end
foo
), filename: "somedir/bar.cr").to_string.should eq("somedir")
end

it "forwards line number" do
run(%(
macro foo
bar
end
macro bar(line = __LINE__)
{{line}}
end
foo
), filename: "somedir/bar.cr", inject_primitives: false).to_i.should eq(10)
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
@@ -200,6 +200,10 @@ module Crystal

initialize_simple_class_vars_and_constants

if @debug && (filename = @program.filename)
set_current_debug_location Location.new(filename, 1, 1)
end

alloca_vars @program.vars, @program

emit_vars_debug_info(@program.vars) if @debug
1 change: 1 addition & 0 deletions src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
@@ -149,6 +149,7 @@ module Crystal

private def new_program(sources)
program = Program.new
program.filename = sources.first.filename
program.cache_dir = CacheDir.instance.directory_for(sources)
program.target_machine = target_machine
program.flags << "release" if release?
3 changes: 3 additions & 0 deletions src/compiler/crystal/program.cr
Original file line number Diff line number Diff line change
@@ -106,6 +106,9 @@ module Crystal
# Whether to show error trace
property? show_error_trace = false

# The main filename of this program
property filename : String?

def initialize
super(self, self, "main")

4 changes: 2 additions & 2 deletions src/compiler/crystal/syntax/ast.cr
Original file line number Diff line number Diff line change
@@ -2060,15 +2060,15 @@ module Crystal
end

def self.expand_line(location)
location.try(&.line_number) || 0
(location.try(&.original_location) || location).try(&.line_number) || 0
end

def self.expand_file_node(location)
StringLiteral.new(expand_file(location))
end

def self.expand_file(location)
location.try(&.filename.to_s) || "?"
location.try(&.original_filename.to_s) || "?"
end

def self.expand_dir_node(location)