torc 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 717357a904aca8f1c526cac91ed4883e5d68b604
4
- data.tar.gz: dc47ed403e1007b75ea71fe40f82a023f1b3c435
3
+ metadata.gz: 0da95f9ba687792b4b8f712a0f457c751950074e
4
+ data.tar.gz: 29821a2db69bf317c15dc5329c99a0f4352198c5
5
5
  SHA512:
6
- metadata.gz: 3e1ba27b7abb8f4d6b4680c604b18b8b9ea3751c29908baada3a159144fdc5f85c4f52c652b954d568b75104b05590b3dfafc56912cdbe6cd9679b89875ad6d6
7
- data.tar.gz: 451e68be5653acc34a511a8752f26c56d4a8022c5ea01fa3e39f7d22ffc99b370cf5103a9dd6e992ccaa963b7db72fff9a56bec8cefe73c995a5f2d8ce19af82
6
+ metadata.gz: ddc554a04e3ef75f40cd618303e71e72fdfb3bf92afee3f7d21c3614a228715ff09191bdc62df5b222415495abb128c4254bb9a7f0c65c21a7a69473775ca3cd
7
+ data.tar.gz: 735121cd813c161d210c31e582ba236febef4143836915da7370bf263cb2fc31fc2bf8f6dfc736823872820a144623cf6d9841c46ada8715db749d27d318600f
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /vendor/
11
+ /*.gem
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 TODO: Write your name
3
+ Copyright (c) 2015 Nathan Hessler
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -2,28 +2,45 @@ require "torc/version"
2
2
  require "binding_of_caller"
3
3
 
4
4
  module Torc
5
-
6
-
7
- def Torc.included(basename)
8
- basename.class_eval do
9
- include Torc::InstanceMethods
5
+ def tail_call(name, *args)
6
+ if _torc_state[:loop_stack].empty?
7
+ recur name, *args
8
+ else
9
+ _torc_state[:swap_to] = [name, args]
10
+ _torc_state[:finished] = false
10
11
  end
11
12
  end
12
13
 
13
- module InstanceMethods
14
- def recurse(*args)
15
- return [:recurse, args] if instance_variable_defined? :@caller
14
+ def recur(*args)
15
+ name = binding.of_caller(1).eval('__method__')
16
+ if _torc_state[:loop_stack].last == name
17
+ _torc_state[:finished] = false
18
+ return args
19
+ else
20
+ _torc_state[:loop_stack].push name
16
21
  begin
17
- @caller = binding.of_caller(1).eval('__method__')
18
- caller_args = [:start, args]
19
- loop do
20
- caller_args = __send__ @caller, *caller_args.last
21
- return caller_args unless caller_args.respond_to? :first
22
- return caller_args unless caller_args.first == :recurse
23
- end
22
+ begin
23
+ _torc_state[:finished] = true
24
+ args = __send__ name, *args
25
+ if _torc_state[:swap_to]
26
+ name, args = _torc_state[:swap_to]
27
+ _torc_state[:swap_to] = nil
28
+ end
29
+ end until _torc_state[:finished]
30
+ return args
24
31
  ensure
25
- remove_instance_variable :@caller if instance_variable_defined? :@caller
32
+ _torc_state[:loop_stack].pop
26
33
  end
27
34
  end
28
35
  end
36
+
37
+ private
38
+
39
+ def _torc_state
40
+ @_torc_state ||= {
41
+ loop_stack: [],
42
+ swap_to: nil,
43
+ finished: true,
44
+ }
45
+ end
29
46
  end
@@ -1,3 +1,3 @@
1
1
  module Torc
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-07 00:00:00.000000000 Z
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.4.5.1
123
+ rubygems_version: 2.6.4
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: A Tail Optimized Recursive Call Helper