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
f50e061f
Commit
f50e061f
authored
Jul 07, 2013
by
Chris Müller
Browse files
add first print functions for cherry values
parent
add85075
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/cherry/runtime.h
View file @
f50e061f
...
...
@@ -111,15 +111,16 @@ struct org_cherry_value* org_cherry_primitive_add(struct org_cherry_pair* pai
// Symboltables
// ----------------------------------------------------------------------------
struct
org_cherry_symbol
table
;
struct
org_cherry_symbol
list
;
struct
org_cherry_symbol
table
*
org_cherry_symbol
table
(
void
);
struct
org_cherry_value
*
org_cherry_symbollist_get
(
struct
org_cherry_symbol
table
*
table
,
cy_byte_t
*
name
);
struct
org_cherry_symbol
list
*
org_cherry_symbol
list
(
void
);
struct
org_cherry_value
*
org_cherry_symbollist_get
(
struct
org_cherry_symbol
list
*
table
,
cy_byte_t
*
name
);
extern
struct
org_cherry_symbol
table
*
org_cherry_global_symbol
table
;
extern
struct
org_cherry_symbol
list
*
org_cherry_global_symbol
list
;
extern
struct
org_cherry_value
*
org_cherry_symbol_emptylist
;
extern
struct
org_cherry_value
*
org_cherry_symbol_true
;
extern
struct
org_cherry_value
*
org_cherry_symbol_false
;
extern
struct
org_cherry_value
*
org_cherry_symbol_quote
;
extern
struct
org_cherry_value
*
org_cherry_symbol_define
;
extern
struct
org_cherry_value
*
org_cherry_symbol_lambda
;
extern
struct
org_cherry_value
*
org_cherry_symbol_if
;
...
...
@@ -137,6 +138,13 @@ extern struct org_cherry_value* org_cherry_symbol_else;
#define IS_VARIABLE(value) \
IS_SYMBOL(value)
// ----------------------------------------------------------------------------
// Print
// ----------------------------------------------------------------------------
void
org_cherry_print
(
FILE
*
out
,
struct
org_cherry_value
*
value
);
// ----------------------------------------------------------------------------
// Default
// ----------------------------------------------------------------------------
...
...
source/tables.c
View file @
f50e061f
...
...
@@ -35,9 +35,9 @@ struct RbNode {
struct
RbNode
*
right
;
};
struct
org_cherry_symbol
table
{
struct
org_cherry_symbol
list
{
struct
RbNode
*
root
;
struct
org_cherry_symbol
table
*
parent
;
struct
org_cherry_symbol
list
*
parent
;
};
...
...
@@ -141,7 +141,7 @@ rbnode_trinode_restructering(struct RbNode* node)
static
void
rbnode_remedy_double_red
(
struct
org_cherry_symbol
table
*
tree
,
struct
RbNode
*
node_z
)
rbnode_remedy_double_red
(
struct
org_cherry_symbol
list
*
tree
,
struct
RbNode
*
node_z
)
{
assert
(
tree
!=
0
&&
node_z
!=
0
);
...
...
@@ -177,7 +177,7 @@ rbnode_remedy_double_red(struct org_cherry_symboltable* tree, struct RbNode* nod
static
void
rbnode_remedey_double_black
(
struct
org_cherry_symbol
table
*
tree
,
struct
RbNode
*
node_x
,
struct
RbNode
*
node_r
)
rbnode_remedey_double_black
(
struct
org_cherry_symbol
list
*
tree
,
struct
RbNode
*
node_x
,
struct
RbNode
*
node_r
)
{
assert
(
node_x
!=
0
);
...
...
@@ -243,10 +243,10 @@ rbnode_remedey_double_black(struct org_cherry_symboltable* tree, struct RbNode*
}
struct
org_cherry_symbol
table
*
org_cherry_symbol
table
(
void
)
struct
org_cherry_symbol
list
*
org_cherry_symbol
list
(
void
)
{
struct
org_cherry_symbol
table
*
s
=
GC_MALLOC
(
sizeof
(
struct
org_cherry_symbol
table
));
struct
org_cherry_symbol
list
*
s
=
GC_MALLOC
(
sizeof
(
struct
org_cherry_symbol
list
));
s
->
root
=
0
;
s
->
parent
=
0
;
return
s
;
...
...
@@ -288,7 +288,7 @@ string_compare(cy_byte_t* A, cy_byte_t* B)
struct
org_cherry_value
*
org_cherry_symbollist_get
(
struct
org_cherry_symbol
table
*
tree
,
cy_byte_t
*
name
)
org_cherry_symbollist_get
(
struct
org_cherry_symbol
list
*
tree
,
cy_byte_t
*
name
)
{
assert
(
tree
!=
0
&&
name
!=
0
);
...
...
source/value.c
View file @
f50e061f
...
...
@@ -25,11 +25,18 @@
// globals
// ----------------------------------------------------------------------------
struct
org_cherry_symbol
table
*
org_cherry_global_symbol
table
;
struct
org_cherry_symbol
list
*
org_cherry_global_symbol
list
;
struct
org_cherry_value
*
org_cherry_symbol_emptylist
;
struct
org_cherry_value
*
org_cherry_symbol_true
;
struct
org_cherry_value
*
org_cherry_symbol_false
;
struct
org_cherry_value
*
org_cherry_symbol_define
;
struct
org_cherry_value
*
org_cherry_symbol_lambda
;
struct
org_cherry_value
*
org_cherry_symbol_cond
;
struct
org_cherry_value
*
org_cherry_symbol_if
;
struct
org_cherry_value
*
org_cherry_symbol_else
;
struct
org_cherry_value
*
org_cherry_symbol_quote
;
// ----------------------------------------------------------------------------
// cherry object constructors
...
...
@@ -150,7 +157,7 @@ org_cherry_primitive_add(struct org_cherry_pair* pair)
void
org_cherry_initialize
(
struct
org_cherry_pair
*
arguments
)
{
org_cherry_global_symbol
table
=
org_cherry_symbol
table
();
org_cherry_global_symbol
list
=
org_cherry_symbol
list
();
org_cherry_symbol_true
=
org_cherry_value_alloc
();
org_cherry_symbol_true
->
meta
.
type
=
CY_BOOLEAN
;
...
...
@@ -163,9 +170,100 @@ org_cherry_initialize(struct org_cherry_pair* arguments)
org_cherry_symbol_emptylist
=
org_cherry_value_alloc
();
org_cherry_symbol_emptylist
->
meta
.
type
=
CY_EMPTYLIST
;
org_cherry_symbol_define
=
org_cherry_symbol
(
"quote"
);
org_cherry_symbol_define
=
org_cherry_symbol
(
"define"
);
org_cherry_symbol_lambda
=
org_cherry_symbol
(
"lambda"
);
org_cherry_symbol_if
=
org_cherry_symbol
(
"if"
);
org_cherry_symbol_cond
=
org_cherry_symbol
(
"cond"
);
org_cherry_symbol_else
=
org_cherry_symbol
(
"else"
);
}
// ----------------------------------------------------------------------------
// Print
// ----------------------------------------------------------------------------
static
void
print_pair
(
FILE
*
out
,
struct
org_cherry_pair
*
value
)
{
org_cherry_value
*
head
=
HEAD
(
value
);
org_cherry_value
*
tail
=
TAIL
(
value
);
org_cherry_print
(
out
,
head
);
if
(
IS_PAIR
(
tail
))
{
fprintf
(
out
,
" "
);
print_pair
(
out
,
tail
);
}
else
if
(
IS_NULL
(
tail
))
{
return
;
}
else
{
fprintf
(
out
,
" . "
);
org_cherry_print
(
out
,
tail
);
}
}
void
org_cherry_print
(
FILE
*
out
,
struct
org_cherry_pair
*
value
)
{
cy_byte_t
*
p
;
switch
(
value
->
meta
.
type
)
{
case
CY_EMPTYLIST
:
fprintf
(
out
,
"()"
);
break
;
case
CY_BOOLEAN
:
fprintf
(
out
,
(
value
->
boolean_value
)
?
"true"
:
"false"
);
break
;
case
CY_SYMBOL
:
fprintf
(
out
,
"%s"
,
value
->
symbol_value
);
break
;
case
CY_FIXNUM
:
fprintf
(
out
,
"%ld"
,
value
->
fixnum_value
);
break
;
case
CY_FLOAT
:
fprintf
(
out
,
"%lf"
,
value
->
float_value
);
break
;
case
CY_CHAR
:
fprintf
(
out
,
"
\\
"
);
switch
(
value
->
char_value
)
{
case
'\n'
:
fprintf
(
out
,
"newline"
);
break
case
' '
:
fprintf
(
out
,
"space"
);
break
;
default:
fprintf
(
out
,
"%c"
,
value
->
char_value
);
}
break
;
case
CY_STRING
:
p
=
value
->
string_value
;
fprintf
(
out
,
"
\"
"
);
while
(
*
p
!=
'\0'
)
{
switch
(
*
p
)
{
case
'\n'
:
fprintf
(
out
,
"
\\
n"
);
break
;
case
'\\'
:
fprintf
(
out
,
"
\\
"
);
break
;
case
'\"'
:
fprintf
(
out
,
"
\\\"
"
);
break
;
default:
fprintf
(
out
,
"%c"
,
*
p
);
}
p
++
;
}
fprintf
(
out
,
"
\"
"
);
break
;
case
CY_PAIR
:
fprintf
(
out
,
"("
);
print_pair
(
value
);
fprintf
(
out
,
")"
);
break
;
default:
fprintf
(
stderr
,
"cannot write unknown type
\n
"
);
break
;
}
}
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