/
operator.cr
64 lines (50 loc) · 1.02 KB
/
operator.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
abstract class Crinja::Operator
macro name(name, end_tag = nil)
def name
{{ name }}
end
def end_tag : String?
{{ end_tag }}
end
end
def inspect(io : IO)
to_s(io)
end
def to_s(io : IO)
io << "operator[" << name << "]"
end
def unary?
false
end
def binary?
false
end
def ternary?
false
end
class Library < FeatureLibrary(Operator)
register_default [Plus, Minus, Divide, IntDivide, Modulo, Multiply, Power,
Tilde,
Equals, NotEquals, GreaterThan, GreaterThanEquals, LowerThan, LowerThanEquals,
And, Or, Not]
end
module Binary
def binary?
true
end
abstract def value(env : Crinja, op1 : Value, op2 : Value)
end
module Unary
def unary?
true
end
abstract def value(env : Crinja, op : Value)
end
module Logic
def binary?
true
end
abstract def value(env : Crinja, op1 : Value, &block : -> Value)
end
end
require "./operator/*"