mirror of https://github.com/tildeio/helix
Allow arbitrary attributes for methods
This commit is contained in:
parent
358f12ae18
commit
a8e1f37362
|
@ -4,7 +4,7 @@ cache:
|
|||
|
||||
environment:
|
||||
# can't run game_of_life since termion doesn't support windows https://github.com/redox-os/termion/issues/103
|
||||
EXAMPLES: duration calculator console geometry membership text_transform turbo_blank json_builder
|
||||
EXAMPLES: unit calculator console duration docopt geometry json_builder membership text_transform turbo_blank
|
||||
VERBOSE: true
|
||||
RUST_BACKTRACE: 1
|
||||
matrix:
|
||||
|
|
|
@ -21,7 +21,7 @@ cache:
|
|||
|
||||
env:
|
||||
global:
|
||||
- EXAMPLES="duration calculator console game_of_life geometry membership text_transform turbo_blank json_builder"
|
||||
- EXAMPLES="unit calculator console duration docopt game_of_life geometry json_builder membership text_transform turbo_blank"
|
||||
- VERBOSE=true
|
||||
- RUST_BACKTRACE=1
|
||||
- RUST_VERSION=stable
|
||||
|
|
|
@ -20,7 +20,7 @@ travis-ci = { repository = "tildeio/helix", branch = "master" }
|
|||
appveyor = { repository = "tildeio/helix", branch = "master", service = "github" }
|
||||
|
||||
[workspace]
|
||||
members = ["examples/calculator", "examples/console", "examples/docopt", "examples/game_of_life", "examples/geometry", "examples/duration", "examples/membership", "examples/text_transform", "examples/turbo_blank", "examples/json_builder"]
|
||||
members = ["examples/calculator", "examples/console", "examples/docopt", "examples/duration", "examples/game_of_life", "examples/geometry", "examples/json_builder", "examples/membership", "examples/text_transform", "examples/turbo_blank", "examples/unit"]
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.0"
|
||||
|
|
4
Rakefile
4
Rakefile
|
@ -4,7 +4,7 @@ task :test do
|
|||
sh "bundle exec rake"
|
||||
end
|
||||
|
||||
examples = ENV["EXAMPLES"] || "duration calculator console docopt game_of_life geometry membership text_transform turbo_blank json_builder"
|
||||
examples = ENV["EXAMPLES"] || "unit calculator console docopt duration game_of_life geometry json_builder membership text_transform turbo_blank"
|
||||
|
||||
sh "bash ./examples/runner default #{examples}"
|
||||
end
|
||||
|
@ -15,7 +15,7 @@ task :install do
|
|||
sh "bundle"
|
||||
end
|
||||
|
||||
examples = ENV["EXAMPLES"] || "duration calculator console docopt game_of_life geometry membership text_transform turbo_blank json_builder"
|
||||
examples = ENV["EXAMPLES"] || "unit calculator console docopt duration game_of_life geometry json_builder membership text_transform turbo_blank"
|
||||
|
||||
sh "bash ./examples/runner install #{examples}"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
target
|
||||
tmp
|
||||
*.bundle
|
||||
*.so
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "unit"
|
||||
version = "0.1.0"
|
||||
authors = ["Godfrey Chan <godfrey@tilde.io>"]
|
||||
|
||||
[lib]
|
||||
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies.helix]
|
||||
path = "../.."
|
|
@ -0,0 +1,4 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem 'helix_runtime', path: '../../ruby'
|
||||
gem 'rake', '~> 10.0'
|
|
@ -0,0 +1,14 @@
|
|||
require 'bundler/setup'
|
||||
require 'helix_runtime/build_task'
|
||||
require_relative '../shared.rb'
|
||||
|
||||
# For Windows
|
||||
$stdout.sync = true
|
||||
|
||||
HelixRuntime::BuildTask.new do |t|
|
||||
t.build_root = File.expand_path("../..", __dir__)
|
||||
t.helix_lib_dir = File.expand_path("../../ruby/windows_build", __dir__)
|
||||
t.pre_build = HelixRuntime::Tests.pre_build
|
||||
end
|
||||
|
||||
task :default => :build
|
|
@ -0,0 +1,7 @@
|
|||
require "helix_runtime"
|
||||
|
||||
begin
|
||||
require "unit/native"
|
||||
rescue LoadError
|
||||
warn "Unable to load unit/native. Please run `rake build`"
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
#[macro_use]
|
||||
extern crate helix;
|
||||
|
||||
ruby! {
|
||||
class Attributes {
|
||||
#[doc(hidden)]
|
||||
#[ruby_name="foo"]
|
||||
#[inline]
|
||||
#[cfg(not(foo="bar"))]
|
||||
def bar() {
|
||||
println!("Hello from bar!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -166,6 +166,7 @@ macro_rules! codegen_method {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: { $($attributes:tt)* },
|
||||
self: {
|
||||
ownership: {},
|
||||
name: $self:tt
|
||||
|
@ -175,6 +176,7 @@ macro_rules! codegen_method {
|
|||
body: $body:block
|
||||
}
|
||||
} => {
|
||||
$($attributes)*
|
||||
pub fn $rust_name($self : $crate::Metadata, $($arg : $argty),*) -> $($ret)* $body
|
||||
};
|
||||
|
||||
|
@ -184,12 +186,14 @@ macro_rules! codegen_method {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: { $($attributes:tt)* },
|
||||
self: (),
|
||||
args: [ $($args:tt)* ],
|
||||
ret: { $($ret:tt)* },
|
||||
body: $body:block
|
||||
}
|
||||
} => {
|
||||
$($attributes)*
|
||||
pub fn $rust_name($($args)*) -> $($ret)* $body
|
||||
};
|
||||
|
||||
|
@ -199,6 +203,7 @@ macro_rules! codegen_method {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: { $($attributes:tt)* },
|
||||
self: {
|
||||
ownership: { $($ownership:tt)* },
|
||||
name: $self:tt
|
||||
|
@ -208,6 +213,7 @@ macro_rules! codegen_method {
|
|||
body: $body:block
|
||||
}
|
||||
} => {
|
||||
$($attributes)*
|
||||
pub fn $rust_name($($ownership)* $self, $($args)*) -> $($ret)* $body
|
||||
};
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ macro_rules! codegen_define_method {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: { $($ruby_name:tt)* },
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
self: (),
|
||||
args: [ $($arg:tt : $argty:ty),* ],
|
||||
ret: { $($ret:tt)* },
|
||||
|
@ -143,6 +144,7 @@ macro_rules! codegen_define_method {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: { $($ruby_name:tt)* },
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
self: { ownership: { $($ownership:tt)* }, name: $self:tt },
|
||||
args: [ $($arg:tt : $argty:ty),* ],
|
||||
ret: { $($ret:tt)* },
|
||||
|
@ -200,6 +202,7 @@ macro_rules! codegen_define_method {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: unexported,
|
||||
attributes: $attributes:tt,
|
||||
self: $self:tt,
|
||||
args: [ $($arg:tt : $argty:ty),* ],
|
||||
ret: { $($ret:tt)* },
|
||||
|
@ -226,6 +229,7 @@ macro_rules! codegen_define_method {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: { $($ruby_name:tt)* },
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
self: { ownership: {}, name: $self:tt },
|
||||
args: [ $($arg:tt : $argty:ty),* ],
|
||||
ret: { $($ret:tt)* },
|
||||
|
|
|
@ -295,6 +295,7 @@ macro_rules! parse {
|
|||
rust_name: uninitialized,
|
||||
ruby_name: uninitialized,
|
||||
ruby_visibility: public,
|
||||
attributes: {},
|
||||
$($stack)*
|
||||
}
|
||||
}
|
||||
|
@ -302,6 +303,26 @@ macro_rules! parse {
|
|||
|
||||
// STATE: parse_method_attributes
|
||||
|
||||
{
|
||||
state: parse_method_attributes,
|
||||
buffer: { #[ruby_name = $ruby_name:tt] $($rest:tt)* },
|
||||
stack: {
|
||||
rust_name: uninitialized,
|
||||
ruby_name: uninitialized,
|
||||
$($stack:tt)*
|
||||
}
|
||||
} => {
|
||||
parse! {
|
||||
state: parse_method_attributes,
|
||||
buffer: { $($rest)* },
|
||||
stack: {
|
||||
rust_name: uninitialized,
|
||||
ruby_name: { $ruby_name },
|
||||
$($stack)*
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
state: parse_method_attributes,
|
||||
buffer: { #[ruby_visibility = $ruby_visibility:tt] $($rest:tt)* },
|
||||
|
@ -326,10 +347,12 @@ macro_rules! parse {
|
|||
|
||||
{
|
||||
state: parse_method_attributes,
|
||||
buffer: { #[ruby_name = $ruby_name:tt] $($rest:tt)* },
|
||||
buffer: { #[$($attribute:tt)*] $($rest:tt)* },
|
||||
stack: {
|
||||
rust_name: uninitialized,
|
||||
ruby_name: uninitialized,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: { $($attributes:tt)* },
|
||||
$($stack:tt)*
|
||||
}
|
||||
} => {
|
||||
|
@ -338,7 +361,9 @@ macro_rules! parse {
|
|||
buffer: { $($rest)* },
|
||||
stack: {
|
||||
rust_name: uninitialized,
|
||||
ruby_name: { $ruby_name },
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: { $($attributes)* #[$($attribute)*] },
|
||||
$($stack)*
|
||||
}
|
||||
}
|
||||
|
@ -407,6 +432,7 @@ macro_rules! parse {
|
|||
rust_name: initialize,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class: $class:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -419,6 +445,7 @@ macro_rules! parse {
|
|||
buffer: { $($args)* },
|
||||
stack: {
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
class_body: { $($rest)* },
|
||||
class: $class,
|
||||
$($stack)*
|
||||
|
@ -433,6 +460,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
} => {
|
||||
|
@ -443,6 +471,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
class_body: { $($rest)* },
|
||||
$($stack)*
|
||||
}
|
||||
|
@ -456,6 +485,7 @@ macro_rules! parse {
|
|||
buffer: { $helix_arg:tt, $($args:tt)+ },
|
||||
stack: {
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class_body: $class_body:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -471,6 +501,7 @@ macro_rules! parse {
|
|||
rust_name: initialize,
|
||||
ruby_name: { "initialize" },
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: {
|
||||
ownership: { },
|
||||
name: $helix_arg
|
||||
|
@ -489,6 +520,7 @@ macro_rules! parse {
|
|||
buffer: { $helix_arg:tt },
|
||||
stack: {
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class_body: $class_body:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -504,6 +536,7 @@ macro_rules! parse {
|
|||
rust_name: initialize,
|
||||
ruby_name: { "initialize" },
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: {
|
||||
ownership: { },
|
||||
name: $helix_arg
|
||||
|
@ -526,6 +559,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class_body: $class_body:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -541,6 +575,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: {
|
||||
ownership: { &mut },
|
||||
name: $self_arg
|
||||
|
@ -561,6 +596,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class_body: $class_body:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -576,6 +612,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: {
|
||||
ownership: { &mut },
|
||||
name: $self_arg
|
||||
|
@ -596,6 +633,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class_body: $class_body:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -611,6 +649,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: {
|
||||
ownership: { & },
|
||||
name: $self_arg
|
||||
|
@ -631,6 +670,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class_body: $class_body:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -646,6 +686,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: {
|
||||
ownership: { & },
|
||||
name: $self_arg
|
||||
|
@ -666,6 +707,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class_body: $class_body:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -681,6 +723,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: {
|
||||
ownership: { },
|
||||
name: $self_arg
|
||||
|
@ -701,6 +744,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class_body: $class_body:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -716,6 +760,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: {
|
||||
ownership: { },
|
||||
name: $self_arg
|
||||
|
@ -736,6 +781,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
class_body: $class_body:tt,
|
||||
$($stack:tt)*
|
||||
}
|
||||
|
@ -749,6 +795,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: (),
|
||||
args: [ $($args)* ],
|
||||
ret: uninitialized,
|
||||
|
@ -770,6 +817,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
self: $self:tt,
|
||||
args: $args:tt,
|
||||
ret: uninitialized,
|
||||
|
@ -789,6 +837,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: $self,
|
||||
args: $args,
|
||||
ret: { $ret },
|
||||
|
@ -808,6 +857,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_method_name:tt,
|
||||
ruby_name: $ruby_method_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
self: $self:tt,
|
||||
args: $args:tt,
|
||||
ret: uninitialized,
|
||||
|
@ -833,6 +883,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_method_name,
|
||||
ruby_name: $ruby_method_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: $self,
|
||||
args: $args,
|
||||
ret: { $rust_class_name },
|
||||
|
@ -860,6 +911,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
self: $self:tt,
|
||||
args: $args:tt,
|
||||
ret: uninitialized,
|
||||
|
@ -877,6 +929,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
self: $self,
|
||||
args: $args,
|
||||
ret: { () },
|
||||
|
|
Loading…
Reference in New Issue