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
43376d6e
Commit
43376d6e
authored
Jul 17, 2013
by
Chris Müller
Browse files
Add list, head and tail to the runtime environment
parent
5f852e4a
Changes
3
Show whitespace changes
Inline
Side-by-side
include/cherry/primitives.h
View file @
43376d6e
...
...
@@ -19,10 +19,18 @@
#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_tuple
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
...
...
@@ -31,7 +39,9 @@ struct org_cherry_value* org_cherry_core_sub(struct org_cherry_environment* e
struct
org_cherry_value
*
org_cherry_core_mul
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
struct
org_cherry_value
*
org_cherry_core_div
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
// org.cherry.io
struct
org_cherry_value
*
org_cherry_io_println
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
// org.cherry.system
struct
org_cherry_value
*
org_cherry_system_exit
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
);
source/primitives/core.c
View file @
43376d6e
...
...
@@ -43,6 +43,8 @@ org_cherry_core_type(struct org_cherry_environment* env, struct org_cherry_value
return
org_cherry_symbol
(
"#primitive"
);
case
CY_PAIR
:
return
org_cherry_symbol
(
"#pair"
);
case
CY_TUPLE
:
return
org_cherry_symbol
(
"#tuple"
);
}
return
org_cherry_false
;
...
...
@@ -60,6 +62,33 @@ org_cherry_core_cons(struct org_cherry_environment* env, struct org_cherry_value
}
struct
org_cherry_value
*
org_cherry_core_list
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
)
{
return
args
;
}
struct
org_cherry_value
*
org_cherry_core_head
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
)
{
if
(
IS_NULL
(
args
)
||
!
IS_PAIR
(
HEAD
(
args
)))
org_cherry_env_raise
(
env
,
org_cherry_string
(
"no list is given for the first operand"
));
return
HEAD
(
HEAD
(
args
));
}
struct
org_cherry_value
*
org_cherry_core_tail
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
)
{
if
(
IS_NULL
(
args
)
||
!
IS_PAIR
(
HEAD
(
args
)))
org_cherry_env_raise
(
env
,
org_cherry_string
(
"no list is given for the first operand"
));
return
TAIL
(
HEAD
(
args
));
}
struct
org_cherry_value
*
org_cherry_core_tuple
(
struct
org_cherry_environment
*
env
,
struct
org_cherry_value
*
args
)
{
...
...
source/runtime.c
View file @
43376d6e
...
...
@@ -93,8 +93,11 @@ org_cherry_environment(void)
proc_to_env
(
env
,
"-"
,
org_cherry_core_sub
);
proc_to_env
(
env
,
"*"
,
org_cherry_core_mul
);
proc_to_env
(
env
,
"/"
,
org_cherry_core_div
);
proc_to_env
(
env
,
"tuple"
,
org_cherry_core_tuple
);
proc_to_env
(
env
,
"cons"
,
org_cherry_core_cons
);
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
,
"tuple"
,
org_cherry_core_tuple
);
proc_to_env
(
env
,
"exit"
,
org_cherry_system_exit
);
return
env
;
...
...
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