Skip to content

Commit

Permalink
remove Atomy.make_wrapper_module, use Atomy::Module.new
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed May 2, 2012
1 parent 5e36c14 commit 07b8ac9
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 40 deletions.
3 changes: 1 addition & 2 deletions bin/atomy
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ def run_atomy(options)
return if run
end


require("repl").repl(
File.expand_path("~/.atomy_history"),
TOPLEVEL_BINDING,
nil,
options[:debug]
)
end
Expand Down
2 changes: 1 addition & 1 deletion kernel/meta.ay
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Atomy AST open:
ast(LetMacro(.body, [.macros]))

LetMacro bytecode(g, mod) := do:
new = Atomy make-wrapper-module(mod file)
new = Atomy Module new(mod file)
new delegate = mod

new send(.include, mod)
Expand Down
21 changes: 11 additions & 10 deletions kernel/repl.ay
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ pretty = require("pretty")

require("readline")

try(source, mod, debug = false) =
with-restarts(retry -> try(source, bnd), abort -> .ok):
{ signal(.evaluated(mod eval(source, debug)))
try(source, module, debug = false) =
with-restarts(retry -> try(source, module), abort -> .ok):
{ signal(.evaluated(module eval(source, debug)))
} rescue:
(e: StandardError | ScriptError) -> error(e)

basic-repl(mod, debug = false) =
basic-repl(module, debug = false) =
loop:
prompt =
with-restarts(use-prompt(p) -> p):
Expand All @@ -34,7 +34,7 @@ basic-repl(mod, debug = false) =

source:
signal(.input(source))
try(source, mod, debug)
try(source, module, debug)

signal(.loop)

Expand All @@ -55,17 +55,18 @@ ReplDebugger = class:
condition DefaultDebugger show-options-for(e)

-- TODO: inherit original binding
{ basic-repl(Atomy make-wrapper-module) } bind:
{ basic-repl(Atomy Module new) } bind:
.prompt -> restart(.use-prompt, "[!]> ")

.special(n ? =~ r"\d+") ->
^(condition Restarts) [n to-i] invoke

.quit -> exit(1)

repl(history = nil, bnd = nil, debug = false) := do:
mod = Atomy make-wrapper-module(."(repl)")
mod use("atomy")
repl(history = nil, module = nil, debug = false) := do:
unless(module):
module =! Atomy Module new(."(repl)")
module use("atomy")

when(history and File exists(history)?):
File open(history, "r") [f]:
Expand All @@ -79,7 +80,7 @@ repl(history = nil, bnd = nil, debug = false) := do:
pretty Colored = true):
frame = 0

{ basic-repl(mod, bnd, debug)
{ basic-repl(module, debug)
} bind:
.prompt ->
restart(.use-prompt, "[" + frame to-s + "]> ")
Expand Down
2 changes: 1 addition & 1 deletion lib/atomy/code_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def load_file(fn, debug = false)
needs_loading = compilation_needed?(found)
return loaded if loaded and not needs_loading

mod = Atomy.make_wrapper_module(file)
mod = Atomy::Module.new(file)

begin
LOADED[file] = mod
Expand Down
15 changes: 15 additions & 0 deletions lib/atomy/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ module Atomy
class Module < ::Module
attr_accessor :file, :delegate

def initialize(file = :local)
super()

@file = file

unless @file == :local
Rubinius::Type.set_module_name(
self,
File.basename(file.to_s).to_sym,
Object)
end

const_set(:Self, self)
end

dynamic_method(:__binding__) do |g|
g.push_self
g.add_scope
Expand Down
17 changes: 0 additions & 17 deletions lib/atomy/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,4 @@ def self.current_module

nil
end

def self.make_wrapper_module(file = :local)
mod = Atomy::Module.new

# just to make debugging a bit easier
unless file == :local
Rubinius::Type.set_module_name(
mod,
File.basename(file.to_s).to_sym,
Object)
end

mod.const_set(:Self, mod)
mod.file = file

mod
end
end
12 changes: 6 additions & 6 deletions spec/suite/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def wildcard
describe(Module) do
describe(:atomy_methods) do
it("contains a hash of Atomy-defined methods") do
mod = Atomy.make_wrapper_module
mod = Atomy::Module.new

x = Module.new

Expand Down Expand Up @@ -36,7 +36,7 @@ def wildcard
describe(Atomy::Branch) do
describe(:total_args) do
it("is the amount of required or default arguments") do
mod = Atomy.make_wrapper_module
mod = Atomy::Module.new

Atomy::Branch.new(mod, wildcard).total_args.must_equal 0

Expand All @@ -53,7 +53,7 @@ def wildcard
end

it("does not reflect splatiness") do
mod = Atomy.make_wrapper_module
mod = Atomy::Module.new

Atomy::Branch.new(
mod,
Expand All @@ -66,7 +66,7 @@ def wildcard

describe(:<=>) do
it("prioritizes a method with more arguments over another") do
mod = Atomy.make_wrapper_module
mod = Atomy::Module.new
a = Atomy::Branch.new(mod, wildcard, [wildcard], [wildcard])
b = Atomy::Branch.new(mod, wildcard, [wildcard])
(a <=> b).must_equal 1
Expand All @@ -78,7 +78,7 @@ def wildcard
describe(Atomy) do
describe(:define_branch) do
it("adds a method branch to the target module") do
mod = Atomy.make_wrapper_module
mod = Atomy::Module.new

x = Class.new

Expand All @@ -90,7 +90,7 @@ def wildcard
end

it("replaces branches with equivalent patterns") do
mod = Atomy.make_wrapper_module
mod = Atomy::Module.new

x = Class.new

Expand Down
2 changes: 1 addition & 1 deletion spec/suite/patterns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ module Atomy::Patterns
it("targets the singleton class of its body for definition") do
x = Object.new
p = SingletonClass.new(Atomy::AST::Literal.new(0, x))
mod = Atomy.make_wrapper_module
mod = Atomy::Module.new
p.in_context(mod)
p.definition_target.must_equal x.singleton_class
end
Expand Down
4 changes: 2 additions & 2 deletions spec/suite/patterns_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def match(pat, val)
0,
pat),
Atomy::AST::Literal.new(0, val)),
Atomy.make_wrapper_module,
Atomy::Module.new
Binding.setup(
Rubinius::VariableScope.of_sender,
Rubinius::CompiledMethod.of_sender,
Expand All @@ -18,7 +18,7 @@ def expr(str)
end

def pat(str)
mod = Atomy.make_wrapper_module
mod = Atomy::Module.new
p = expr(str).to_pattern
p.in_context(mod)
p
Expand Down

0 comments on commit 07b8ac9

Please sign in to comment.