Refactor with new name uclisp
This commit is contained in:
144
src/builtins.c
144
src/builtins.c
@@ -1,6 +1,6 @@
|
||||
#include "nihilispm.h"
|
||||
#include "nihilispm_internal.h"
|
||||
#include "nihilispm_utility.h"
|
||||
#include "uclisp.h"
|
||||
#include "internal.h"
|
||||
#include "utility.h"
|
||||
#include "builtins.h"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -8,131 +8,131 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
LISP_FUNC_0(nl_builtin_hello_world) {
|
||||
return nl_string_create(strdup("Hello, world!"));
|
||||
LISP_FUNC_0(ucl_builtin_hello_world) {
|
||||
return ucl_string_create(strdup("Hello, world!"));
|
||||
}
|
||||
|
||||
LISP_FUNC_1(nl_builtin_type, arg) {
|
||||
LISP_FUNC_1(ucl_builtin_type, arg) {
|
||||
switch (arg->type) {
|
||||
case NL_TYPE_CELL:
|
||||
return nl_symbol_create(strdup("list"));
|
||||
case NL_TYPE_SYMBOL:
|
||||
return nl_symbol_create(strdup("symbol"));
|
||||
case NL_TYPE_INT:
|
||||
return nl_symbol_create(strdup("int"));
|
||||
case NL_TYPE_STRING:
|
||||
return nl_symbol_create(strdup("string"));
|
||||
case NL_TYPE_ERROR:
|
||||
return nl_symbol_create(strdup("error"));
|
||||
case NL_TYPE_COUNT:
|
||||
case UCL_TYPE_CELL:
|
||||
return ucl_symbol_create(strdup("list"));
|
||||
case UCL_TYPE_SYMBOL:
|
||||
return ucl_symbol_create(strdup("symbol"));
|
||||
case UCL_TYPE_INT:
|
||||
return ucl_symbol_create(strdup("int"));
|
||||
case UCL_TYPE_STRING:
|
||||
return ucl_symbol_create(strdup("string"));
|
||||
case UCL_TYPE_ERROR:
|
||||
return ucl_symbol_create(strdup("error"));
|
||||
case UCL_TYPE_COUNT:
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
LISP_FUNC_1(nl_builtin_error, arg) {
|
||||
if (arg->type != NL_TYPE_STRING) {
|
||||
return nl_error_create("Expected type string passed to 'error'");
|
||||
LISP_FUNC_1(ucl_builtin_error, arg) {
|
||||
if (arg->type != UCL_TYPE_STRING) {
|
||||
return ucl_error_create("Expected type string passed to 'error'");
|
||||
}
|
||||
|
||||
return nl_error_create(strdup(arg->error));
|
||||
return ucl_error_create(strdup(arg->error));
|
||||
}
|
||||
|
||||
LISP_FUNC_1(nl_builtin_symbol_p, arg) {
|
||||
return nl_predicate(arg->type == NL_TYPE_SYMBOL);
|
||||
LISP_FUNC_1(ucl_builtin_symbol_p, arg) {
|
||||
return ucl_predicate(arg->type == UCL_TYPE_SYMBOL);
|
||||
}
|
||||
|
||||
LISP_FUNC_1(nl_builtin_string_p, arg) {
|
||||
return nl_predicate(arg->type == NL_TYPE_STRING);
|
||||
LISP_FUNC_1(ucl_builtin_string_p, arg) {
|
||||
return ucl_predicate(arg->type == UCL_TYPE_STRING);
|
||||
}
|
||||
|
||||
LISP_FUNC_1(nl_builtin_int_p, arg) {
|
||||
return nl_predicate(arg->type == NL_TYPE_INT);
|
||||
LISP_FUNC_1(ucl_builtin_int_p, arg) {
|
||||
return ucl_predicate(arg->type == UCL_TYPE_INT);
|
||||
}
|
||||
|
||||
LISP_FUNC_1(nl_builtin_list_p, arg) {
|
||||
return nl_predicate(arg->type == NL_TYPE_CELL);
|
||||
LISP_FUNC_1(ucl_builtin_list_p, arg) {
|
||||
return ucl_predicate(arg->type == UCL_TYPE_CELL);
|
||||
}
|
||||
|
||||
LISP_FUNC_1(nl_builtin_error_p, arg) {
|
||||
return nl_predicate(arg->type == NL_TYPE_ERROR);
|
||||
LISP_FUNC_1(ucl_builtin_error_p, arg) {
|
||||
return ucl_predicate(arg->type == UCL_TYPE_ERROR);
|
||||
}
|
||||
|
||||
LISP_FUNC_1(nl_builtin_car, arg) {
|
||||
return nl_car(arg);
|
||||
LISP_FUNC_1(ucl_builtin_car, arg) {
|
||||
return ucl_car(arg);
|
||||
}
|
||||
|
||||
LISP_FUNC_1(nl_builtin_cdr, arg) {
|
||||
return nl_cdr(arg);
|
||||
LISP_FUNC_1(ucl_builtin_cdr, arg) {
|
||||
return ucl_cdr(arg);
|
||||
}
|
||||
|
||||
LISP_FUNC_2(nl_builtin_add, arg0, arg1) {
|
||||
if (arg0->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 0 to 'add'");
|
||||
LISP_FUNC_2(ucl_builtin_add, arg0, arg1) {
|
||||
if (arg0->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 0 to 'add'");
|
||||
}
|
||||
|
||||
if (arg1->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 1 to 'add'");
|
||||
if (arg1->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 1 to 'add'");
|
||||
}
|
||||
|
||||
return nl_int_create(arg0->integer + arg1->integer);
|
||||
return ucl_int_create(arg0->integer + arg1->integer);
|
||||
}
|
||||
|
||||
LISP_FUNC_2(nl_builtin_sub, arg0, arg1) {
|
||||
if (arg0->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 0 to 'sub'");
|
||||
LISP_FUNC_2(ucl_builtin_sub, arg0, arg1) {
|
||||
if (arg0->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 0 to 'sub'");
|
||||
}
|
||||
|
||||
if (arg1->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 1 to 'sub'");
|
||||
if (arg1->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 1 to 'sub'");
|
||||
}
|
||||
|
||||
return nl_int_create(arg0->integer - arg1->integer);
|
||||
return ucl_int_create(arg0->integer - arg1->integer);
|
||||
}
|
||||
|
||||
LISP_FUNC_2(nl_builtin_mul, arg0, arg1) {
|
||||
if (arg0->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 0 to 'mul'");
|
||||
LISP_FUNC_2(ucl_builtin_mul, arg0, arg1) {
|
||||
if (arg0->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 0 to 'mul'");
|
||||
}
|
||||
|
||||
if (arg1->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 1 to 'mul'");
|
||||
if (arg1->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 1 to 'mul'");
|
||||
}
|
||||
|
||||
return nl_int_create(arg0->integer * arg1->integer);
|
||||
return ucl_int_create(arg0->integer * arg1->integer);
|
||||
}
|
||||
|
||||
LISP_FUNC_2(nl_builtin_div, arg0, arg1) {
|
||||
if (arg0->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 0 to 'div'");
|
||||
LISP_FUNC_2(ucl_builtin_div, arg0, arg1) {
|
||||
if (arg0->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 0 to 'div'");
|
||||
}
|
||||
|
||||
if (arg1->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 1 to 'div'");
|
||||
if (arg1->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 1 to 'div'");
|
||||
}
|
||||
|
||||
return nl_int_create(arg0->integer / arg1->integer);
|
||||
return ucl_int_create(arg0->integer / arg1->integer);
|
||||
}
|
||||
|
||||
LISP_FUNC_2(nl_builtin_mod, arg0, arg1) {
|
||||
if (arg0->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 0 to 'mod'");
|
||||
LISP_FUNC_2(ucl_builtin_mod, arg0, arg1) {
|
||||
if (arg0->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 0 to 'mod'");
|
||||
}
|
||||
|
||||
if (arg1->type != NL_TYPE_INT) {
|
||||
return nl_error_create("Invalid type of argument 1 to 'mod'");
|
||||
if (arg1->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 1 to 'mod'");
|
||||
}
|
||||
|
||||
return nl_int_create(arg0->integer % arg1->integer);
|
||||
return ucl_int_create(arg0->integer % arg1->integer);
|
||||
}
|
||||
|
||||
LISP_FUNC_2(nl_builtin_concat, arg0, arg1) {
|
||||
if (arg0->type != NL_TYPE_STRING) {
|
||||
return nl_error_create("Invalid type of argument 0 to 'concat'");
|
||||
LISP_FUNC_2(ucl_builtin_concat, arg0, arg1) {
|
||||
if (arg0->type != UCL_TYPE_STRING) {
|
||||
return ucl_error_create("Invalid type of argument 0 to 'concat'");
|
||||
}
|
||||
|
||||
if (arg1->type != NL_TYPE_STRING) {
|
||||
return nl_error_create("Invalid type of argument 1 to 'concat'");
|
||||
if (arg1->type != UCL_TYPE_STRING) {
|
||||
return ucl_error_create("Invalid type of argument 1 to 'concat'");
|
||||
}
|
||||
|
||||
int len = strlen(arg0->string) + strlen(arg1->string);
|
||||
@@ -141,10 +141,10 @@ LISP_FUNC_2(nl_builtin_concat, arg0, arg1) {
|
||||
strcat(outstr, arg0->string);
|
||||
strcat(outstr, arg1->string);
|
||||
|
||||
return nl_string_create(outstr);
|
||||
return ucl_string_create(outstr);
|
||||
}
|
||||
|
||||
LISP_FUNC_0(nl_builtin_now_millis_mono) {
|
||||
LISP_FUNC_0(ucl_builtin_now_millis_mono) {
|
||||
// TODO: Implement and move to a 'platform' file
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user