root/src/obj_boolean.c

Revision 1ffd3187f60715d349b1be1c5328479b50dda298, 2.9 kB (checked in by redbrain <redbrain@…>, 2 years ago)

cleanups

  • Property mode set to 100644
Line 
1/**
2 * obj_integer.c -> Part of Crules Programming language
3 *
4 * Crules is the legal property of its developers. Please refer to the
5 * COPYRIGHT file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21#ifdef HAVE_CONFIG_H
22# include "config.h"
23#else
24# define CMAKE 1
25# include "config.h.cmake"
26#endif
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31
32#include <stdbool.h>
33
34#include <crules/crules.h>
35#include <crules/opcodes.h>
36#include <crules/symbols.h>
37#include <crules/objects.h>
38#include <crules/backend.h>
39#include <crules/runtime.h>
40#include <crules/garbage.h>
41#include <crules/operators.h>
42
43crl_type_boolean_t *
44crl_obj_boolean_init( crl_symbol_obj * args,
45                      crl_type_obj_def_t ** def )
46{
47  crl_type_boolean_t *s = crl_malloc( ((*def)->builtin_type_size) );
48  crl_assert( args->op_a_t == TYPE_BOOLEAN );
49  memcpy( &(s->boolean), &(args->op_a.boolean),
50          sizeof(bool) );
51  return s;
52}
53
54crl_symbol_obj *
55crl_obj_boolean_to_string( crl_symbol_obj * caller, crl_symbol_obj * self,
56                           crl_context_table * caller_ctx,
57                           crl_context_table * function_ctx )
58{
59  return NULL;
60}
61
62bool crl_obj_boolean_print( crl_type_boolean_t * self, FILE * fd,
63                            bool newline )
64{
65  bool retval = true;
66
67  if( self->boolean )
68    {
69      fprintf( fd, "True" );
70    }
71  else
72    {
73      fprintf( fd, "False" );
74    }
75
76  if( newline )
77    {
78      fprintf( fd, "\n" );
79    }
80  return retval;
81}
82
83void crl_obj_boolean_destroy( crl_type_boolean_t * self )
84{
85  if( self )
86    crl_free( self );
87}
88
89struct crl_number_prot_t boolean_module_binary_ops = {
90  false,
91  NULL,
92  NULL,
93  NULL,
94  NULL,
95  NULL,
96  NULL,
97  NULL,
98  NULL,
99  NULL,
100  NULL,
101  NULL,
102  NULL,
103  NULL,
104};
105
106struct crl_builtin_function_def_t boolean_module_function_table[] = {
107  { NULL, 0, NULL },
108} ;
109
110struct crl_builtin_member_def_t boolean_module_member_table[] = {
111  { 0, NULL },
112} ;
113
114struct crl_type_obj_def_t boolean_object = {
115  "Bool",
116  sizeof( crl_type_boolean_t ),
117  &crl_obj_boolean_init,
118  &crl_obj_boolean_destroy,
119  &crl_obj_boolean_print,
120  NULL,
121  &boolean_module_binary_ops,
122  boolean_module_member_table,
123  boolean_module_function_table,
124  true,
125} ;
126
127bool crl_obj_boolean_module_init( crl_context_table * context )
128{
129  bool retval = false;
130  retval = crl_rr_context_intilize_module( &boolean_object, context );
131  return retval;
132}
Note: See TracBrowser for help on using the browser.