Skip to content

Commit

Permalink
+ A start towards forking V processes
Browse files Browse the repository at this point in the history
  • Loading branch information
kschiess committed Feb 9, 2011
1 parent 7414b67 commit bb50163
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/verneuil/compiler.rb
Expand Up @@ -68,6 +68,21 @@ def visit(sexp)

#--------------------------------------------------------- visitor methods

# s(:colon2, s(:const, :Verneuil), :Process) - access something inside
# a namespace. Constants are resolved at compile time!
#
def accept_colon2(left, right)
left_const = visit(left)
const = left_const.const_get(right)
@generator.load const
end

# s(:const, :Verneuil) - Resolve a constant globally and return it.
#
def accept_const(const)
eval(const.to_s)
end

# s(:call, RECEIVER, NAME, ARGUMENTS) - Method calls with or without
# receiver.
#
Expand Down Expand Up @@ -278,7 +293,7 @@ def accept_return(val)
# s(:iter, s(:call, RECEIVER, METHOD, ARGUMENTS), ASSIGNS, BLOCK) - call
# a method with a block.
#
def accept_iter(call, assigns, block)
def accept_iter(call, assigns, block=nil)
# Jump over the block code
adr_end_of_block = @generator.fwd_adr
@generator.jump adr_end_of_block
Expand All @@ -291,7 +306,7 @@ def accept_iter(call, assigns, block)
unless type == :lasgn
accept_args(*names)
end
visit(block)
visit(block) if block
@generator.return

adr_end_of_block.resolve
Expand Down
6 changes: 6 additions & 0 deletions lib/verneuil/process.rb
Expand Up @@ -48,6 +48,12 @@ def step
halted? ? @stack.last : nil
end

# Override Kernel.fork here so that nobody forks for real without wanting
# to.
def self.fork(*args, &block)
fail "BUG: Forking inside verneuil code should not call Kernel.fork."
end

# Returns true if the process has halted because it has reached its end.
#
def halted?
Expand Down
7 changes: 7 additions & 0 deletions spec/acceptance/forking_spec.rb
@@ -0,0 +1,7 @@
require 'spec_helper'

describe "Simple method calls" do
it "should delegate calls without receiver to the context" do
process(sample('fork_01.rb'), nil).run.should be_kind_of(Verneuil::Process)
end
end
3 changes: 3 additions & 0 deletions spec/acceptance/program_serializability_spec.rb
Expand Up @@ -5,7 +5,10 @@

# Some samples that cannot be run without setup
short_name = File.basename(sample_name, '.rb')

# Exceptions that cannot be run during this test.
next if short_name == 'simple_methods'
next if short_name == 'fork_01'

describe '"' + short_name + '"' do
it "should serialize at every step of execution" do
Expand Down
6 changes: 6 additions & 0 deletions spec/programs/fork_01.rb
@@ -0,0 +1,6 @@

child = Verneuil::Process.fork do
# Whoa look ma, spoon and fork!
end

child

0 comments on commit bb50163

Please sign in to comment.