File: abstract-syntax/core/expression/unary/container/tuple.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: AbstractSyntax#8
  module: Core#10
  module: Expression#12
has properties
function: make_tuple / 2 #59
  module: Unary#14
  module: Container#16
  class: Tuple#18
inherits from
  Expressions ( Umu::AbstractSyntax::Core::Expression::Unary::Container::Abstraction )
has properties
method: initialize / 2 #19
method: to_s #27
method: pretty_print / 1 #32
method: __evaluate__ / 2 #39

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module AbstractSyntax
   9 
  10  module Core
  11 
  12  module Expression
  13 
  14  module Unary
  15 
  16  module Container
  17 
  18  class Tuple < Abstraction::Expressions
  19      def initialize(loc, exprs)
  20          ASSERT.kind_of exprs, ::Array
  21          ASSERT.assert exprs.size >= 2   # Pair or More
  22 
  23          super
  24      end
  25 
  26 
  27      def to_s
  28          format "(%s)", self.map(&:to_s).join(', ')
  29      end
  30 
  31 
  32      def pretty_print(q)
  33          PRT.group_for_enum q, self, bb:'(', eb:')', join:', '
  34      end
  35 
  36 
  37  private
  38 
  39      def __evaluate__(env, event)
  40          ASSERT.kind_of env,     E::Entry
  41          ASSERT.kind_of event,   E::Tracer::Event
  42 
  43 
  44          new_env = env.enter event
  45 
  46          VC.make_tuple(
  47              *(self.map { |expr| expr.evaluate(new_env).value })
  48          )
  49      end
  50  end
  51 
  52  end # Umu::AbstractSyntax::Core::Expression::Unary::Container
  53 
  54  end # Umu::AbstractSyntax::Core::Expression::Unary
  55 
  56 
  57  module_function
  58 
  59      def make_tuple(loc, exprs)
  60          ASSERT.kind_of loc,     LOC::Entry
  61          ASSERT.kind_of exprs,   ::Array
  62 
  63          Unary::Container::Tuple.new(loc, exprs.freeze).freeze
  64      end
  65 
  66  end # Umu::AbstractSyntax::Core::Expression
  67 
  68  end # Umu::AbstractSyntax::Core
  69 
  70  end # Umu::AbstractSyntax
  71 
  72  end # Umu