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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bceafae3cf07b42eeafcd42847e29426ee8b9694
4
- data.tar.gz: 947dd8fccf1bc29439a8948e18850f7e53f502b9
3
+ metadata.gz: e41db73ab84b38134f0f19c0340c0863ff2d134b
4
+ data.tar.gz: db5f29aa5ce74764ffa96124d5982b3734491790
5
5
  SHA512:
6
- metadata.gz: 541944fb0f9e729886145707c46f88c70677a9ea63272021e9fa67d083b867a2ec35c24e1035763c04c21ab8006cccd111717c144c40ed297c06e0b8b6b7ec4a
7
- data.tar.gz: 297ce451632080bd09e888c2e16fe1991722485375348ce08b06225c2a15b3f34220a805e05f22fcb623e37aba26e982629c89709b1c643ee8af13f8f63a733e
6
+ metadata.gz: 7a48bf413dab63621f2c246fe4997ea8b0a1b9a04e3ac66ff14db4e697156cc20a56bd4ec2fee9493facbdc9466433d1f96d0e7d3a47162126402bf38e39ac88
7
+ data.tar.gz: 9def829a4ad8936700eba39ae1aaefebd0526def79a9c289cbfc06c2abf0b2be54771826b97c739d2cda39455223e0b60dd4f6d7e45a96bc39884338bd2312e9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- finitio (0.7.0.pre.rc3)
4
+ finitio (0.7.0.pre.rc4)
5
5
  citrus (>= 2.4, < 4.0)
6
6
 
7
7
  GEM
@@ -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
- require "finitio/syntax"
32
- Syntax.compile(source)
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(
@@ -7,7 +7,7 @@ module Finitio
7
7
 
8
8
  def compile(system)
9
9
  file = system.resolve_url(import_url)
10
- imported = Finitio.system(file)
10
+ imported = Finitio.send(:_system, file)
11
11
  system.add_import(imported)
12
12
  system
13
13
  end
@@ -104,8 +104,10 @@ module Finitio
104
104
  next unless found = i.get_type(t.name)
105
105
  if found == t
106
106
  STDERR.puts "WARN: duplicate type def `#{t.name}`"
107
+ break
107
108
  else
108
109
  STDERR.puts "NOTICE: Type erasure `#{t.name}`"
110
+ break
109
111
  end
110
112
  end
111
113
  end
@@ -3,7 +3,7 @@ module Finitio
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- TINY = "0-rc3"
6
+ TINY = "0-rc4"
7
7
 
8
8
  def self.to_s
9
9
  [ MAJOR, MINOR, TINY ].join('.')
@@ -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.rc3
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