root/src/obj_string.c

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

cleanups

  • Property mode set to 100644
Line 
1/**
2 * obj_string.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_string_t *
42crl_obj_string_init( crl_symbol_obj * args,
43                     crl_type_obj_def_t ** def )
44{
45  crl_string_t *s = crl_malloc( ((*def)->builtin_type_size) );
46  crl_assert( args->op_a_t == TYPE_STRING );
47  s->string = crl_strdup( args->op_a.string);
48  return s;
49}
50
51
52bool crl_obj_string_print( crl_string_t * self, FILE * fd,
53                           bool newline )
54{
55  bool retval = true;
56  fprintf( fd, "%s", self->string );
57  if( newline )
58    {
59      fprintf( fd, "\n" );
60    }
61  return retval;
62}
63
64void crl_obj_string_destroy( crl_string_t * self  )
65{
66  if( self )
67    {
68      if( self->string )
69        {
70          crl_free( self->string );
71        }
72      crl_free( self );
73    }
74}
75
76struct crl_number_prot_t string_module_binary_ops = {
77  false,
78  NULL,
79  NULL,
80  NULL,
81  NULL,
82  NULL,
83  NULL,
84  NULL,
85  NULL,
86  NULL,
87  NULL,
88  NULL,
89  NULL,
90  NULL,
91} ;
92
93struct crl_builtin_function_def_t string_module_function_table[] = {
94  { NULL, 0, NULL },
95} ;
96
97struct crl_builtin_member_def_t string_module_member_table[] = {
98  { 0, NULL },
99} ;
100
101struct crl_type_obj_def_t string_object = {
102  "String",
103  sizeof( crl_string_t ),
104  &crl_obj_string_init,
105  &crl_obj_string_destroy,
106  &crl_obj_string_print,
107  NULL,
108  &string_module_binary_ops,
109  string_module_member_table,
110  string_module_function_table,
111  true,
112} ;
113
114bool crl_obj_string_module_init( crl_context_table * context )
115{
116  bool retval = false;
117  retval = crl_rr_context_intilize_module( &string_object, context );
118  return retval;
119}
Note: See TracBrowser for help on using the browser.