lib/sfrp/mono/type.rb
# Generate allocator-function for type.
Generate allocator-function for type.
Generate allocator - function for type .
def gen_allocator(src_set, dest_set)
        return if static?
        count = src_set.memory(@str)
        memory_var = "memory_#{low_type_str}"
        dest_set << L.function(low_allocator_str, low_type_str) do |f|
          f.append_param('int', 'clean_up')
          f << L.stmt('static int i = 0')
          f << L.stmt("static struct #{low_type_str} #{memory_var}[#{count}]")
          f << L.if_stmt('clean_up') do |if_stmts|
            e = "#{memory_var}[i].meta.mark = 0"
            if_stmts << L.stmt("for (i = 0; i < #{count}; i++) #{e}")
            if_stmts << L.stmt('i = 0')
            if_stmts << L.stmt('return 0')
          end
          f << L.stmt("while (#{memory_var}[i++].meta.mark)")
          f << L.stmt("return #{memory_var} + (i - 1)")
        end
      end
def gen_allocator ( src_set , dest_set ) return if static? count = src_set . memory ( @str ) memory_var = "memory_#{low_type_str}" dest_set << L . function ( low_allocator_str , low_type_str ) do | f | f . append_param ( 'int' , 'clean_up' ) f << L . stmt ( 'static int i = 0' ) f << L . stmt ( "static struct #{low_type_str} #{memory_var}[#{count}]" ) f << L . if_stmt ( 'clean_up' ) do | if_stmts | e = "#{memory_var}[i].meta.mark = 0" if_stmts << L . stmt ( "for (i = 0; i < #{count}; i++) #{e}" ) if_stmts << L . stmt ( 'i = 0' ) if_stmts << L . stmt ( 'return 0' ) end f << L . stmt ( "while (#{memory_var}[i++].meta.mark)" ) f << L . stmt ( "return #{memory_var} + (i - 1)" ) end end
Generate allocator-function for type.
Generate allocator - function for type .
src_set
dest_set