emfrp 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/emfrp/compile/c/codegen_context.rb +4 -1
- data/lib/emfrp/compile/c/monofy.rb +2 -2
- data/lib/emfrp/compile/c/syntax_codegen.rb +7 -7
- data/lib/emfrp/interpreter/command_manager.rb +3 -3
- data/lib/emfrp/interpreter/interpreter.rb +2 -2
- data/lib/emfrp/parser/newnode_convert.rb +72 -0
- data/lib/emfrp/parser/parser.rb +6 -1
- data/lib/emfrp/parser/toplevel.rb +34 -2
- data/lib/emfrp/syntax.rb +2 -0
- data/lib/emfrp/version.rb +1 -1
- data/tests/Rakefile.common +1 -1
- data/tests/compiler/UseData/Rakefile +2 -0
- data/tests/compiler/UseData/UseData.mfrp +8 -0
- data/tests/compiler/UseData/UseDataMain.c +19 -0
- data/tests/compiler/UseData/actual_out.txt +10 -0
- data/tests/compiler/UseData/expected_out.txt +10 -0
- data/tests/compiler/UseData/in.txt +0 -0
- data/tests/compiler/UseSubModule/Rakefile +2 -0
- data/tests/compiler/UseSubModule/SubModule.mfrp +8 -0
- data/tests/compiler/UseSubModule/SubModule2.mfrp +5 -0
- data/tests/compiler/UseSubModule/UseSubModule.mfrp +11 -0
- data/tests/compiler/UseSubModule/UseSubModuleMain.c +15 -0
- data/tests/compiler/UseSubModule/actual_out.txt +2 -0
- data/tests/compiler/UseSubModule/expected_out.txt +2 -0
- data/tests/compiler/UseSubModule/in.txt +2 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59d962a4e429994cc567a8b55d5f2af0e0740315
|
4
|
+
data.tar.gz: aedf5fea2452340e9eed146c46df4e13499eeeb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dccd435654a7e1c861d50b7940e84e9adbe643d2807834b316b28deda96198c356450f6b0233ed8ed696fd8e44861f135d78beb1cb694afb4890f89161e58c45
|
7
|
+
data.tar.gz: d6e567bea262b2e6989cd5adc549ce017b73e02d2f53ab31dae6306a94ea9c82f632a3787af9614505a489630acd47b046c43ff33ba4af5fb95abe2bdf6a4bed
|
data/README.md
CHANGED
@@ -75,9 +75,9 @@ module Emfrp
|
|
75
75
|
@update = false
|
76
76
|
@datas.each do |d|
|
77
77
|
key = Link.new(d)
|
78
|
-
unless @top[:dict][:
|
78
|
+
unless @top[:dict][:sorted_datas].find{|x| x == key}
|
79
79
|
monofy_exp(d[:exp])
|
80
|
-
@top[:dict][:
|
80
|
+
@top[:dict][:sorted_datas] << key
|
81
81
|
end
|
82
82
|
end
|
83
83
|
@ifuncs.each do |ifunc|
|
@@ -35,7 +35,7 @@ module Emfrp
|
|
35
35
|
self[:dict][:used_pfuncs].each do |v|
|
36
36
|
v.get.codegen(ct)
|
37
37
|
end
|
38
|
-
self[:dict][:sorted_datas].each do |v|
|
38
|
+
self[:dict][:sorted_datas].reverse.each do |v|
|
39
39
|
v.get.codegen(ct)
|
40
40
|
end
|
41
41
|
memory_gen(ct, ar)
|
@@ -87,7 +87,7 @@ module Emfrp
|
|
87
87
|
"#{pn.node_var_name(ct)}[#{x[:last] ? "last_side" : "current_side"}]"
|
88
88
|
end
|
89
89
|
output_arg = "&#{node.node_var_name(ct)}[current_side]"
|
90
|
-
stmts << "#{node.node_func_name(ct)}(#{[args,
|
90
|
+
stmts << "#{node.node_func_name(ct)}(#{[*args, output_arg].join(", ")});"
|
91
91
|
t = ct.tdef(node)
|
92
92
|
if t.is_a?(TypeDef) && !t.enum?(ct)
|
93
93
|
mark_val = "Counter + #{ar.life_point(node)}"
|
@@ -265,15 +265,15 @@ module Emfrp
|
|
265
265
|
end
|
266
266
|
|
267
267
|
def init_func_name(ct)
|
268
|
-
"init_#{self[:name][:desc]}"
|
268
|
+
"init_#{ct.escape_name(self[:name][:desc])}"
|
269
269
|
end
|
270
270
|
|
271
271
|
def node_func_name(ct)
|
272
|
-
"node_#{self[:name][:desc]}"
|
272
|
+
"node_#{ct.escape_name(self[:name][:desc])}"
|
273
273
|
end
|
274
274
|
|
275
275
|
def node_var_name(ct)
|
276
|
-
"node_memory_#{self[:name][:desc]}"
|
276
|
+
"node_memory_#{ct.escape_name(self[:name][:desc])}"
|
277
277
|
end
|
278
278
|
|
279
279
|
def var_suffix(ct)
|
@@ -308,8 +308,8 @@ module Emfrp
|
|
308
308
|
class DataDef
|
309
309
|
def codegen(ct)
|
310
310
|
t = ct.tref(self)
|
311
|
-
ct.define_global_var(t, var_name(ct))
|
312
|
-
ct.define_init_stmt(var_name(ct
|
311
|
+
ct.define_global_var(t, var_name(ct, self[:name][:desc]))
|
312
|
+
ct.define_init_stmt("#{var_name(ct, self[:name][:desc])} = #{init_func_name(ct)}();")
|
313
313
|
ct.define_func(t, init_func_name(ct), []) do |x|
|
314
314
|
x << "return #{self[:exp].codegen(ct, x)};"
|
315
315
|
end
|
@@ -159,9 +159,9 @@ module Emfrp
|
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
|
-
desc "Executing all commands
|
163
|
-
command "exec-
|
164
|
-
|
162
|
+
desc "Executing all commands embedded on source-files."
|
163
|
+
command "exec-embedded-commands" do
|
164
|
+
exec_embedded_commands()
|
165
165
|
end
|
166
166
|
|
167
167
|
desc "Define documentation about function. (in preparation)"
|
@@ -92,13 +92,13 @@ module Emfrp
|
|
92
92
|
end
|
93
93
|
|
94
94
|
#-> true-like(abnormal-term) / false-like(normal-term)
|
95
|
-
def
|
95
|
+
def exec_embedded_commands(only_on_main_path=false) #
|
96
96
|
@top[:commands].any? do |com|
|
97
97
|
if !only_on_main_path || com[:file_name] == @file_loader.loaded_full_path(@main_path)
|
98
98
|
unless process_repl_line(com[:command_str])
|
99
99
|
nil
|
100
100
|
else
|
101
|
-
puts "
|
101
|
+
puts "Embedded command on #{com[:file_name]}:#{com[:line_number]}\n"
|
102
102
|
true
|
103
103
|
end
|
104
104
|
else
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Emfrp
|
2
|
+
module NewNodeConvert
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def parse_module(mod_name, newnode, file_loader)
|
6
|
+
src_str, file_name = file_loader.load(newnode[:module_path].map{|x| x[:desc]})
|
7
|
+
top = Parser.parse_src(src_str, file_name, file_loader)
|
8
|
+
uniq_key = "#{mod_name}(#{newnode[:names].map{|x| x[:desc]}.join(",")})"
|
9
|
+
rename_nodes(top, uniq_key)
|
10
|
+
top[:inputs].zip(newnode[:args]).each do |input, arg_exp|
|
11
|
+
input[:name][:desc] << "##{uniq_key}"
|
12
|
+
top[:nodes] << NodeDef.new(
|
13
|
+
:name => input[:name],
|
14
|
+
:init_exp => nil,
|
15
|
+
:params => nil,
|
16
|
+
:type => nil,
|
17
|
+
:exp => arg_exp,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
top[:inputs] = []
|
21
|
+
top[:outputs].zip(newnode[:names]).each do |output, newnode_name|
|
22
|
+
output[:name][:desc] << "##{uniq_key}"
|
23
|
+
top[:nodes] << NodeDef.new(
|
24
|
+
:name => newnode_name,
|
25
|
+
:init_exp => nil,
|
26
|
+
:params => nil,
|
27
|
+
:type => nil,
|
28
|
+
:exp => VarRef.new(:name => output[:name])
|
29
|
+
)
|
30
|
+
end
|
31
|
+
top[:outputs] = []
|
32
|
+
return top
|
33
|
+
end
|
34
|
+
|
35
|
+
def rename_nodes(top, uniq_key)
|
36
|
+
datas = Hash[top[:datas].map{|x| [x[:name][:desc], true]}]
|
37
|
+
top[:nodes].each do |n|
|
38
|
+
white_list = {}
|
39
|
+
n[:name][:desc] << "##{uniq_key}"
|
40
|
+
if n[:params]
|
41
|
+
n[:params].each do |pn|
|
42
|
+
white_list[pn[:as][:desc].clone] = true
|
43
|
+
pn[:name][:desc] << "##{uniq_key}"
|
44
|
+
pn[:as][:desc] << "##{uniq_key}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
rename_node_exp(n[:exp], datas, white_list, uniq_key, {})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def rename_node_exp(exp, datas, white_list, uniq_key, local_vars)
|
52
|
+
case exp
|
53
|
+
when VarRef
|
54
|
+
name = exp[:name][:desc]
|
55
|
+
if !local_vars[name] && (white_list[name] || !datas[name])
|
56
|
+
if name =~ /^(.*)@last$/
|
57
|
+
exp[:name][:desc] = "#{$1}##{uniq_key}@last"
|
58
|
+
else
|
59
|
+
exp[:name][:desc] << "##{uniq_key}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
when Case
|
63
|
+
vs = Hash[exp[:pattern].find_refs.map{|x| [x[:desc], true]}]
|
64
|
+
rename_node_exp(exp[:exp], datas, white_list, uniq_key, local_vars.merge(vs))
|
65
|
+
when Syntax
|
66
|
+
rename_node_exp(exp.values, datas, white_list, uniq_key, local_vars)
|
67
|
+
when Array
|
68
|
+
exp.each{|e| rename_node_exp(e, datas, white_list, uniq_key, local_vars)}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/emfrp/parser/parser.rb
CHANGED
@@ -6,6 +6,7 @@ require 'emfrp/parser/expression'
|
|
6
6
|
require 'emfrp/parser/misc'
|
7
7
|
require 'emfrp/parser/operator'
|
8
8
|
require 'emfrp/parser/parsing_error'
|
9
|
+
require 'emfrp/parser/newnode_convert'
|
9
10
|
|
10
11
|
module Emfrp
|
11
12
|
class Parser < ParserCombinator::StringParser
|
@@ -22,10 +23,14 @@ module Emfrp
|
|
22
23
|
when Fail
|
23
24
|
raise ParsingError.new(src_str, file_name, res.status)
|
24
25
|
when Ok
|
26
|
+
newnode_tops = res.parsed[:newnodes].map do |newnode|
|
27
|
+
NewNodeConvert.parse_module(res.parsed[:module_name][:desc], newnode, file_loader)
|
28
|
+
end
|
29
|
+
res.parsed[:newnodes] = []
|
25
30
|
tops = res.parsed[:uses].map do |use_path|
|
26
31
|
parse_input(use_path.map{|x| x[:desc]}, file_loader, material_file)
|
27
32
|
end
|
28
|
-
return Top.new(*tops, res.parsed)
|
33
|
+
return Top.new(*tops, res.parsed, *newnode_tops)
|
29
34
|
else
|
30
35
|
raise "unexpected return of parser (bug)"
|
31
36
|
end
|
@@ -7,7 +7,18 @@ module Emfrp
|
|
7
7
|
# --------------------
|
8
8
|
|
9
9
|
parser :module_top_def do
|
10
|
-
|
10
|
+
defs = [
|
11
|
+
data_def,
|
12
|
+
func_def,
|
13
|
+
node_def,
|
14
|
+
type_def,
|
15
|
+
infix_def,
|
16
|
+
primtype_def,
|
17
|
+
primfunc_def,
|
18
|
+
command_def,
|
19
|
+
newnode_def,
|
20
|
+
]
|
21
|
+
defs.inject(&:^).map do |x|
|
11
22
|
[x].flatten
|
12
23
|
end
|
13
24
|
end
|
@@ -65,6 +76,7 @@ module Emfrp
|
|
65
76
|
when PrimTypeDef then :ptypes
|
66
77
|
when PrimFuncDef then :pfuncs
|
67
78
|
when CommandDef then :commands
|
79
|
+
when NewNodeDef then :newnodes
|
68
80
|
end
|
69
81
|
t[k] << d
|
70
82
|
end
|
@@ -206,7 +218,7 @@ module Emfrp
|
|
206
218
|
whole_name = x[:pattern][:ref]
|
207
219
|
else
|
208
220
|
whole_name = SSymbol.new(
|
209
|
-
:desc => "
|
221
|
+
:desc => "anonymous" + x[:pattern].object_id.to_s,
|
210
222
|
:keyword => x[:pattern].deep_copy
|
211
223
|
)
|
212
224
|
end
|
@@ -333,6 +345,26 @@ module Emfrp
|
|
333
345
|
end
|
334
346
|
end
|
335
347
|
|
348
|
+
parser :newnode_def do
|
349
|
+
seq(
|
350
|
+
symbol("newnode").name(:keyword1),
|
351
|
+
many1(ws),
|
352
|
+
many1_fail(ident_begin_lower, comma_separator).name(:names),
|
353
|
+
many(ws),
|
354
|
+
char("="),
|
355
|
+
many(ws),
|
356
|
+
load_path.name(:module_path),
|
357
|
+
many(ws),
|
358
|
+
char("("),
|
359
|
+
many(ws),
|
360
|
+
many_fail(exp, comma_separator).name(:args),
|
361
|
+
many(ws),
|
362
|
+
symbol(")").name(:keyword2)
|
363
|
+
).map do |x|
|
364
|
+
NewNodeDef.new(x.to_h)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
336
368
|
# Func associated
|
337
369
|
# --------------------
|
338
370
|
|
data/lib/emfrp/syntax.rb
CHANGED
@@ -110,6 +110,7 @@ module Emfrp
|
|
110
110
|
:itypes,
|
111
111
|
:ifuncs,
|
112
112
|
:commands,
|
113
|
+
:newnodes,
|
113
114
|
]
|
114
115
|
|
115
116
|
def initialize(*tops)
|
@@ -152,6 +153,7 @@ module Emfrp
|
|
152
153
|
Types = [
|
153
154
|
:InputDef, :OutputDef, :DataDef, :FuncDef, :NodeDef, :TypeDef, :InfixDef,
|
154
155
|
:PrimTypeDef, :PrimFuncDef, :CommandDef,
|
156
|
+
:NewNodeDef,
|
155
157
|
|
156
158
|
:ParamDef, :Type, :TypeVar, :TValue, :TValueParam, :NodeConst, :ForeignExp,
|
157
159
|
|
data/lib/emfrp/version.rb
CHANGED
data/tests/Rakefile.common
CHANGED
@@ -6,7 +6,7 @@ TARGETS = Dir.glob("./*.mfrp").map{|x| x =~ /^\.\/(.*).mfrp$/; $1}
|
|
6
6
|
def exec_test(file_name)
|
7
7
|
puts "TESTING #{file_name}".colorize(:light_blue)
|
8
8
|
inter = Emfrp::Interpreter.new(Emfrp::IncludeDirs, STDOUT, file_name)
|
9
|
-
unless inter.
|
9
|
+
unless inter.exec_embedded_commands(true)
|
10
10
|
puts " => ok".colorize(:green)
|
11
11
|
else
|
12
12
|
puts " => fail".colorize(:red)
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "UseSubModule.h"
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
|
5
|
+
void Input(int* x) {
|
6
|
+
if (scanf("%d", x) == EOF) {
|
7
|
+
exit(0);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
void Output(int* a1, int* b1, int* a2, int* b2) {
|
11
|
+
printf("%d %d %d %d\n", *a1, *b1, *a2, *b2);
|
12
|
+
}
|
13
|
+
int main() {
|
14
|
+
ActivateUseSubModule();
|
15
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emfrp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kensuke Sawada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/emfrp/interpreter/interpreter.rb
|
112
112
|
- lib/emfrp/parser/expression.rb
|
113
113
|
- lib/emfrp/parser/misc.rb
|
114
|
+
- lib/emfrp/parser/newnode_convert.rb
|
114
115
|
- lib/emfrp/parser/operator.rb
|
115
116
|
- lib/emfrp/parser/parser.rb
|
116
117
|
- lib/emfrp/parser/parsing_error.rb
|
@@ -146,6 +147,20 @@ files:
|
|
146
147
|
- tests/compiler/LCDPositioner/in.txt
|
147
148
|
- tests/compiler/Rakefile
|
148
149
|
- tests/compiler/Rakefile.common
|
150
|
+
- tests/compiler/UseData/Rakefile
|
151
|
+
- tests/compiler/UseData/UseData.mfrp
|
152
|
+
- tests/compiler/UseData/UseDataMain.c
|
153
|
+
- tests/compiler/UseData/actual_out.txt
|
154
|
+
- tests/compiler/UseData/expected_out.txt
|
155
|
+
- tests/compiler/UseData/in.txt
|
156
|
+
- tests/compiler/UseSubModule/Rakefile
|
157
|
+
- tests/compiler/UseSubModule/SubModule.mfrp
|
158
|
+
- tests/compiler/UseSubModule/SubModule2.mfrp
|
159
|
+
- tests/compiler/UseSubModule/UseSubModule.mfrp
|
160
|
+
- tests/compiler/UseSubModule/UseSubModuleMain.c
|
161
|
+
- tests/compiler/UseSubModule/actual_out.txt
|
162
|
+
- tests/compiler/UseSubModule/expected_out.txt
|
163
|
+
- tests/compiler/UseSubModule/in.txt
|
149
164
|
- tests/core/FromAnnotation.mfrp
|
150
165
|
- tests/core/Last.mfrp
|
151
166
|
- tests/core/Rakefile
|