hdl 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/hdl/base.rb +1 -1
  2. data/lib/hdl/chip/table_chip.rb +57 -0
  3. metadata +15 -16
@@ -2,7 +2,7 @@ module HDL
2
2
  class << self
3
3
 
4
4
  def version
5
- "1.0.2"
5
+ "1.0.3"
6
6
  end
7
7
 
8
8
  def path
@@ -21,6 +21,7 @@ class HDL::TableChip < HDL::Chip
21
21
  memoize(pins) do
22
22
  check_pins!(pins)
23
23
  row = find_row(pins)
24
+ row ||= dnf_for(pins)
24
25
  select_outputs(row)
25
26
  end
26
27
  end
@@ -37,4 +38,60 @@ class HDL::TableChip < HDL::Chip
37
38
  Hash[filtered]
38
39
  end
39
40
 
41
+ def dnf_for(pins)
42
+ outputs.inject({}) do |hash, out|
43
+ true_rows = @table.select { |row| row[out] }
44
+
45
+ clauses = true_rows.map do |row|
46
+ clause = clause_for(row, pins)
47
+ end
48
+
49
+ clauses.reject! { |c| c.any? { |t| t == false } }
50
+
51
+ hash.merge(out => expression_for(clauses))
52
+ end
53
+ end
54
+
55
+ def clause_for(row, pins)
56
+ row = row.select { |k, v| inputs.include?(k) }
57
+ row = Hash[row]
58
+
59
+ terms = inputs.map do |input|
60
+ term_for(input, row, pins)
61
+ end
62
+
63
+ terms.reject { |t| t == true }
64
+ end
65
+
66
+ def term_for(input, row, pins)
67
+ bool = row[input]
68
+ term = pins[input]
69
+
70
+ if bool
71
+ term
72
+ elsif [true, false].include?(term)
73
+ !term
74
+ else
75
+ "NOT(#{term})"
76
+ end
77
+ end
78
+
79
+ def expression_for(clauses)
80
+ expr = clauses.map { |c| c.join(" AND ") }.join(" OR ")
81
+ simplify(expr)
82
+ end
83
+
84
+ def simplify(expression, previous = nil)
85
+ this = expression.dup
86
+
87
+ # TODO
88
+
89
+ # Simplify until no improvements can be made.
90
+ if this == previous
91
+ this
92
+ else
93
+ simplify(this, this)
94
+ end
95
+ end
96
+
40
97
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hdl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Patuzzo
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-06-22 00:00:00 +01:00
19
- default_executable:
18
+ date: 2013-08-11 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: treetop
@@ -70,27 +69,26 @@ extra_rdoc_files: []
70
69
 
71
70
  files:
72
71
  - README.md
73
- - lib/hdl.rb
74
- - lib/hdl/chip.rb
72
+ - lib/hdl/base.rb
75
73
  - lib/hdl/chip/schema_chip/evaluator.rb
76
74
  - lib/hdl/chip/schema_chip.rb
77
75
  - lib/hdl/chip/table_chip.rb
78
- - lib/hdl/base.rb
76
+ - lib/hdl/chip.rb
79
77
  - lib/hdl/dependency.rb
80
- - lib/hdl/parser/validator.rb
81
- - lib/hdl/parser/tree_walker.rb
82
- - lib/hdl/parser/grammar/pins.treetop
78
+ - lib/hdl/loader.rb
83
79
  - lib/hdl/parser/grammar/hdl.treetop
80
+ - lib/hdl/parser/grammar/pins.treetop
84
81
  - lib/hdl/parser/grammar/schema.treetop
85
82
  - lib/hdl/parser/grammar/table.treetop
86
83
  - lib/hdl/parser/grammar/vars.treetop
87
- - lib/hdl/parser/validator/table_validator.rb
84
+ - lib/hdl/parser/tree_walker.rb
88
85
  - lib/hdl/parser/validator/input_validator.rb
89
86
  - lib/hdl/parser/validator/schema_validator.rb
90
- - lib/hdl/loader.rb
87
+ - lib/hdl/parser/validator/table_validator.rb
88
+ - lib/hdl/parser/validator.rb
91
89
  - lib/hdl/parser.rb
92
- has_rdoc: true
93
- homepage: https://github.com/cpatuzzo/hdl
90
+ - lib/hdl.rb
91
+ homepage: https://github.com/tuzz/hdl
94
92
  licenses: []
95
93
 
96
94
  post_install_message:
@@ -119,9 +117,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
117
  requirements: []
120
118
 
121
119
  rubyforge_project:
122
- rubygems_version: 1.6.2
120
+ rubygems_version: 1.8.25
123
121
  signing_key:
124
122
  specification_version: 3
125
123
  summary: HDL
126
124
  test_files: []
127
125
 
126
+ has_rdoc: