summaryrefslogtreecommitdiff
path: root/tool/compile_prelude.rb
blob: cdf6861794d9914f8fb079f563ecbcac52764d38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

prelude, outfile = *ARGV
lines = []

lines = File.readlines(prelude).map{|line|
  line.dump
}

open(outfile, 'w'){|f|
f.puts <<EOS__

#include "ruby/ruby.h"
#include "vm_core.h"

static const char *prelude_code = 
#{lines.join("\n")}
;
void
Init_prelude(void)
{
  rb_iseq_eval(rb_iseq_compile(
    rb_str_new2(prelude_code),
    rb_str_new2("#{File.basename(prelude)}"), INT2FIX(1)));

#if 0
    printf("%s\n", prelude_code);
#endif
}
EOS__
}