cauterize 0.0.1.pre7 → 0.0.1.pre8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,13 +33,31 @@ used to abstract the process of packaging and unpackaging different elements.
33
33
 
34
34
  # Different Types
35
35
 
36
- There are 6 fundamental classes of types in Cauterize. These types have several characteristics:
36
+ There are 7 fundamental classes of types in Cauterize. These types have several characteristics:
37
37
 
38
38
  * They can be copied with `memcpy`.
39
39
  * They do not attempt to cover the concept of indirection or pointers.
40
40
  * They are simple.
41
41
  * They cannot be defined recursively.
42
42
 
43
+ ## Primitives
44
+
45
+ * 1 Byte Primitives
46
+ * `:bool` - a boolean value
47
+ * `:int8` - a signed, 8 bit value
48
+ * `:uint8` - an unsigned, 8 bit value
49
+ * 2 Byte Primitives
50
+ * `:int16` - a signed, 16 bit value
51
+ * `:uint16` - an unsigned, 16 bit value
52
+ * 4 Byte Primitives
53
+ * `:int32` - a signed, 32 bit value
54
+ * `:uint32` - an unsigned, 32 bit value
55
+ * `:float32` - a 32 bit floating point value
56
+ * 8 Byte Primitives
57
+ * `:int64` - a signed, 64 bit value
58
+ * `:uint64` - an unsigned, 64 bit value
59
+ * `:float64` - a 64 bit floating point value
60
+
43
61
  ## Scalars
44
62
 
45
63
  Scalars are any type that corresponds to a C scalar value. That is, something
data/example/Cauterize CHANGED
@@ -40,6 +40,8 @@ composite(:nonsensical) do |c|
40
40
  c.field :color, :color
41
41
  c.field :color_list, :color_list
42
42
  c.field :numbers, :numbers
43
+ c.field :a_float, :float64
44
+ c.field :a_bool, :bool
43
45
  end
44
46
 
45
47
  composite(:crazy) do |c|
@@ -3,10 +3,10 @@ module Cauterize
3
3
  module C
4
4
  class BuiltIn < Buildable
5
5
  @@C_TYPE_MAPPING = {
6
- 1 => {signed: :int8_t, unsigned: :uint8_t},
7
- 2 => {signed: :int16_t, unsigned: :uint16_t},
8
- 4 => {signed: :int32_t, unsigned: :uint32_t},
9
- 8 => {signed: :int64_t, unsigned: :uint64_t},
6
+ 1 => {signed: :int8_t, unsigned: :uint8_t, :float => nil, :bool => :bool},
7
+ 2 => {signed: :int16_t, unsigned: :uint16_t, :float => nil, :bool => nil},
8
+ 4 => {signed: :int32_t, unsigned: :uint32_t, :float => :float, :bool => nil},
9
+ 8 => {signed: :int64_t, unsigned: :uint64_t, :float => :double, :bool => nil},
10
10
  }
11
11
 
12
12
  def render
@@ -35,8 +35,7 @@ module Cauterize
35
35
  private
36
36
 
37
37
  def render_ctype
38
- s_key = @blueprint.is_signed ? :signed : :unsigned
39
- @@C_TYPE_MAPPING[@blueprint.byte_length][s_key]
38
+ @@C_TYPE_MAPPING[@blueprint.byte_length][@blueprint.flavor]
40
39
  end
41
40
  end
42
41
  end
@@ -1,10 +1,10 @@
1
1
  module Cauterize::Builders::CS
2
2
  class BuiltIn < Buildable
3
3
  @@CS_TYPE_MAPPING = {
4
- 1 => {signed: "SByte", unsigned: "Byte"},
5
- 2 => {signed: "Int16", unsigned: "UInt16"},
6
- 4 => {signed: "Int32", unsigned: "UInt32"},
7
- 8 => {signed: "Int64", unsigned: "UInt64"},
4
+ 1 => {signed: "SByte", unsigned: "Byte", :float => nil, :bool => "bool"},
5
+ 2 => {signed: "Int16", unsigned: "UInt16", :float => nil, :bool => nil},
6
+ 4 => {signed: "Int32", unsigned: "UInt32", :float => "Float", :bool => nil},
7
+ 8 => {signed: "Int64", unsigned: "UInt64", :float => "Double", :bool => nil},
8
8
  }
9
9
 
10
10
  def render
@@ -14,8 +14,7 @@ module Cauterize::Builders::CS
14
14
  private
15
15
 
16
16
  def render_cstype
17
- s_key = @blueprint.is_signed ? :signed : :unsigned
18
- @@CS_TYPE_MAPPING[@blueprint.byte_length][s_key]
17
+ @@CS_TYPE_MAPPING[@blueprint.byte_length][@blueprint.flavor]
19
18
  end
