Class: SFRP::Mono::VConst
- Inherits:
-
Object
- Object
- SFRP::Mono::VConst
- Defined in:
- lib/sfrp/mono/vconst.rb
Instance Attribute Summary collapse
-
#str ⇒ Object
readonly
Returns the value of attribute str.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #all_pattern_examples(set) ⇒ Object
- #comp ⇒ Object
-
#gen_constructor(src_set, term_id, dest_set) ⇒ Object
Generate constructor-function in C.
-
#gen_term_definition(set, term_id, terms) ⇒ Object
Generate a struct-element of term for this vconst.
-
#initialize(str, type_str, arg_type_strs, native_str = nil) ⇒ VConst
constructor
A new instance of VConst.
-
#low_compare_exps(set, receiver_exp) ⇒ Object
Return conditional-low-exps to match this vconst and receiver-exp.
-
#low_constructor_call_exp(low_arg_exps) ⇒ Object
return low-expression to make a new instance by this vconst.
-
#low_constructor_str ⇒ Object
name of constructor-function in C for this vconst.
-
#low_macro_for_alias(alias_str) ⇒ Object
Return alias of the constructor of this vconst.
-
#low_mark_element_exps(set, term_id, receiver_str) ⇒ Object
Return low-exp to mark elements of this vconst.
- #low_member_pointers(type, receiver_str) ⇒ Object
-
#memory(set) ⇒ Object
Return max memory size to hold an instance of this vconst.
-
#native? ⇒ Boolean
Is this vconst expressed in native C value?.
- #native_args?(set) ⇒ Boolean
-
#param_needing_mark?(set) ⇒ Boolean
Do elements of this vconst need marking?.
Constructor Details
#initialize(str, type_str, arg_type_strs, native_str = nil) ⇒ VConst
Returns a new instance of VConst.
6 7 8 9 10 11 |
# File 'lib/sfrp/mono/vconst.rb', line 6 def initialize(str, type_str, arg_type_strs, native_str = nil) @str = str @type_str = type_str @arg_type_strs = arg_type_strs @native_str = native_str end |
Instance Attribute Details
#str ⇒ Object (readonly)
Returns the value of attribute str.
4 5 6 |
# File 'lib/sfrp/mono/vconst.rb', line 4 def str @str end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/sfrp/mono/vconst.rb', line 17 def ==(other) comp == other.comp end |
#all_pattern_examples(set) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/sfrp/mono/vconst.rb', line 37 def all_pattern_examples(set) return [Pattern::PatternExample.new(@str, [])] if @arg_type_strs.empty? head, *tail = @arg_type_strs.map do |type_str| set.type(type_str).all_pattern_examples(set) end head.product(*tail).map do |args| Pattern::PatternExample.new(@str, args) end end |
#comp ⇒ Object
13 14 15 |
# File 'lib/sfrp/mono/vconst.rb', line 13 def comp [@str, @type_str, @arg_type_strs, @native_str] end |
#gen_constructor(src_set, term_id, dest_set) ⇒ Object
Generate constructor-function in C.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/sfrp/mono/vconst.rb', line 64 def gen_constructor(src_set, term_id, dest_set) return if native? type = src_set.type(@type_str) dest_set << L.function(low_constructor_str, type.low_type_str) do |f| @arg_type_strs.each_with_index.map do |t_str, mem_idx| f.append_param(src_set.type(t_str).low_type_str, "member#{mem_idx}") end if type.static? f << L.stmt("#{type.low_type_str} x") else f << L.stmt("#{type.low_type_str} x = #{type.low_allocator_str}(0)") end if type. f << L.stmt("#{type.('x')}.term_id = #{term_id}") end @arg_type_strs.size.times do |mem_idx| terms = type.terms_access_str('x') m = "member#{mem_idx}" f << L.stmt("#{terms}.term#{term_id}.#{m} = #{m}") end f << L.stmt('return x') end end |
#gen_term_definition(set, term_id, terms) ⇒ Object
Generate a struct-element of term for this vconst.
48 49 50 51 52 53 54 55 56 |
# File 'lib/sfrp/mono/vconst.rb', line 48 def gen_term_definition(set, term_id, terms) return if native? terms << L.member_structure('struct', "term#{term_id}") do |term| @arg_type_strs.each_with_index do |t_str, idx| low_type_str = set.type(t_str).low_type_str term << L.member("#{low_type_str} member#{idx}") end end end |
#low_compare_exps(set, receiver_exp) ⇒ Object
Return conditional-low-exps to match this vconst and receiver-exp.
95 96 97 98 99 100 101 102 |
# File 'lib/sfrp/mono/vconst.rb', line 95 def low_compare_exps(set, receiver_exp) type = set.type(@type_str) return [] if type.single_vconst? return ["#{receiver_exp} == #{@native_str}"] if native? = type.(receiver_exp) term_id = type.term_id(@str) ["#{}.term_id == #{term_id}"] end |
#low_constructor_call_exp(low_arg_exps) ⇒ Object
return low-expression to make a new instance by this vconst
89 90 91 92 |
# File 'lib/sfrp/mono/vconst.rb', line 89 def low_constructor_call_exp(low_arg_exps) return @native_str if native? "#{low_constructor_str}(#{low_arg_exps.join(', ')})" end |
#low_constructor_str ⇒ Object
name of constructor-function in C for this vconst
105 106 107 |
# File 'lib/sfrp/mono/vconst.rb', line 105 def low_constructor_str 'VC_' + @str end |
#low_macro_for_alias(alias_str) ⇒ Object
Return alias of the constructor of this vconst.
110 111 112 113 |
# File 'lib/sfrp/mono/vconst.rb', line 110 def low_macro_for_alias(alias_str) arg = ('a'..'z').take(@arg_type_strs.size).join(', ') L.macro("#{alias_str}(#{arg}) #{low_constructor_str}(#{arg})") end |
#low_mark_element_exps(set, term_id, receiver_str) ⇒ Object
Return low-exp to mark elements of this vconst.
116 117 118 119 120 121 122 123 |
# File 'lib/sfrp/mono/vconst.rb', line 116 def low_mark_element_exps(set, term_id, receiver_str) types = @arg_type_strs.map { |t_str| set.type(t_str) } types_needing_mark = types.select { |t| t.need_mark?(set) } types_needing_mark.each_with_index.map do |type, mem_idx| term_access = "#{type.terms_access_str(receiver_str)}.term#{term_id}" "#{type.low_mark_func_str}(#{term_access}.member#{mem_idx})" end end |
#low_member_pointers(type, receiver_str) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/sfrp/mono/vconst.rb', line 125 def low_member_pointers(type, receiver_str) term_id = type.term_id(@str) terms_access = "#{type.terms_access_str(receiver_str)}.term#{term_id}" @arg_type_strs.each_with_index.map do |_, mem_idx| "&#{terms_access}.member#{mem_idx}" end end |
#memory(set) ⇒ Object
Return max memory size to hold an instance of this vconst.
22 23 24 25 26 |
# File 'lib/sfrp/mono/vconst.rb', line 22 def memory(set) @arg_type_strs.reduce(Memory.empty) do |m, t_str| m.and(set.type(t_str).memory(set)) end end |
#native? ⇒ Boolean
Is this vconst expressed in native C value?
29 30 31 |
# File 'lib/sfrp/mono/vconst.rb', line 29 def native? @native_str end |
#native_args?(set) ⇒ Boolean
33 34 35 |
# File 'lib/sfrp/mono/vconst.rb', line 33 def native_args?(set) @arg_type_strs.all? { |s| set.type(s).native? } end |
#param_needing_mark?(set) ⇒ Boolean
Do elements of this vconst need marking?
59 60 61 |
# File 'lib/sfrp/mono/vconst.rb', line 59 def param_needing_mark?(set) @arg_type_strs.any? { |type_str| set.type(type_str).need_mark?(set) } end |