Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment: add MAIN_FILE constant #7466

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/compiler/crystal/program.cr
Expand Up @@ -108,7 +108,7 @@ module Crystal
property? show_error_trace = false

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

# A `ProgressTracker` object which tracks compilation progress.
property progress_tracker = ProgressTracker.new
Expand Down Expand Up @@ -230,6 +230,14 @@ module Crystal
define_crystal_constants
end

def filename=(filename : String?)
@filename = filename

if filename
types["MAIN_FILE"] = Const.new self, self, "MAIN_FILE", StringLiteral.new(filename)
end
end

# Returns a `LiteralExpander` useful to expand literal like arrays and hashes
# into simpler forms.
getter(literal_expander) { LiteralExpander.new self }
Expand Down