Refactor with new name uclisp

This commit is contained in:
2022-10-28 23:19:19 -04:00
parent 26a0d17074
commit d97be8ec4b
22 changed files with 596 additions and 580 deletions

View File

@@ -1,61 +1,66 @@
#include "nihilispm_utility.h"
#ifndef _UCLISP_BUILTINS_H_
#define _UCLISP_BUILTINS_H_
#include "utility.h"
#define LISP_FUNC_0(func_name) \
static struct nl_object *func_name##_impl(); \
struct nl_object *func_name(struct nl_object *args) { \
static struct ucl_object *func_name##_impl(); \
struct ucl_object *func_name(struct ucl_object *args) { \
if (args->cell.car != NULL) { \
return NULL; \
} \
return func_name##_impl(); \
} \
static struct nl_object *func_name##_impl()
static struct ucl_object *func_name##_impl()
#define LISP_FUNC_1(func_name, arg0_name) \
static struct nl_object *func_name##_impl(struct nl_object *arg0_name); \
struct nl_object *func_name(struct nl_object *args) { \
struct nl_object *len_obj = nl_list_length(args); \
if (len_obj->type != NL_TYPE_INT) { \
static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name); \
struct ucl_object *func_name(struct ucl_object *args) { \
struct ucl_object *len_obj = ucl_list_length(args); \
if (len_obj->type != UCL_TYPE_INT) { \
return NULL; \
} \
if (len_obj->integer != 1) { \
return NULL; \
} \
struct nl_object *arg0 = nl_car(args); \
struct ucl_object *arg0 = ucl_car(args); \
return func_name##_impl(arg0); \
} \
static struct nl_object *func_name##_impl(struct nl_object *arg0_name)
static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name)
// TODO: Unroll the args more efficiently, this is O(n^2)
#define LISP_FUNC_2(func_name, arg0_name, arg1_name) \
static struct nl_object *func_name##_impl(struct nl_object *arg0_name, struct nl_object *arg1_name); \
struct nl_object *func_name(struct nl_object *args) { \
struct nl_object *len_obj = nl_list_length(args); \
if (len_obj->type != NL_TYPE_INT) { \
static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name, struct ucl_object *arg1_name); \
struct ucl_object *func_name(struct ucl_object *args) { \
struct ucl_object *len_obj = ucl_list_length(args); \
if (len_obj->type != UCL_TYPE_INT) { \
return NULL; \
} \
if (len_obj->integer != 2) { \
return NULL; \
} \
struct nl_object *arg0 = nl_list_nth(args, 0); \
struct nl_object *arg1 = nl_list_nth(args, 1); \
struct ucl_object *arg0 = ucl_list_nth(args, 0); \
struct ucl_object *arg1 = ucl_list_nth(args, 1); \
return func_name##_impl(arg0, arg1); \
} \
static struct nl_object *func_name##_impl(struct nl_object *arg0_name, struct nl_object *arg1_name)
static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name, struct ucl_object *arg1_name)
struct nl_object *nl_builtin_hello_world(struct nl_object *args);
struct nl_object *nl_builtin_error(struct nl_object *args);
struct nl_object *nl_builtin_type(struct nl_object *args);
struct nl_object *nl_builtin_symbol_p(struct nl_object *args);
struct nl_object *nl_builtin_string_p(struct nl_object *args);
struct nl_object *nl_builtin_int_p(struct nl_object *args);
struct nl_object *nl_builtin_list_p(struct nl_object *args);
struct ucl_object *ucl_builtin_hello_world(struct ucl_object *args);
struct ucl_object *ucl_builtin_error(struct ucl_object *args);
struct ucl_object *ucl_builtin_type(struct ucl_object *args);
struct ucl_object *ucl_builtin_symbol_p(struct ucl_object *args);
struct ucl_object *ucl_builtin_string_p(struct ucl_object *args);
struct ucl_object *ucl_builtin_int_p(struct ucl_object *args);
struct ucl_object *ucl_builtin_list_p(struct ucl_object *args);
struct nl_object *nl_builtin_add(struct nl_object *args);
struct nl_object *nl_builtin_sub(struct nl_object *args);
struct nl_object *nl_builtin_mul(struct nl_object *args);
struct nl_object *nl_builtin_div(struct nl_object *args);
struct nl_object *nl_builtin_mod(struct nl_object *args);
struct nl_object *nl_builtin_concat(struct nl_object *args);
struct ucl_object *ucl_builtin_add(struct ucl_object *args);
struct ucl_object *ucl_builtin_sub(struct ucl_object *args);
struct ucl_object *ucl_builtin_mul(struct ucl_object *args);
struct ucl_object *ucl_builtin_div(struct ucl_object *args);
struct ucl_object *ucl_builtin_mod(struct ucl_object *args);
struct ucl_object *ucl_builtin_concat(struct ucl_object *args);
struct nl_object *nl_builtin_now_millis_mono(struct nl_object *args);
struct ucl_object *ucl_builtin_now_millis_mono(struct ucl_object *args);
#endif