Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Chris Müller
cherry
Commits
487f0053
Commit
487f0053
authored
Jul 20, 2013
by
Chris Müller
Browse files
Add named let as loop to cherry.
parent
5b68b0f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
bootstrap/bootstrap.h
View file @
487f0053
...
...
@@ -186,6 +186,7 @@ extern struct cherry_value* cherry_symbol_define;
extern
struct
cherry_value
*
cherry_symbol_let
;
extern
struct
cherry_value
*
cherry_symbol_lambda
;
extern
struct
cherry_value
*
cherry_symbol_if
;
extern
struct
cherry_value
*
cherry_symbol_loop
;
extern
struct
cherry_value
*
cherry_symbol_begin
;
extern
struct
cherry_value
*
cherry_symbol_try
;
...
...
@@ -251,6 +252,9 @@ struct cherry_value* cherry_system_exit(struct cherry_environment* env, struc
#define IS_LAMBDA(value) \
IS_TAGGED(value, cherry_symbol_lambda)
#define IS_LOOP(value) \
IS_TAGGED(value, cherry_symbol_loop)
#define IS_BEGIN(value) \
IS_TAGGED(value, cherry_symbol_begin)
...
...
bootstrap/read.c
View file @
487f0053
...
...
@@ -689,7 +689,7 @@ cherry_read_pair(struct cherry_context* context)
head
=
cherry_read
(
context
);
tail
=
cherry_read_pair
(
context
);
return
(
struct
cherry_value
*
)
cherry_list_cons
(
head
,
tail
);
return
cherry_list_cons
(
head
,
tail
);
}
static
struct
cherry_value
*
...
...
@@ -754,6 +754,32 @@ cherry_transform_if(struct cherry_value* value)
}
static
struct
cherry_value
*
cherry_transform_loop
(
struct
cherry_value
*
value
)
{
struct
cherry_value
*
name
=
HEAD
(
HEAD
(
value
));
struct
cherry_value
*
args
=
cherry_list_reverse
(
TAIL
(
HEAD
(
value
)));
struct
cherry_value
*
body
=
TAIL
(
value
);
struct
cherry_value
*
params
=
cherry_emptylist
;
struct
cherry_value
*
values
=
cherry_emptylist
;
while
(
!
IS_NULL
(
args
))
{
struct
cherry_value
*
duo
=
HEAD
(
args
);
params
=
cherry_list_cons
(
HEAD
(
duo
),
params
);
values
=
cherry_list_cons
(
HEAD
(
TAIL
(
duo
)),
values
);
args
=
TAIL
(
args
);
}
struct
cherry_value
*
lambda
=
cherry_list_cons
(
cherry_symbol_lambda
,
cherry_list_cons
(
params
,
body
));
struct
cherry_value
*
let
=
cherry_list_cons
(
cherry_symbol_let
,
cherry_list_cons
(
name
,
cherry_list_cons
(
lambda
,
cherry_emptylist
)));
struct
cherry_value
*
app
=
cherry_list_cons
(
name
,
values
);
return
cherry_list_cons
(
cherry_symbol_begin
,
cherry_list_cons
(
let
,
cherry_list_cons
(
app
,
cherry_emptylist
)));
}
static
struct
cherry_value
*
cherry_transform
(
struct
cherry_value
*
value
)
{
...
...
@@ -763,7 +789,9 @@ cherry_transform(struct cherry_value* value)
return
cherry_transform_define
(
TAIL
(
value
));
else
if
(
IS_IF
(
value
))
return
cherry_transform_if
(
value
);
else
else
if
(
IS_LOOP
(
value
))
{
return
cherry_transform_loop
(
TAIL
(
value
));
}
else
return
value
;
}
...
...
@@ -829,5 +857,6 @@ cherry_read(struct cherry_context* context)
return
0
;
RETURN_VALUE:
return
cherry_transform
(
value
);
}
bootstrap/runtime.c
View file @
487f0053
...
...
@@ -35,6 +35,7 @@ struct cherry_value* cherry_symbol_let;
struct
cherry_value
*
cherry_symbol_lambda
;
struct
cherry_value
*
cherry_symbol_if
;
struct
cherry_value
*
cherry_symbol_quote
;
struct
cherry_value
*
cherry_symbol_loop
;
struct
cherry_value
*
cherry_symbol_try
;
struct
cherry_value
*
cherry_symbol_begin
;
...
...
@@ -66,6 +67,7 @@ cherry_initialize(struct cherry_value* arguments)
cherry_symbol_let
=
cherry_symbol
(
"let"
);
cherry_symbol_lambda
=
cherry_symbol
(
"lambda"
);
cherry_symbol_if
=
cherry_symbol
(
"if"
);
cherry_symbol_loop
=
cherry_symbol
(
"loop"
);
cherry_symbol_begin
=
cherry_symbol
(
"begin"
);
cherry_symbol_catch
=
cherry_symbol
(
"catch"
);
cherry_symbol_try
=
cherry_symbol
(
"try"
);
...
...
Write
Preview
Markdown
is supported
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