-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Implement the options generator.
1 parent
0617393
commit adddfdb
Showing
5 changed files
with
136 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. | ||
# This code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
# redistribute it and/or modify it under the terms of the: | ||
# | ||
# Eclipse Public License version 1.0 | ||
# GNU General Public License version 2 | ||
# GNU Lesser General Public License version 2.1 | ||
|
||
require 'ostruct' | ||
require 'yaml' | ||
require 'erb' | ||
|
||
options = YAML.load_file('truffle/src/main/java/org/jruby/truffle/options/options.yml') | ||
|
||
options = options.map do |constant, (name, type, default, description)| | ||
case type | ||
when 'boolean' | ||
type = 'boolean' | ||
type_cons = 'BooleanOptionDescription' | ||
default = default.to_s | ||
when 'string-array' | ||
type = 'String[]' | ||
type_cons = 'StringArrayOptionDescription' | ||
default = "new String[]{#{default.map(&:inspect).join(', ')}}" | ||
else | ||
raise type | ||
end | ||
|
||
OpenStruct.new( | ||
:constant => constant, | ||
:name => name, | ||
:type => type, | ||
:default => default, | ||
:description => description, | ||
:type_cons => type_cons | ||
) | ||
end | ||
|
||
File.write('truffle/src/main/java/org/jruby/truffle/options/NewOptions.java', ERB.new(%{/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
// This file is automatically generated by options.yml with 'jt build options' | ||
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; | ||
import javax.annotation.Generated; | ||
@Generated("tool/truffle/generate-options.rb") | ||
public class NewOptions { | ||
<% options.each do |o| %> | ||
<% if o.type.end_with?('[]') %>@CompilationFinal(dimensions=1) <% end %>public final <%= o.type %> <%= o.constant %>; | ||
<% end %> | ||
NewOptions(OptionsBuilder builder) { | ||
<% options.each do |o| %> | ||
<%= o.constant %> = builder.getOrDefault(OptionsCatalog.<%= o.constant %>); | ||
<% end %> | ||
} | ||
} | ||
}).result) | ||
|
||
File.write('truffle/src/main/java/org/jruby/truffle/options/OptionsCatalog.java', ERB.new(%{/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
// This file is automatically generated by options.yml with 'jt build options' | ||
import javax.annotation.Generated; | ||
@Generated("tool/truffle/generate-options.rb") | ||
public class OptionsCatalog { | ||
<% options.each do |o| %> | ||
public static final OptionDescription <%= o.constant %> = new <%= o.type_cons %>("<%= o.name %>", "<%= o.description %>", <%= o.default %>); | ||
<% end %> | ||
public static OptionDescription fromName(String name) { | ||
switch (name) { | ||
<% options.each do |o| %> | ||
case "<%= o.name %>": | ||
return <%= o.constant %>; | ||
<% end %> | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
}).result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ARGUMENTS: [arguments, string-array, [], Foo bar baz] | ||
EXCEPTIONS_PRINT_JAVA: [exceptions.print_java, boolean, false, Foo bar baz] | ||
ARGUMENTS: [arguments, string-array, [], Command line arguments for the Ruby program] | ||
EXCEPTIONS_PRINT_JAVA: [exceptions.print_java, boolean, false, Print Java exceptions at the point of translating them to Ruby exceptions] |