rubex 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -2
- data/.travis.yml +9 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +4 -1
- data/Rakefile +2 -2
- data/bin/rubex +4 -5
- data/lib/rubex.rb +4 -4
- data/lib/rubex/ast.rb +4 -1
- data/lib/rubex/ast/expression.rb +22 -1191
- data/lib/rubex/ast/expression/actual_arg_list.rb +40 -0
- data/lib/rubex/ast/expression/analysed_element_ref.rb +26 -0
- data/lib/rubex/ast/expression/analysed_element_ref/c_var_element_ref.rb +30 -0
- data/lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb +42 -0
- data/lib/rubex/ast/expression/arg_declaration.rb +43 -0
- data/lib/rubex/ast/expression/binary.rb +57 -0
- data/lib/rubex/ast/expression/binary/binary_boolean.rb +23 -0
- data/lib/rubex/ast/expression/binary/binary_boolean_special_op.rb +20 -0
- data/lib/rubex/ast/expression/binary/empty_classes.rb +62 -0
- data/lib/rubex/ast/expression/block_given.rb +15 -0
- data/lib/rubex/ast/expression/coerce_object.rb +15 -0
- data/lib/rubex/ast/expression/command_call.rb +74 -0
- data/lib/rubex/ast/expression/command_call/struct_or_union_member_call.rb +38 -0
- data/lib/rubex/ast/expression/element_ref.rb +64 -0
- data/lib/rubex/ast/expression/empty.rb +13 -0
- data/lib/rubex/ast/expression/from_ruby_object.rb +20 -0
- data/lib/rubex/ast/expression/func_ptr_arg_declaration.rb +21 -0
- data/lib/rubex/ast/expression/func_ptr_internal_arg_declaration.rb +13 -0
- data/lib/rubex/ast/expression/literal.rb +30 -0
- data/lib/rubex/ast/expression/literal/array_lit.rb +51 -0
- data/lib/rubex/ast/expression/literal/c_null.rb +15 -0
- data/lib/rubex/ast/expression/literal/char.rb +36 -0
- data/lib/rubex/ast/expression/literal/double.rb +14 -0
- data/lib/rubex/ast/expression/literal/false.rb +33 -0
- data/lib/rubex/ast/expression/literal/hash_lit.rb +45 -0
- data/lib/rubex/ast/expression/literal/int.rb +14 -0
- data/lib/rubex/ast/expression/literal/nil.rb +14 -0
- data/lib/rubex/ast/expression/literal/ruby_symbol.rb +22 -0
- data/lib/rubex/ast/expression/literal/string_lit.rb +45 -0
- data/lib/rubex/ast/expression/literal/true.rb +29 -0
- data/lib/rubex/ast/expression/method_call.rb +52 -0
- data/lib/rubex/ast/expression/method_call/c_function_call.rb +40 -0
- data/lib/rubex/ast/expression/method_call/ruby_method_call.rb +83 -0
- data/lib/rubex/ast/expression/name.rb +127 -0
- data/lib/rubex/ast/expression/ruby_constant.rb +25 -0
- data/lib/rubex/ast/expression/ruby_object_element_ref/ruby_array_element_ref.rb +20 -0
- data/lib/rubex/ast/expression/ruby_object_element_ref/ruby_hash_element_ref.rb +22 -0
- data/lib/rubex/ast/expression/self.rb +15 -0
- data/lib/rubex/ast/expression/size_of.rb +22 -0
- data/lib/rubex/ast/expression/struct_or_union_member_call/element_ref_member_call.rb +23 -0
- data/lib/rubex/ast/expression/to_ruby_object.rb +21 -0
- data/lib/rubex/ast/expression/typecast.rb +20 -0
- data/lib/rubex/ast/expression/typecast_to.rb +10 -0
- data/lib/rubex/ast/expression/unary.rb +37 -0
- data/lib/rubex/ast/expression/unary_base.rb +24 -0
- data/lib/rubex/ast/expression/unary_base/ampersand.rb +16 -0
- data/lib/rubex/ast/expression/unary_base/unary_bit_not.rb +18 -0
- data/lib/rubex/ast/expression/unary_base/unary_not.rb +18 -0
- data/lib/rubex/ast/expression/unary_base/unary_sub.rb +18 -0
- data/lib/rubex/ast/node.rb +111 -111
- data/lib/rubex/ast/statement.rb +9 -1160
- data/lib/rubex/ast/statement/alias.rb +43 -0
- data/lib/rubex/ast/statement/argument_list.rb +59 -0
- data/lib/rubex/ast/statement/assign.rb +35 -0
- data/lib/rubex/ast/statement/begin_block.rb +14 -0
- data/lib/rubex/ast/statement/begin_block/begin.rb +202 -0
- data/lib/rubex/ast/statement/begin_block/else.rb +21 -0
- data/lib/rubex/ast/statement/begin_block/ensure.rb +21 -0
- data/lib/rubex/ast/statement/begin_block/rescue.rb +34 -0
- data/lib/rubex/ast/statement/break.rb +18 -0
- data/lib/rubex/ast/statement/c_array_decl.rb +49 -0
- data/lib/rubex/ast/statement/c_base_type.rb +26 -0
- data/lib/rubex/ast/statement/c_function_decl.rb +30 -0
- data/lib/rubex/ast/statement/c_ptr_decl.rb +52 -0
- data/lib/rubex/ast/statement/c_ptr_decl/c_ptr_func_decl.rb +25 -0
- data/lib/rubex/ast/statement/c_struct_or_union_def.rb +49 -0
- data/lib/rubex/ast/statement/expression.rb +26 -0
- data/lib/rubex/ast/statement/for.rb +73 -0
- data/lib/rubex/ast/statement/forward_decl.rb +31 -0
- data/lib/rubex/ast/statement/if_block.rb +64 -0
- data/lib/rubex/ast/statement/if_block/else.rb +30 -0
- data/lib/rubex/ast/statement/if_block/elsif.rb +22 -0
- data/lib/rubex/ast/statement/if_block/helper.rb +38 -0
- data/lib/rubex/ast/statement/print.rb +49 -0
- data/lib/rubex/ast/statement/raise.rb +66 -0
- data/lib/rubex/ast/statement/return.rb +45 -0
- data/lib/rubex/ast/statement/var_decl.rb +49 -0
- data/lib/rubex/ast/statement/while.rb +34 -0
- data/lib/rubex/ast/statement/yield.rb +41 -0
- data/lib/rubex/ast/top_statement.rb +1 -815
- data/lib/rubex/ast/top_statement/c_bindings.rb +145 -0
- data/lib/rubex/ast/top_statement/klass.rb +125 -0
- data/lib/rubex/ast/top_statement/klass/attached_klass.rb +417 -0
- data/lib/rubex/ast/top_statement/method_def.rb +110 -0
- data/lib/rubex/ast/top_statement/method_def/c_function_def.rb +26 -0
- data/lib/rubex/ast/top_statement/method_def/ruby_method_def.rb +33 -0
- data/lib/rubex/cli.rb +26 -0
- data/lib/rubex/code_writer.rb +1 -1
- data/lib/rubex/compiler.rb +49 -28
- data/lib/rubex/compiler_config.rb +4 -2
- data/lib/rubex/constants.rb +71 -71
- data/lib/rubex/data_type.rb +9 -675
- data/lib/rubex/data_type/c_array.rb +33 -0
- data/lib/rubex/data_type/c_function.rb +23 -0
- data/lib/rubex/data_type/c_ptr.rb +71 -0
- data/lib/rubex/data_type/c_str.rb +23 -0
- data/lib/rubex/data_type/c_struct_or_union.rb +23 -0
- data/lib/rubex/data_type/char.rb +30 -0
- data/lib/rubex/data_type/f_32.rb +38 -0
- data/lib/rubex/data_type/f_64.rb +38 -0
- data/lib/rubex/data_type/int.rb +32 -0
- data/lib/rubex/data_type/int/c_boolean.rb +13 -0
- data/lib/rubex/data_type/int_16.rb +32 -0
- data/lib/rubex/data_type/int_32.rb +32 -0
- data/lib/rubex/data_type/int_64.rb +36 -0
- data/lib/rubex/data_type/int_8.rb +33 -0
- data/lib/rubex/data_type/l_int.rb +38 -0
- data/lib/rubex/data_type/l_l_int.rb +26 -0
- data/lib/rubex/data_type/ruby_method.rb +22 -0
- data/lib/rubex/data_type/ruby_object.rb +19 -0
- data/lib/rubex/data_type/ruby_object/boolean.rb +11 -0
- data/lib/rubex/data_type/ruby_object/boolean/false_type.rb +5 -0
- data/lib/rubex/data_type/ruby_object/boolean/true_type.rb +5 -0
- data/lib/rubex/data_type/ruby_object/nil_type.rb +9 -0
- data/lib/rubex/data_type/ruby_object/ruby_array.rb +10 -0
- data/lib/rubex/data_type/ruby_object/ruby_constant.rb +18 -0
- data/lib/rubex/data_type/ruby_object/ruby_constant/ruby_class.rb +18 -0
- data/lib/rubex/data_type/ruby_object/ruby_hash.rb +9 -0
- data/lib/rubex/data_type/ruby_object/ruby_string.rb +10 -0
- data/lib/rubex/data_type/ruby_object/ruby_symbol.rb +10 -0
- data/lib/rubex/data_type/type_def.rb +34 -0
- data/lib/rubex/data_type/u_char.rb +27 -0
- data/lib/rubex/data_type/u_int.rb +32 -0
- data/lib/rubex/data_type/u_int_16.rb +22 -0
- data/lib/rubex/data_type/u_int_32.rb +22 -0
- data/lib/rubex/data_type/u_int_64.rb +26 -0
- data/lib/rubex/data_type/u_int_8.rb +22 -0
- data/lib/rubex/data_type/u_l_int.rb +36 -0
- data/lib/rubex/data_type/u_l_int/size_t.rb +10 -0
- data/lib/rubex/data_type/u_l_l_int.rb +26 -0
- data/lib/rubex/data_type/void.rb +15 -0
- data/lib/rubex/data_type_helpers/float_helpers.rb +8 -0
- data/lib/rubex/data_type_helpers/helpers.rb +48 -0
- data/lib/rubex/data_type_helpers/int_helpers.rb +10 -0
- data/lib/rubex/data_type_helpers/u_int_helpers.rb +11 -0
- data/lib/rubex/helpers.rb +35 -118
- data/lib/rubex/helpers/node_type_methods.rb +9 -0
- data/lib/rubex/helpers/writers.rb +79 -0
- data/lib/rubex/parser.racc +83 -34
- data/lib/rubex/parser.racc.rb +233 -184
- data/lib/rubex/version.rb +2 -2
- data/rubex.gemspec +2 -0
- data/spec/basic_ruby_method_spec.rb +1 -1
- data/spec/binding_ptr_args_spec.rb +2 -2
- data/spec/bitwise_operators_spec.rb +1 -1
- data/spec/blocks_spec.rb +2 -2
- data/spec/c_bindings_spec.rb +1 -1
- data/spec/c_constants_spec.rb +1 -1
- data/spec/c_function_ptrs_spec.rb +1 -1
- data/spec/c_functions_spec.rb +2 -2
- data/spec/c_struct_interface_spec.rb +1 -1
- data/spec/call_by_reference_spec.rb +2 -2
- data/spec/class_methods_spec.rb +2 -2
- data/spec/class_spec.rb +4 -4
- data/spec/cli_spec.rb +43 -0
- data/spec/comments_spec.rb +2 -2
- data/spec/default_args_spec.rb +21 -23
- data/spec/error_handling_spec.rb +1 -1
- data/spec/examples_spec.rb +4 -4
- data/spec/expressions_spec.rb +1 -1
- data/spec/fixtures/cli/cli.rubex +3 -0
- data/spec/fixtures/examples/array_to_hash.rubex +1 -1
- data/spec/fixtures/examples/rcsv.rubex +10 -6
- data/spec/fixtures/loops/loops.rubex +1 -1
- data/spec/fixtures/ruby_strings/string_blank_bm.rb +7 -5
- data/spec/fixtures/struct/struct.rubex +7 -2
- data/spec/fixtures/temp_allocation/temp_allocation.rubex +8 -0
- data/spec/if_else_spec.rb +3 -7
- data/spec/implicit_lib_include_spec.rb +1 -1
- data/spec/init_ruby_objects_with_literal_syntax_spec.rb +1 -1
- data/spec/loops_spec.rb +1 -1
- data/spec/recursion_spec.rb +18 -21
- data/spec/ruby_constant_method_calls_spec.rb +4 -4
- data/spec/ruby_operators_spec.rb +1 -1
- data/spec/ruby_raise_spec.rb +1 -1
- data/spec/ruby_strings_spec.rb +3 -3
- data/spec/ruby_symbols_spec.rb +1 -1
- data/spec/ruby_types_spec.rb +2 -2
- data/spec/spec_helper.rb +42 -10
- data/spec/statement_expression_spec.rb +3 -3
- data/spec/static_array_spec.rb +3 -3
- data/spec/string_literals_spec.rb +2 -2
- data/spec/struct_spec.rb +4 -4
- data/spec/temp_allocation_spec.rb +35 -0
- data/spec/typecasting_spec.rb +2 -2
- data/spec/var_declarions_spec.rb +2 -2
- metadata +168 -3
@@ -0,0 +1,33 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class CArray
|
4
|
+
include Helpers
|
5
|
+
# Dimension of the array
|
6
|
+
attr_reader :dimension
|
7
|
+
# Type of elements stored in array
|
8
|
+
attr_reader :type # FIXME: Make this base_type to make it more explicit.
|
9
|
+
|
10
|
+
def initialize(dimension, type)
|
11
|
+
@dimension = dimension
|
12
|
+
@type = type
|
13
|
+
end
|
14
|
+
|
15
|
+
def carray?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def <=>(other)
|
20
|
+
@type <=>
|
21
|
+
if self.class == other.class
|
22
|
+
other.type
|
23
|
+
else
|
24
|
+
other
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def base_type
|
29
|
+
@type
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class CFunction
|
4
|
+
include Helpers
|
5
|
+
attr_reader :name, :type, :c_name
|
6
|
+
attr_accessor :scope, :arg_list
|
7
|
+
|
8
|
+
# FIXME: all attributes should be initialized upon class creation to maintain
|
9
|
+
# sanity and consistency.
|
10
|
+
def initialize(name, c_name, arg_list, type, scope)
|
11
|
+
@name = name
|
12
|
+
@c_name = c_name
|
13
|
+
@arg_list = arg_list
|
14
|
+
@type = type
|
15
|
+
@scope = scope
|
16
|
+
end
|
17
|
+
|
18
|
+
def c_function?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class CPtr
|
4
|
+
include Helpers
|
5
|
+
# The data type that this pointer is pointing to.
|
6
|
+
attr_reader :type
|
7
|
+
|
8
|
+
def initialize(type)
|
9
|
+
@type = type
|
10
|
+
end
|
11
|
+
|
12
|
+
def p_formatter
|
13
|
+
'%s' if char_ptr?
|
14
|
+
end
|
15
|
+
|
16
|
+
def cptr?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
base_type = @type.base_type
|
22
|
+
if base_type.c_function?
|
23
|
+
ptr = ptr_level
|
24
|
+
|
25
|
+
str = "#{base_type.type} (#{ptr} #{base_type.c_name})"
|
26
|
+
str << '(' + base_type.arg_list.map { |e| e.type.to_s }.join(',') + ')'
|
27
|
+
else
|
28
|
+
t = @type
|
29
|
+
str = '*'
|
30
|
+
if t.cptr?
|
31
|
+
str << '*'
|
32
|
+
t = t.type
|
33
|
+
end
|
34
|
+
str.prepend t.to_s
|
35
|
+
str
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def base_type
|
40
|
+
return @type unless @type.is_a?(self.class)
|
41
|
+
@type.base_type
|
42
|
+
end
|
43
|
+
|
44
|
+
def ptr_level
|
45
|
+
temp = @type
|
46
|
+
ptr = '*'
|
47
|
+
while temp.cptr?
|
48
|
+
ptr << '*'
|
49
|
+
temp = @type.type
|
50
|
+
end
|
51
|
+
|
52
|
+
ptr
|
53
|
+
end
|
54
|
+
|
55
|
+
# from a Ruby function get a pointer to some value.
|
56
|
+
def from_ruby_object(arg)
|
57
|
+
return "StringValueCStr(#{arg})" if @type.char?
|
58
|
+
arg
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_ruby_object(arg)
|
62
|
+
return "rb_str_new2(#{arg})" if @type.char?
|
63
|
+
arg
|
64
|
+
end
|
65
|
+
|
66
|
+
def <=>(_other)
|
67
|
+
-1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class CStr
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
def cstr?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def p_formatter
|
11
|
+
'%s'
|
12
|
+
end
|
13
|
+
|
14
|
+
def from_ruby_object(arg)
|
15
|
+
"StringValueCStr(#{arg})"
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_ruby_object(arg)
|
19
|
+
"rb_str_new_cstr(#{arg})"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class CStructOrUnion
|
4
|
+
include Helpers
|
5
|
+
attr_reader :kind, :name, :c_name, :scope
|
6
|
+
|
7
|
+
def initialize(kind, name, c_name, scope)
|
8
|
+
@kind = kind
|
9
|
+
@name = name
|
10
|
+
@c_name = c_name
|
11
|
+
@scope = scope
|
12
|
+
end
|
13
|
+
|
14
|
+
def struct_or_union?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
@c_name.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class Char
|
4
|
+
include Helpers
|
5
|
+
def to_s
|
6
|
+
'char'
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_ruby_object(arg, _literal = false)
|
10
|
+
"#{Rubex::C_FUNC_CHAR2RUBYSTR}(#{arg})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def from_ruby_object(arg)
|
14
|
+
"(char)NUM2INT(#{arg})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def p_formatter
|
18
|
+
'%c'
|
19
|
+
end
|
20
|
+
|
21
|
+
def char?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def <=>(other)
|
26
|
+
other.char? ? 0 : 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class F32
|
4
|
+
include FloatHelpers
|
5
|
+
def to_s
|
6
|
+
'float'
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_ruby_object(arg)
|
10
|
+
"rb_float_new((double)(#{arg}))"
|
11
|
+
end
|
12
|
+
|
13
|
+
def from_ruby_object(arg)
|
14
|
+
"(float)NUM2DBL(#{arg})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def float32?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def p_formatter
|
22
|
+
'%f'
|
23
|
+
end
|
24
|
+
|
25
|
+
def <=>(other)
|
26
|
+
if other.char? || other.int8? || other.int16? || other.int32? ||
|
27
|
+
other.int64? || other.int? || other.uint8? || other.uint16? ||
|
28
|
+
other.uint32? || other.uint64?
|
29
|
+
1
|
30
|
+
elsif other.float32?
|
31
|
+
0
|
32
|
+
else # other is float64
|
33
|
+
-1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class F64
|
4
|
+
include FloatHelpers
|
5
|
+
def to_s
|
6
|
+
'double'
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_ruby_object(arg)
|
10
|
+
"rb_float_new(#{arg})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def from_ruby_object(arg)
|
14
|
+
"NUM2DBL(#{arg})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def float64?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def p_formatter
|
22
|
+
'%f'
|
23
|
+
end
|
24
|
+
|
25
|
+
def <=>(other)
|
26
|
+
if other.char? || other.int8? || other.int16? || other.int32? ||
|
27
|
+
other.int64? || other.int? || other.uint8? || other.uint16? ||
|
28
|
+
other.uint32? || other.uint64? || other.float32?
|
29
|
+
1
|
30
|
+
elsif other.float64?
|
31
|
+
0
|
32
|
+
else
|
33
|
+
-1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class Int
|
4
|
+
include IntHelpers
|
5
|
+
def to_s
|
6
|
+
'int'
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_ruby_object(arg)
|
10
|
+
"NUM2INT(#{arg})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def int?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def p_formatter
|
18
|
+
'%d'
|
19
|
+
end
|
20
|
+
|
21
|
+
def <=>(other)
|
22
|
+
if other.char? || other.int8? || other.int16?
|
23
|
+
1
|
24
|
+
elsif other.int? || other.int32?
|
25
|
+
0
|
26
|
+
else # other is int64 or greater
|
27
|
+
-1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class Int16
|
4
|
+
include IntHelpers
|
5
|
+
def to_s
|
6
|
+
'int16_t'
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_ruby_object(arg)
|
10
|
+
"(int16_t)NUM2INT(#{arg})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def int16?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def p_formatter
|
18
|
+
'%d'
|
19
|
+
end
|
20
|
+
|
21
|
+
def <=>(other)
|
22
|
+
if other.char? || other.int8?
|
23
|
+
1
|
24
|
+
elsif other.int16?
|
25
|
+
0
|
26
|
+
else
|
27
|
+
-1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class Int32
|
4
|
+
include IntHelpers
|
5
|
+
def to_s
|
6
|
+
'int32_t'
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_ruby_object(arg)
|
10
|
+
"(int32_t)NUM2INT(#{arg})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def int32?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def p_formatter
|
18
|
+
'%d'
|
19
|
+
end
|
20
|
+
|
21
|
+
def <=>(other)
|
22
|
+
if other.char? || other.int8? || other.int16?
|
23
|
+
1
|
24
|
+
elsif other.int32? || other.int?
|
25
|
+
0
|
26
|
+
else
|
27
|
+
-1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class Int64
|
4
|
+
include IntHelpers
|
5
|
+
def to_s
|
6
|
+
'int64_t'
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_ruby_object(arg)
|
10
|
+
"LONG2NUM(#{arg})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def from_ruby_object(arg)
|
14
|
+
"(int64_t)NUM2LONG(#{arg})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def p_formatter
|
18
|
+
'%ld'
|
19
|
+
end
|
20
|
+
|
21
|
+
def int64?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def <=>(other)
|
26
|
+
if other.char? || other.int8? || other.int16? || other.int32? || other.int?
|
27
|
+
1
|
28
|
+
elsif other.int64?
|
29
|
+
0
|
30
|
+
else
|
31
|
+
-1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Rubex
|
2
|
+
module DataType
|
3
|
+
class Int8
|
4
|
+
include IntHelpers
|
5
|
+
|
6
|
+
def to_s
|
7
|
+
'int8_t'
|
8
|
+
end
|
9
|
+
|
10
|
+
def from_ruby_object(arg)
|
11
|
+
"(int8_t)NUM2INT(#{arg})"
|
12
|
+
end
|
13
|
+
|
14
|
+
def int8?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def p_formatter
|
19
|
+
'%d'
|
20
|
+
end
|
21
|
+
|
22
|
+
def <=>(other)
|
23
|
+
if other.char?
|
24
|
+
1
|
25
|
+
elsif other.int8?
|
26
|
+
0
|
27
|
+
else
|
28
|
+
-1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|