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

Revision 22686, 1.8 kB (checked in by fujidig, 6 years ago)

run-in-shell で任意のパスのJavaScriptコマンドが使えるように

  • Property svn:executable set to *
Line 
1#!/usr/bin/env ruby1.9
2require 'optparse'
3
4use_repl = false
5package_path = nil
6show_sequence = false
7js_type = 'spider-monkey'
8js = nil
9
10opt = OptionParser.new
11opt.on('--repl') {|v| use_repl = v}
12opt.on('--package=PATH') {|v| package_path = v }
13opt.on('--[no-]show-sequence') {|v| show_sequence = v }
14opt.on('--js=COMMAND') {|v| js = v }
15opt.on('--v8') {|v| js ||= js_type = 'v8' }
16opt.on('--rhino') {|v| js ||= js_type = 'rhino' }
17
18opt.parse!(ARGV)
19js ||= 'js'
20
21message = IO.popen('hspcmp -d t.hsp'){|io|io.read}
22if $?.exitstatus != 0
23  puts message.encode(Encoding.default_external, 'cp932')
24  exit 1
25end
26
27dump = open('t.ax','rb') do |f|
28  f.each_byte.each_slice(16).map do |i|
29    "'%s'" % i.map{|j| '\x%02x'%j }.join
30  end.join(",\n")
31end
32
33open('t.ax.js', 'wb') do |f|
34  f.puts "var axbinary = [\n#{dump}\n].join('');"
35  f.puts "var showSequence = #{show_sequence};"
36end
37
38if package_path
39  filenames = [package_path]
40else
41  filenames = %w[
42    binary-parser.js
43    cp932.js
44    utils.js
45    vcrandom.js
46    formatter.js
47    exception.js
48    axdata.js
49    instruction.js
50    user-def-func.js
51    builtin-func-names.js
52    builtin-funcs.js
53    vartype.js
54    value.js
55    label.js
56    str-value.js
57    double-value.js
58    int-value.js
59    struct-value.js
60    jump-type.js
61    str-buffer.js
62    hsp-array.js
63    reference.js
64    label-array.js
65    str-array.js
66    double-array.js
67    int-array.js
68    struct-array.js
69    variable.js
70    variable-agent.js
71    compiler.js
72    evaluator.js
73  ]
74end
75
76filenames << 't.ax.js' << 'run-in-shell.js'
77
78if use_repl and js_type != 'v8'
79  filenames << '-'
80end
81
82case js_type
83when 'rhino'
84  system(js, *filenames.map{|i|["-f", i]}.flatten)
85when 'v8'
86  system(js, *(use_repl ? ['--shell'] : []), *filenames)
87else
88  system(js, '-s', '-w', *filenames.map{|i|["-f", i]}.flatten)
89end
90
Note: See TracBrowser for help on using the browser.