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 Atom
17
18 module Number
19
20 class Abstract < Atom::Abstract
21 def initialize(loc, obj)
22 ASSERT.kind_of obj, ::Numeric
23
24 super
25 end
26
27
28 def to_s
29 self.obj.to_s
30 end
31 end
32
33
34 class Int < Abstract
35 def initialize(loc, obj)
36 ASSERT.kind_of obj, ::Integer
37
38 super
39 end
40
41
42 private
43
44 def __evaluate__(_env, _event)
45 VC.make_integer self.obj
46 end
47 end
48
49
50 class Float < Abstract
51 def initialize(loc, obj)
52 ASSERT.kind_of obj, ::Float
53
54 super
55 end
56
57
58 private
59
60 def __evaluate__(_env, _event)
61 VC.make_float self.obj
62 end
63 end
64
65 end # Umu::AbstractSyntax::Core::Expression::Unary::Atom::Number
66
67 end # Umu::AbstractSyntax::Core::Expression::Unary::Atom
68
69 end # Umu::AbstractSyntax::Core::Expression::Unary
70
71
72 module_function
73
74 def make_integer(loc, obj)
75 ASSERT.kind_of loc, LOC::Entry
76 ASSERT.kind_of obj, ::Integer
77
78 Unary::Atom::Number::Int.new(loc, obj).freeze
79 end
80
81
82 def make_float(loc, obj)
83 ASSERT.kind_of loc, LOC::Entry
84 ASSERT.kind_of obj, ::Float
85
86 Unary::Atom::Number::Float.new(loc, obj).freeze
87 end
88
89 end # Umu::AbstractSyntax::Core::Expression
90
91 end # Umu::AbstractSyntax::Core
92
93 end # Umu::AbstractSyntax
94
95 end # Umu