20
19
  end
21
20
  end
@@ -2,14 +2,17 @@ module Cauterize
2
2
  module_function
3
3
 
4
4
  BUILT_IN_TYPES = [
5
- { :name => :int8, :size => 1, :signed => true },
6
- { :name => :int16, :size => 2, :signed => true },
7
- { :name => :int32, :size => 4, :signed => true },
8
- { :name => :int64, :size => 8, :signed => true },
9
- { :name => :uint8, :size => 1, :signed => false },
10
- { :name => :uint16, :size => 2, :signed => false },
11
- { :name => :uint32, :size => 4, :signed => false },
12
- { :name => :uint64, :size => 8, :signed => false },
5
+ { :name => :int8, :size => 1, :flavor => :signed },
6
+ { :name => :int16, :size => 2, :flavor => :signed },
7
+ { :name => :int32, :size => 4, :flavor => :signed },
8
+ { :name => :int64, :size => 8, :flavor => :signed },
9
+ { :name => :uint8, :size => 1, :flavor => :unsigned },
10
+ { :name => :uint16, :size => 2, :flavor => :unsigned },
11
+ { :name => :uint32, :size => 4, :flavor => :unsigned },
12
+ { :name => :uint64, :size => 8, :flavor => :unsigned },
13
+ { :name => :float32, :size => 4, :flavor => :float },
14
+ { :name => :float64, :size => 8, :flavor => :float },
15
+ { :name => :bool, :size => 1, :flavor => :bool },
13
16
  ]
14
17
 
15
18
  def builtins
@@ -20,7 +23,7 @@ module Cauterize
20
23
  BUILT_IN_TYPES.each do |b|
21
24
  _b = BuiltIn.new(b[:name], nil)
22
25
  _b.byte_length(b[:size])
23
- _b.is_signed(b[:signed])
26
+ _b.flavor(b[:flavor])
24
27
  builtins[b[:name]] = _b
25
28
  end
26
29
  end
@@ -30,11 +33,11 @@ module Cauterize
30
33
  super
31
34
  end
32
35
 
33
- def is_signed(signed = nil)
34
- unless signed.nil?
35
- @is_signed = signed
36
+ def flavor(f = nil)
37
+ unless f.nil?
38
+ @flavor = f
36
39
  else
37
- @is_signed
40
+ @flavor
38
41
  end
39
42
  end
40
43
 
@@ -1,3 +1,3 @@
1
1
  module Cauterize
2
- VERSION = "0.0.1.pre7"
2
+ VERSION = "0.0.1.pre8"
3
3
  end
@@ -2,7 +2,7 @@ module Cauterize
2
2
  describe Builders::C::BuiltIn do
3
3
  let(:bi) do
4
4
  b = BuiltIn.new(:foo)
5
- b.is_signed(false)
5
+ b.flavor(:unsigned)
6
6
  b.byte_length(4)
7
7
  b
8
8
  end
data/spec/builtin_spec.rb CHANGED
@@ -4,11 +4,11 @@ module Cauterize
4
4
  describe :initialize do
5
5
  it "creates a builtin" do
6
6
  b = BuiltIn.new(:foo)
7
- b.is_signed(false)
7
+ b.flavor(:unsigned)
8
8
  b.byte_length(4)
9
9
 
10
10
  b.name.should == :foo
11
- b.is_signed.should == false
11
+ b.flavor.should == :unsigned
12
12
  b.byte_length.should == 4
13
13
  end
14
14
  end
@@ -30,6 +30,8 @@ module Cauterize
30
30
  Cauterize.builtins.keys.should =~ [
31
31
  :int8, :int16, :int32, :int64,
32
32
  :uint8, :uint16, :uint32, :uint64,
33
+ :float32, :float64,
34
+ :bool,
33
35
  ]
34
36
  end
35
37
 
@@ -134,6 +134,21 @@ Cauterize Class: built-in
134
134
  Description: <none>
135
135
  data - size: 8 bytes
136
136
 
137
+ Type Name: float32
138
+ Cauterize Class: built-in
139
+ Description: <none>
140
+ data - size: 4 bytes
141
+
142
+ Type Name: float64
143
+ Cauterize Class: built-in
144
+ Description: <none>
145
+ data - size: 8 bytes
146
+
147
+ Type Name: bool
148
+ Cauterize Class: built-in
149
+ Description: <none>
150
+ data - size: 1 bytes
151
+
137
152
  Type Name: an_int
138
153
  Cauterize Class: scalar
139
154
  Description: - a useful int
@@ -3,6 +3,7 @@
3
3
 
4
4
  #ifndef CUSTOM_TYPES
