File: abstract-syntax/core/declaration/import.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: AbstractSyntax#8
  module: Core#10
  module: Declaration#12
has properties
function: make_import / 2 #66
  class: Import#14
inherits from
  Abstract ( Umu::AbstractSyntax::Core::Declaration )
has properties
attribute: id [R] #15
method: initialize / 2 #18
method: to_s #27
method: __evaluate__ / 1 #34

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 Declaration
  13 
  14  class Import < Declaration::Abstract
  15      attr_reader :id
  16 
  17 
  18      def initialize(loc, id)
  19          ASSERT.kind_of id, ASCEU::Identifier::Abstract
  20 
  21          super(loc)
  22 
  23          @id = id
  24      end
  25 
  26 
  27      def to_s
  28          '%IMPORT ' + self.id.to_s
  29      end
  30 
  31 
  32  private
  33 
  34      def __evaluate__(env)
  35          ASSERT.kind_of env, E::Entry
  36 
  37          result = self.id.evaluate env
  38          ASSERT.kind_of result, ASR::Value
  39 
  40          struct_value = result.value
  41          unless struct_value.kind_of? VC::Struct::Entry
  42              raise X::TypeError.new(
  43                  self.loc,
  44                  env,
  45                  "Expected a Struct in <import> declaration, but %s : %s",
  46                  struct_value,
  47                  struct_value.type_sym
  48              )
  49          end
  50 
  51          bindings = struct_value.inject({}) { |hash, field|
  52              hash.merge(
  53                  field.label => ECV.make_value_target(field.value)
  54              ) { |label, old_value, new_value|
  55                  ASSERT.abort format("No case, label: %s", label)
  56              }
  57          }
  58 
  59          env.va_extend_bindings bindings
  60      end
  61  end
  62 
  63 
  64  module_function
  65 
  66      def make_import(loc, id)
  67          ASSERT.kind_of loc, LOC::Entry
  68          ASSERT.kind_of id,  ASCEU::Identifier::Abstract
  69 
  70          Import.new(loc, id).freeze
  71      end
  72 
  73  end # Umu::AbstractSyntax::Core::Declaration
  74 
  75  end # Umu::AbstractSyntax::Core
  76 
  77  end # Umu::AbstractSyntax
  78 
  79  end # Umu