root/lang/javascript/hsp-on-js/trunk/src/run-in-shell @ 20224

Revision 20224, 1.3 kB (checked in by fujidig, 6 years ago)

文字列型変数をメモリ操作命令に対応。
HSPの文字列型変数の動作をエミュレートするように(代入しても内容と0の後ろに元の内容が残っているなど)

  • Property svn:executable set to *
Line 
1#!/usr/bin/env ruby1.9
2message = IO.popen('hspcmp -d t.hsp'){|io|io.read}
3if $?.exitstatus != 0
4  puts message.encode(Encoding.default_external, 'cp932')
5  exit 1
6end
7
8dump = open('t.ax','rb'){|f|f.each_byte.each_slice(16).map{|i|"'%s'"%i.map{|j|'\x%02x'%j}.join}.join(",\n")}
9a = open('run-in-shell.js','rb'){|f|f.read}
10replaced = false
11a = a.gsub(/^([ \t]*var data = \[\n).*?^([ \t]*\])/m) {replaced = true;"#{$1}#{dump}\n#{$2}"}
12warn 'not replaced' unless replaced
13open('run-in-shell.js', 'wb'){|f| f.write a}
14
15filenames = %w[
16binary-parser.js
17cp932.js
18utils.js
19vcrandom.js
20exception.js
21axdata.js
22instruction.js
23builtin-func-names.js
24builtin-funcs.js
25vartype.js
26value.js
27label.js
28str-value.js
29double-value.js
30int-value.js
31jump-type.js
32hsp-array.js
33label-array.js
34str-array.js
35double-array.js
36int-array.js
37variable.js
38variable-agent.js
39compiler.js
40evaluator.js
41run-in-shell.js
42]
43
44if ARGV.delete('--for-win32-rhino')
45  open('for-win32-rhino.js','wb:cp932') do |out|
46    filenames.each do |filename|
47      open(filename, 'rb:utf-8') {|f| out.puts f.read }
48    end
49  end
50  system('rhino -w -f for-win32-rhino.js')
51  exit
52end
53
54if ARGV.delete('--shell')
55  filenames << '-'
56end
57
58if ARGV.delete('--rhino')
59  system(*%w[rhino -w]+filenames.map{|i|["-f", i]}.flatten)
60else
61  system(*%w[js -s -w]+filenames.map{|i|["-f", i]}.flatten)
62end
63
Note: See TracBrowser for help on using the browser.