Commit 3ad75844 authored by Chris Müller's avatar Chris Müller
Browse files

add cons primitive to runtime environment

implement and add cons to the runtime environment.
parent 2341d653
......@@ -22,6 +22,8 @@
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_add(struct org_cherry_environment* env, struct org_cherry_value* args);
struct org_cherry_value* org_cherry_core_sub(struct org_cherry_environment* env, struct org_cherry_value* args);
struct org_cherry_value* org_cherry_core_mul(struct org_cherry_environment* env, struct org_cherry_value* args);
......
......@@ -48,6 +48,18 @@ org_cherry_core_type(struct org_cherry_environment* env, struct org_cherry_value
return org_cherry_false;
}
struct org_cherry_value*
org_cherry_core_cons(struct org_cherry_environment* env, struct org_cherry_value* args)
{
if(IS_NULL(args) || IS_NULL(TAIL(args)) || !IS_NULL(TAIL(TAIL(args))))
org_cherry_env_raise(env, org_cherry_string("cons only accept exactly two parameters"));
TAIL(args) = HEAD(TAIL(args));
return args;
}
struct org_cherry_value*
org_cherry_core_add(struct org_cherry_environment* env, struct org_cherry_value* args)
{
......
......@@ -93,6 +93,7 @@ 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, "cons", org_cherry_core_cons);
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