fwi 1.0.0 → 1.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: 87be340eab8e5bf9eb089e92cff12a5334be00e7
4
- data.tar.gz: 688dc30f47412cabbd679f6d8a2571e9a71980b8
3
+ metadata.gz: eae98e13b6ec9a8846176fa727bbb962397b1c5f
4
+ data.tar.gz: 7352bb31bed27f0a41cc332f59276bc57bf35b70
5
5
  SHA512:
6
- metadata.gz: 7df2c8cdffdee78b64599afbddf8d04efad76f37ed20f0b32de2051988de2ccaa6015d46aa65dcaf1ab75e95389e7d5fa074da9236145f75940ca69263ef6481
7
- data.tar.gz: 3593cba598bc3cf4a2b552cca783a58f02ad8aa3dcb7c0a0deba5d9327b19160a5e2b9d2ffea3ed5ee00c51bc279dbdf0aa7ba989697f51fc8cc24315bf271ee
6
+ metadata.gz: 675e87dea63eb8189a13de38e72b00b85c14bbfe84d83463c56f13272671bce276aa4bf558152294d596a96f4f9f8590e9cdc9c9666956de41612f59db1022ea
7
+ data.tar.gz: a2a3deb6e44f6d372b9ec90bcd2f45aff0fc5dd33f9a9e93f8fb11910432aa56f631020b1f1ff8f608547a3efd1a72f4bf65f847f05b44e4557c5be03dc79645
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in waitress-core.gemspec
4
3
  gemspec
data/fwi.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fwi"
6
- spec.version = "1.0.0"
6
+ spec.version = "1.1.0"
7
7
  spec.authors = ["Jaci Brunning"]
8
8
  spec.email = ["jaci.brunning@gmail.com"]
9
9
 
data/lib/fwi/compiler.rb CHANGED
@@ -1,13 +1,17 @@
1
- require_relative 'cpp/compiler.rb'
1
+ require 'fwi/compilers/cpp/compiler.rb'
2
+ require 'fwi/compilers/js/compiler.rb'
3
+ # require_relative 'js/compiler.rb'
4
+
2
5
  require_relative 'parser.rb'
3
6
  require 'optparse'
4
7
 
5
8
  COMPILERS = {
6
- "cpp" => CPPCompiler.new
9
+ "cpp" => CPPCompiler.new,
10
+ "js" => JSCompiler.new
7
11
  };
8
12
 
9
13
  options = {
10
- :source_root => "."
14
+ :source_root => ".", :output => "."
11
15
  }
12
16
  optp = OptionParser.new do |opts|
13
17
 
@@ -24,10 +28,12 @@ optp = OptionParser.new do |opts|
24
28
  options[:language] = lang
25
29
  end
26
30
 
27
- opts.on("-d", "--source-directory DIRECTORY", "Set the source directory to pull files from") do |directory|
31
+ opts.on("-d", "--source-dir [DIRECTORY]", "Set the source directory to pull files from") do |directory|
28
32
  options[:source_root] = directory
29
33
  end
30
34
 
35
+ opts.on("-o", "--output [DIRECTORY]", "Directory to put Generated Files") { |x| options[:output] = x }
36
+
31
37
  COMPILERS.each do |n,x|
32
38
  opts.separator ""
33
39
  opts.separator n
@@ -19,9 +19,7 @@ class CPPCompiler
19
19
  o.on("--header-only", "Compile as header-only") { |x| @options[:hpp_only] = true }
20
20
  end
21
21
 
22
- def after_parse
23
- end
24
-
22
+ def after_parse; end
25
23
  def on_selected; end
26
24
 
27
25
  def compile file, lex, bitmap, options
