~singpolyma/rld

be390053302623e569164b2eaf5297fabd0bcd47 — Stephen Paul Weber 2 years ago 8b7e5b2
Improvements so rld can link itself
1 files changed, 13 insertions(+), 5 deletions(-)

M bin/rld
M bin/rld => bin/rld +13 -5
@@ 88,9 88,14 @@ class Linker < Parser::TreeRewriter
		in [:send, [:gvar, :$: | :$LOAD_PATH], (:<< | :push | :unshift) => m, arg]
			loc = arg.location.expression
			file = Pathname.new(loc.source_buffer.name)
			path = eval(loc.source, binding, file.to_s, loc.line)
			$LOAD_PATH.public_send(m, Pathname.new(path).relative? ? "#{file.dirname}/#{path}" : path)
			remove(node.location.expression)
			begin
				path = eval(loc.source, binding, file.to_s, loc.line)
				$LOAD_PATH.public_send(m, Pathname.new(path).relative? ? "#{file.dirname}/#{path}" : path)
				remove(node.location.expression)
			rescue
				loc = node.location.expression
				warn "#{loc}: WARNING: ignoring non-string-literal #{loc.source}"
			end
		in [:send, nil, :require, [:str, arg] => argnode]
			path = require(arg)
			realpath = Pathname.new(path).realdirpath


@@ 117,8 122,11 @@ class Linker < Parser::TreeRewriter
end

$options[:p] ||= Pathname.new(ARGV[0]).dirname.realdirpath
$LOAD_PATH.unshift($options[:p])
$LOAD_PATH.unshift("#{$options[:p]}/lib")

# Use public_send so we can link ourselves, otherwise this global is defined
# So it will "work" and the lines would be removed in linked output
$LOAD_PATH.public_send(:unshift, $options[:p])
$LOAD_PATH.public_send(:unshift, "#{$options[:p]}/lib")

$options[:l].each(&$options[:o].method(:puts)) unless $options[:i]