5
5
  #include <stdint.h>
6
+ #include <stdbool.h>
6
7
  #include <stddef.h>
7
8
  #else
8
9
  #include "cauterize_custom_types.h"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cauterize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre7
4
+ version: 0.0.1.pre8
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-15 00:00:00.000000000 Z
12
+ date: 2013-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -126,7 +126,6 @@ files:
126
126
  - cauterize.gemspec
127
127
  - example/Cauterize
128
128
  - example/build.sh
129
- - example/doc_cauterize_output/example_project.txt
130
129
  - example/ruby_ex.rb
131
130
  - lib/cauterize.rb
132
131
  - lib/cauterize/base_type.rb
@@ -251,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
251
250
  version: '0'
252
251
  segments:
253
252
  - 0
254
- hash: -3520063422642430845
253
+ hash: 1539031795664628107
255
254
  required_rubygems_version: !ruby/object:Gem::Requirement
256
255
  none: false
257
256
  requirements:
@@ -1,124 +0,0 @@
1
- Type Name: int8
2
- Cauterize Class: built-in
3
- Description: <none>
4
- data - size: 1 bytes
5
-
6
- Type Name: int16
7
- Cauterize Class: built-in
8
- Description: <none>
9
- data - size: 2 bytes
10
-
11
- Type Name: int32
12
- Cauterize Class: built-in
13
- Description: <none>
14
- data - size: 4 bytes
15
-
16
- Type Name: int64
17
- Cauterize Class: built-in
18
- Description: <none>
19
- data - size: 8 bytes
20
-
21
- Type Name: uint8
22
- Cauterize Class: built-in
23
- Description: <none>
24
- data - size: 1 bytes
25
-
26
- Type Name: uint16
27
- Cauterize Class: built-in
28
- Description: <none>
29
- data - size: 2 bytes
30
-
31
- Type Name: uint32
32
- Cauterize Class: built-in
33
- Description: <none>
34
- data - size: 4 bytes
35
-
36
- Type Name: uint64
37
- Cauterize Class: built-in
38
- Description: <none>
39
- data - size: 8 bytes
40
-
41
- Type Name: bigint
42
- Cauterize Class: scalar
43
- Description: <none>
44
- data - type: int32
45
-
46
- Type Name: usmallint
47
- Cauterize Class: scalar
48
- Description: <none>
49
- data - type: uint8
50
-
51
- Type Name: color
52
- Cauterize Class: enumeration
53
- Description: <none>
54
- Encoding: int8
55
- red = 0
56
- blue = 1
57
- green = 2
58
-
59
- Type Name: large_value
60
- Cauterize Class: enumeration
61
- Description: <none>
62
- Encoding: int16
63
- negative = -500
64
- positive = 500
65
-
66
- Type Name: weirdness
67
- Cauterize Class: composite
68
- Description: <none>
69
- val - type: large_value
70
- num - type: int8
71
-
72
- Type Name: color_list
73
- Cauterize Class: fixed-array
74
- Description: <none>
75
- Stored Type: color
76
- Value Count: 4
77
- data - 4 values of type color
78
-
79
- Type Name: color_list_list
80
- Cauterize Class: fixed-array
81
- Description: <none>
82
- Stored Type: color_list
83
- Value Count: 4
84
- data - 4 values of type color_list
85
-
86
- Type Name: numbers
87
- Cauterize Class: variable-array
88
- Description: <none>
89
- Maximum Value Count: 128
90
- length - type usmallint
91
- data - 0 to 128 values of type bigint
92
-
93
- Type Name: nonsensical
94
- Cauterize Class: composite
95
- Description: <none>
96
- color - type: color
97
- color_list - type: color_list
98
- numbers - type: numbers
99
-
100
- Type Name: crazy
101
- Cauterize Class: composite
102
- Description: <none>
103
- first_numbers - type: numbers
104
- second_numbers - type: numbers
105
- third_numbers - type: numbers
106
-
107
- Type Name: insanity
108
- Cauterize Class: group
109
- Description: <none>
110
- kind tag: group_insanity_type
111
- kinds:
112
- nonsensical - payload: nonsensical
113
- crazy - payload: crazy
114
- any_empty_entry - payload: <no payload>
115
- another_empty - payload: <no payload>
116
-
117
- Type Name: group_insanity_type
118
- Cauterize Class: enumeration
119
- Description: <none>
120
- Encoding: int8
121
- GROUP_INSANITY_TYPE_NONSENSICAL = 0
122
- GROUP_INSANITY_TYPE_CRAZY = 1
123
- GROUP_INSANITY_TYPE_ANY_EMPTY_ENTRY = 2
124
- GROUP_INSANITY_TYPE_ANOTHER_EMPTY = 3