rggen-core 0.33.1 → 0.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/rggen/core/base/component_factory.rb +2 -2
- data/lib/rggen/core/base/feature.rb +5 -4
- data/lib/rggen/core/base/feature_variable.rb +112 -0
- data/lib/rggen/core/base/internal_struct.rb +2 -2
- data/lib/rggen/core/builder/builder.rb +5 -4
- data/lib/rggen/core/builder/component_registry.rb +6 -6
- data/lib/rggen/core/builder/feature_entry_base.rb +4 -4
- data/lib/rggen/core/builder/feature_registry.rb +21 -20
- data/lib/rggen/core/builder/general_feature_entry.rb +5 -6
- data/lib/rggen/core/builder/input_component_registry.rb +2 -2
- data/lib/rggen/core/builder/layer.rb +65 -34
- data/lib/rggen/core/builder/list_feature_entry.rb +12 -9
- data/lib/rggen/core/builder/loader_registry.rb +4 -4
- data/lib/rggen/core/builder/plugin_manager.rb +14 -3
- data/lib/rggen/core/builder/simple_feature_entry.rb +5 -6
- data/lib/rggen/core/configuration/component_factory.rb +2 -2
- data/lib/rggen/core/configuration/feature.rb +0 -2
- data/lib/rggen/core/configuration/feature_factory.rb +0 -1
- data/lib/rggen/core/configuration/input_data.rb +2 -4
- data/lib/rggen/core/configuration/loader.rb +0 -1
- data/lib/rggen/core/core_extensions/kernel.rb +1 -1
- data/lib/rggen/core/core_extensions/object.rb +0 -7
- data/lib/rggen/core/dsl.rb +2 -1
- data/lib/rggen/core/exceptions.rb +3 -3
- data/lib/rggen/core/input_base/component_factory.rb +10 -7
- data/lib/rggen/core/input_base/error.rb +1 -1
- data/lib/rggen/core/input_base/feature.rb +63 -72
- data/lib/rggen/core/input_base/feature_factory.rb +2 -1
- data/lib/rggen/core/input_base/input_data.rb +6 -4
- data/lib/rggen/core/input_base/input_vaue_parser.rb +2 -12
- data/lib/rggen/core/input_base/loader.rb +2 -0
- data/lib/rggen/core/input_base/option_hash_parser.rb +1 -1
- data/lib/rggen/core/input_base/property.rb +4 -4
- data/lib/rggen/core/input_base/verifier.rb +11 -4
- data/lib/rggen/core/options.rb +2 -2
- data/lib/rggen/core/output_base/code_generatable.rb +77 -0
- data/lib/rggen/core/output_base/feature.rb +16 -86
- data/lib/rggen/core/register_map/component_factory.rb +2 -4
- data/lib/rggen/core/register_map/feature.rb +0 -1
- data/lib/rggen/core/register_map/feature_factory.rb +0 -1
- data/lib/rggen/core/register_map/input_data.rb +10 -12
- data/lib/rggen/core/utility/attribute_setter.rb +13 -10
- data/lib/rggen/core/utility/code_utility/source_file.rb +1 -1
- data/lib/rggen/core/utility/code_utility.rb +2 -2
- data/lib/rggen/core/utility/regexp_patterns.rb +1 -1
- data/lib/rggen/core/version.rb +1 -1
- data/lib/rggen/core.rb +2 -3
- metadata +7 -11
- data/lib/rggen/core/configuration/error.rb +0 -20
- data/lib/rggen/core/output_base/code_generator.rb +0 -45
- data/lib/rggen/core/register_map/error.rb +0 -20
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RgGen
|
4
|
+
module Core
|
5
|
+
module OutputBase
|
6
|
+
module CodeGeneratable
|
7
|
+
CODE_PHASES = [
|
8
|
+
:pre_code, :main_code, :post_code
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
VARIABLE_NAMES =
|
12
|
+
CODE_PHASES
|
13
|
+
.to_h { |phase| [phase, :"@#{phase}_blocks"] }
|
14
|
+
.freeze
|
15
|
+
|
16
|
+
module Extension
|
17
|
+
private
|
18
|
+
|
19
|
+
CODE_PHASES.each do |phase|
|
20
|
+
define_method(phase) do |kind, **options, &body|
|
21
|
+
regiter_code_block(__method__, kind, **options, &body)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def regiter_code_block(phase, kind, **options, &body)
|
26
|
+
block =
|
27
|
+
if options[:from_template]
|
28
|
+
path = extract_template_path(options)
|
29
|
+
location = caller_locations(2, 1).first
|
30
|
+
-> { process_template(path, location) }
|
31
|
+
else
|
32
|
+
body
|
33
|
+
end
|
34
|
+
return unless block
|
35
|
+
|
36
|
+
variable_name = VARIABLE_NAMES[phase]
|
37
|
+
feature_hash_array_variable_push(variable_name, kind, block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def extract_template_path(options)
|
41
|
+
path = options[:from_template]
|
42
|
+
path.equal?(true) ? nil : path
|
43
|
+
end
|
44
|
+
|
45
|
+
def template_engine(engine)
|
46
|
+
@template_engine = engine.instance
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.included(klass)
|
51
|
+
klass.extend(Extension)
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate_code(code, phase, kind)
|
55
|
+
blocks = feature_hash_array_variable_get(VARIABLE_NAMES[phase])
|
56
|
+
return unless blocks
|
57
|
+
|
58
|
+
blocks[kind]&.each do |block|
|
59
|
+
if block.arity.zero?
|
60
|
+
code << instance_exec(&block)
|
61
|
+
else
|
62
|
+
instance_exec(code, &block)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def process_template(path = nil, caller_location = nil)
|
70
|
+
caller_location ||= caller_locations(1, 1).first
|
71
|
+
template_engine = feaure_scala_variable_get(:@template_engine)
|
72
|
+
template_engine.process_template(self, path, caller_location)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -5,89 +5,32 @@ module RgGen
|
|
5
5
|
module OutputBase
|
6
6
|
class Feature < Base::Feature
|
7
7
|
include Base::FeatureLayerExtension
|
8
|
+
include CodeGeneratable
|
8
9
|
include RaiseError
|
9
10
|
|
10
11
|
class << self
|
11
|
-
attr_reader :pre_builders
|
12
|
-
attr_reader :builders
|
13
|
-
|
14
|
-
def code_generators
|
15
|
-
@code_generators ||= {}
|
16
|
-
end
|
17
|
-
|
18
|
-
def template_engine(engine = nil)
|
19
|
-
@template_engine = engine.instance if engine
|
20
|
-
@template_engine
|
21
|
-
end
|
22
|
-
|
23
|
-
attr_reader :file_writer
|
24
|
-
|
25
12
|
def exported_methods
|
26
|
-
|
13
|
+
feature_array_variable_get(:@exported_methods)
|
27
14
|
end
|
28
15
|
|
29
16
|
private
|
30
17
|
|
31
18
|
def pre_build(&body)
|
32
|
-
|
33
|
-
@pre_builders << body
|
19
|
+
feature_array_variable_push(:@pre_builders, body)
|
34
20
|
end
|
35
21
|
|
36
22
|
def build(&body)
|
37
|
-
|
38
|
-
@builders << body
|
39
|
-
end
|
40
|
-
|
41
|
-
[:pre_code, :main_code, :post_code].each do |phase|
|
42
|
-
define_method(phase) do |kind, **options, &body|
|
43
|
-
register_code_generator(__method__, kind, **options, &body)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def register_code_generator(phase, kind, **options, &body)
|
48
|
-
block =
|
49
|
-
if options[:from_template]
|
50
|
-
path = extract_template_path(options)
|
51
|
-
location = caller_locations(2, 1).first
|
52
|
-
-> { process_template(path, location) }
|
53
|
-
else
|
54
|
-
body
|
55
|
-
end
|
56
|
-
(code_generators[phase] ||= CodeGenerator.new)
|
57
|
-
.register(kind, &block)
|
58
|
-
end
|
59
|
-
|
60
|
-
def extract_template_path(options)
|
61
|
-
path = options[:from_template]
|
62
|
-
path.equal?(true) ? nil : path
|
23
|
+
feature_array_variable_push(:@builders, body)
|
63
24
|
end
|
64
25
|
|
65
|
-
def write_file(file_name_pattern, &
|
66
|
-
@file_writer = FileWriter.new(file_name_pattern, &
|
26
|
+
def write_file(file_name_pattern, &)
|
27
|
+
@file_writer = FileWriter.new(file_name_pattern, &)
|
67
28
|
end
|
68
29
|
|
69
30
|
def export(*methods)
|
70
31
|
methods.each do |method|
|
71
|
-
exported_methods
|
72
|
-
(exported_methods
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class << self
|
78
|
-
def inherited(subclass)
|
79
|
-
super
|
80
|
-
export_instance_variable(:@pre_builders, subclass, &:dup)
|
81
|
-
export_instance_variable(:@builders, subclass, &:dup)
|
82
|
-
export_instance_variable(:@template_engine, subclass)
|
83
|
-
export_instance_variable(:@file_writer, subclass)
|
84
|
-
export_instance_variable(:@exported_methods, subclass, &:dup)
|
85
|
-
copy_code_generators(subclass)
|
86
|
-
end
|
87
|
-
|
88
|
-
def copy_code_generators(subclass)
|
89
|
-
@code_generators&.each do |phase, generator|
|
90
|
-
subclass.code_generators[phase] = generator.copy
|
32
|
+
exported_methods&.include?(method) ||
|
33
|
+
feature_array_variable_push(:@exported_methods, method)
|
91
34
|
end
|
92
35
|
end
|
93
36
|
end
|
@@ -97,22 +40,20 @@ module RgGen
|
|
97
40
|
end
|
98
41
|
|
99
42
|
def pre_build
|
100
|
-
|
101
|
-
.pre_builders
|
43
|
+
feature_array_variable_get(:@pre_builders)
|
102
44
|
&.each { |body| instance_exec(&body) }
|
103
45
|
end
|
104
46
|
|
105
47
|
def build
|
106
|
-
|
107
|
-
.builders
|
48
|
+
feature_array_variable_get(:@builders)
|
108
49
|
&.each { |body| instance_exec(&body) }
|
109
50
|
end
|
110
51
|
|
111
52
|
def export(*methods)
|
112
53
|
methods.each do |method|
|
113
|
-
unless exported_methods(:class)
|
114
|
-
exported_methods(:object)
|
115
|
-
exported_methods
|
54
|
+
unless exported_methods(:class)&.include?(method) ||
|
55
|
+
exported_methods(:object)&.include?(method)
|
56
|
+
(@exported_methods ||= []) << method
|
116
57
|
end
|
117
58
|
end
|
118
59
|
end
|
@@ -121,18 +62,13 @@ module RgGen
|
|
121
62
|
if scope == :class
|
122
63
|
self.class.exported_methods
|
123
64
|
else
|
124
|
-
@exported_methods
|
65
|
+
@exported_methods
|
125
66
|
end
|
126
67
|
end
|
127
68
|
|
128
|
-
def generate_code(code, phase, kind)
|
129
|
-
generator = self.class.code_generators[phase]
|
130
|
-
generator&.generate(self, code, kind)
|
131
|
-
end
|
132
|
-
|
133
69
|
def write_file(directory = nil)
|
134
|
-
file_writer
|
135
|
-
|
70
|
+
feaure_scala_variable_get(:@file_writer)
|
71
|
+
&.write_file(self, directory)
|
136
72
|
end
|
137
73
|
|
138
74
|
private
|
@@ -140,12 +76,6 @@ module RgGen
|
|
140
76
|
def configuration
|
141
77
|
component.configuration
|
142
78
|
end
|
143
|
-
|
144
|
-
def process_template(path = nil, caller_location = nil)
|
145
|
-
caller_location ||= caller_locations(1, 1).first
|
146
|
-
template_engine = self.class.template_engine
|
147
|
-
template_engine.process_template(self, path, caller_location)
|
148
|
-
end
|
149
79
|
end
|
150
80
|
end
|
151
81
|
end
|
@@ -4,16 +4,14 @@ module RgGen
|
|
4
4
|
module Core
|
5
5
|
module RegisterMap
|
6
6
|
class ComponentFactory < InputBase::ComponentFactory
|
7
|
-
include RaiseError
|
8
|
-
|
9
7
|
private
|
10
8
|
|
11
9
|
def select_actual_sources(configuration, *_)
|
12
10
|
configuration
|
13
11
|
end
|
14
12
|
|
15
|
-
def create_input_data(configuration, &
|
16
|
-
InputData.new(:root, valid_value_lists, configuration, &
|
13
|
+
def create_input_data(configuration, &)
|
14
|
+
InputData.new(:root, valid_value_lists, configuration, &)
|
17
15
|
end
|
18
16
|
|
19
17
|
def find_child_factory(_configuration, register_map)
|
@@ -4,27 +4,25 @@ module RgGen
|
|
4
4
|
module Core
|
5
5
|
module RegisterMap
|
6
6
|
class InputData < InputBase::InputData
|
7
|
-
include RaiseError
|
8
|
-
|
9
7
|
module Root
|
10
|
-
def register_block(value_list = nil, &
|
11
|
-
child(:register_block, value_list, &
|
8
|
+
def register_block(value_list = nil, &)
|
9
|
+
child(:register_block, value_list, &)
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
module RegisterBlockRegisterFile
|
16
|
-
def register_file(value_list = nil, &
|
17
|
-
child(:register_file, value_list, &
|
14
|
+
def register_file(value_list = nil, &)
|
15
|
+
child(:register_file, value_list, &)
|
18
16
|
end
|
19
17
|
|
20
|
-
def register(value_list = nil, &
|
21
|
-
child(:register, value_list, &
|
18
|
+
def register(value_list = nil, &)
|
19
|
+
child(:register, value_list, &)
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
25
23
|
module Register
|
26
|
-
def bit_field(value_list = nil, &
|
27
|
-
child(:bit_field, value_list, &
|
24
|
+
def bit_field(value_list = nil, &)
|
25
|
+
child(:bit_field, value_list, &)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
@@ -50,8 +48,8 @@ module RgGen
|
|
50
48
|
|
51
49
|
private
|
52
50
|
|
53
|
-
def create_child_data(layer, &
|
54
|
-
super(layer, @configuration, &
|
51
|
+
def create_child_data(layer, &)
|
52
|
+
super(layer, @configuration, &)
|
55
53
|
end
|
56
54
|
|
57
55
|
def raise_unknown_field_error(field_name, position)
|
@@ -5,16 +5,14 @@ module RgGen
|
|
5
5
|
module Utility
|
6
6
|
module AttributeSetter
|
7
7
|
module Extension
|
8
|
-
|
9
|
-
@attributes ||= []
|
10
|
-
end
|
8
|
+
attr_reader :attributes
|
11
9
|
|
12
10
|
private
|
13
11
|
|
14
12
|
DEFAULT_VALUE = Object.new.freeze
|
15
13
|
|
16
14
|
def define_attribute(name, default_value = nil)
|
17
|
-
attributes << name.to_sym
|
15
|
+
(@attributes ||= []) << name.to_sym
|
18
16
|
variable_name = "@#{name}"
|
19
17
|
define_method(name) do |value = DEFAULT_VALUE|
|
20
18
|
if value.equal?(DEFAULT_VALUE)
|
@@ -24,11 +22,6 @@ module RgGen
|
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
27
|
-
|
28
|
-
def inherited(subclass)
|
29
|
-
super
|
30
|
-
export_instance_variable(:@attributes, subclass, &:dup)
|
31
|
-
end
|
32
25
|
end
|
33
26
|
|
34
27
|
def self.included(class_or_module)
|
@@ -37,7 +30,7 @@ module RgGen
|
|
37
30
|
|
38
31
|
def apply_attributes(**attributes)
|
39
32
|
attributes.each do |name, value|
|
40
|
-
__send__(name, value) if
|
33
|
+
__send__(name, value) if attribute?(name)
|
41
34
|
end
|
42
35
|
end
|
43
36
|
|
@@ -52,6 +45,16 @@ module RgGen
|
|
52
45
|
default_value
|
53
46
|
end
|
54
47
|
end
|
48
|
+
|
49
|
+
def attribute?(name)
|
50
|
+
klass = self.class
|
51
|
+
while klass.respond_to?(:attributes)
|
52
|
+
return true if klass.attributes&.include?(name)
|
53
|
+
klass = klass.superclass
|
54
|
+
end
|
55
|
+
|
56
|
+
false
|
57
|
+
end
|
55
58
|
end
|
56
59
|
end
|
57
60
|
end
|
data/lib/rggen/core/version.rb
CHANGED
data/lib/rggen/core.rb
CHANGED
@@ -31,6 +31,7 @@ require_relative 'core/utility/type_checker'
|
|
31
31
|
|
32
32
|
require_relative 'core/exceptions'
|
33
33
|
|
34
|
+
require_relative 'core/base/feature_variable'
|
34
35
|
require_relative 'core/base/internal_struct'
|
35
36
|
require_relative 'core/base/shared_context'
|
36
37
|
require_relative 'core/base/component'
|
@@ -61,7 +62,6 @@ require_relative 'core/input_base/option_hash_parser'
|
|
61
62
|
require_relative 'core/input_base/hash_list_parser'
|
62
63
|
require_relative 'core/input_base/feature_factory'
|
63
64
|
|
64
|
-
require_relative 'core/configuration/error'
|
65
65
|
require_relative 'core/configuration/input_data'
|
66
66
|
require_relative 'core/configuration/component'
|
67
67
|
require_relative 'core/configuration/component_factory'
|
@@ -75,7 +75,6 @@ require_relative 'core/configuration/toml_loader'
|
|
75
75
|
require_relative 'core/configuration/yaml_loader'
|
76
76
|
require_relative 'core/configuration'
|
77
77
|
|
78
|
-
require_relative 'core/register_map/error'
|
79
78
|
require_relative 'core/register_map/input_data'
|
80
79
|
require_relative 'core/register_map/component'
|
81
80
|
require_relative 'core/register_map/component_factory'
|
@@ -91,8 +90,8 @@ require_relative 'core/register_map'
|
|
91
90
|
|
92
91
|
require_relative 'core/output_base/template_engine'
|
93
92
|
require_relative 'core/output_base/erb_engine'
|
94
|
-
require_relative 'core/output_base/code_generator'
|
95
93
|
require_relative 'core/output_base/file_writer'
|
94
|
+
require_relative 'core/output_base/code_generatable'
|
96
95
|
require_relative 'core/output_base/raise_error'
|
97
96
|
require_relative 'core/output_base/component'
|
98
97
|
require_relative 'core/output_base/component_factory'
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rggen-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.34.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taichi Ishitani
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-23 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: docile
|
@@ -91,6 +90,7 @@ files:
|
|
91
90
|
- lib/rggen/core/base/feature.rb
|
92
91
|
- lib/rggen/core/base/feature_factory.rb
|
93
92
|
- lib/rggen/core/base/feature_layer_extension.rb
|
93
|
+
- lib/rggen/core/base/feature_variable.rb
|
94
94
|
- lib/rggen/core/base/internal_struct.rb
|
95
95
|
- lib/rggen/core/base/shared_context.rb
|
96
96
|
- lib/rggen/core/builder.rb
|
@@ -112,7 +112,6 @@ files:
|
|
112
112
|
- lib/rggen/core/configuration.rb
|
113
113
|
- lib/rggen/core/configuration/component.rb
|
114
114
|
- lib/rggen/core/configuration/component_factory.rb
|
115
|
-
- lib/rggen/core/configuration/error.rb
|
116
115
|
- lib/rggen/core/configuration/feature.rb
|
117
116
|
- lib/rggen/core/configuration/feature_factory.rb
|
118
117
|
- lib/rggen/core/configuration/hash_loader.rb
|
@@ -149,7 +148,7 @@ files:
|
|
149
148
|
- lib/rggen/core/input_base/verifier.rb
|
150
149
|
- lib/rggen/core/input_base/yaml_loader.rb
|
151
150
|
- lib/rggen/core/options.rb
|
152
|
-
- lib/rggen/core/output_base/
|
151
|
+
- lib/rggen/core/output_base/code_generatable.rb
|
153
152
|
- lib/rggen/core/output_base/component.rb
|
154
153
|
- lib/rggen/core/output_base/component_factory.rb
|
155
154
|
- lib/rggen/core/output_base/document_component_factory.rb
|
@@ -164,7 +163,6 @@ files:
|
|
164
163
|
- lib/rggen/core/register_map.rb
|
165
164
|
- lib/rggen/core/register_map/component.rb
|
166
165
|
- lib/rggen/core/register_map/component_factory.rb
|
167
|
-
- lib/rggen/core/register_map/error.rb
|
168
166
|
- lib/rggen/core/register_map/feature.rb
|
169
167
|
- lib/rggen/core/register_map/feature_factory.rb
|
170
168
|
- lib/rggen/core/register_map/hash_loader.rb
|
@@ -193,7 +191,6 @@ metadata:
|
|
193
191
|
rubygems_mfa_required: 'true'
|
194
192
|
source_code_uri: https://github.com/rggen/rggen-core
|
195
193
|
wiki_uri: https://github.com/rggen/rggen/wiki
|
196
|
-
post_install_message:
|
197
194
|
rdoc_options: []
|
198
195
|
require_paths:
|
199
196
|
- lib
|
@@ -201,15 +198,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
198
|
requirements:
|
202
199
|
- - ">="
|
203
200
|
- !ruby/object:Gem::Version
|
204
|
-
version: 3.
|
201
|
+
version: 3.1.0
|
205
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
203
|
requirements:
|
207
204
|
- - ">="
|
208
205
|
- !ruby/object:Gem::Version
|
209
206
|
version: '0'
|
210
207
|
requirements: []
|
211
|
-
rubygems_version: 3.
|
212
|
-
signing_key:
|
208
|
+
rubygems_version: 3.6.2
|
213
209
|
specification_version: 4
|
214
|
-
summary: rggen-core-0.
|
210
|
+
summary: rggen-core-0.34.0
|
215
211
|
test_files: []
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RgGen
|
4
|
-
module Core
|
5
|
-
module Configuration
|
6
|
-
class ConfigurationError < Core::RuntimeError
|
7
|
-
end
|
8
|
-
|
9
|
-
module RaiseError
|
10
|
-
include InputBase::RaiseError
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def error_exception
|
15
|
-
ConfigurationError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RgGen
|
4
|
-
module Core
|
5
|
-
module OutputBase
|
6
|
-
class CodeGenerator
|
7
|
-
def register(kind, &block)
|
8
|
-
block_given? && (code_blocks[kind] << block)
|
9
|
-
end
|
10
|
-
|
11
|
-
def generate(context, code, kind)
|
12
|
-
code_blocks[kind].each do |block|
|
13
|
-
execute_code_block(context, code, &block)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def copy
|
18
|
-
generator = CodeGenerator.new
|
19
|
-
generator.copy_code_blocks(@code_blocks) if @code_blocks
|
20
|
-
generator
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def code_blocks
|
26
|
-
@code_blocks ||= Hash.new { |blocks, kind| blocks[kind] = [] }
|
27
|
-
end
|
28
|
-
|
29
|
-
def execute_code_block(context, code, &block)
|
30
|
-
if block.arity.zero?
|
31
|
-
code << context.instance_exec(&block)
|
32
|
-
else
|
33
|
-
context.instance_exec(code, &block)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
protected
|
38
|
-
|
39
|
-
def copy_code_blocks(original_blocks)
|
40
|
-
original_blocks.each { |kind, blocks| code_blocks[kind] = blocks.dup }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RgGen
|
4
|
-
module Core
|
5
|
-
module RegisterMap
|
6
|
-
class RegisterMapError < Core::RuntimeError
|
7
|
-
end
|
8
|
-
|
9
|
-
module RaiseError
|
10
|
-
include InputBase::RaiseError
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def error_exception
|
15
|
-
RegisterMapError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|