excel_to_code 0.1.4 → 0.1.5

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: ca693af405aeeb0685579ce213a0b8f1fa776403
4
- data.tar.gz: 3e83af580291765c4aaf0834b8eb28a6028e0f8a
3
+ metadata.gz: 0f1f2fd79b3625aa813b46493b34cae10d4455b3
4
+ data.tar.gz: 3d5c4b5065c321940d108565458ceb6426c10595
5
5
  SHA512:
6
- metadata.gz: a06a537725eca97fa804b9b94532762d4fb91906bde7cf4cde3d06d0b39f111bf25ff15a3c5a696957273cab1d57335ff17fa5d162d694e538c72c6cbace829d
7
- data.tar.gz: c186227348931f515bd5ba5b8b8bb5c6ece9d553a1b8e9e3b5df48647ab3f4a87478d295cdd2f7ac5f2f7a0c4eab2d71e03963320c4820233df0edbda0cff0f6
6
+ metadata.gz: cbb44e22f54c3d0d086cd8fae0e82cdd717ef22ad0f72acf1bc577db80aaaf3c7516e38bf3e6c28d7a3df3a173d94c8d0adcd44fe071b048206810ca6a0ff2f3
7
+ data.tar.gz: b865adf4a4797e207e50ba43134599321b1b54bbd1ba28dabe9c882870504d6f2d773f5f7eaa17846b69d1d7c2ced7fbb1dff781b2d8ae23509aca7a21b26ec0
data/README.md CHANGED
@@ -28,6 +28,11 @@ this should work:
28
28
  3. bundle
