Wire up more builtins and slightly improve printing
This commit is contained in:
@@ -8,10 +8,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
LISP_FUNC_0(ucl_builtin_hello_world) {
|
|
||||||
return ucl_string_create(strdup("Hello, world!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
LISP_FUNC_1(ucl_builtin_type, arg) {
|
LISP_FUNC_1(ucl_builtin_type, arg) {
|
||||||
switch (arg->type) {
|
switch (arg->type) {
|
||||||
case UCL_TYPE_CELL:
|
case UCL_TYPE_CELL:
|
||||||
|
|||||||
@@ -46,7 +46,6 @@
|
|||||||
static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name, struct ucl_object *arg1_name)
|
static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name, struct ucl_object *arg1_name)
|
||||||
|
|
||||||
|
|
||||||
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_error(struct ucl_object *args);
|
||||||
struct ucl_object *ucl_builtin_type(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_symbol_p(struct ucl_object *args);
|
||||||
|
|||||||
25
src/main.c
25
src/main.c
@@ -17,13 +17,32 @@ int main(int argc, const char **argv) {
|
|||||||
ucl_state_put(state, "/", ucl_builtin_create(ucl_builtin_div));
|
ucl_state_put(state, "/", ucl_builtin_create(ucl_builtin_div));
|
||||||
ucl_state_put(state, "%", ucl_builtin_create(ucl_builtin_mod));
|
ucl_state_put(state, "%", ucl_builtin_create(ucl_builtin_mod));
|
||||||
|
|
||||||
|
ucl_state_put(state, "concat", ucl_builtin_create(ucl_builtin_concat));
|
||||||
|
|
||||||
|
ucl_state_put(state, "error", ucl_builtin_create(ucl_builtin_error));
|
||||||
|
ucl_state_put(state, "type", ucl_builtin_create(ucl_builtin_type));
|
||||||
|
ucl_state_put(state, "symbol-p", ucl_builtin_create(ucl_builtin_symbol_p));
|
||||||
|
ucl_state_put(state, "string-p", ucl_builtin_create(ucl_builtin_string_p));
|
||||||
|
ucl_state_put(state, "int-p", ucl_builtin_create(ucl_builtin_int_p));
|
||||||
|
ucl_state_put(state, "list-p", ucl_builtin_create(ucl_builtin_list_p));
|
||||||
|
|
||||||
struct ucl_object *sexp = ucl_parse(argv[1]);
|
struct ucl_object *sexp = ucl_parse(argv[1]);
|
||||||
struct ucl_object *result = ucl_evaluate(state, ucl_car(sexp));
|
struct ucl_object *result = ucl_evaluate(state, ucl_car(sexp));
|
||||||
|
|
||||||
assert(result != NULL);
|
switch (result->type) {
|
||||||
assert(result->type == UCL_TYPE_INT);
|
case UCL_TYPE_INT:
|
||||||
|
|
||||||
printf("%d\n", result->integer);
|
printf("%d\n", result->integer);
|
||||||
|
break;
|
||||||
|
case UCL_TYPE_STRING:
|
||||||
|
printf("\"%s\"\n", result->string);
|
||||||
|
break;
|
||||||
|
case UCL_TYPE_SYMBOL:
|
||||||
|
printf("%s\n", result->string);
|
||||||
|
break;
|
||||||
|
case UCL_TYPE_ERROR:
|
||||||
|
printf("ERROR: %s\n", result->error);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user