Commit 43376d6e authored by Chris Müller's avatar Chris Müller
Browse files

Add list, head and tail to the runtime environment

parent 5f852e4a
......@@ -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);
......@@ -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)
{
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment