emfrp 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +45 -12
- data/bin/emfrp +4 -1
- data/examples/LCDClock/LCDClock.mfrp +93 -93
- data/examples/LCDClock/LCDClock_LPC1768.bin +0 -0
- data/examples/LCDClock/README.md +24 -24
- data/examples/LCDPositioner/LCDPositioner.mfrp +30 -30
- data/examples/LCDPositioner/LCDPositionerMain.c +15 -15
- data/examples/MostDistantPoint/MostDistantPoint.mfrp +25 -25
- data/examples/MostDistantPoint/MostDistantPointMain.c +14 -14
- data/lib/emfrp/compile/c/alloc.rb +200 -200
- data/lib/emfrp/compile/c/codegen.rb +18 -18
- data/lib/emfrp/compile/c/codegen_context.rb +218 -218
- data/lib/emfrp/compile/c/monofy.rb +185 -185
- data/lib/emfrp/compile/c/syntax_codegen.rb +364 -364
- data/lib/emfrp/compile/c/syntax_exp_codegen.rb +119 -119
- data/lib/emfrp/compile/graphviz/graphviz.rb +53 -53
- data/lib/emfrp/compile_error.rb +95 -95
- data/lib/emfrp/interpreter/command_manager.rb +367 -367
- data/lib/emfrp/interpreter/evaluater.rb +146 -146
- data/lib/emfrp/interpreter/file_loader.rb +52 -52
- data/lib/emfrp/interpreter/interpreter.rb +200 -195
- data/lib/emfrp/parser/expression.rb +386 -386
- data/lib/emfrp/parser/misc.rb +184 -184
- data/lib/emfrp/parser/newnode_convert.rb +72 -72
- data/lib/emfrp/parser/operator.rb +25 -25
- data/lib/emfrp/parser/parser.rb +150 -150
- data/lib/emfrp/parser/parsing_error.rb +49 -49
- data/lib/emfrp/parser/toplevel.rb +555 -555
- data/lib/emfrp/pre_convert/pre_convert.rb +32 -32
- data/lib/emfrp/syntax.rb +171 -171
- data/lib/emfrp/typing/typing_error.rb +47 -47
- data/lib/emfrp/typing/union_type.rb +197 -197
- data/lib/emfrp/version.rb +1 -1
- data/mfrp_include/Std.mfrp +122 -122
- data/tests/Rakefile +8 -8
- data/tests/Rakefile.common +27 -27
- data/tests/command/Rakefile +2 -2
- data/tests/command/ReplaceNode.mfrp +39 -39
- data/tests/compiler/ComplexDataType/ComplexDataType.mfrp +14 -14
- data/tests/compiler/ComplexDataType/ComplexDataTypeMain.c +15 -15
- data/tests/compiler/ComplexDataType/Rakefile +2 -2
- data/tests/compiler/ComplexDataType/expected_out.txt +0 -0
- data/tests/compiler/ComplexDataType/in.txt +5 -5
- data/tests/compiler/LCDClock/LCDClock.mfrp +90 -90
- data/tests/compiler/LCDClock/LCDClockMain.c +0 -0
- data/tests/compiler/LCDClock/Rakefile +2 -2
- data/tests/compiler/LCDClock/expected_out.txt +0 -0
- data/tests/compiler/LCDClock/in.txt +0 -0
- data/tests/compiler/LCDPositioner/LCDPositioner.mfrp +30 -30
- data/tests/compiler/LCDPositioner/LCDPositionerMain.c +15 -15
- data/tests/compiler/LCDPositioner/Rakefile +2 -2
- data/tests/compiler/LCDPositioner/graph.dot +0 -0
- data/tests/compiler/LCDPositioner/graph.png +0 -0
- data/tests/compiler/Rakefile +8 -8
- data/tests/compiler/Rakefile.common +23 -23
- data/tests/compiler/UseData/Rakefile +2 -2
- data/tests/compiler/UseData/UseData.mfrp +8 -8
- data/tests/compiler/UseSubModule/Rakefile +2 -2
- data/tests/compiler/UseSubModule/SubModule.mfrp +8 -8
- data/tests/compiler/UseSubModule/SubModule2.mfrp +5 -5
- data/tests/compiler/UseSubModule/UseSubModule.mfrp +11 -11
- data/tests/core/FromAnnotation.mfrp +18 -18
- data/tests/core/Last.mfrp +10 -10
- data/tests/core/Rakefile +2 -2
- data/tests/core/TypingTest.mfrp +11 -11
- data/tests/core/WithoutInputs.mfrp +19 -19
- data/tests/load_time_error/Rakefile +32 -32
- data/tests/load_time_error/TypeMismatch.mfrp +4 -4
- metadata +3 -3
@@ -1,197 +1,197 @@
|
|
1
|
-
module Emfrp
|
2
|
-
module Typing
|
3
|
-
class UnionType
|
4
|
-
class UnifyError < RuntimeError
|
5
|
-
attr_reader :a, :b
|
6
|
-
def initialize(a, b)
|
7
|
-
@a, @b = a, b
|
8
|
-
end
|
9
|
-
end
|
10
|
-
NameCounter = (0..10000).to_a
|
11
|
-
attr_reader :typename, :typeargs
|
12
|
-
attr_accessor :name_id, :original_typevar_name, :union
|
13
|
-
|
14
|
-
|
15
|
-
def self.from_type(type, tbl={})
|
16
|
-
case type
|
17
|
-
when Emfrp::Type
|
18
|
-
new(type[:name][:desc], type[:args].map{|a| from_type(a, tbl)})
|
19
|
-
when TypeVar
|
20
|
-
name = type[:name][:desc]
|
21
|
-
if tbl[name]
|
22
|
-
tbl[name]
|
23
|
-
else
|
24
|
-
a = new()
|
25
|
-
tbl[name] = a
|
26
|
-
a.original_typevar_name = name
|
27
|
-
a
|
28
|
-
end
|
29
|
-
when UnionType
|
30
|
-
type
|
31
|
-
else
|
32
|
-
raise "unexpected type #{type.class} (bug)"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def initialize(*args)
|
37
|
-
if args.length == 2
|
38
|
-
@typename = args[0]
|
39
|
-
@typeargs = args[1]
|
40
|
-
elsif args.length == 0
|
41
|
-
@union = [self]
|
42
|
-
@name_id = NameCounter.shift
|
43
|
-
@original_name_id = @name_id
|
44
|
-
else
|
45
|
-
raise "Wrong number of arguments (#{args.length} for 0, 2)"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def var?
|
50
|
-
@union
|
51
|
-
end
|
52
|
-
|
53
|
-
def match?(other)
|
54
|
-
if self.var? && other.var?
|
55
|
-
self.name_id == other.name_id
|
56
|
-
elsif !self.var? && !other.var?
|
57
|
-
if self.typename == other.typename && self.typeargs.size == other.typeargs.size
|
58
|
-
self.typeargs.zip(other.typeargs).all?{|a, b| a.match?(b)}
|
59
|
-
else
|
60
|
-
false
|
61
|
-
end
|
62
|
-
else
|
63
|
-
false
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def include?(other)
|
68
|
-
if self.match?(other)
|
69
|
-
true
|
70
|
-
elsif !self.var?
|
71
|
-
self.typeargs.any?{|x| x.include?(other)}
|
72
|
-
else
|
73
|
-
false
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def has_var?
|
78
|
-
if self.var?
|
79
|
-
true
|
80
|
-
else
|
81
|
-
self.typeargs.any?{|x| x.has_var?}
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def unite(a, b)
|
86
|
-
new_union = (a.collect_union + b.collect_union).uniq
|
87
|
-
substitute_id = new_union.map{|t| t.name_id}.min
|
88
|
-
new_union.each{|t| t.name_id = substitute_id}
|
89
|
-
a.union = new_union
|
90
|
-
b.union = new_union
|
91
|
-
end
|
92
|
-
|
93
|
-
def collect_union(visited={})
|
94
|
-
return [] if visited[self]
|
95
|
-
visited[self] = true
|
96
|
-
res = @union + @union.map{|t| t.collect_union(visited)}.flatten
|
97
|
-
return res.uniq
|
98
|
-
end
|
99
|
-
|
100
|
-
def typevars
|
101
|
-
if var?
|
102
|
-
[self]
|
103
|
-
else
|
104
|
-
typeargs.map{|t| t.typevars}.flatten
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def transform(other)
|
109
|
-
@typename = other.typename
|
110
|
-
@typeargs = other.typeargs
|
111
|
-
@union = nil
|
112
|
-
end
|
113
|
-
|
114
|
-
def clone_utype(tbl={})
|
115
|
-
if self.var?
|
116
|
-
if tbl[self]
|
117
|
-
tbl[self]
|
118
|
-
else
|
119
|
-
alt = self.class.new
|
120
|
-
self.union.each{|t| tbl[t] = alt}
|
121
|
-
alt
|
122
|
-
end
|
123
|
-
else
|
124
|
-
self.class.new(self.typename, self.typeargs.map{|t| t.clone_utype(tbl)})
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def unify(other)
|
129
|
-
if !self.var? && !other.var?
|
130
|
-
if self.typename == other.typename && self.typeargs.size == other.typeargs.size
|
131
|
-
self.typeargs.zip(other.typeargs).each{|t1, t2| t1.unify(t2)}
|
132
|
-
else
|
133
|
-
raise UnifyError.new(nil, nil)
|
134
|
-
end
|
135
|
-
elsif !self.var? && other.var?
|
136
|
-
other.collect_union.each do |t|
|
137
|
-
self.occur_check(t)
|
138
|
-
t.transform(self)
|
139
|
-
end
|
140
|
-
elsif self.var? && !other.var?
|
141
|
-
self.collect_union.each do |t|
|
142
|
-
other.occur_check(t)
|
143
|
-
t.transform(other)
|
144
|
-
end
|
145
|
-
else
|
146
|
-
self.unite(self, other)
|
147
|
-
end
|
148
|
-
rescue UnifyError => err
|
149
|
-
raise UnifyError.new(self, other)
|
150
|
-
end
|
151
|
-
|
152
|
-
def occur_check(var)
|
153
|
-
if !self.var?
|
154
|
-
self.typeargs.each{|t| t.occur_check(var)}
|
155
|
-
end
|
156
|
-
if self == var
|
157
|
-
raise UnifyError.new(nil, nil)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def to_uniq_str
|
162
|
-
if self.var?
|
163
|
-
raise "error"
|
164
|
-
end
|
165
|
-
if self.typeargs.size > 0
|
166
|
-
args = self.typeargs.map{|t| t.to_uniq_str}.join(", ")
|
167
|
-
"#{self.typename}[#{args}]"
|
168
|
-
else
|
169
|
-
"#{self.typename}"
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
|
174
|
-
def to_flatten_uniq_str
|
175
|
-
if self.var?
|
176
|
-
raise "error"
|
177
|
-
end
|
178
|
-
if self.typeargs.size > 0
|
179
|
-
args = self.typeargs.map{|t| t.to_flatten_uniq_str}.join("_")
|
180
|
-
"#{self.typename}_#{args}"
|
181
|
-
else
|
182
|
-
"#{self.typename}"
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def inspect
|
187
|
-
if self.var?
|
188
|
-
#"a#{self.name_id}[#{@original_name_id}]" + (@original_typevar_name ? "(#{@original_typevar_name})" : "")
|
189
|
-
"a#{self.name_id}" + (@original_typevar_name ? "(#{@original_typevar_name})" : "")
|
190
|
-
else
|
191
|
-
args = self.typeargs.size > 0 ? "[#{self.typeargs.map{|t| t.inspect}.join(", ")}]" : ""
|
192
|
-
"#{self.typename}#{args}"
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
1
|
+
module Emfrp
|
2
|
+
module Typing
|
3
|
+
class UnionType
|
4
|
+
class UnifyError < RuntimeError
|
5
|
+
attr_reader :a, :b
|
6
|
+
def initialize(a, b)
|
7
|
+
@a, @b = a, b
|
8
|
+
end
|
9
|
+
end
|
10
|
+
NameCounter = (0..10000).to_a
|
11
|
+
attr_reader :typename, :typeargs
|
12
|
+
attr_accessor :name_id, :original_typevar_name, :union
|
13
|
+
|
14
|
+
|
15
|
+
def self.from_type(type, tbl={})
|
16
|
+
case type
|
17
|
+
when Emfrp::Type
|
18
|
+
new(type[:name][:desc], type[:args].map{|a| from_type(a, tbl)})
|
19
|
+
when TypeVar
|
20
|
+
name = type[:name][:desc]
|
21
|
+
if tbl[name]
|
22
|
+
tbl[name]
|
23
|
+
else
|
24
|
+
a = new()
|
25
|
+
tbl[name] = a
|
26
|
+
a.original_typevar_name = name
|
27
|
+
a
|
28
|
+
end
|
29
|
+
when UnionType
|
30
|
+
type
|
31
|
+
else
|
32
|
+
raise "unexpected type #{type.class} (bug)"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(*args)
|
37
|
+
if args.length == 2
|
38
|
+
@typename = args[0]
|
39
|
+
@typeargs = args[1]
|
40
|
+
elsif args.length == 0
|
41
|
+
@union = [self]
|
42
|
+
@name_id = NameCounter.shift
|
43
|
+
@original_name_id = @name_id
|
44
|
+
else
|
45
|
+
raise "Wrong number of arguments (#{args.length} for 0, 2)"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def var?
|
50
|
+
@union
|
51
|
+
end
|
52
|
+
|
53
|
+
def match?(other)
|
54
|
+
if self.var? && other.var?
|
55
|
+
self.name_id == other.name_id
|
56
|
+
elsif !self.var? && !other.var?
|
57
|
+
if self.typename == other.typename && self.typeargs.size == other.typeargs.size
|
58
|
+
self.typeargs.zip(other.typeargs).all?{|a, b| a.match?(b)}
|
59
|
+
else
|
60
|
+
false
|
61
|
+
end
|
62
|
+
else
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def include?(other)
|
68
|
+
if self.match?(other)
|
69
|
+
true
|
70
|
+
elsif !self.var?
|
71
|
+
self.typeargs.any?{|x| x.include?(other)}
|
72
|
+
else
|
73
|
+
false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def has_var?
|
78
|
+
if self.var?
|
79
|
+
true
|
80
|
+
else
|
81
|
+
self.typeargs.any?{|x| x.has_var?}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def unite(a, b)
|
86
|
+
new_union = (a.collect_union + b.collect_union).uniq
|
87
|
+
substitute_id = new_union.map{|t| t.name_id}.min
|
88
|
+
new_union.each{|t| t.name_id = substitute_id}
|
89
|
+
a.union = new_union
|
90
|
+
b.union = new_union
|
91
|
+
end
|
92
|
+
|
93
|
+
def collect_union(visited={})
|
94
|
+
return [] if visited[self]
|
95
|
+
visited[self] = true
|
96
|
+
res = @union + @union.map{|t| t.collect_union(visited)}.flatten
|
97
|
+
return res.uniq
|
98
|
+
end
|
99
|
+
|
100
|
+
def typevars
|
101
|
+
if var?
|
102
|
+
[self]
|
103
|
+
else
|
104
|
+
typeargs.map{|t| t.typevars}.flatten
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def transform(other)
|
109
|
+
@typename = other.typename
|
110
|
+
@typeargs = other.typeargs
|
111
|
+
@union = nil
|
112
|
+
end
|
113
|
+
|
114
|
+
def clone_utype(tbl={})
|
115
|
+
if self.var?
|
116
|
+
if tbl[self]
|
117
|
+
tbl[self]
|
118
|
+
else
|
119
|
+
alt = self.class.new
|
120
|
+
self.union.each{|t| tbl[t] = alt}
|
121
|
+
alt
|
122
|
+
end
|
123
|
+
else
|
124
|
+
self.class.new(self.typename, self.typeargs.map{|t| t.clone_utype(tbl)})
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def unify(other)
|
129
|
+
if !self.var? && !other.var?
|
130
|
+
if self.typename == other.typename && self.typeargs.size == other.typeargs.size
|
131
|
+
self.typeargs.zip(other.typeargs).each{|t1, t2| t1.unify(t2)}
|
132
|
+
else
|
133
|
+
raise UnifyError.new(nil, nil)
|
134
|
+
end
|
135
|
+
elsif !self.var? && other.var?
|
136
|
+
other.collect_union.each do |t|
|
137
|
+
self.occur_check(t)
|
138
|
+
t.transform(self)
|
139
|
+
end
|
140
|
+
elsif self.var? && !other.var?
|
141
|
+
self.collect_union.each do |t|
|
142
|
+
other.occur_check(t)
|
143
|
+
t.transform(other)
|
144
|
+
end
|
145
|
+
else
|
146
|
+
self.unite(self, other)
|
147
|
+
end
|
148
|
+
rescue UnifyError => err
|
149
|
+
raise UnifyError.new(self, other)
|
150
|
+
end
|
151
|
+
|
152
|
+
def occur_check(var)
|
153
|
+
if !self.var?
|
154
|
+
self.typeargs.each{|t| t.occur_check(var)}
|
155
|
+
end
|
156
|
+
if self == var
|
157
|
+
raise UnifyError.new(nil, nil)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def to_uniq_str
|
162
|
+
if self.var?
|
163
|
+
raise "error"
|
164
|
+
end
|
165
|
+
if self.typeargs.size > 0
|
166
|
+
args = self.typeargs.map{|t| t.to_uniq_str}.join(", ")
|
167
|
+
"#{self.typename}[#{args}]"
|
168
|
+
else
|
169
|
+
"#{self.typename}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
def to_flatten_uniq_str
|
175
|
+
if self.var?
|
176
|
+
raise "error"
|
177
|
+
end
|
178
|
+
if self.typeargs.size > 0
|
179
|
+
args = self.typeargs.map{|t| t.to_flatten_uniq_str}.join("_")
|
180
|
+
"#{self.typename}_#{args}"
|
181
|
+
else
|
182
|
+
"#{self.typename}"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def inspect
|
187
|
+
if self.var?
|
188
|
+
#"a#{self.name_id}[#{@original_name_id}]" + (@original_typevar_name ? "(#{@original_typevar_name})" : "")
|
189
|
+
"a#{self.name_id}" + (@original_typevar_name ? "(#{@original_typevar_name})" : "")
|
190
|
+
else
|
191
|
+
args = self.typeargs.size > 0 ? "[#{self.typeargs.map{|t| t.inspect}.join(", ")}]" : ""
|
192
|
+
"#{self.typename}#{args}"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
data/lib/emfrp/version.rb
CHANGED
data/mfrp_include/Std.mfrp
CHANGED
@@ -1,122 +1,122 @@
|
|
1
|
-
material Std
|
2
|
-
|
3
|
-
type Maybe[a] = Just(a) | Nothing
|
4
|
-
type static Opt[a] = Some(a) | None
|
5
|
-
|
6
|
-
# Tuple
|
7
|
-
# --------------------
|
8
|
-
#@ :assert-equals 1, (1,2).fst
|
9
|
-
#@ :assert-equals 2, (1,2).snd
|
10
|
-
|
11
|
-
type Unit = Unit
|
12
|
-
type Tuple1[t0] = Tuple1(t0)
|
13
|
-
type Tuple2[t0, t1] = Tuple2(t0, t1)
|
14
|
-
type Tuple3[t0, t1, t2] = Tuple3(t0, t1, t2)
|
15
|
-
type Tuple4[t0, t1, t2, t3] = Tuple4(t0, t1, t2, t3)
|
16
|
-
type Tuple5[t0, t1, t2, t3, t4] = Tuple5(t0, t1, t2, t3, t4)
|
17
|
-
type Tuple6[t0, t1, t2, t3, t4, t5] = Tuple6(t0, t1, t2, t3, t4, t5)
|
18
|
-
type Tuple7[t0, t1, t2, t3, t4, t5, t6] = Tuple7(t0, t1, t2, t3, t4, t5, t6)
|
19
|
-
|
20
|
-
#@ :set-func-doc
|
21
|
-
#- fst("Tuple2") = "first element of Tuple2"
|
22
|
-
func fst (t) = t of (x, y) -> x
|
23
|
-
|
24
|
-
#@ :set-func-doc
|
25
|
-
#- snd("Tuple2") = "second element of Tuple2"
|
26
|
-
func snd (t) = t of (x, y) -> y
|
27
|
-
|
28
|
-
# Pair
|
29
|
-
# --------------------
|
30
|
-
type Pair[a] = Pair(a, a)
|
31
|
-
|
32
|
-
# Arithmetic Operations
|
33
|
-
# --------------------
|
34
|
-
#@ :assert-equals 11, 1+2*3+4
|
35
|
-
#@ :assert-equals -4, 1-2-3
|
36
|
-
|
37
|
-
primtype Int = c{ int }
|
38
|
-
|
39
|
-
infixl 7 *
|
40
|
-
infixl 7 /
|
41
|
-
infixl 7 %
|
42
|
-
infixl 6 +
|
43
|
-
infixl 6 -
|
44
|
-
infix 4 <
|
45
|
-
infix 4 >
|
46
|
-
infix 4 <=
|
47
|
-
infix 4 >=
|
48
|
-
infix 4 ==
|
49
|
-
infix 4 !=
|
50
|
-
infix 4 /=
|
51
|
-
|
52
|
-
primfunc + (a : Int, b : Int) : Int = c{ a + b }, ruby{ a + b }
|
53
|
-
primfunc - (a : Int, b : Int) : Int = c{ a - b }, ruby{ a - b }
|
54
|
-
primfunc * (a : Int, b : Int) : Int = c{ a * b }, ruby{ a * b }
|
55
|
-
primfunc / (a : Int, b : Int) : Int = c{ a / b }, ruby{ a / b }
|
56
|
-
primfunc % (a : Int, b : Int) : Int = c{ a % b }, ruby{ a % b }
|
57
|
-
primfunc < (a : Int, b : Int) : Bool = c{ a < b }, ruby{ a < b ? [:True] : [:False] }
|
58
|
-
primfunc > (a : Int, b : Int) : Bool = c{ a > b }, ruby{ a > b ? [:True] : [:False] }
|
59
|
-
primfunc <= (a : Int, b : Int) : Bool = c{ a <= b }, ruby{ a <= b ? [:True] : [:False] }
|
60
|
-
primfunc >= (a : Int, b : Int) : Bool = c{ a >= b }, ruby{ a >= b ? [:True] : [:False] }
|
61
|
-
primfunc == (a : Int, b : Int) : Bool = c{ a == b }, ruby{ a == b ? [:True] : [:False] }
|
62
|
-
primfunc != (a : Int, b : Int) : Bool = c{ a != b }, ruby{ a != b ? [:True] : [:False] }
|
63
|
-
primfunc /= (a : Int, b : Int) : Bool = c{ a != b }, ruby{ a != b ? [:True] : [:False] }
|
64
|
-
primfunc @- (a : Int) : Int = c{ -a }, ruby{ -a }
|
65
|
-
primfunc @+ (a : Int) : Int = c{ +a }, ruby{ +a }
|
66
|
-
|
67
|
-
primtype Double = c{ double }
|
68
|
-
|
69
|
-
infixl 7 *.
|
70
|
-
infixl 7 /.
|
71
|
-
infixl 6 +.
|
72
|
-
infixl 6 -.
|
73
|
-
infix 4 <.
|
74
|
-
infix 4 >.
|
75
|
-
infix 4 <=.
|
76
|
-
infix 4 >=.
|
77
|
-
infix 4 ==.
|
78
|
-
infix 4 !=.
|
79
|
-
infix 4 /=.
|
80
|
-
|
81
|
-
primfunc +. (a : Double, b : Double) : Double = c{ a + b }, ruby{ a + b }
|
82
|
-
primfunc -. (a : Double, b : Double) : Double = c{ a - b }, ruby{ a - b }
|
83
|
-
primfunc *. (a : Double, b : Double) : Double = c{ a * b }, ruby{ a * b }
|
84
|
-
primfunc /. (a : Double, b : Double) : Double = c{ a / b }, ruby{ a / b }
|
85
|
-
primfunc <. (a : Double, b : Double) : Bool = c{ a < b }, ruby{ a < b ? [:True] : [:False] }
|
86
|
-
primfunc >. (a : Double, b : Double) : Bool = c{ a > b }, ruby{ a > b ? [:True] : [:False] }
|
87
|
-
primfunc <=. (a : Double, b : Double) : Bool = c{ a <= b }, ruby{ a <= b ? [:True] : [:False] }
|
88
|
-
primfunc >=. (a : Double, b : Double) : Bool = c{ a >= b }, ruby{ a >= b ? [:True] : [:False] }
|
89
|
-
primfunc ==. (a : Double, b : Double) : Bool = c{ a == b }, ruby{ a == b ? [:True] : [:False] }
|
90
|
-
primfunc !=. (a : Double, b : Double) : Bool = c{ a != b }, ruby{ a != b ? [:True] : [:False] }
|
91
|
-
primfunc /=. (a : Double, b : Double) : Bool = c{ a != b }, ruby{ a != b ? [:True] : [:False] }
|
92
|
-
primfunc @-. (a : Double) : Double = c{ -a }, ruby{ -a }
|
93
|
-
primfunc @+. (a : Double) : Double = c{ +a }, ruby{ +a }
|
94
|
-
|
95
|
-
|
96
|
-
primfunc doubleToInt(a : Double) : Int = c{ ((int)a) }, ruby{ a.to_i }
|
97
|
-
primfunc intToDouble(a : Int) : Double = c{ ((double)a) }, ruby{ a.to_f }
|
98
|
-
|
99
|
-
|
100
|
-
# Boolean Operations
|
101
|
-
# --------------------
|
102
|
-
#@ :assert-equals True, !False
|
103
|
-
#@ :assert-equals False, !True
|
104
|
-
#@ :assert-equals True, True && True
|
105
|
-
#@ :assert-equals False, True && False
|
106
|
-
#@ :assert-equals False, False && True
|
107
|
-
#@ :assert-equals False, False && False
|
108
|
-
#@ :assert-equals True, True || True
|
109
|
-
#@ :assert-equals True, True || False
|
110
|
-
#@ :assert-equals True, False || True
|
111
|
-
#@ :assert-equals False, False || False
|
112
|
-
|
113
|
-
type static Bool = False | True
|
114
|
-
|
115
|
-
infixr 3 &&
|
116
|
-
infixr 2 ||
|
117
|
-
|
118
|
-
primfunc && (a : Bool, b : Bool) : Bool = c{ a && b }, ruby{ a == [:True] && b == [:True] ? [:True] : [:False] }
|
119
|
-
primfunc || (a : Bool, b : Bool) : Bool = c{ a || b }, ruby{ a == [:True] || b == [:True] ? [:True] : [:False] }
|
120
|
-
primfunc @! (a : Bool) : Bool = c{ !a }, ruby{ a == [:True] ? [:False] : [:True] }
|
121
|
-
|
122
|
-
primfunc boolToInt(a : Bool) : Int = c{ a }, ruby{ a == [:True] ? 1 : 0 }
|
1
|
+
material Std
|
2
|
+
|
3
|
+
type Maybe[a] = Just(a) | Nothing
|
4
|
+
type static Opt[a] = Some(a) | None
|
5
|
+
|
6
|
+
# Tuple
|
7
|
+
# --------------------
|
8
|
+
#@ :assert-equals 1, (1,2).fst
|
9
|
+
#@ :assert-equals 2, (1,2).snd
|
10
|
+
|
11
|
+
type Unit = Unit
|
12
|
+
type Tuple1[t0] = Tuple1(t0)
|
13
|
+
type Tuple2[t0, t1] = Tuple2(t0, t1)
|
14
|
+
type Tuple3[t0, t1, t2] = Tuple3(t0, t1, t2)
|
15
|
+
type Tuple4[t0, t1, t2, t3] = Tuple4(t0, t1, t2, t3)
|
16
|
+
type Tuple5[t0, t1, t2, t3, t4] = Tuple5(t0, t1, t2, t3, t4)
|
17
|
+
type Tuple6[t0, t1, t2, t3, t4, t5] = Tuple6(t0, t1, t2, t3, t4, t5)
|
18
|
+
type Tuple7[t0, t1, t2, t3, t4, t5, t6] = Tuple7(t0, t1, t2, t3, t4, t5, t6)
|
19
|
+
|
20
|
+
#@ :set-func-doc
|
21
|
+
#- fst("Tuple2") = "first element of Tuple2"
|
22
|
+
func fst (t) = t of (x, y) -> x
|
23
|
+
|
24
|
+
#@ :set-func-doc
|
25
|
+
#- snd("Tuple2") = "second element of Tuple2"
|
26
|
+
func snd (t) = t of (x, y) -> y
|
27
|
+
|
28
|
+
# Pair
|
29
|
+
# --------------------
|
30
|
+
type Pair[a] = Pair(a, a)
|
31
|
+
|
32
|
+
# Arithmetic Operations
|
33
|
+
# --------------------
|
34
|
+
#@ :assert-equals 11, 1+2*3+4
|
35
|
+
#@ :assert-equals -4, 1-2-3
|
36
|
+
|
37
|
+
primtype Int = c{ int }
|
38
|
+
|
39
|
+
infixl 7 *
|
40
|
+
infixl 7 /
|
41
|
+
infixl 7 %
|
42
|
+
infixl 6 +
|
43
|
+
infixl 6 -
|
44
|
+
infix 4 <
|
45
|
+
infix 4 >
|
46
|
+
infix 4 <=
|
47
|
+
infix 4 >=
|
48
|
+
infix 4 ==
|
49
|
+
infix 4 !=
|
50
|
+
infix 4 /=
|
51
|
+
|
52
|
+
primfunc + (a : Int, b : Int) : Int = c{ a + b }, ruby{ a + b }
|
53
|
+
primfunc - (a : Int, b : Int) : Int = c{ a - b }, ruby{ a - b }
|
54
|
+
primfunc * (a : Int, b : Int) : Int = c{ a * b }, ruby{ a * b }
|
55
|
+
primfunc / (a : Int, b : Int) : Int = c{ a / b }, ruby{ a / b }
|
56
|
+
primfunc % (a : Int, b : Int) : Int = c{ a % b }, ruby{ a % b }
|
57
|
+
primfunc < (a : Int, b : Int) : Bool = c{ a < b }, ruby{ a < b ? [:True] : [:False] }
|
58
|
+
primfunc > (a : Int, b : Int) : Bool = c{ a > b }, ruby{ a > b ? [:True] : [:False] }
|
59
|
+
primfunc <= (a : Int, b : Int) : Bool = c{ a <= b }, ruby{ a <= b ? [:True] : [:False] }
|
60
|
+
primfunc >= (a : Int, b : Int) : Bool = c{ a >= b }, ruby{ a >= b ? [:True] : [:False] }
|
61
|
+
primfunc == (a : Int, b : Int) : Bool = c{ a == b }, ruby{ a == b ? [:True] : [:False] }
|
62
|
+
primfunc != (a : Int, b : Int) : Bool = c{ a != b }, ruby{ a != b ? [:True] : [:False] }
|
63
|
+
primfunc /= (a : Int, b : Int) : Bool = c{ a != b }, ruby{ a != b ? [:True] : [:False] }
|
64
|
+
primfunc @- (a : Int) : Int = c{ -a }, ruby{ -a }
|
65
|
+
primfunc @+ (a : Int) : Int = c{ +a }, ruby{ +a }
|
66
|
+
|
67
|
+
primtype Double = c{ double }
|
68
|
+
|
69
|
+
infixl 7 *.
|
70
|
+
infixl 7 /.
|
71
|
+
infixl 6 +.
|
72
|
+
infixl 6 -.
|
73
|
+
infix 4 <.
|
74
|
+
infix 4 >.
|
75
|
+
infix 4 <=.
|
76
|
+
infix 4 >=.
|
77
|
+
infix 4 ==.
|
78
|
+
infix 4 !=.
|
79
|
+
infix 4 /=.
|
80
|
+
|
81
|
+
primfunc +. (a : Double, b : Double) : Double = c{ a + b }, ruby{ a + b }
|
82
|
+
primfunc -. (a : Double, b : Double) : Double = c{ a - b }, ruby{ a - b }
|
83
|
+
primfunc *. (a : Double, b : Double) : Double = c{ a * b }, ruby{ a * b }
|
84
|
+
primfunc /. (a : Double, b : Double) : Double = c{ a / b }, ruby{ a / b }
|
85
|
+
primfunc <. (a : Double, b : Double) : Bool = c{ a < b }, ruby{ a < b ? [:True] : [:False] }
|
86
|
+
primfunc >. (a : Double, b : Double) : Bool = c{ a > b }, ruby{ a > b ? [:True] : [:False] }
|
87
|
+
primfunc <=. (a : Double, b : Double) : Bool = c{ a <= b }, ruby{ a <= b ? [:True] : [:False] }
|
88
|
+
primfunc >=. (a : Double, b : Double) : Bool = c{ a >= b }, ruby{ a >= b ? [:True] : [:False] }
|
89
|
+
primfunc ==. (a : Double, b : Double) : Bool = c{ a == b }, ruby{ a == b ? [:True] : [:False] }
|
90
|
+
primfunc !=. (a : Double, b : Double) : Bool = c{ a != b }, ruby{ a != b ? [:True] : [:False] }
|
91
|
+
primfunc /=. (a : Double, b : Double) : Bool = c{ a != b }, ruby{ a != b ? [:True] : [:False] }
|
92
|
+
primfunc @-. (a : Double) : Double = c{ -a }, ruby{ -a }
|
93
|
+
primfunc @+. (a : Double) : Double = c{ +a }, ruby{ +a }
|
94
|
+
|
95
|
+
|
96
|
+
primfunc doubleToInt(a : Double) : Int = c{ ((int)a) }, ruby{ a.to_i }
|
97
|
+
primfunc intToDouble(a : Int) : Double = c{ ((double)a) }, ruby{ a.to_f }
|
98
|
+
|
99
|
+
|
100
|
+
# Boolean Operations
|
101
|
+
# --------------------
|
102
|
+
#@ :assert-equals True, !False
|
103
|
+
#@ :assert-equals False, !True
|
104
|
+
#@ :assert-equals True, True && True
|
105
|
+
#@ :assert-equals False, True && False
|
106
|
+
#@ :assert-equals False, False && True
|
107
|
+
#@ :assert-equals False, False && False
|
108
|
+
#@ :assert-equals True, True || True
|
109
|
+
#@ :assert-equals True, True || False
|
110
|
+
#@ :assert-equals True, False || True
|
111
|
+
#@ :assert-equals False, False || False
|
112
|
+
|
113
|
+
type static Bool = False | True
|
114
|
+
|
115
|
+
infixr 3 &&
|
116
|
+
infixr 2 ||
|
117
|
+
|
118
|
+
primfunc && (a : Bool, b : Bool) : Bool = c{ a && b }, ruby{ a == [:True] && b == [:True] ? [:True] : [:False] }
|
119
|
+
primfunc || (a : Bool, b : Bool) : Bool = c{ a || b }, ruby{ a == [:True] || b == [:True] ? [:True] : [:False] }
|
120
|
+
primfunc @! (a : Bool) : Bool = c{ !a }, ruby{ a == [:True] ? [:False] : [:True] }
|
121
|
+
|
122
|
+
primfunc boolToInt(a : Bool) : Int = c{ a }, ruby{ a == [:True] ? 1 : 0 }
|
data/tests/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
task :default do
|
2
|
-
Dir.glob("[a-zA-Z0-9_]*") do |d|
|
3
|
-
Dir.chdir(d) do
|
4
|
-
puts "moved into directory `#{d}'"
|
5
|
-
sh "rake"
|
6
|
-
end if Dir.exist?(d)
|
7
|
-
end
|
8
|
-
end
|
1
|
+
task :default do
|
2
|
+
Dir.glob("[a-zA-Z0-9_]*") do |d|
|
3
|
+
Dir.chdir(d) do
|
4
|
+
puts "moved into directory `#{d}'"
|
5
|
+
sh "rake"
|
6
|
+
end if Dir.exist?(d)
|
7
|
+
end
|
8
|
+
end
|