finitio 0.7.0.pre.rc3 → 0.7.0.pre.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/finitio.rb +34 -4
- data/lib/finitio/syntax/import.rb +1 -1
- data/lib/finitio/system.rb +2 -0
- data/lib/finitio/version.rb +1 -1
- data/spec/finitio/test_stdlib_memoization.rb +22 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e41db73ab84b38134f0f19c0340c0863ff2d134b
|
4
|
+
data.tar.gz: db5f29aa5ce74764ffa96124d5982b3734491790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a48bf413dab63621f2c246fe4997ea8b0a1b9a04e3ac66ff14db4e697156cc20a56bd4ec2fee9493facbdc9466433d1f96d0e7d3a47162126402bf38e39ac88
|
7
|
+
data.tar.gz: 9def829a4ad8936700eba39ae1aaefebd0526def79a9c289cbfc06c2abf0b2be54771826b97c739d2cda39455223e0b60dd4f6d7e45a96bc39884338bd2312e9
|
data/Gemfile.lock
CHANGED
data/lib/finitio.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'set'
|
2
2
|
require 'time'
|
3
3
|
require 'pathname'
|
4
|
+
require 'thread'
|
4
5
|
|
5
6
|
module Finitio
|
6
7
|
|
@@ -9,6 +10,7 @@ module Finitio
|
|
9
10
|
require_relative "finitio/support"
|
10
11
|
require_relative 'finitio/type'
|
11
12
|
require_relative 'finitio/system'
|
13
|
+
require_relative "finitio/syntax"
|
12
14
|
|
13
15
|
IDENTITY = ->(object){ object }
|
14
16
|
|
@@ -18,25 +20,53 @@ module Finitio
|
|
18
20
|
File.expand_path('../finitio/stdlib', __FILE__)
|
19
21
|
]
|
20
22
|
|
23
|
+
MEMOIZED_SYSTEMS = {}
|
24
|
+
|
25
|
+
MEMOIZATION_SEMAPHORE = Mutex.new
|
26
|
+
|
21
27
|
def stdlib_path(path)
|
22
28
|
STDLIB_PATHS << path
|
23
29
|
end
|
24
30
|
|
25
31
|
def parse(source)
|
26
|
-
require "finitio/syntax"
|
27
32
|
Syntax.parse(source)
|
28
33
|
end
|
29
34
|
|
30
35
|
def system(source)
|
31
|
-
|
32
|
-
|
36
|
+
MEMOIZATION_SEMAPHORE.synchronize {
|
37
|
+
_system(source)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def _system(source)
|
42
|
+
if expanded = is_stdlib_source?(source)
|
43
|
+
MEMOIZED_SYSTEMS[expanded] ||= Syntax.compile(source)
|
44
|
+
else
|
45
|
+
Syntax.compile(source)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
private :_system
|
49
|
+
|
50
|
+
def clear_saved_systems!
|
51
|
+
MEMOIZATION_SEMAPHORE.synchronize {
|
52
|
+
MEMOIZED_SYSTEMS.clear
|
53
|
+
}
|
33
54
|
end
|
34
55
|
|
35
56
|
def ast(source)
|
36
|
-
require "finitio/syntax"
|
37
57
|
Syntax.ast(source)
|
38
58
|
end
|
39
59
|
|
60
|
+
def is_stdlib_source?(source)
|
61
|
+
return false unless source.respond_to?(:to_path)
|
62
|
+
stdlib = STDLIB_PATHS.any?{|stdlib|
|
63
|
+
a_list = File.expand_path(source.to_path).split('/')
|
64
|
+
b_list = File.expand_path(stdlib).split('/')
|
65
|
+
a_list[0..b_list.size-1] == b_list
|
66
|
+
}
|
67
|
+
stdlib ? File.expand_path(source.to_path) : nil
|
68
|
+
end
|
69
|
+
|
40
70
|
extend self
|
41
71
|
|
42
72
|
DEFAULT_SYSTEM = system(File.read(
|
data/lib/finitio/system.rb
CHANGED
data/lib/finitio/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Finitio, "stdlib memoization" do
|
3
|
+
|
4
|
+
describe "is_stdlib_source?" do
|
5
|
+
|
6
|
+
it 'says false when source code' do
|
7
|
+
expect(Finitio.is_stdlib_source?(".String")).to be_falsy
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'says false when a source file' do
|
11
|
+
expect(Finitio.is_stdlib_source?(Path.dir/"system.fio")).to be_falsy
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'says true when a stdlib file' do
|
15
|
+
source = Path.dir.parent.parent/"lib/finitio/stdlib/finitio/data.fio"
|
16
|
+
expect(source).to be_file
|
17
|
+
expect(Finitio.is_stdlib_source?(source)).to be_truthy
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: finitio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.pre.
|
4
|
+
version: 0.7.0.pre.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- spec/finitio/system.fio
|
153
153
|
- spec/finitio/test_ast.rb
|
154
154
|
- spec/finitio/test_parse.rb
|
155
|
+
- spec/finitio/test_stdlib_memoization.rb
|
155
156
|
- spec/finitio/test_system.rb
|
156
157
|
- spec/finitio/with-duplicates.fio
|
157
158
|
- spec/heading/test_allow_extra.rb
|
@@ -366,6 +367,7 @@ test_files:
|
|
366
367
|
- spec/finitio/system.fio
|
367
368
|
- spec/finitio/test_system.rb
|
368
369
|
- spec/finitio/test_parse.rb
|
370
|
+
- spec/finitio/test_stdlib_memoization.rb
|
369
371
|
- spec/system/test_initialize.rb
|
370
372
|
- spec/system/test_get_type.rb
|
371
373
|
- spec/system/test_fetch.rb
|