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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 739151824444ba84586ec87772d5cbb30bb2157c
4
- data.tar.gz: 76b48e983b31abd5459cea456f68976af359fa0f
3
+ metadata.gz: 59d962a4e429994cc567a8b55d5f2af0e0740315
4
+ data.tar.gz: aedf5fea2452340e9eed146c46df4e13499eeeb5
5
5
  SHA512:
6
- metadata.gz: 1b77eb4ab6596bcb41269a2b72fc22ad28b8137895c604ef013e0b7047677698b2bce41396c5b84eb0f535fdb5de6c9447773f4e66d953b21702a838c79e8de3
7
- data.tar.gz: 73353f055c801bb8b2841651137b75112f1f96c94b93ffe2979c3e7a8a4eaadb36a7727ca3f65a494a3ab7c3fcbdd71b9af34a95a8025628a894751970dcff60
6
+ metadata.gz: dccd435654a7e1c861d50b7940e84e9adbe643d2807834b316b28deda96198c356450f6b0233ed8ed696fd8e44861f135d78beb1cb694afb4890f89161e58c45
7
+ data.tar.gz: d6e567bea262b2e6989cd5adc549ce017b73e02d2f53ab31dae6306a94ea9c82f632a3787af9614505a489630acd47b046c43ff33ba4af5fb95abe2bdf6a4bed
data/README.md CHANGED
@@ -24,4 +24,5 @@ $ emfrp <src-file>
24
24
 
25
25
  ## Usage
26
26
 
27
- In prepraration...
27
+ Here is a (temporary) easy introduction:
28
+ https://github.com/sawaken/emfrp/wiki
@@ -19,7 +19,10 @@ module Emfrp
19
19
  "^" => "_caret_",
20
20
  "|" => "_vertial_",
21
21
  "-" => "_minus_",
22
- "~" => "_tilde_"
22
+ "~" => "_tilde_",
23
+ "(" => "_cpbegin_",
24
+ ")" => "_cpend_",
25
+ "," => "_comma_"
23
26
  }
24
27
 
25
28
  def initialize(top)
@@ -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][:used_datas].find{|x| x == key}
78
+ unless @top[:dict][:sorted_datas].find{|x| x == key}
79
79
  monofy_exp(d[:exp])
80
- @top[:dict][:used_datas] << key
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, *output_arg].join(", ")});"
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), "#{init_func_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 embeded on source-files."
163
- command "exec-embeded-commands" do
164
- exec_embeded_commands()
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 exec_embeded_commands(only_on_main_path=false) #
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 "Embeded command on #{com[:file_name]}:#{com[:line_number]}\n"
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
@@ -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
- (data_def ^ func_def ^ node_def ^ type_def ^ infix_def ^ primtype_def ^ primfunc_def ^ command_def).map do |x|
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 => "tmpNode" + x[:pattern].object_id.to_s,
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
@@ -1,3 +1,3 @@
1
1
  module Emfrp
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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.exec_embeded_commands(true)
9
+ unless inter.exec_embedded_commands(true)
10
10
  puts " => ok".colorize(:green)
11
11
  else
12
12
  puts " => fail".colorize(:red)
@@ -0,0 +1,2 @@
1
+ NAME = "UseData"
2
+ load File.expand_path('../../Rakefile.common', __FILE__)
@@ -0,0 +1,8 @@
1
+ module UseData out x use Std
2
+
3
+
4
+ data one = 1
5
+ data two = one + 1
6
+ data three = two + 1
7
+
8
+ node x = three
@@ -0,0 +1,19 @@
1
+ #include "UseData.h"
2
+ #include <stdio.h>
3
+ #include <stdlib.h>
4
+
5
+ int i = 0;
6
+
7
+ void Input() {
8
+ }
9
+
10
+ void Output(int* x) {
11
+ printf("%d\n", *x);
12
+ if (++i == 10) {
13
+ exit(0);
14
+ }
15
+ }
16
+
17
+ int main() {
18
+ ActivateUseData();
19
+ }
@@ -0,0 +1,10 @@
1
+ 3
2
+ 3
3
+ 3
4
+ 3
5
+ 3
6
+ 3
7
+ 3
8
+ 3
9
+ 3
10
+ 3
@@ -0,0 +1,10 @@
1
+ 3
2
+ 3
3
+ 3
4
+ 3
5
+ 3
6
+ 3
7
+ 3
8
+ 3
9
+ 3
10
+ 3
File without changes
@@ -0,0 +1,2 @@
1
+ NAME = "UseSubModule"
2
+ load File.expand_path('../../Rakefile.common', __FILE__)
@@ -0,0 +1,8 @@
1
+ module SubModule
2
+ in i1 : Int, i2 : Int
3
+ out x, y
4
+ use Std
5
+
6
+ newnode a = SubModule2(i1)
7
+ node x = a * i2
8
+ node init[0] y = y@last + i2
@@ -0,0 +1,5 @@
1
+ module SubModule2
2
+ in x : Int
3
+ out y
4
+
5
+ node y = x
@@ -0,0 +1,11 @@
1
+ module UseSubModule
2
+ in x : Int
3
+ out a1, b1, a2, b2
4
+ use Std
5
+
6
+ newnode a1, b1 = SubModule(x, 2)
7
+ newnode a2, b2 = SubModule(x + 1, 3)
8
+
9
+ #@ :assert-module
10
+ #- 0 => 0, 2, 3, 3
11
+ #@ : 1 => 2, 4, 6, 6
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ 0 2 3 3
2
+ 2 4 6 6
@@ -0,0 +1,2 @@
1
+ 0 2 3 3
2
+ 2 4 6 6
@@ -0,0 +1,2 @@
1
+ 0
2
+ 1
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.1
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-17 00:00:00.000000000 Z
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