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
d53e1fc8
Commit
d53e1fc8
authored
Jul 09, 2013
by
Chris Müller
Browse files
extend runtime environment and evaluation for characters
parent
e605af77
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/cherry/runtime.h
View file @
d53e1fc8
...
...
@@ -93,12 +93,8 @@ struct org_cherry_pair {
#define TAIL(pair) pair->tail
struct
org_cherry_pair
*
org_cherry_list_cons
(
struct
org_cherry_value
*
head
,
struct
org_cherry_value
*
tail
);
struct
org_cherry_value
*
org_cherry_list_head
(
struct
org_cherry_pair
*
pair
);
struct
org_cherry_value
*
org_cherry_list_tail
(
struct
org_cherry_pair
*
pair
);
struct
org_cherry_value
*
org_cherry_list_length
(
struct
org_cherry_pair
*
pair
);
struct
org_cherry_value
*
org_cherry_primitive_add
(
struct
org_cherry_pair
*
pair
);
// ----------------------------------------------------------------------------
// Symboltables
...
...
@@ -126,12 +122,6 @@ extern struct org_cherry_value* org_cherry_symbol_if;
extern
struct
org_cherry_value
*
org_cherry_symbol_cond
;
extern
struct
org_cherry_value
*
org_cherry_symbol_else
;
// ----------------------------------------------------------------------------
// Structure
// ----------------------------------------------------------------------------
struct
org_cherry_pair
*
org_cherry_application
(
struct
org_cherry_value
*
operator
,
struct
org_cherry_value
*
operands
);
// ----------------------------------------------------------------------------
...
...
source/value.c
View file @
d53e1fc8
...
...
@@ -90,7 +90,28 @@ org_cherry_float_from_string(const cy_byte_t* str)
struct
org_cherry_value
*
org_cherry_char_from_string
(
const
cy_byte_t
*
str
)
{
return
0
;
if
(
org_cherry_utf8_compare
(
str
+
1
,
"newline"
)
==
0
)
return
org_cherry_char
(
'\n'
);
else
if
(
org_cherry_utf8_compare
(
str
+
1
,
"null"
)
==
0
)
return
org_cherry_char
(
'\0'
);
else
if
(
org_cherry_utf8_compare
(
str
+
1
,
"bell"
)
==
0
)
return
org_cherry_char
(
'\a'
);
else
if
(
org_cherry_utf8_compare
(
str
+
1
,
"backspace"
)
==
0
)
return
org_cherry_char
(
'\b'
);
else
if
(
org_cherry_utf8_compare
(
str
+
1
,
"formfeed"
)
==
0
)
return
org_cherry_char
(
'\f'
);
else
if
(
org_cherry_utf8_compare
(
str
+
1
,
"space"
)
==
0
)
return
org_cherry_char
(
' '
);
else
if
(
org_cherry_utf8_compare
(
str
+
1
,
"return"
)
==
0
)
return
org_cherry_char
(
'\r'
);
else
if
(
org_cherry_utf8_compare
(
str
+
1
,
"tab"
)
==
0
)
return
org_cherry_char
(
'\t'
);
else
if
(
org_cherry_utf8_compare
(
str
+
1
,
"vtab"
)
==
0
)
return
org_cherry_char
(
'\v'
);
// TODO: \uFFFF \UFFFFFF
return
org_cherry_char
(
org_cherry_utf8_get
(
str
+
1
));
}
struct
org_cherry_value
*
...
...
@@ -106,6 +127,7 @@ org_cherry_string_from_string(const cy_byte_t* str)
cy_byte_t
*
s
=
p
;
cy_byte_t
buffer
[
7
];
cy_unicode_t
c
;
int
len
;
while
(
*
str
!=
'\0'
)
{
if
(
*
str
==
'\\'
)
{
...
...
@@ -141,14 +163,20 @@ org_cherry_string_from_string(const cy_byte_t* str)
memcpy
(
buffer
,
str
+
2
,
4
);
buffer
[
4
]
=
'\0'
;
c
=
strtol
(
buffer
,
0
,
16
);
str
+=
4
;
break
;
len
=
org_cherry_unicode_to_utf8
(
buffer
,
c
);
memcpy
(
s
,
buffer
,
len
);
str
+=
6
;
s
+=
len
;
continue
;
case
'U'
:
memcpy
(
buffer
,
str
+
2
,
6
);
buffer
[
6
]
=
'\0'
;
c
=
strtol
(
buffer
,
0
,
16
);
str
+=
6
;
break
;
len
=
org_cherry_unicode_to_utf8
(
buffer
,
c
);
memcpy
(
s
,
buffer
,
len
);
str
+=
8
;
s
+=
len
;
continue
;
}
str
++
;
}
else
{
...
...
@@ -254,32 +282,6 @@ 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_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_fixnum
(
result
);
}
void
org_cherry_initialize
(
struct
org_cherry_pair
*
arguments
)
...
...
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