root/src/obj_character.c

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

cleanups

  • Property mode set to 100644
Line 
1/**
2 * obj_character.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 <crules/crules.h>
33#include <crules/opcodes.h>
34#include <crules/symbols.h>
35#include <crules/objects.h>
36#include <crules/backend.h>
37#include <crules/runtime.h>
38#include <crules/garbage.h>
39#include <crules/operators.h>
40
41crl_type_character_t *
42crl_obj_character_init( crl_symbol_obj * args,
43                        crl_type_obj_def_t ** def )
44{
45  crl_type_character_t *s = crl_malloc( ((*def)->builtin_type_size) );
46  crl_assert( args->op_a_t == TYPE_CHAR );
47  memcpy( &(s->character), &(args->op_a.character),
48          sizeof(char) );
49  return s;
50}
51
52bool crl_obj_character_print( crl_type_character_t * self, FILE * fd,
53                              bool newline )
54{
55  bool retval = true;
56  fprintf( fd, "%c", self->character );
57  if( newline )
58    {
59      fprintf( fd, "\n" );
60    }
61  return retval;
62}
63
64void crl_obj_character_destroy( crl_type_character_t * self )
65{
66  if( self )
67    crl_free( self );
68}
69
70struct crl_number_prot_t character_module_binary_ops = {
71  false,
72  NULL,
73  NULL,
74  NULL,
75  NULL,
76  NULL,
77  NULL,
78  NULL,
79  NULL,
80  NULL,
81  NULL,
82  NULL,
83  NULL,
84  NULL,
85};
86
87struct crl_builtin_function_def_t character_module_function_table[] = {
88  { NULL, 0, NULL },
89} ;
90
91struct crl_builtin_member_def_t character_module_member_table[] = {
92  { 0, NULL },
93} ;
94
95struct crl_type_obj_def_t character_object = {
96  "Char",
97  sizeof( crl_type_character_t ),
98  &crl_obj_character_init,
99  &crl_obj_character_destroy,
100  &crl_obj_character_print,
101  NULL,
102  &character_module_binary_ops,
103  character_module_member_table,
104  character_module_function_table,
105  true,
106} ;
107
108bool crl_obj_character_module_init( crl_context_table * context )
109{
110  bool retval = false;
111  retval = crl_rr_context_intilize_module( &character_object, context );
112  return retval;
113}
Note: See TracBrowser for help on using the browser.