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
548d84a6
Commit
548d84a6
authored
Jul 17, 2013
by
Chris Müller
Browse files
Add list length primitive to runtime environment
parent
43376d6e
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/cherry/primitives.h
View file @
548d84a6
...
...
@@ -19,18 +19,15 @@
#include "cherry/runtime.h"
#define DECLARE_FUN(Name) \
struct org_cherry_value* Name(struct org_cherry_environment* env, struct org_cherry_value* args)
// org.cherry.core
struct
org_cherry_value
*
org_cherry_core_type
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
struct
org_cherry_value
*
org_cherry_core_raise
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
struct
org_cherry_value
*
org_cherry_core_cons
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
struct
org_cherry_value
*
org_cherry_core_list
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
DECLARE_FUN
(
org_cherry_core_head
);
DECLARE_FUN
(
org_cherry_core_tail
);
struct
org_cherry_value
*
org_cherry_core_head
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
struct
org_cherry_value
*
org_cherry_core_tail
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
struct
org_cherry_value
*
org_cherry_core_length
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
struct
org_cherry_value
*
org_cherry_core_tuple
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
...
...
include/cherry/runtime.h
View file @
548d84a6
...
...
@@ -202,6 +202,8 @@ extern struct org_cherry_value* org_cherry_symbol_catch;
#define IS_SELF_EVALUATING(value) \
(IS_BOOLEAN(value) || IS_FIXNUM(value) || IS_CHAR(value) || IS_STRING(value) || IS_FLOAT(value))
#define IS_LIST(obj) (IS_PAIR(obj) || IS_NULL(obj))
#define IS_VARIABLE(value) \
IS_SYMBOL(value)
...
...
source/primitives/core.c
View file @
548d84a6
...
...
@@ -87,6 +87,23 @@ org_cherry_core_tail(struct org_cherry_environment* env, struct org_cherry_value
}
struct
org_cherry_value
*
org_cherry_core_length
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
)
{
if
(
IS_NULL
(
args
)
||
!
IS_LIST
(
HEAD
(
args
)))
org_cherry_env_raise
(
env
,
org_cherry_string
(
"no list is given for the first operand"
));
struct
org_cherry_value
*
lst
=
HEAD
(
args
);
cy_fixnum_t
length
=
0
;
while
(
!
IS_NULL
(
lst
))
{
length
++
;
lst
=
TAIL
(
lst
);
}
return
org_cherry_fixnum
(
length
);
}
struct
org_cherry_value
*
...
...
source/runtime.c
View file @
548d84a6
...
...
@@ -97,6 +97,7 @@ org_cherry_environment(void)
proc_to_env
(
env
,
"list"
,
org_cherry_core_list
);
proc_to_env
(
env
,
"head"
,
org_cherry_core_head
);
proc_to_env
(
env
,
"tail"
,
org_cherry_core_tail
);
proc_to_env
(
env
,
"length"
,
org_cherry_core_length
);
proc_to_env
(
env
,
"tuple"
,
org_cherry_core_tuple
);
proc_to_env
(
env
,
"exit"
,
org_cherry_system_exit
);
...
...
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