emfrp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +6 -0
- data/LICENSE +28 -0
- data/README.md +27 -0
- data/Rakefile +2 -0
- data/bin/emfrp +21 -0
- data/bin/emfrpi +24 -0
- data/emfrp.gemspec +26 -0
- data/examples/LCDPositioner/LCDPositioner.c +278 -0
- data/examples/LCDPositioner/LCDPositioner.h +6 -0
- data/examples/LCDPositioner/LCDPositioner.mfrp +30 -0
- data/examples/LCDPositioner/LCDPositionerMain.c +15 -0
- data/examples/LCDPositioner/LCDPositionerMain.c.gen +11 -0
- data/examples/LCDPositioner/graph.dot +31 -0
- data/examples/LCDPositioner/graph.png +0 -0
- data/examples/MostDistantPoint/MostDistantPoint.c +199 -0
- data/examples/MostDistantPoint/MostDistantPoint.h +6 -0
- data/examples/MostDistantPoint/MostDistantPoint.mfrp +25 -0
- data/examples/MostDistantPoint/MostDistantPointMain.c +14 -0
- data/examples/MostDistantPoint/graph.dot +12 -0
- data/examples/MostDistantPoint/graph.png +0 -0
- data/lib/emfrp/compile/c/alloc.rb +200 -0
- data/lib/emfrp/compile/c/codegen.rb +18 -0
- data/lib/emfrp/compile/c/codegen_context.rb +215 -0
- data/lib/emfrp/compile/c/monofy.rb +185 -0
- data/lib/emfrp/compile/c/syntax_codegen.rb +364 -0
- data/lib/emfrp/compile/c/syntax_exp_codegen.rb +119 -0
- data/lib/emfrp/compile/graphviz/graphviz.rb +49 -0
- data/lib/emfrp/compile_error.rb +95 -0
- data/lib/emfrp/interpreter/command_manager.rb +367 -0
- data/lib/emfrp/interpreter/evaluater.rb +146 -0
- data/lib/emfrp/interpreter/file_loader.rb +52 -0
- data/lib/emfrp/interpreter/interpreter.rb +195 -0
- data/lib/emfrp/parser/expression.rb +386 -0
- data/lib/emfrp/parser/misc.rb +184 -0
- data/lib/emfrp/parser/operator.rb +25 -0
- data/lib/emfrp/parser/parser.rb +145 -0
- data/lib/emfrp/parser/parsing_error.rb +49 -0
- data/lib/emfrp/parser/toplevel.rb +523 -0
- data/lib/emfrp/pre_convert/alpha_convert.rb +119 -0
- data/lib/emfrp/pre_convert/make_name_dict.rb +96 -0
- data/lib/emfrp/pre_convert/node_check.rb +60 -0
- data/lib/emfrp/pre_convert/pre_convert.rb +32 -0
- data/lib/emfrp/syntax.rb +169 -0
- data/lib/emfrp/typing/typing.rb +256 -0
- data/lib/emfrp/typing/typing_error.rb +47 -0
- data/lib/emfrp/typing/union_type.rb +197 -0
- data/lib/emfrp/version.rb +3 -0
- data/lib/emfrp.rb +14 -0
- data/mfrp_include/Std.mfrp +122 -0
- data/tests/Rakefile +8 -0
- data/tests/Rakefile.common +27 -0
- data/tests/command/Rakefile +2 -0
- data/tests/command/ReplaceNode.mfrp +39 -0
- data/tests/compiler/ComplexDataType/ComplexDataType.mfrp +14 -0
- data/tests/compiler/ComplexDataType/ComplexDataTypeMain.c +15 -0
- data/tests/compiler/ComplexDataType/Rakefile +2 -0
- data/tests/compiler/ComplexDataType/actual_out.txt +5 -0
- data/tests/compiler/ComplexDataType/expected_out.txt +5 -0
- data/tests/compiler/ComplexDataType/graph.png +0 -0
- data/tests/compiler/ComplexDataType/in.txt +5 -0
- data/tests/compiler/LCDPositioner/LCDPositioner.mfrp +30 -0
- data/tests/compiler/LCDPositioner/LCDPositionerMain.c +15 -0
- data/tests/compiler/LCDPositioner/Rakefile +2 -0
- data/tests/compiler/LCDPositioner/actual_out.txt +9 -0
- data/tests/compiler/LCDPositioner/expected_out.txt +9 -0
- data/tests/compiler/LCDPositioner/graph.dot +31 -0
- data/tests/compiler/LCDPositioner/graph.png +0 -0
- data/tests/compiler/LCDPositioner/in.txt +11 -0
- data/tests/compiler/Rakefile +8 -0
- data/tests/compiler/Rakefile.common +23 -0
- data/tests/core/FromAnnotation.mfrp +18 -0
- data/tests/core/Last.mfrp +10 -0
- data/tests/core/Rakefile +2 -0
- data/tests/core/TypingTest.mfrp +11 -0
- data/tests/core/WithoutInputs.mfrp +19 -0
- data/tests/load_time_error/Rakefile +32 -0
- data/tests/load_time_error/TypeMismatch.mfrp +4 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 739151824444ba84586ec87772d5cbb30bb2157c
|
4
|
+
data.tar.gz: 76b48e983b31abd5459cea456f68976af359fa0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b77eb4ab6596bcb41269a2b72fc22ad28b8137895c604ef013e0b7047677698b2bce41396c5b84eb0f535fdb5de6c9447773f4e66d953b21702a838c79e8de3
|
7
|
+
data.tar.gz: 73353f055c801bb8b2841651137b75112f1f96c94b93ffe2979c3e7a8a4eaadb36a7727ca3f65a494a3ab7c3fcbdd71b9af34a95a8025628a894751970dcff60
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Copyright (c) 2015, Kensuke Sawada
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
3. Neither the name of the copyright holder nor the names of its
|
15
|
+
contributors may be used to endorse or promote products derived from
|
16
|
+
this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
21
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22
|
+
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
24
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
25
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
26
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Emfrp
|
2
|
+
|
3
|
+
Pure Functional Programming with your microcomputer.
|
4
|
+
|
5
|
+
# Requirement
|
6
|
+
|
7
|
+
* Ruby2.0 or later (and it's Gem client)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
You can get executables via RubyGems.
|
11
|
+
```sh
|
12
|
+
$ gem install emfrp
|
13
|
+
```
|
14
|
+
|
15
|
+
# Command-line-interpreter (REPL)
|
16
|
+
```sh
|
17
|
+
$ emfrpi
|
18
|
+
```
|
19
|
+
|
20
|
+
# Compiler
|
21
|
+
```sh
|
22
|
+
$ emfrp <src-file>
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
In prepraration...
|
data/Rakefile
ADDED
data/bin/emfrp
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'emfrp'
|
5
|
+
|
6
|
+
unless ARGV[0]
|
7
|
+
puts "usage: emfrp <emfrp-module-file-path>"
|
8
|
+
exit(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
inter = Emfrp::Interpreter.new(Emfrp::IncludeDirs, STDOUT, ARGV[0])
|
13
|
+
if inter.compile_default()
|
14
|
+
exit(1)
|
15
|
+
end
|
16
|
+
rescue Emfrp::Interpreter::InterpreterError
|
17
|
+
exit(1)
|
18
|
+
rescue Emfrp::FileLoader::FileLoadError => err
|
19
|
+
puts err.message
|
20
|
+
exit(1)
|
21
|
+
end
|
data/bin/emfrpi
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'emfrp'
|
5
|
+
require 'readline'
|
6
|
+
|
7
|
+
begin
|
8
|
+
inter = Emfrp::Interpreter.new(Emfrp::IncludeDirs, STDOUT, ARGV[0] || "Std")
|
9
|
+
Readline.completion_proc = inter.completion_proc
|
10
|
+
while true
|
11
|
+
input = Readline.readline("emfrpi:#{inter.current_readline_id}> ", true)
|
12
|
+
if input == nil
|
13
|
+
inter.close()
|
14
|
+
exit(0)
|
15
|
+
else
|
16
|
+
inter.process_repl_line(input)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
rescue Emfrp::Interpreter::InterpreterError
|
20
|
+
exit(1)
|
21
|
+
rescue Emfrp::FileLoader::FileLoadError => err
|
22
|
+
puts err.message
|
23
|
+
exit(1)
|
24
|
+
end
|
data/emfrp.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'emfrp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "emfrp"
|
8
|
+
spec.version = Emfrp::VERSION
|
9
|
+
spec.authors = ["Kensuke Sawada"]
|
10
|
+
spec.email = ["sasasawada@gmail.com"]
|
11
|
+
spec.summary = %q{A compier of Emfrp, a FRP language for small embeded systems.}
|
12
|
+
spec.description = %q{Pure Functional Programming with your microcomputer.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "The BSD 3-Clause License"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "colorize", ">= 0.7.7"
|
22
|
+
spec.add_dependency "parser_combinator", ">= 0.0.3"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
@@ -0,0 +1,278 @@
|
|
1
|
+
#include "LCDPositioner.h"
|
2
|
+
/* Primitive functions (Macros) */
|
3
|
+
#define _plus_(a, b) (a + b)
|
4
|
+
#define _anpersand_anpersand(a, b) (a && b)
|
5
|
+
#define _eq__eq_(a, b) (a == b)
|
6
|
+
#define _parcent_(a, b) (a % b)
|
7
|
+
#define boolToInt(a) (a)
|
8
|
+
#define _minus_(a, b) (a - b)
|
9
|
+
/* Data types */
|
10
|
+
struct Tuple2_Int_Int{
|
11
|
+
int mark;
|
12
|
+
union {
|
13
|
+
struct {
|
14
|
+
int member0;
|
15
|
+
int member1;
|
16
|
+
}Tuple2;
|
17
|
+
}value;
|
18
|
+
};
|
19
|
+
struct Tuple2_Bool_Int{
|
20
|
+
int mark;
|
21
|
+
union {
|
22
|
+
struct {
|
23
|
+
int member0;
|
24
|
+
int member1;
|
25
|
+
}Tuple2;
|
26
|
+
}value;
|
27
|
+
};
|
28
|
+
/* Global variables */
|
29
|
+
int node_memory_up[2];
|
30
|
+
int node_memory_down[2];
|
31
|
+
int node_memory_left[2];
|
32
|
+
int node_memory_right[2];
|
33
|
+
int node_memory_pulse10ms[2];
|
34
|
+
struct Tuple2_Bool_Int* node_memory_k[2];
|
35
|
+
int node_memory_dx[2];
|
36
|
+
int node_memory_dy[2];
|
37
|
+
int node_memory_pulse40ms[2];
|
38
|
+
int node_memory_pulse40msCount[2];
|
39
|
+
struct Tuple2_Int_Int* node_memory_pos[2];
|
40
|
+
int node_memory_x[2];
|
41
|
+
int node_memory_y[2];
|
42
|
+
struct Tuple2_Bool_Int memory_Tuple2_Bool_Int[2];
|
43
|
+
int size_Tuple2_Bool_Int = 2;
|
44
|
+
int counter_Tuple2_Bool_Int = 0;
|
45
|
+
struct Tuple2_Int_Int memory_Tuple2_Int_Int[2];
|
46
|
+
int size_Tuple2_Int_Int = 2;
|
47
|
+
int counter_Tuple2_Int_Int = 0;
|
48
|
+
int Counter = 1;
|
49
|
+
int NodeSize = 8;
|
50
|
+
/* Static prototypes */
|
51
|
+
static struct Tuple2_Int_Int* Tuple2_0(int, int);
|
52
|
+
static void mark_Tuple2_Int_Int(struct Tuple2_Int_Int*, int);
|
53
|
+
static struct Tuple2_Bool_Int* Tuple2_1(int, int);
|
54
|
+
static void mark_Tuple2_Bool_Int(struct Tuple2_Bool_Int*, int);
|
55
|
+
static int node_k(int, int, struct Tuple2_Bool_Int**);
|
56
|
+
static struct Tuple2_Bool_Int* init_k();
|
57
|
+
static int node_dx(int, int, int*);
|
58
|
+
static int node_dy(int, int, int*);
|
59
|
+
static int node_pulse40ms(struct Tuple2_Bool_Int*, int*);
|
60
|
+
static int init_pulse40ms();
|
61
|
+
static int node_pulse40msCount(struct Tuple2_Bool_Int*, int*);
|
62
|
+
static int init_pulse40msCount();
|
63
|
+
static int node_pos(int, int, int, int, int, struct Tuple2_Int_Int*, struct Tuple2_Int_Int**);
|
64
|
+
static struct Tuple2_Int_Int* init_pos();
|
65
|
+
static int node_x(struct Tuple2_Int_Int*, int*);
|
66
|
+
static int init_x();
|
67
|
+
static int node_y(struct Tuple2_Int_Int*, int*);
|
68
|
+
static int init_y();
|
69
|
+
static void refreshMark();
|
70
|
+
extern void Input(int*, int*, int*, int*, int*);
|
71
|
+
extern void Output(int*, int*);
|
72
|
+
/* Functions, Constructors, GCMarkers, etc... */
|
73
|
+
static struct Tuple2_Int_Int* Tuple2_0(int member0, int member1) {
|
74
|
+
struct Tuple2_Int_Int* x;
|
75
|
+
while (1) {
|
76
|
+
counter_Tuple2_Int_Int++;
|
77
|
+
counter_Tuple2_Int_Int %= size_Tuple2_Int_Int;
|
78
|
+
if (memory_Tuple2_Int_Int[counter_Tuple2_Int_Int].mark < Counter) { x = memory_Tuple2_Int_Int + counter_Tuple2_Int_Int; break; }
|
79
|
+
}
|
80
|
+
x->value.Tuple2.member0 = member0;
|
81
|
+
x->value.Tuple2.member1 = member1;
|
82
|
+
return x;
|
83
|
+
}
|
84
|
+
static void mark_Tuple2_Int_Int(struct Tuple2_Int_Int* x, int mark) {
|
85
|
+
x->mark = mark;
|
86
|
+
}
|
87
|
+
static struct Tuple2_Bool_Int* Tuple2_1(int member0, int member1) {
|
88
|
+
struct Tuple2_Bool_Int* x;
|
89
|
+
while (1) {
|
90
|
+
counter_Tuple2_Bool_Int++;
|
91
|
+
counter_Tuple2_Bool_Int %= size_Tuple2_Bool_Int;
|
92
|
+
if (memory_Tuple2_Bool_Int[counter_Tuple2_Bool_Int].mark < Counter) { x = memory_Tuple2_Bool_Int + counter_Tuple2_Bool_Int; break; }
|
93
|
+
}
|
94
|
+
x->value.Tuple2.member0 = member0;
|
95
|
+
x->value.Tuple2.member1 = member1;
|
96
|
+
return x;
|
97
|
+
}
|
98
|
+
static void mark_Tuple2_Bool_Int(struct Tuple2_Bool_Int* x, int mark) {
|
99
|
+
x->mark = mark;
|
100
|
+
}
|
101
|
+
static int node_k(int pulse10ms, int pulse40msCount_at_last, struct Tuple2_Bool_Int** output) {
|
102
|
+
int _tmp001;
|
103
|
+
struct Tuple2_Bool_Int* _tmp000;
|
104
|
+
_tmp001 = _parcent_(_plus_(pulse40msCount_at_last, boolToInt(pulse10ms)), 4);
|
105
|
+
if (1) {
|
106
|
+
int pvar0_c = _tmp001;
|
107
|
+
_tmp000 = Tuple2_1(_anpersand_anpersand(_eq__eq_(pvar0_c, 0), pulse10ms), pvar0_c);
|
108
|
+
}
|
109
|
+
*output = _tmp000;
|
110
|
+
return 1;
|
111
|
+
}
|
112
|
+
static struct Tuple2_Bool_Int* init_k() {
|
113
|
+
return Tuple2_1(0, 0);
|
114
|
+
}
|
115
|
+
static int node_dx(int right, int left, int* output) {
|
116
|
+
*output = _minus_(boolToInt(right), boolToInt(left));
|
117
|
+
return 1;
|
118
|
+
}
|
119
|
+
static int node_dy(int down, int up, int* output) {
|
120
|
+
*output = _minus_(boolToInt(down), boolToInt(up));
|
121
|
+
return 1;
|
122
|
+
}
|
123
|
+
static int node_pulse40ms(struct Tuple2_Bool_Int* k, int* output) {
|
124
|
+
int _tmp002;
|
125
|
+
if (1) {
|
126
|
+
struct Tuple2_Bool_Int* pvar1_k = k;
|
127
|
+
int pvar1_pulse40ms = k->value.Tuple2.member0;
|
128
|
+
int pvar1_pulse40msCount = k->value.Tuple2.member1;
|
129
|
+
_tmp002 = pvar1_pulse40ms;
|
130
|
+
}
|
131
|
+
*output = _tmp002;
|
132
|
+
return 1;
|
133
|
+
}
|
134
|
+
static int init_pulse40ms() {
|
135
|
+
struct Tuple2_Bool_Int* _tmp004;
|
136
|
+
int _tmp003;
|
137
|
+
_tmp004 = Tuple2_1(0, 0);
|
138
|
+
if (1) {
|
139
|
+
struct Tuple2_Bool_Int* pvar2_k = _tmp004;
|
140
|
+
int pvar2_pulse40ms = _tmp004->value.Tuple2.member0;
|
141
|
+
int pvar2_pulse40msCount = _tmp004->value.Tuple2.member1;
|
142
|
+
_tmp003 = pvar2_pulse40ms;
|
143
|
+
}
|
144
|
+
return _tmp003;
|
145
|
+
}
|
146
|
+
static int node_pulse40msCount(struct Tuple2_Bool_Int* k, int* output) {
|
147
|
+
int _tmp005;
|
148
|
+
if (1) {
|
149
|
+
struct Tuple2_Bool_Int* pvar3_k = k;
|
150
|
+
int pvar3_pulse40ms = k->value.Tuple2.member0;
|
151
|
+
int pvar3_pulse40msCount = k->value.Tuple2.member1;
|
152
|
+
_tmp005 = pvar3_pulse40msCount;
|
153
|
+
}
|
154
|
+
*output = _tmp005;
|
155
|
+
return 1;
|
156
|
+
}
|
157
|
+
static int init_pulse40msCount() {
|
158
|
+
struct Tuple2_Bool_Int* _tmp007;
|
159
|
+
int _tmp006;
|
160
|
+
_tmp007 = Tuple2_1(0, 0);
|
161
|
+
if (1) {
|
162
|
+
struct Tuple2_Bool_Int* pvar4_k = _tmp007;
|
163
|
+
int pvar4_pulse40ms = _tmp007->value.Tuple2.member0;
|
164
|
+
int pvar4_pulse40msCount = _tmp007->value.Tuple2.member1;
|
165
|
+
_tmp006 = pvar4_pulse40msCount;
|
166
|
+
}
|
167
|
+
return _tmp006;
|
168
|
+
}
|
169
|
+
static int node_pos(int pulse40ms, int x_at_last, int dx, int y_at_last, int dy, struct Tuple2_Int_Int* pos_at_last, struct Tuple2_Int_Int** output) {
|
170
|
+
struct Tuple2_Int_Int* _tmp008;
|
171
|
+
if (pulse40ms == 1) {
|
172
|
+
_tmp008 = Tuple2_0(_plus_(x_at_last, dx), _plus_(y_at_last, dy));
|
173
|
+
}
|
174
|
+
else if (pulse40ms == 0) {
|
175
|
+
_tmp008 = pos_at_last;
|
176
|
+
}
|
177
|
+
*output = _tmp008;
|
178
|
+
return 1;
|
179
|
+
}
|
180
|
+
static struct Tuple2_Int_Int* init_pos() {
|
181
|
+
return Tuple2_0(0, 0);
|
182
|
+
}
|
183
|
+
static int node_x(struct Tuple2_Int_Int* pos, int* output) {
|
184
|
+
int _tmp009;
|
185
|
+
if (1) {
|
186
|
+
struct Tuple2_Int_Int* pvar5_pos = pos;
|
187
|
+
int pvar5_x = pos->value.Tuple2.member0;
|
188
|
+
int pvar5_y = pos->value.Tuple2.member1;
|
189
|
+
_tmp009 = pvar5_x;
|
190
|
+
}
|
191
|
+
*output = _tmp009;
|
192
|
+
return 1;
|
193
|
+
}
|
194
|
+
static int init_x() {
|
195
|
+
struct Tuple2_Int_Int* _tmp011;
|
196
|
+
int _tmp010;
|
197
|
+
_tmp011 = Tuple2_0(0, 0);
|
198
|
+
if (1) {
|
199
|
+
struct Tuple2_Int_Int* pvar6_pos = _tmp011;
|
200
|
+
int pvar6_x = _tmp011->value.Tuple2.member0;
|
201
|
+
int pvar6_y = _tmp011->value.Tuple2.member1;
|
202
|
+
_tmp010 = pvar6_x;
|
203
|
+
}
|
204
|
+
return _tmp010;
|
205
|
+
}
|
206
|
+
static int node_y(struct Tuple2_Int_Int* pos, int* output) {
|
207
|
+
int _tmp012;
|
208
|
+
if (1) {
|
209
|
+
struct Tuple2_Int_Int* pvar7_pos = pos;
|
210
|
+
int pvar7_x = pos->value.Tuple2.member0;
|
211
|
+
int pvar7_y = pos->value.Tuple2.member1;
|
212
|
+
_tmp012 = pvar7_y;
|
213
|
+
}
|
214
|
+
*output = _tmp012;
|
215
|
+
return 1;
|
216
|
+
}
|
217
|
+
static int init_y() {
|
218
|
+
struct Tuple2_Int_Int* _tmp014;
|
219
|
+
int _tmp013;
|
220
|
+
_tmp014 = Tuple2_0(0, 0);
|
221
|
+
if (1) {
|
222
|
+
struct Tuple2_Int_Int* pvar8_pos = _tmp014;
|
223
|
+
int pvar8_x = _tmp014->value.Tuple2.member0;
|
224
|
+
int pvar8_y = _tmp014->value.Tuple2.member1;
|
225
|
+
_tmp013 = pvar8_y;
|
226
|
+
}
|
227
|
+
return _tmp013;
|
228
|
+
}
|
229
|
+
static void refreshMark() {
|
230
|
+
int i;
|
231
|
+
for (i = 0; i < size_Tuple2_Bool_Int; i++) {
|
232
|
+
if (memory_Tuple2_Bool_Int[i].mark < Counter) memory_Tuple2_Bool_Int[i].mark = 0;
|
233
|
+
else memory_Tuple2_Bool_Int[i].mark -= Counter - 1;
|
234
|
+
}
|
235
|
+
for (i = 0; i < size_Tuple2_Int_Int; i++) {
|
236
|
+
if (memory_Tuple2_Int_Int[i].mark < Counter) memory_Tuple2_Int_Int[i].mark = 0;
|
237
|
+
else memory_Tuple2_Int_Int[i].mark -= Counter - 1;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
void ActivateLCDPositioner() {
|
241
|
+
int current_side = 0, last_side = 1;
|
242
|
+
node_memory_k[last_side] = init_k();
|
243
|
+
mark_Tuple2_Bool_Int(node_memory_k[last_side], 0);
|
244
|
+
node_memory_pulse40ms[last_side] = init_pulse40ms();
|
245
|
+
node_memory_pulse40msCount[last_side] = init_pulse40msCount();
|
246
|
+
node_memory_pos[last_side] = init_pos();
|
247
|
+
mark_Tuple2_Int_Int(node_memory_pos[last_side], 6);
|
248
|
+
node_memory_x[last_side] = init_x();
|
249
|
+
node_memory_y[last_side] = init_y();
|
250
|
+
Counter = NodeSize + 1;
|
251
|
+
refreshMark();
|
252
|
+
while (1) {
|
253
|
+
Counter = 1;
|
254
|
+
Input(&node_memory_up[current_side], &node_memory_down[current_side], &node_memory_left[current_side], &node_memory_right[current_side], &node_memory_pulse10ms[current_side]);
|
255
|
+
node_k(node_memory_pulse10ms[current_side], node_memory_pulse40msCount[last_side], &node_memory_k[current_side]);
|
256
|
+
mark_Tuple2_Bool_Int(node_memory_k[current_side], Counter + 4);
|
257
|
+
Counter++;
|
258
|
+
node_dx(node_memory_right[current_side], node_memory_left[current_side], &node_memory_dx[current_side]);
|
259
|
+
Counter++;
|
260
|
+
node_dy(node_memory_down[current_side], node_memory_up[current_side], &node_memory_dy[current_side]);
|
261
|
+
Counter++;
|
262
|
+
node_pulse40ms(node_memory_k[current_side], &node_memory_pulse40ms[current_side]);
|
263
|
+
Counter++;
|
264
|
+
node_pulse40msCount(node_memory_k[current_side], &node_memory_pulse40msCount[current_side]);
|
265
|
+
Counter++;
|
266
|
+
node_pos(node_memory_pulse40ms[current_side], node_memory_x[last_side], node_memory_dx[current_side], node_memory_y[last_side], node_memory_dy[current_side], node_memory_pos[last_side], &node_memory_pos[current_side]);
|
267
|
+
mark_Tuple2_Int_Int(node_memory_pos[current_side], Counter + 8);
|
268
|
+
Counter++;
|
269
|
+
node_x(node_memory_pos[current_side], &node_memory_x[current_side]);
|
270
|
+
Counter++;
|
271
|
+
node_y(node_memory_pos[current_side], &node_memory_y[current_side]);
|
272
|
+
Counter++;
|
273
|
+
Output(&node_memory_x[current_side], &node_memory_y[current_side]);
|
274
|
+
refreshMark();
|
275
|
+
current_side ^= 1;
|
276
|
+
last_side ^= 1;
|
277
|
+
}
|
278
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module LCDPositioner
|
2
|
+
in
|
3
|
+
up : Bool,
|
4
|
+
down : Bool,
|
5
|
+
left : Bool,
|
6
|
+
right : Bool,
|
7
|
+
pulse10ms : Bool
|
8
|
+
out
|
9
|
+
x, y
|
10
|
+
use
|
11
|
+
Std
|
12
|
+
|
13
|
+
node dy = down.boolToInt - up.boolToInt
|
14
|
+
node dx = right.boolToInt - left.boolToInt
|
15
|
+
|
16
|
+
node init[(False, 0)] (pulse40ms, pulse40msCount) as pulse = {
|
17
|
+
c = (pulse40msCount@last + pulse10ms.boolToInt) % 4
|
18
|
+
(c == 0 && pulse10ms, c)
|
19
|
+
}
|
20
|
+
|
21
|
+
node init[(0,0)] (x, y) as pos =
|
22
|
+
if pulse40ms then (x@last + dx, y@last + dy) else pos@last
|
23
|
+
|
24
|
+
|
25
|
+
#@ :assert-module
|
26
|
+
#- True, False, False, False, True => 0, 0
|
27
|
+
#@ : True, False, False, False, True => 0, 0
|
28
|
+
#@ : True, False, False, False, True => 0, 0
|
29
|
+
#@ : True, False, False, False, True => 0, -1
|
30
|
+
#@ : True, False, False, False, True => 0, -1
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "LCDPositioner.h"
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
|
5
|
+
void Input(int* up, int* down, int* left, int* right, int* pulse10ms) {
|
6
|
+
if (scanf("%d %d %d %d %d", up, down, left, right, pulse10ms) == EOF) {
|
7
|
+
exit(0);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
void Output(int* x, int* y) {
|
11
|
+
printf("%d %d\n", *x, *y);
|
12
|
+
}
|
13
|
+
int main() {
|
14
|
+
ActivateLCDPositioner();
|
15
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
digraph LCDPositioner {
|
2
|
+
pulse10ms [label = "pulse10ms : Bool", shape = "invhouse"];
|
3
|
+
pulse40msCount [label = "pulse40msCount : Int"];
|
4
|
+
pulse [label = "pulse : Tuple2[Bool, Int]"];
|
5
|
+
pulse40ms [label = "pulse40ms : Bool"];
|
6
|
+
right [label = "right : Bool", shape = "invhouse"];
|
7
|
+
left [label = "left : Bool", shape = "invhouse"];
|
8
|
+
dx [label = "dx : Int"];
|
9
|
+
y [label = "y : Int", style = filled, fillcolor = "#e4e4e4"];
|
10
|
+
down [label = "down : Bool", shape = "invhouse"];
|
11
|
+
up [label = "up : Bool", shape = "invhouse"];
|
12
|
+
dy [label = "dy : Int"];
|
13
|
+
pos [label = "pos : Tuple2[Int, Int]"];
|
14
|
+
x [label = "x : Int", style = filled, fillcolor = "#e4e4e4"];
|
15
|
+
pos -> x;
|
16
|
+
pulse40ms -> pos;
|
17
|
+
pulse -> pulse40ms;
|
18
|
+
pulse10ms -> pulse;
|
19
|
+
pulse40msCount -> pulse [style = dashed];
|
20
|
+
pulse -> pulse40msCount;
|
21
|
+
x -> pos [style = dashed];
|
22
|
+
dx -> pos;
|
23
|
+
right -> dx;
|
24
|
+
left -> dx;
|
25
|
+
y -> pos [style = dashed];
|
26
|
+
pos -> y;
|
27
|
+
dy -> pos;
|
28
|
+
down -> dy;
|
29
|
+
up -> dy;
|
30
|
+
pos -> pos [style = dashed];
|
31
|
+
}
|
Binary file
|