File: value/core/suspension.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Value#8
  module: Core#10
has properties
function: make_suspension / 2 #64
  class: Susp#12
inherits from
  Object ( Umu::Value::Core )
has properties
attribute: expr [R] #13
attribute: va_context [R] #13
attribute: memorized_value [R] #14
method: initialize / 2 #16
method: to_s #29
method: pretty_print / 1 #34
method: meth_force / 3 #41

Class Hierarchy

Object ( Builtin-Module )
Top ( Umu::Value::Core )
Object ( Umu::Value::Core )
  Susp    #12

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module Value
   9 
  10  module Core
  11 
  12  class Susp < Object
  13      attr_reader :expr, :va_context
  14      attr_reader :memorized_value
  15 
  16      def initialize(expr, va_context)
  17          ASSERT.kind_of expr,       ASCE::Abstract
  18          ASSERT.kind_of va_context, ECV::Abstract
  19 
  20          super()
  21 
  22          @expr       = expr
  23          @va_context = va_context
  24 
  25          @memorized_value = nil
  26      end
  27 
  28 
  29      def to_s
  30          format "#Susp<%s>", self.expr.to_s
  31      end
  32 
  33 
  34      def pretty_print(q)
  35          PRT.group q, bb:'#Susp<', eb:'>' do
  36              q.pp self.expr
  37          end
  38      end
  39 
  40 
  41      def meth_force(loc, env, event)
  42          ASSERT.kind_of loc,     LOC::Entry
  43          ASSERT.kind_of env,     E::Entry
  44          ASSERT.kind_of event,   E::Tracer::Event
  45 
  46          unless @memorized_value
  47              new_env = env.update_va_context(self.va_context)
  48                           .enter(event)
  49 
  50              result  = self.expr.evaluate new_env
  51              ASSERT.kind_of result, ASR::Value
  52 
  53              @memorized_value = result.value
  54          end
  55 
  56          ASSERT.kind_of @memorized_value, VC::Top
  57      end
  58  end
  59  Susp.freeze
  60 
  61 
  62  module_function
  63 
  64      def make_suspension(expr, va_context)
  65          ASSERT.kind_of expr,       ASCE::Abstract
  66          ASSERT.kind_of va_context, ECV::Abstract
  67 
  68          Susp.new(expr, va_context)   # Does NOT freeze!!
  69      end
  70 
  71  end # Umu::Value::Core
  72 
  73  end # Umu::Value
  74 
  75  end # Umu