29
29
  4. rspec spec/*
30
30
 
31
+ To test the C runtime:
32
+ 1. cd src/compile/c
33
+ 2. cc excel_to_c_runtime
34
+ 3. ./a.out
35
+
31
36
  # Hacking excel_to_code
32
37
 
33
38
  There are some how to guides in the doc folder.
@@ -37,6 +42,6 @@ There are some how to guides in the doc folder.
37
42
  1. Not tested at all on Windows
38
43
  2. INDIRECT formula must be convertable at runtime into a standard formula
39
44
  3. Doesn't implement all functions (see doc/Which_functions_are_implemented.md)
40
- 4. Doesn't implement references that involve range unions and lists
45
+ 4. Doesn't implement references that involve range unions and lists (but does implement standard ranges)
41
46
  5. Sometimes gives cells as being empty, when excel would give the cell as having a numeric value of zero
42
47
  6. The generated C version does not multithread and will give bad results if you try
@@ -214,7 +214,10 @@ class #{ruby_module_name}Shim
214
214
 
215
215
  def get(name)
216
216
  return 0 unless #{ruby_module_name}.respond_to?(name)
217
- excel_value = #{ruby_module_name}.send(name)
217
+ ruby_value_from_excel_value(#{ruby_module_name}.send(name))
218
+ end
219
+
220
+ def ruby_value_from_excel_value(excel_value)
218
221
  case excel_value[:type]
219
222
  when :ExcelNumber; excel_value[:number]
220
223
  when :ExcelString; excel_value[:string].read_string.force_encoding("utf-8")
@@ -228,7 +231,7 @@ class #{ruby_module_name}Shim
228
231
  a = Array.new(r) { Array.new(c) }
229
232
  (0...r).each do |row|
230
233
  (0...c).each do |column|
231
- a[row][column] = ruby_from_excel_value(#{ruby_module_name}::ExcelValue.new(p + (((row*c)+column)*s)))
234
+ a[row][column] = ruby_value_from_excel_value(#{ruby_module_name}::ExcelValue.new(p + (((row*c)+column)*s)))
232
235
  end
233
236
  end
234
237
  return a
@@ -143,6 +143,11 @@ class ExcelToX
143
143
  extract_data_from_worksheets
144
144
  merge_table_files
145
145
 
146
+ # This turns named references that are specified as getters and setters
147
+ # into a series of required cell references
148
+ transfer_named_references_to_keep_into_cells_to_keep
149
+ transfer_named_references_that_can_be_set_at_runtime_into_cells_that_can_be_set_at_runtime
150
+
146
151
  # These perform some translations to simplify the excel
147
152
  # Including:
148
153
  # * Turning row and column references (e.g., A:A) to areas, based on the size of the worksheet
@@ -157,9 +162,6 @@ class ExcelToX
157
162
  # that are in the excel.
158
163
  simplify_worksheets # Replacing shared strings and named references with their actual values, tidying arithmetic
159
164
 
160
- transfer_named_references_to_keep_into_cells_to_keep
161
- transfer_named_references_that_can_be_set_at_runtime_into_cells_that_can_be_set_at_runtime
162
-
163
165
  # In case this hasn't been set by the user
164
166
  if cells_that_can_be_set_at_runtime.empty?
165
167
  log.info "Creating a good set of cells that should be settable"
Binary file
@@ -5,6 +5,9 @@
5
5
  #include <ctype.h>
6
6
  #include <math.h>
7
7
 
8
+ // To run the tests at the end of this file
9
+ // cc excel_to_c_runtime; ./a.out
10
+
8
11
  // FIXME: Extract a header file
9
12
 
10
13
  // I predefine an array of ExcelValues to store calculations
@@ -469,8 +472,6 @@ static ExcelValue not_equal(ExcelValue a_v, ExcelValue b_v) {
469
472
 
470
473
  static ExcelValue excel_if(ExcelValue condition, ExcelValue true_case, ExcelValue false_case ) {
471
474
  CHECK_FOR_PASSED_ERROR(condition)
472
- CHECK_FOR_PASSED_ERROR(true_case)
473
- CHECK_FOR_PASSED_ERROR(false_case)
474
475
 
475
476
  switch (condition.type) {
476
477
  case ExcelBoolean:
@@ -1586,6 +1587,8 @@ int test_functions() {
1586
1587
  assert(excel_if(FALSE,new_excel_number(10),new_excel_number(20)).type == ExcelNumber);
1587
1588
  assert(excel_if(FALSE,new_excel_number(10),new_excel_number(20)).number == 20);
1588
1589
  assert(excel_if(NA,new_excel_number(10),new_excel_number(20)).type == ExcelError);
1590
+ assert(excel_if(TRUE,new_excel_number(10),NA).type == ExcelNumber);
1591
+ assert(excel_if(TRUE,new_excel_number(10),NA).number == 10);
1589
1592
 
1590
1593
  // Test excel_match
1591
1594
  ExcelValue excel_match_array_1[] = { new_excel_number(10), new_excel_number(100) };
@@ -11,9 +11,20 @@ class MapFormulaeToValues
11
11
  def initialize
12
12
  @value_for_ast = MapValuesToRuby.new
13
13
  @calculator = FormulaeCalculator.new
14
+ @cache = {}
14
15
  end
15
-
16
+
17
+ def reset
18
+ @cache = {}
19
+ end
20
+
21
+ # FIXME: Caching works in the odd edge cases of long formula
22
+ # but I really need to find the root cause of the problem
16
23
  def map(ast)
24
+ @cache[ast] ||= do_map(ast)
25
+ end
26
+
27
+ def do_map(ast)
17
28
  return ast unless ast.is_a?(Array)
18
29
  operator = ast[0]
19
30
  if respond_to?(operator)
@@ -12,6 +12,7 @@ class ReplaceFormulaeWithCalculatedValues
12
12
  begin
13
13
  ref, ast = line.split("\t")
14
14
  output.puts "#{ref}\t#{rewriter.map(eval(ast)).inspect}"
15
+ rewriter.reset
15
16
  rescue Exception => e
16
17
  puts "Exception at line #{line}"
17
18
  raise
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel_to_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Counsell, Green on Black Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-19 00:00:00.000000000 Z
11
+ date: 2013-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypeg
@@ -76,13 +76,15 @@ description: "# excel_to_code\n\nConverts some excel spreadsheets (.xlsx, not .x
76
76
  worksheet> --prune-except <name of output worksheet> <excel file name> \n\t\nthis
77
77
  should work:\n\n\t./bin/excel_to_c --help\n\n# Testing excel_to_code\n\n1. Make
78
78
  sure you have ruby 1.9.2 or later installed\n2. gem install bundler # May need to
79
- use sudo\n3. bundle\n4. rspec spec/*\n\n# Hacking excel_to_code\n\nThere are some
80
- how to guides in the doc folder. \n\n# Limitations\n\n1. Not tested at all on Windows\n2.
79
+ use sudo\n3. bundle\n4. rspec spec/*\n\nTo test the C runtime:\n1. cd src/compile/c\n2.
80
+ cc excel_to_c_runtime\n3. ./a.out\n\n# Hacking excel_to_code\n\nThere are some how
81
+ to guides in the doc folder. \n\n# Limitations\n\n1. Not tested at all on Windows\n2.
81
82
  INDIRECT formula must be convertable at runtime into a standard formula\n3. Doesn't
82
83
  implement all functions (see doc/Which_functions_are_implemented.md)\n4. Doesn't
83
- implement references that involve range unions and lists\n5. Sometimes gives cells
84
- as being empty, when excel would give the cell as having a numeric value of zero\n6.
85
- The generated C version does not multithread and will give bad results if you try\n"
84
+ implement references that involve range unions and lists (but does implement standard
85
+ ranges)\n5. Sometimes gives cells as being empty, when excel would give the cell
86
+ as having a numeric value of zero\n6. The generated C version does not multithread
87
+ and will give bad results if you try\n"
86
88
  email: tamc@greenonblack.com
87
89
  executables:
88
90
  - excel_to_c
@@ -96,6 +98,7 @@ files:
96
98
  - src/commands/excel_to_ruby.rb
97
99
  - src/commands/excel_to_x.rb
98
100
  - src/commands.rb
101
+ - src/compile/c/a.out
99
102
  - src/compile/c/compile_named_reference_setters.rb
100
103
  - src/compile/c/compile_to_c.rb
101
104
  - src/compile/c/compile_to_c_header.rb