11#include "ruby_basic.h"
22
3- void cbasic_free (void * ptr ){
3+ void cbasic_free (void * ptr )
4+ {
45 basic_struct * basic_ptr = ptr ;
56 basic_free_stack (basic_ptr );
67}
78
8- void cbasic_free_heap (void * ptr ) {
9+ void cbasic_free_heap (void * ptr )
10+ {
911 basic_struct * basic_ptr = ptr ;
1012 basic_free_heap (basic_ptr );
1113}
1214
13- VALUE cbasic_alloc (VALUE klass ){
15+ VALUE cbasic_alloc (VALUE klass )
16+ {
1417 basic_struct * struct_ptr = basic_new_heap ();
1518 return Data_Wrap_Struct (klass , NULL , cbasic_free_heap , struct_ptr );
1619}
1720
18- VALUE cbasic_binary_op (VALUE self , VALUE operand2 , void (* cwfunc_ptr )(basic_struct * , const basic_struct * , const basic_struct * )){
21+ VALUE cbasic_binary_op (VALUE self , VALUE operand2 ,
22+ void (* cwfunc_ptr )(basic_struct * , const basic_struct * ,
23+ const basic_struct * ))
24+ {
1925 basic_struct * this , * cresult ;
2026 VALUE result ;
2127
@@ -27,46 +33,56 @@ VALUE cbasic_binary_op(VALUE self, VALUE operand2, void (*cwfunc_ptr)(basic_stru
2733
2834 cresult = basic_new_heap ();
2935 cwfunc_ptr (cresult , this , cbasic_operand2 );
30- result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap , cresult );
36+ result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap ,
37+ cresult );
3138 basic_free_stack (cbasic_operand2 );
3239
3340 return result ;
3441}
3542
36- VALUE cbasic_unary_op (VALUE self , void (* cwfunc_ptr )(basic_struct * , const basic_struct * )){
43+ VALUE cbasic_unary_op (VALUE self ,
44+ void (* cwfunc_ptr )(basic_struct * , const basic_struct * ))
45+ {
3746 basic_struct * this , * cresult ;
3847 VALUE result ;
3948
4049 Data_Get_Struct (self , basic_struct , this );
4150
4251 cresult = basic_new_heap ();
4352 cwfunc_ptr (cresult , this );
44- result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap , cresult );
53+ result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap ,
54+ cresult );
4555
4656 return result ;
4757}
4858
49- VALUE cbasic_add (VALUE self , VALUE operand2 ){
59+ VALUE cbasic_add (VALUE self , VALUE operand2 )
60+ {
5061 return cbasic_binary_op (self , operand2 , basic_add );
5162}
5263
53- VALUE cbasic_sub (VALUE self , VALUE operand2 ){
64+ VALUE cbasic_sub (VALUE self , VALUE operand2 )
65+ {
5466 return cbasic_binary_op (self , operand2 , basic_sub );
5567}
5668
57- VALUE cbasic_mul (VALUE self , VALUE operand2 ){
69+ VALUE cbasic_mul (VALUE self , VALUE operand2 )
70+ {
5871 return cbasic_binary_op (self , operand2 , basic_mul );
5972}
6073
61- VALUE cbasic_div (VALUE self , VALUE operand2 ){
74+ VALUE cbasic_div (VALUE self , VALUE operand2 )
75+ {
6276 return cbasic_binary_op (self , operand2 , basic_div );
6377}
6478
65- VALUE cbasic_pow (VALUE self , VALUE operand2 ){
79+ VALUE cbasic_pow (VALUE self , VALUE operand2 )
80+ {
6681 return cbasic_binary_op (self , operand2 , basic_pow );
6782}
6883
69- VALUE cbasic_diff (VALUE self , VALUE operand2 ) {
84+ VALUE cbasic_diff (VALUE self , VALUE operand2 )
85+ {
7086 basic_struct * this , * cresult ;
7187 VALUE result ;
7288
@@ -83,13 +99,15 @@ VALUE cbasic_diff(VALUE self, VALUE operand2) {
8399 basic_free_heap (cresult );
84100 return Qnil ;
85101 }
86- result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap , cresult );
102+ result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap ,
103+ cresult );
87104 basic_free_stack (cbasic_operand2 );
88105
89106 return result ;
90107}
91108
92- VALUE cbasic_eq (VALUE self , VALUE operand2 ) {
109+ VALUE cbasic_eq (VALUE self , VALUE operand2 )
110+ {
93111
94112 basic_struct * this ;
95113
@@ -98,35 +116,40 @@ VALUE cbasic_eq(VALUE self, VALUE operand2) {
98116 Data_Get_Struct (self , basic_struct , this );
99117
100118 VALUE ret = check_sympify (operand2 , cbasic_operand2 );
101- if (ret == Qfalse ) return Qfalse ;
119+ if (ret == Qfalse )
120+ return Qfalse ;
102121
103122 VALUE ret_val = basic_eq (this , cbasic_operand2 ) ? Qtrue : Qfalse ;
104123 basic_free_stack (cbasic_operand2 );
105124
106125 return ret_val ;
107126}
108127
109- VALUE cbasic_neq (VALUE self , VALUE operand2 ) {
128+ VALUE cbasic_neq (VALUE self , VALUE operand2 )
129+ {
110130 basic_struct * this ;
111131
112132 basic cbasic_operand2 ;
113133 basic_new_stack (cbasic_operand2 );
114134 Data_Get_Struct (self , basic_struct , this );
115135
116136 VALUE ret = check_sympify (operand2 , cbasic_operand2 );
117- if (ret == Qfalse ) return Qtrue ;
137+ if (ret == Qfalse )
138+ return Qtrue ;
118139
119- VALUE ret_val = basic_neq (this , cbasic_operand2 ) ? Qtrue : Qfalse ;
140+ VALUE ret_val = basic_neq (this , cbasic_operand2 ) ? Qtrue : Qfalse ;
120141 basic_free_stack (cbasic_operand2 );
121142
122143 return ret_val ;
123144}
124145
125- VALUE cbasic_neg (VALUE self ){
146+ VALUE cbasic_neg (VALUE self )
147+ {
126148 return cbasic_unary_op (self , basic_neg );
127149}
128150
129- VALUE cbasic_get_args (VALUE self ) {
151+ VALUE cbasic_get_args (VALUE self )
152+ {
130153 basic_struct * this ;
131154 CVecBasic * args = vecbasic_new ();
132155 int size = 0 ;
@@ -138,17 +161,19 @@ VALUE cbasic_get_args(VALUE self) {
138161 VALUE ruby_array = rb_ary_new2 (size );
139162 int i = 0 ;
140163 VALUE temp ;
141- for (i = 0 ; i < size ; i ++ ) {
164+ for (i = 0 ; i < size ; i ++ ) {
142165 basic_struct * temp_basic = basic_new_heap ();
143166 vecbasic_get (args , i , temp_basic );
144- temp = Data_Wrap_Struct (rb_obj_class (self ), NULL , cbasic_free_heap , temp_basic );
167+ temp = Data_Wrap_Struct (rb_obj_class (self ), NULL , cbasic_free_heap ,
168+ temp_basic );
145169 rb_ary_push (ruby_array , temp );
146170 }
147171 vecbasic_free (args );
148172 return ruby_array ;
149173}
150174
151- VALUE cbasic_free_symbols (VALUE self ) {
175+ VALUE cbasic_free_symbols (VALUE self )
176+ {
152177 basic_struct * this ;
153178 CSetBasic * symbols = setbasic_new ();
154179 int size = 0 ;
@@ -160,17 +185,19 @@ VALUE cbasic_free_symbols(VALUE self) {
160185 VALUE ruby_array = rb_ary_new2 (size );
161186 int i = 0 ;
162187 VALUE temp ;
163- for (i = 0 ; i < size ; i ++ ) {
188+ for (i = 0 ; i < size ; i ++ ) {
164189 basic_struct * temp_basic = basic_new_heap ();
165190 setbasic_get (symbols , i , temp_basic );
166- temp = Data_Wrap_Struct (rb_obj_class (self ), NULL , cbasic_free_heap , temp_basic );
191+ temp = Data_Wrap_Struct (rb_obj_class (self ), NULL , cbasic_free_heap ,
192+ temp_basic );
167193 rb_ary_push (ruby_array , temp );
168194 }
169195 setbasic_free (symbols );
170196 return ruby_array ;
171197}
172198
173- VALUE cbasic_to_str (VALUE self ){
199+ VALUE cbasic_to_str (VALUE self )
200+ {
174201 basic_struct * this ;
175202 char * str_ptr ;
176203 VALUE result ;
@@ -184,11 +211,13 @@ VALUE cbasic_to_str(VALUE self){
184211 return result ;
185212}
186213
187- VALUE cbasic_expand (VALUE self ){
214+ VALUE cbasic_expand (VALUE self )
215+ {
188216 return cbasic_unary_op (self , basic_expand );
189217}
190218
191- VALUE cbasic_hash (VALUE self ){
219+ VALUE cbasic_hash (VALUE self )
220+ {
192221 basic_struct * this ;
193222 Data_Get_Struct (self , basic_struct , this );
194223 // All ruby objects return FIXNUM when `hash` method is called.
@@ -203,7 +232,8 @@ VALUE cbasic_hash(VALUE self){
203232 return SIZET2NUM (basic_hash (this ));
204233}
205234
206- int insert_entries (VALUE key , VALUE val , VALUE input ) {
235+ int insert_entries (VALUE key , VALUE val , VALUE input )
236+ {
207237 CMapBasicBasic * cmapbb ;
208238 Data_Get_Struct (input , CMapBasicBasic , cmapbb );
209239
@@ -220,18 +250,21 @@ int insert_entries(VALUE key, VALUE val, VALUE input) {
220250 return ST_CONTINUE ;
221251}
222252
223- VALUE cbasic_subs (int argc , VALUE * argv , VALUE self ) {
253+ VALUE cbasic_subs (int argc , VALUE * argv , VALUE self )
254+ {
224255 basic_struct * this , * cresult ;
225256 cresult = basic_new_heap ();
226257
227258 VALUE val_a , val_b ;
228259 Data_Get_Struct (self , basic_struct , this );
229260
230- rb_scan_args (argc , argv , "11" , & val_a , & val_b ); // 1 mandatory and 1 optional parameter
261+ rb_scan_args (argc , argv , "11" , & val_a ,
262+ & val_b ); // 1 mandatory and 1 optional parameter
231263 if (argc == 1 ) {
232264 Check_Type (val_a , T_HASH );
233265 CMapBasicBasic * cmapbb = mapbasicbasic_new ();
234- VALUE mapbb = Data_Wrap_Struct (rb_cObject , NULL , mapbasicbasic_free , cmapbb );
266+ VALUE mapbb
267+ = Data_Wrap_Struct (rb_cObject , NULL , mapbasicbasic_free , cmapbb );
235268
236269 rb_hash_foreach (val_a , insert_entries , mapbb );
237270 basic_subs (cresult , this , cmapbb );
@@ -248,13 +281,16 @@ VALUE cbasic_subs(int argc, VALUE *argv, VALUE self) {
248281 basic_free_stack (b );
249282 }
250283
251- return Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap , cresult );
284+ return Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap ,
285+ cresult );
252286}
253287
254- VALUE cbasic_coerce (VALUE self , VALUE other ){
288+ VALUE cbasic_coerce (VALUE self , VALUE other )
289+ {
255290 basic_struct * cbasic_operand2 ;
256291 cbasic_operand2 = basic_new_heap ();
257292 sympify (other , cbasic_operand2 );
258- VALUE new_other = Data_Wrap_Struct (Klass_of_Basic (cbasic_operand2 ), NULL , cbasic_free_heap , cbasic_operand2 );
293+ VALUE new_other = Data_Wrap_Struct (Klass_of_Basic (cbasic_operand2 ), NULL ,
294+ cbasic_free_heap , cbasic_operand2 );
259295 return rb_assoc_new (new_other , self );
260296}
0 commit comments