mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Fix prelude to use IBF
Since universal-parser and prism support, prelude code used functions inaccessible from outside libruby shared library. ``` linking goruby /usr/bin/ld: goruby.o: in function `prelude_eval': /home/runner/work/ruby/ruby/build/golf_prelude.c:221: undefined reference to `rb_ruby_prism_ptr' /usr/bin/ld: goruby.o: in function `pm_prelude_load': /home/runner/work/ruby/ruby/build/golf_prelude.c:192: undefined reference to `pm_options_line_set' /usr/bin/ld: /home/runner/work/ruby/ruby/build/golf_prelude.c:193: undefined reference to `pm_parse_string' /usr/bin/ld: goruby.o: in function `prelude_eval': /home/runner/work/ruby/ruby/build/golf_prelude.c:224: undefined reference to `pm_iseq_new_with_opt' /usr/bin/ld: /home/runner/work/ruby/ruby/build/golf_prelude.c:226: undefined reference to `pm_parse_result_free' /usr/bin/ld: goruby.o: in function `prelude_ast_value': /home/runner/work/ruby/ruby/build/golf_prelude.c:181: undefined reference to `rb_ruby_ast_data_get' /usr/bin/ld: goruby.o: in function `prelude_eval': /home/runner/work/ruby/ruby/build/golf_prelude.c:231: undefined reference to `rb_ruby_ast_data_get' /usr/bin/ld: goruby.o: in function `pm_prelude_load': /home/runner/work/ruby/ruby/build/golf_prelude.c:196: undefined reference to `pm_parse_result_free' collect2: error: ld returned 1 exit status ```
This commit is contained in:
parent
70871fa6e3
commit
ecb58a8d08
6 changed files with 61 additions and 80 deletions
|
@ -252,7 +252,6 @@ INSTALLED_LIST= .installed.list
|
|||
|
||||
NEWLINE_C = enc/trans/newline.c
|
||||
MINIPRELUDE_C = miniprelude.c
|
||||
GOLF_PRELUDE_C= golf_prelude.c
|
||||
RBCONFIG = .rbconfig.time
|
||||
|
||||
MAINSRC = $(MAINOBJ:.$(OBJEXT)=.c)
|
||||
|
|
|
@ -21,16 +21,11 @@ class Prelude
|
|||
def initialize(output, preludes, vpath)
|
||||
@output = output
|
||||
@vpath = vpath
|
||||
@prelude_count = 0
|
||||
@builtin_count = 0
|
||||
@preludes = {}
|
||||
@mains = preludes.map do |filename|
|
||||
if prelude = filename.end_with?("golf_prelude.rb")
|
||||
@prelude_count += 1
|
||||
else
|
||||
@builtin_count += 1
|
||||
end
|
||||
translate(filename, (filename unless prelude))[0]
|
||||
@builtin_count += 1
|
||||
translate(filename, filename)[0]
|
||||
end
|
||||
@preludes.delete_if {|_, (_, _, lines, sub)| sub && lines.empty?}
|
||||
end
|
||||
|
@ -137,7 +132,6 @@ static const struct {
|
|||
|
||||
COMPILER_WARNING_POP
|
||||
|
||||
% unless preludes.empty?
|
||||
#define PRELUDE_NAME(n) rb_usascii_str_new_static(prelude_name##n, sizeof(prelude_name##n)-1)
|
||||
#define PRELUDE_CODE(n) rb_utf8_str_new_static(prelude_code##n.L0, sizeof(prelude_code##n))
|
||||
|
||||
|
@ -166,64 +160,10 @@ rb_builtin_find(const char *feature_name, VALUE *name_str, int *start_line)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
% end
|
||||
% if @prelude_count > 0
|
||||
COMPILER_WARNING_PUSH
|
||||
#if GCC_VERSION_SINCE(4, 2, 0)
|
||||
COMPILER_WARNING_ERROR(-Wmissing-field-initializers)
|
||||
#endif
|
||||
static void
|
||||
prelude_eval(VALUE code, VALUE name, int line)
|
||||
{
|
||||
static const rb_compile_option_t optimization = {
|
||||
TRUE, /* unsigned int inline_const_cache; */
|
||||
TRUE, /* unsigned int peephole_optimization; */
|
||||
FALSE,/* unsigned int tailcall_optimization; */
|
||||
TRUE, /* unsigned int specialized_instruction; */
|
||||
TRUE, /* unsigned int operands_unification; */
|
||||
TRUE, /* unsigned int instructions_unification; */
|
||||
TRUE, /* unsigned int frozen_string_literal; */
|
||||
FALSE, /* unsigned int debug_frozen_string_literal; */
|
||||
FALSE, /* unsigned int coverage_enabled; */
|
||||
0, /* int debug_level; */
|
||||
};
|
||||
|
||||
if (*rb_ruby_prism_ptr()) {
|
||||
pm_parse_result_t result = { 0 };
|
||||
pm_prelude_load(&result, name, code, line);
|
||||
rb_iseq_eval(pm_iseq_new_with_opt(&result.node, name, name, Qnil, line,
|
||||
NULL, 0, ISEQ_TYPE_TOP, &optimization));
|
||||
pm_parse_result_free(&result);
|
||||
}
|
||||
else {
|
||||
rb_ast_t *ast;
|
||||
VALUE ast_value = prelude_ast_value(name, code, line);
|
||||
ast = rb_ruby_ast_data_get(ast_value);
|
||||
rb_iseq_eval(rb_iseq_new_with_opt(ast_value, name, name, Qnil, line,
|
||||
NULL, 0, ISEQ_TYPE_TOP, &optimization,
|
||||
Qnil));
|
||||
rb_ast_dispose(ast);
|
||||
}
|
||||
}
|
||||
COMPILER_WARNING_POP
|
||||
|
||||
% end
|
||||
%end
|
||||
% init_name = @output && @output[/\w+(?=_prelude.c\b)/] || 'prelude'
|
||||
void
|
||||
Init_<%=init_name%><%=%>(void)
|
||||
{
|
||||
%unless @prelude_count.zero?
|
||||
% preludes.each do |i, prelude, lines, sub, start_line|
|
||||
% next if sub
|
||||
prelude_eval(PRELUDE_CODE(<%=i%><%=%>), PRELUDE_NAME(<%=i%><%=%>), <%=start_line%><%=%>);
|
||||
% end
|
||||
|
||||
#if 0
|
||||
% preludes.length.times {|i|
|
||||
printf("%.*s", (int)sizeof(prelude_code<%=i%><%=%>), prelude_code<%=i%><%=%>.L0);
|
||||
% }
|
||||
#endif
|
||||
%end
|
||||
}
|
||||
<%end -%>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue