File: value/core/object.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Value#8
  module: Core#10
  class: Object#12
inherits from
  Top ( Umu::Value::Core )
has properties
method: meth_show / 3 #18
alias: meth_to_string meth_show #28
method: contents #31
method: meth_contents / 3 #41
method: meth_is_equal / 4 #46
method: meth_is_not_equal / 4 #57
method: meth_is_less_than / 4 #71
method: meth_is_greater_than / 4 #82
method: meth_is_less_equal / 4 #102
method: meth_is_greater_equal / 4 #122
method: meth_compare / 4 #142
method: meth_force / 3 #182

Class Hierarchy

Object ( Builtin-Module )
Top ( Umu::Value::Core )
  Object    #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 Object < Top
  13      define_instance_method(
  14          :meth_show,
  15          :show, [],
  16          [], VCA::String
  17      )
  18      def meth_show(_loc, _env, _event)
  19          VC.make_string self.to_s
  20      end
  21 
  22 
  23      define_instance_method(
  24          :meth_to_string,
  25          :'to-s', [],
  26          [], VCA::String
  27      )
  28      alias meth_to_string meth_show
  29 
  30 
  31      def contents
  32          VC.make_unit
  33      end
  34 
  35 
  36      define_instance_method(
  37          :meth_contents,
  38          :contents, [],
  39          [], VC::Top
  40      )
  41      def meth_contents(_loc, _env, _event)
  42          self.contents
  43      end
  44 
  45 
  46      def meth_is_equal(loc, env, _event, _other)
  47          raise X::EqualityError.new(
  48              loc,
  49              env,
  50              "Equality error for %s : %s",
  51                  self.to_s,
  52                  self.type_sym.to_s
  53          )
  54      end
  55 
  56 
  57      def meth_is_not_equal(loc, env, event, other)
  58          ASSERT.kind_of other, VC::Top
  59 
  60          value = if other.kind_of? VC::Object
  61                      bool_value = self.meth_is_equal(loc, env, event, other)
  62                      ASSERT.kind_of bool_value, VCA::Bool
  63                  else
  64                      VC.make_true
  65                  end
  66 
  67          VC.make_bool value.val.!
  68      end
  69 
  70 
  71      def meth_is_less_than(loc, env, _event, _other)
  72          raise X::OrderError.new(
  73              loc,
  74              env,
  75              "Order error for %s : %s",
  76                  self.to_s,
  77                  self.type_sym.to_s
  78          )
  79      end
  80 
  81 
  82      def meth_is_greater_than(loc, env, event, other)
  83          ASSERT.kind_of other, VC::Top
  84 
  85          unless other.kind_of? VC::Object
  86              raise X::TypeError.new(
  87                  loc,
  88                  env,
  89                  "Expected a Object, but %s : %s",
  90                      other.to_s,
  91                      other.type_sym.to_s
  92              )
  93          end
  94 
  95          bool_value = other.meth_is_less_than(loc, env, event, self)
  96          ASSERT.kind_of bool_value, VCA::Bool
  97 
  98          VC.make_bool bool_value.val
  99      end
 100 
 101 
 102      def meth_is_less_equal(loc, env, event, other)
 103          ASSERT.kind_of other, VC::Top
 104 
 105          unless other.kind_of? VC::Object
 106              raise X::TypeError.new(
 107                  loc,
 108                  env,
 109                  "Expected a Object, but %s : %s",
 110                      other.to_s,
 111                      other.type_sym.to_s
 112              )
 113          end
 114 
 115          bool_value = other.meth_is_less_than(loc, env, event, self)
 116          ASSERT.kind_of bool_value, VCA::Bool
 117 
 118          VC.make_bool bool_value.val.!
 119      end
 120 
 121 
 122      def meth_is_greater_equal(loc, env, event, other)
 123          ASSERT.kind_of other, VC::Top
 124 
 125          unless other.kind_of? VC::Object
 126              raise X::TypeError.new(
 127                  loc,
 128                  env,
 129                  "Expected a Object, but %s : %s",
 130                      other.to_s,
 131                      other.type_sym.to_s
 132              )
 133          end
 134 
 135          bool_value = self.meth_is_less_than(loc, env, event, other)
 136          ASSERT.kind_of bool_value, VCA::Bool
 137 
 138          VC.make_bool bool_value.val.!
 139      end
 140 
 141 
 142      def meth_compare(loc, env, event, other)
 143          ASSERT.kind_of other, VC::Top
 144 
 145          unless other.kind_of? VC::Object
 146              raise X::TypeError.new(
 147                  loc,
 148                  env,
 149                  "Expected a Object, but %s : %s",
 150                      other.to_s,
 151                      other.type_sym.to_s
 152              )
 153          end
 154 
 155          bool_value_1 = self.meth_is_less_than(loc, env, event, other)
 156          ASSERT.kind_of bool_value_1, VCA::Bool
 157 
 158          result = (
 159              if bool_value_1.val
 160                  VC.make_integer(-1)
 161              else
 162                  value = other.meth_is_less_than(loc, env, event, self)
 163                  ASSERT.kind_of value, VCA::Bool
 164 
 165                  if value.val
 166                      VC.make_integer 1
 167                  else
 168                      VC.make_integer 0
 169                  end
 170              end
 171          )
 172 
 173          ASSERT.kind_of result, VCAN::Int
 174      end
 175 
 176 
 177      define_instance_method(
 178          :meth_force,
 179          :force, [],
 180          [], VC::Top
 181      )
 182      def meth_force(_loc, _env, _event)
 183          self
 184      end
 185  end
 186  Object.freeze
 187 
 188  end # Umu::Value::Core
 189 
 190  end # Umu::Value
 191 
 192  end # Umu