File without changes
@@ -0,0 +1,24 @@
1
+ require_relative 'gen.rb'
2
+ require 'fileutils'
3
+
4
+ class JSCompiler
5
+ GEN = FWI::Generator::JS.new
6
+
7
+ def populate_options o
8
+ end
9
+
10
+ def after_parse; end
11
+ def on_selected; end
12
+
13
+ def compile file, lex, bitmap, options
14
+ base = File.basename(file, File.extname(file))
15
+
16
+ files = GEN.gen bitmap
17
+ files.each do |fn, contents|
18
+ f = File.join(options[:output], fn)
19
+ FileUtils.mkdir_p File.expand_path("..", f)
20
+ File.write(f, contents)
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,174 @@
1
+ module FWI
2
+ module Generator
3
+ class JS
4
+ def append buffer, indent, string
5
+ string.split(/\n/).each { |y| buffer << ("\t" * indent) + y + "\n" }
6
+ end
7
+
8
+ def _func_util obj, member, mode
9
+ type = member[:type]
10
+ internal_type = type.to_s
11
+ internal_type = "child" if type == :reference && member[:element_type] == :block
12
+ internal_type = "u8" if type == :reference && member[:element_type] == :enum
13
+
14
+ param = member[:array].nil? ? "" : "int index#{mode == :setter ? ', ' : ''}"
15
+ custom_getter = member[:attribute_map]["getter"]
16
+ custom_setter = member[:attribute_map]["setter"]
17
+ custom_length = member[:attribute_map]["length_func"]
18
+
19
+ func_name = nil
20
+ func_sig = nil
21
+ if mode == :setter
22
+ func_name = custom_setter.nil? ? "set_#{member[:name]}" : custom_setter
23
+ func_sig = "function(#{param}value) {"
24
+ elsif mode == :getter
25
+ func_name = custom_getter.nil? ? "get_#{member[:name]}" : custom_getter
26
+ func_sig = "function(#{param}) {"
27
+ elsif mode == :length
28
+ func_name = custom_length.nil? ? "#{member[:name]}_length" : custom_length
29
+ func_sig = "function(#{param}) {"
30
+ end
31
+
32
+ index = member[:index]
33
+ index = "#{index} + (#{member[:typesize]} * index)" unless member[:array].nil?
34
+ { :internal_type => internal_type, :index => index, :func_name => func_name, :func_sig => func_sig }
35
+ end
36
+
37
+ def write_getter obj, member, str, indent
38
+ return "" if member[:attributes].include? "no-getter"
39
+ util = _func_util(obj, member, :getter)
40
+
41
+ fullfunc = obj + ".prototype." + util[:func_name] + " = " + util[:func_sig]
42
+ append(str, indent, fullfunc)
43
+ type = member[:type]
44
+ if type == :reference && member[:element_type] == :block
45
+ type = member[:element_name].gsub("::", ".")
46
+ append(str, indent + 1, "return this.get_child(#{type}, #{util[:index]});")
47
+ elsif type == :bool
48
+ if member[:array].nil?
49
+ append(str, indent + 1, "return this.get_bool(#{util[:index]}, #{member[:bit_index]});")
50
+ else
51
+ append(str, indent + 1, "return this.get_bool(#{member[:index]} + index / 8, index % 8, value);")
52
+ end
53
+ else
54
+ append(str, indent + 1, "return this.get_#{util[:internal_type]}(#{util[:index]});")
55
+ end
56
+ append(str, indent, "};")
57
+ end
58
+
59
+ def write_setter obj, member, str, indent
60
+ return "" if member[:attributes].include? "no-setter"
61
+ util = _func_util(obj, member, :setter)
62
+
63
+ fullfunc = obj + ".prototype." + util[:func_name] + " = " + util[:func_sig]
64
+ append(str, indent, fullfunc)
65
+ type = member[:type]
66
+ if type == :bool
67
+ if member[:array].nil?
68
+ append(str, indent + 1, "this.set_bool(#{util[:index]}, #{member[:bit_index]}, value);")
69
+ else
70
+ append(str, indent + 1, "this.set_bool(#{member[:index]} + index / 8, index % 8, value);")
71
+ end
72
+ else
73
+ append(str, indent + 1, "this.set_#{util[:internal_type]}(#{util[:index]}, value);")
74
+ end
75
+ append(str, indent, "};")
76
+ end
77
+
78
+ def write_length obj, member, str, indent
79
+ return "" if member[:attributes].include? "no-len"
80
+ util = _func_util(obj, member, :length)
81
+
82
+ fullfunc = obj + ".prototype." + util[:func_name] + " = " + util[:func_sig]
83
+ append(str, indent, fullfunc)
84
+ append(str, indent + 1, "return #{member[:size]};")
85
+ append(str, indent, "};")
86
+ end
87
+
88
+ def gen_prototype obj, member, str, indent
89
+ write_getter obj, member, str, indent
90
+ if member[:type] == :reference
91
+ if member[:element_type] == :enum
92
+ write_setter obj, member, str, indent
93
+ end
94
+ else
95
+ write_setter obj, member, str, indent
96
+ write_length(obj, member, str, indent)if member[:type] == :string
97
+ end
98
+ end
99
+
100
+ def gen_for_ns parent, name, ns, str, indent
101
+ is_root = name == "<root>"
102
+ has_parent = parent != "<root>"
103
+ unless has_parent
104
+ append str, indent, "var #{name} = {};" unless is_root
105
+ else
106
+ append str, indent, "#{parent}.#{name} = {};" unless is_root
107
+ end
108
+
109
+ fqn_ns = name
110
+ fqn_ns = parent + "." + fqn_ns if has_parent
111
+
112
+ unless is_root
113
+ append(str, indent, "FWI.util.exports().#{fqn_ns} = #{fqn_ns};")
114
+ end
115
+
116
+ ns[:members].each do |el_name, element|
117
+ fqn = fqn_ns + "." + el_name
118
+ fqn = el_name if is_root
119
+ type_decl = is_root ? "var #{fqn}" : "#{fqn}"
120
+
121
+ if element[:type] == :namespace
122
+ gen_for_ns(fqn_ns, el_name, element, str, indent);
123
+ elsif element[:type] == :block
124
+ append str, indent, type_decl + " = FWI.block(\"#{fqn}\", #{element[:size]});"
125
+ element[:members].each do |mem|
126
+ gen_prototype(fqn, mem, str, indent)
127
+ end
128
+ elsif element[:type] == :enum
129
+ maps = element[:members].map do |e|
130
+ "#{e[:name]}: #{e[:val]},"
131
+ end
132
+ maps.last.sub!(",","")
133
+ append str, indent, type_decl + " = {"
134
+ maps.each do |m|
135
+ append str, indent+1, m
136
+ end
137
+ append str, indent, "};"
138
+ end
139
+
140
+ if is_root
141
+ append(str, indent, "FWI.util.exports().#{fqn} = #{fqn};")
142
+ end
143
+ end
144
+ end
145
+
146
+ def _get_for_file bitmap, file
147
+ map = { :members => {}, :type => :namespace }
148
+ bitmap[:members].each do |name, member|
149
+ if member[:type] == :namespace
150
+ ret = _get_for_file member, file
151
+ map[:members][name] = ret unless ret[:members].empty?
152
+ else
153
+ map[:members][name] = member if member[:file] == file
154
+ end
155
+ end
156
+ map
157
+ end
158
+
159
+ def gen bitmap
160
+ map = {}
161
+ bitmap[:files].each do |name, file|
162
+ filename = name.sub ".fwi", ".js"
163
+ contents = "(function() {\n"
164
+
165
+ gen_for_ns("<root>", "<root>", _get_for_file(bitmap, name), contents, 1)
166
+
167
+ contents += "})();"
168
+ map[filename] = contents
169
+ end
170
+ map
171
+ end
172
+ end
173
+ end
174
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fwi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaci Brunning
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-01 00:00:00.000000000 Z
11
+ date: 2016-08-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -23,8 +23,10 @@ files:
23
23
  - bin/fwi
24
24
  - fwi.gemspec
25
25
  - lib/fwi/compiler.rb
26
- - lib/fwi/cpp/compiler.rb
27
- - lib/fwi/cpp/gen.rb
26
+ - lib/fwi/compilers/cpp/compiler.rb
27
+ - lib/fwi/compilers/cpp/gen.rb
28
+ - lib/fwi/compilers/js/compiler.rb
29
+ - lib/fwi/compilers/js/gen.rb
28
30
  - lib/fwi/parser.rb
29
31
  homepage: http://github.com/JacisNonsense/Fixed-Width-Interchange
30
32
  licenses: []