Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Chris Müller
cherry
Commits
6ab26875
Commit
6ab26875
authored
Jul 04, 2013
by
Chris Müller
Browse files
add value implementation for cherry c runtime system
parent
055f63df
Changes
2
Hide whitespace changes
Inline
Side-by-side
runtime/CMakeLists.txt
0 → 100644
View file @
6ab26875
set
(
SOURCES
value.c
)
add_library
(
cherry-runtime SHARED
${
SOURCES
}
)
target_link_libraries
(
cherry-runtime gc
)
runtime/value.c
0 → 100644
View file @
6ab26875
/*
* Cherry programming language
* Copyright (C) 2013 Christoph Mueller
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"cherry/runtime.h"
#include
<gc.h>
// ----------------------------------------------------------------------------
// cherry object constructors
// ----------------------------------------------------------------------------
struct
org_cherry_value
*
__org_cherry_make_fixnum
(
cy_fixnum_t
value
)
{
struct
org_cherry_value
*
cy_value
=
GC_MALLOC
(
sizeof
(
struct
org_cherry_value
));
cy_value
->
meta
.
type
=
CY_FIXNUM
;
cy_value
->
fixnum_value
=
value
;
return
cy_value
;
}
struct
org_cherry_value
*
__org_cherry_make_float
(
cy_float_t
value
)
{
struct
org_cherry_value
*
cy_value
=
GC_MALLOC
(
sizeof
(
struct
org_cherry_value
));
cy_value
->
meta
.
type
=
CY_FLOAT
;
cy_value
->
float_value
=
value
;
return
cy_value
;
}
struct
org_cherry_value
*
__org_cherry_make_string
(
cy_byte_t
*
value
)
{
struct
org_cherry_value
*
cy_value
=
GC_MALLOC
(
sizeof
(
struct
org_cherry_value
));
cy_value
->
meta
.
type
=
CY_STRING
;
cy_value
->
string_value
=
value
;
return
cy_value
;
}
struct
org_cherry_value
*
__org_cherry_make_char
(
cy_unicode_t
value
)
{
struct
org_cherry_value
*
cy_value
=
GC_MALLOC
(
sizeof
(
struct
org_cherry_value
));
cy_value
->
meta
.
type
=
CY_CHAR
;
cy_value
->
char_value
=
value
;
return
cy_value
;
}
// ----------------------------------------------------------------------------
// cherry list operations
// ----------------------------------------------------------------------------
struct
org_cherry_pair
*
__org_cherry_list_cons
(
struct
org_cherry_value
*
head
,
struct
org_cherry_value
*
tail
)
{
struct
org_cherry_pair
*
pair
=
GC_MALLOC
(
sizeof
(
struct
org_cherry_pair
));
pair
->
meta
.
type
=
CY_PAIR
;
pair
->
head
=
head
;
pair
->
tail
=
tail
;
return
pair
;
}
struct
org_cherry_value
*
__org_cherry_list_head
(
struct
org_cherry_pair
*
pair
)
{
return
pair
->
head
;
}
struct
org_cherry_value
*
__org_cherry_list_tail
(
struct
org_cherry_pair
*
pair
)
{
return
pair
->
tail
;
}
struct
org_cherry_value
*
__org_cherry_list_length
(
struct
org_cherry_pair
*
pair
)
{
cy_fixnum_t
length
=
0
;
while
(
pair
->
meta
.
type
==
CY_PAIR
)
{
length
++
;
pair
=
(
struct
org_cherry_pair
*
)
pair
->
tail
;
}
return
__org_cherry_make_fixnum
(
length
);
}
struct
org_cherry_value
*
__org_cherry_primitive_add
(
struct
org_cherry_pair
*
pair
)
{
cy_fixnum_t
result
=
0
;
while
(
pair
->
meta
.
type
==
CY_PAIR
)
{
result
+=
pair
->
head
->
fixnum_value
;
pair
=
(
struct
org_cherry_pair
*
)
pair
->
tail
;
}
return
__org_cherry_make_fixnum
(
result
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment