diff --git a/.gitignore b/.gitignore
index 0bfda7b..0eb8c0b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,14 @@
*~
*.a
.build/
+.build_cc_asan
+.build_cc_cov
+.build_cc_debug
+.build_cc_main
+.build_ld_asan
+.build_ld_cov
+.build_ld_debug
+.build_ld_main
/c3-*/
/c3-*.tar.gz
c3c/c3c
diff --git a/.ic3_history b/.ic3_history
index af224cc..94de646 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -1,6 +1,3 @@
-dt(200)
-def dt = macro (x) do
- quote do
x = unquote x
def dt = macro (x) do
quote do
@@ -97,3 +94,6 @@ do end
defmodule Plop do end
quote Plop
quote_cfn Plop
+type(voidÃ
+)
+type(void)
diff --git a/config.subr b/config.subr
index 6949efd..f01736f 100644
--- a/config.subr
+++ b/config.subr
@@ -17,43 +17,43 @@ cd "$(dirname "$0")"
build_lib() {
echo >> ${CONFIG_MK}
- echo "$LIB: $OBJECTS .build/ld_main" >> ${CONFIG_MK}
- echo " .build/ld_main $LIB" >> ${CONFIG_MK}
+ echo "$LIB_ASAN: $OBJECTS_ASAN .build_ld_asan" >> ${CONFIG_MK}
+ echo " ./.build_ld_asan $LIB_ASAN" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
- echo "$LIB_ASAN: $OBJECTS_ASAN .build/ld_asan" >> ${CONFIG_MK}
- echo " .build/ld_asan $LIB_ASAN" >> ${CONFIG_MK}
+ echo "$LIB_COV: $OBJECTS_COV .build_ld_cov" >> ${CONFIG_MK}
+ echo " ./.build_ld_cov $LIB_COV" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
- echo "$LIB_COV: $OBJECTS_COV .build/ld_cov" >> ${CONFIG_MK}
- echo " .build/ld_cov $LIB_COV" >> ${CONFIG_MK}
+ echo "$LIB_DEBUG: $OBJECTS_DEBUG .build_ld_debug" >> ${CONFIG_MK}
+ echo " ./.build_ld_debug $LIB_DEBUG" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
- echo "$LIB_DEBUG: $OBJECTS_DEBUG .build/ld_debug" >> ${CONFIG_MK}
- echo " .build/ld_debug $LIB_DEBUG" >> ${CONFIG_MK}
+ echo "$LIB: $OBJECTS .build_ld_main" >> ${CONFIG_MK}
+ echo " ./.build_ld_main $LIB" >> ${CONFIG_MK}
}
build_lo() {
for SRC in $SOURCES; do
echo >> ${CONFIG_MK}
SRC_ASAN_LO="$(c2ext .asan.lo "$SRC")"
- c_ext_rule .asan.lo "$SRC" .build/cc_asan >> ${CONFIG_MK}
- echo " .build/cc_asan $SRC $SRC_ASAN_LO" >> ${CONFIG_MK}
+ c_ext_rule .asan.lo "$SRC" .build_cc_asan >> ${CONFIG_MK}
+ echo " ./.build_cc_asan $SRC $SRC_ASAN_LO" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
- c_ext_rule .cov.lo "$SRC" .build/cc_cov >> ${CONFIG_MK}
- echo " .build/cc_cov $SRC $SRC_COV_LO" >> ${CONFIG_MK}
+ c_ext_rule .cov.lo "$SRC" .build_cc_cov >> ${CONFIG_MK}
+ echo " ./.build_cc_cov $SRC $SRC_COV_LO" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
SRC_DEBUG_LO="$(c2ext .debug.lo "$SRC")"
- c_ext_rule .debug.lo "$SRC" .build/cc_debug >> ${CONFIG_MK}
- echo " .build/cc_debug $SRC $SRC_DEBUG_LO" >> ${CONFIG_MK}
+ c_ext_rule .debug.lo "$SRC" .build_cc_debug >> ${CONFIG_MK}
+ echo " ./.build_cc_debug $SRC $SRC_DEBUG_LO" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
SRC_LO="$(c2ext .main.lo "$SRC")"
- c_ext_rule .main.lo "$SRC" .build/cc_main >> ${CONFIG_MK}
- echo " .build/cc_main $SRC $SRC_LO" >> ${CONFIG_MK}
+ c_ext_rule .main.lo "$SRC" .build_cc_main >> ${CONFIG_MK}
+ echo " ./.build_cc_main $SRC $SRC_LO" >> ${CONFIG_MK}
done
}
@@ -61,47 +61,45 @@ build_lo_objc() {
for SRC in $OBJC_SOURCES; do
echo >> ${CONFIG_MK}
SRC_LO="$(objc2ext .main.lo "$SRC")"
- objc_ext_rule .main.lo "$SRC" .build/objcc_main >> ${CONFIG_MK}
- echo " .build/objcc_main $SRC $SRC_LO" >> ${CONFIG_MK}
+ objc_ext_rule .main.lo "$SRC" .build_objcc_main >> ${CONFIG_MK}
+ echo " ./.build_objcc_main $SRC $SRC_LO" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
SRC_LO="$(objc2ext .asan.lo "$SRC")"
- objc_ext_rule .asan.lo "$SRC" .build/objcc_asan >> ${CONFIG_MK}
- echo " .build/objcc_asan $SRC $SRC_LO" >> ${CONFIG_MK}
+ objc_ext_rule .asan.lo "$SRC" .build_objcc_asan >> ${CONFIG_MK}
+ echo " ./.build_objcc_asan $SRC $SRC_LO" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
SRC_LO="$(objc2ext .cov.lo "$SRC")"
- objc_ext_rule .cov.lo "$SRC" .build/objcc_cov >> ${CONFIG_MK}
- echo " .build/objcc_cov $SRC $SRC_LO" >> ${CONFIG_MK}
+ objc_ext_rule .cov.lo "$SRC" .build_objcc_cov >> ${CONFIG_MK}
+ echo " ./.build_objcc_cov $SRC $SRC_LO" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
SRC_LO="$(objc2ext .debug.lo "$SRC")"
- objc_ext_rule .debug.lo "$SRC" .build/objcc_debug >> ${CONFIG_MK}
- echo " .build/objcc_debug $SRC $SRC_LO" >> ${CONFIG_MK}
+ objc_ext_rule .debug.lo "$SRC" .build_objcc_debug >> ${CONFIG_MK}
+ echo " ./.build_objcc_debug $SRC $SRC_LO" >> ${CONFIG_MK}
done
}
build_prog() {
echo >> ${CONFIG_MK}
- echo "$PROG_ASAN: $LOCAL_LIBS_ASAN $OBJECTS_ASAN .build/ld_asan" \
+ echo "$PROG_ASAN: $LOCAL_LIBS_ASAN $OBJECTS_ASAN .build_ld_asan" \
>> ${CONFIG_MK}
- echo " .build/ld_asan $PROG_ASAN" >> ${CONFIG_MK}
+ echo " ./.build_ld_asan $PROG_ASAN" >> ${CONFIG_MK}
- if $HAVE_GCOV; then
- echo >> ${CONFIG_MK}
- echo "$PROG_COV: $LOCAL_LIBS_COV $OBJECTS_COV .build/ld_cov" \
- >> ${CONFIG_MK}
- echo " .build/ld_cov $PROG_COV" >> ${CONFIG_MK}
- fi
+ echo >> ${CONFIG_MK}
+ echo "$PROG_COV: $LOCAL_LIBS_COV $OBJECTS_COV .build_ld_cov" \
+ >> ${CONFIG_MK}
+ echo " ./.build_ld_cov $PROG_COV" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
- echo "$PROG_DEBUG: $LOCAL_LIBS_DEBUG $OBJECTS_DEBUG .build/ld_debug" \
+ echo "$PROG_DEBUG: $LOCAL_LIBS_DEBUG $OBJECTS_DEBUG .build_ld_debug" \
>> ${CONFIG_MK}
- echo " .build/ld_debug $PROG_DEBUG" >> ${CONFIG_MK}
+ echo " ./.build_ld_debug $PROG_DEBUG" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
- echo "$PROG: $LOCAL_LIBS $OBJECTS .build/ld_main" >> ${CONFIG_MK}
- echo " .build/ld_main $PROG" >> ${CONFIG_MK}
+ echo "$PROG: $LOCAL_LIBS $OBJECTS .build_ld_main" >> ${CONFIG_MK}
+ echo " ./.build_ld_main $PROG" >> ${CONFIG_MK}
}
c_o_rule() {
@@ -440,10 +438,10 @@ update_and_chmod() {
}
update_build() {
- CC_MAIN=.build/cc_main.tmp
- CC_ASAN=.build/cc_asan.tmp
- CC_COV=.build/cc_cov.tmp
- CC_DEBUG=.build/cc_debug.tmp
+ CC_MAIN=.build_cc_main.tmp
+ CC_ASAN=.build_cc_asan.tmp
+ CC_COV=.build_cc_cov.tmp
+ CC_DEBUG=.build_cc_debug.tmp
mkdir -p .build
COMPILE="${LIBTOOL} --tag=CC --mode=compile"
@@ -457,7 +455,7 @@ update_build() {
echo "CPPFLAGS=\"${CPPFLAGS_ASAN}\"" >> ${CC_ASAN}
echo "CFLAGS=\"${CFLAGS_ASAN}\"" >> ${CC_ASAN}
echo "$COMPILE > \"\$LOG\" 2>&1 || $COMPILE" >> ${CC_ASAN}
- update_and_chmod 755 ${CC_ASAN} .build/cc_asan
+ update_and_chmod 755 ${CC_ASAN} .build_cc_asan
echo "#!/bin/sh" >> ${CC_COV}
echo "# gen by configure" >> ${CC_COV}
@@ -466,7 +464,7 @@ update_build() {
echo "CPPFLAGS=\"${CPPFLAGS_COV}\"" >> ${CC_COV}
echo "CFLAGS=\"${CFLAGS_COV}\"" >> ${CC_COV}
echo "$COMPILE > \"\$LOG\" 2>&1 || $COMPILE" >> ${CC_COV}
- update_and_chmod 755 ${CC_COV} .build/cc_cov
+ update_and_chmod 755 ${CC_COV} .build_cc_cov
echo "#!/bin/sh" >> ${CC_DEBUG}
echo "# gen by configure" >> ${CC_DEBUG}
@@ -475,7 +473,7 @@ update_build() {
echo "CPPFLAGS=\"${CPPFLAGS_DEBUG}\"" >> ${CC_DEBUG}
echo "CFLAGS=\"${CFLAGS_DEBUG}\"" >> ${CC_DEBUG}
echo "$COMPILE > \"\$LOG\" 2>&1 || $COMPILE" >> ${CC_DEBUG}
- update_and_chmod 755 ${CC_DEBUG} .build/cc_debug
+ update_and_chmod 755 ${CC_DEBUG} .build_cc_debug
echo "#!/bin/sh" >> ${CC_MAIN}
echo "# gen by configure" >> ${CC_MAIN}
@@ -484,70 +482,74 @@ update_build() {
echo "CPPFLAGS=\"${CPPFLAGS}\"" >> ${CC_MAIN}
echo "CFLAGS=\"${CFLAGS}\"" >> ${CC_MAIN}
echo "$COMPILE > \"\$LOG\" 2>&1 || $COMPILE" >> ${CC_MAIN}
- update_and_chmod 755 ${CC_MAIN} .build/cc_main
+ update_and_chmod 755 ${CC_MAIN} .build_cc_main
}
update_build_lib() {
- LD_MAIN=.build/ld_main.tmp
- LD_ASAN=.build/ld_asan.tmp
- LD_COV=.build/ld_cov.tmp
- LD_DEBUG=.build/ld_debug.tmp
+ LD_MAIN=.build_ld_main.tmp
+ LD_ASAN=.build_ld_asan.tmp
+ LD_COV=.build_ld_cov.tmp
+ LD_DEBUG=.build_ld_debug.tmp
mkdir -p .build
- LINK="${LIBTOOL} --tag=CC --mode=link"
- LINK="$LINK \${CC} -shared \${LDFLAGS} \${OBJECTS} \${LIBS}"
- LINK="$LINK -rpath ${LIBDIR} -o \"\$1\""
+ LINK="${LIBTOOL} --tag=CC --mode=link "
+ LINK="$LINK \${CC} -shared \${CFLAGS} \${LDFLAGS}"
+ LINK="$LINK \${OBJECTS} \${LIBS} -rpath ${LIBDIR} -o \"\$1\""
echo "#!/bin/sh" >> ${LD_ASAN}
echo "# gen by configure" >> ${LD_ASAN}
echo "LOG=\".build/\$1.asan.log\"" >> ${LD_ASAN}
echo "CC=\"${CC}\"" >> ${LD_ASAN}
+ echo "CFLAGS=\"${CFLAGS_ASAN}\"" >> ${LD_ASAN}
echo "LDFLAGS=\"${LDFLAGS_ASAN}\"" >> ${LD_ASAN}
echo "OBJECTS=\"${OBJECTS_ASAN}\"" >> ${LD_ASAN}
echo "LIBS=\"${LIBS_ASAN}\"" >> ${LD_ASAN}
echo >> ${LD_ASAN}
echo "$LINK > \"\$LOG\" 2>&1 || $LINK" >> ${LD_ASAN}
- update_and_chmod 755 ${LD_ASAN} .build/ld_asan
+ update_and_chmod 755 ${LD_ASAN} .build_ld_asan
echo "#!/bin/sh" >> ${LD_COV}
echo "# gen by configure" >> ${LD_COV}
echo "LOG=\".build/\$1.cov.log\"" >> ${LD_COV}
echo "CC=\"${CC}\"" >> ${LD_COV}
+ echo "CFLAGS=\"${CFLAGS_COV}\"" >> ${LD_COV}
echo "LDFLAGS=\"${LDFLAGS_COV}\"" >> ${LD_COV}
echo "OBJECTS=\"${OBJECTS_COV}\"" >> ${LD_COV}
echo "LIBS=\"${LIBS_COV}\"" >> ${LD_COV}
echo >> ${LD_COV}
echo "$LINK > \"\$LOG\" 2>&1 || $LINK" >> ${LD_COV}
- update_and_chmod 755 ${LD_COV} .build/ld_cov
+ update_and_chmod 755 ${LD_COV} .build_ld_cov
echo "#!/bin/sh" >> ${LD_DEBUG}
echo "# gen by configure" >> ${LD_DEBUG}
echo "LOG=\".build/\$1.debug.log\"" >> ${LD_DEBUG}
echo "CC=\"${CC}\"" >> ${LD_DEBUG}
+ echo "CFLAGS=\"${CFLAGS_DEBUG}\"" >> ${LD_DEBUG}
echo "LDFLAGS=\"${LDFLAGS_DEBUG}\"" >> ${LD_DEBUG}
echo "OBJECTS=\"${OBJECTS_DEBUG}\"" >> ${LD_DEBUG}
echo "LIBS=\"${LIBS_DEBUG}\"" >> ${LD_DEBUG}
echo >> ${LD_DEBUG}
echo "$LINK > \"\$LOG\" 2>&1 || $LINK" >> ${LD_DEBUG}
- update_and_chmod 755 ${LD_DEBUG} .build/ld_debug
+ update_and_chmod 755 ${LD_DEBUG} .build_ld_debug
echo "#!/bin/sh" >> ${LD_MAIN}
echo "# gen by configure" >> ${LD_MAIN}
echo "LOG=\".build/\$1.main.log\"" >> ${LD_MAIN}
echo "CC=\"${CC}\"" >> ${LD_MAIN}
+ echo "CFLAGS=\"${CFLAGS}\"" >> ${LD_MAIN}
echo "LDFLAGS=\"${LDFLAGS}\"" >> ${LD_MAIN}
echo "OBJECTS=\"${OBJECTS}\"" >> ${LD_MAIN}
echo "LIBS=\"${LIBS}\"" >> ${LD_MAIN}
echo >> ${LD_MAIN}
echo "$LINK > \"\$LOG\" 2>&1 || $LINK" >> ${LD_MAIN}
- update_and_chmod 755 ${LD_MAIN} .build/ld_main
+ update_and_chmod 755 ${LD_MAIN} .build_ld_main
}
update_build_objc() {
- OBJCC_MAIN=.build/objcc_main.tmp
- OBJCC_ASAN=.build/objcc_asan.tmp
- OBJCC_COV=.build/objcc_cov.tmp
- OBJCC_DEBUG=.build/objcc_debug.tmp
+ OBJCC_MAIN=.build_objcc_main.tmp
+ OBJCC_ASAN=.build_objcc_asan.tmp
+ OBJCC_COV=.build_objcc_cov.tmp
+ OBJCC_DEBUG=.build_objcc_debug.tmp
mkdir -p .build
echo "#!/bin/sh" >> ${OBJCC_ASAN}
@@ -556,7 +558,7 @@ update_build_objc() {
echo "CPPFLAGS=\"${CPPFLAGS_ASAN}\"" >> ${OBJCC_ASAN}
echo "CFLAGS=\"${CFLAGS_ASAN}\"" >> ${OBJCC_ASAN}
echo "${LIBTOOL} --tag=CC --mode=compile \${OBJCC} \${CPPFLAGS} \${CFLAGS} -c \"\$1\" -o \"\$2\" >> .build/log 2>&1" >> ${OBJCC_ASAN}
- update_and_chmod 755 ${OBJCC_ASAN} .build/objcc_asan
+ update_and_chmod 755 ${OBJCC_ASAN} .build_objcc_asan
echo "#!/bin/sh" >> ${OBJCC_COV}
echo "# gen by configure" >> ${OBJCC_COV}
@@ -564,7 +566,7 @@ update_build_objc() {
echo "CPPFLAGS=\"${CPPFLAGS_COV}\"" >> ${OBJCC_COV}
echo "CFLAGS=\"${CFLAGS_COV}\"" >> ${OBJCC_COV}
echo "${LIBTOOL} --tag=CC --mode=compile \${OBJCC} \${CPPFLAGS} \${CFLAGS} -c \"\$1\" -o \"\$2\" >> .build/log 2>&1" >> ${OBJCC_COV}
- update_and_chmod 755 ${OBJCC_COV} .build/objcc_cov
+ update_and_chmod 755 ${OBJCC_COV} .build_objcc_cov
echo "#!/bin/sh" >> ${OBJCC_DEBUG}
echo "# gen by configure" >> ${OBJCC_DEBUG}
@@ -572,7 +574,7 @@ update_build_objc() {
echo "CPPFLAGS=\"${CPPFLAGS_DEBUG}\"" >> ${OBJCC_DEBUG}
echo "CFLAGS=\"${CFLAGS_DEBUG}\"" >> ${OBJCC_DEBUG}
echo "${LIBTOOL} --tag=CC --mode=compile \${OBJCC} \${CPPFLAGS} \${CFLAGS} -c \"\$1\" -o \"\$2\" >> .build/log 2>&1" >> ${OBJCC_DEBUG}
- update_and_chmod 755 ${OBJCC_DEBUG} .build/objcc_debug
+ update_and_chmod 755 ${OBJCC_DEBUG} .build_objcc_debug
echo "#!/bin/sh" >> ${OBJCC_MAIN}
echo "# gen by configure" >> ${OBJCC_MAIN}
@@ -580,14 +582,14 @@ update_build_objc() {
echo "CPPFLAGS=\"${CPPFLAGS}\"" >> ${OBJCC_MAIN}
echo "CFLAGS=\"${CFLAGS}\"" >> ${OBJCC_MAIN}
echo "${LIBTOOL} --tag=CC --mode=compile \${OBJCC} \${CPPFLAGS} \${CFLAGS} -c \"\$1\" -o \"\$2\" >> .build/log 2>&1" >> ${OBJCC_MAIN}
- update_and_chmod 755 ${OBJCC_MAIN} .build/objcc_main
+ update_and_chmod 755 ${OBJCC_MAIN} .build_objcc_main
}
update_build_prog() {
- LD_MAIN=.build/ld_main.tmp
- LD_ASAN=.build/ld_asan.tmp
- LD_COV=.build/ld_cov.tmp
- LD_DEBUG=.build/ld_debug.tmp
+ LD_MAIN=.build_ld_main.tmp
+ LD_ASAN=.build_ld_asan.tmp
+ LD_COV=.build_ld_cov.tmp
+ LD_DEBUG=.build_ld_debug.tmp
mkdir -p .build
LINK="${LIBTOOL} --tag=CC --mode=link"
@@ -604,7 +606,7 @@ update_build_prog() {
echo "LIBS=\"${LIBS_ASAN}\"" >> ${LD_ASAN}
echo >> ${LD_ASAN}
echo "$LINK > \"\$LOG\" 2>&1 || $LINK" >> ${LD_ASAN}
- update_and_chmod 755 ${LD_ASAN} .build/ld_asan
+ update_and_chmod 755 ${LD_ASAN} .build_ld_asan
echo "#!/bin/sh" >> ${LD_COV}
echo "# gen by configure" >> ${LD_COV}
@@ -616,7 +618,7 @@ update_build_prog() {
echo "LIBS=\"${LIBS_COV}\"" >> ${LD_COV}
echo >> ${LD_COV}
echo "$LINK > \"\$LOG\" 2>&1 || $LINK" >> ${LD_COV}
- update_and_chmod 755 ${LD_COV} .build/ld_cov
+ update_and_chmod 755 ${LD_COV} .build_ld_cov
echo "#!/bin/sh" >> ${LD_DEBUG}
echo "# gen by configure" >> ${LD_DEBUG}
@@ -628,7 +630,7 @@ update_build_prog() {
echo "LIBS=\"${LIBS_DEBUG}\"" >> ${LD_DEBUG}
echo >> ${LD_DEBUG}
echo "$LINK > \"\$LOG\" 2>&1 || $LINK" >> ${LD_DEBUG}
- update_and_chmod 755 ${LD_DEBUG} .build/ld_debug
+ update_and_chmod 755 ${LD_DEBUG} .build_ld_debug
echo "#!/bin/sh" >> ${LD_MAIN}
echo "# gen by configure" >> ${LD_MAIN}
@@ -640,7 +642,7 @@ update_build_prog() {
echo "LIBS=\"${LIBS}\"" >> ${LD_MAIN}
echo >> ${LD_MAIN}
echo "$LINK > \"\$LOG\" 2>&1 || $LINK" >> ${LD_MAIN}
- update_and_chmod 755 ${LD_MAIN} .build/ld_main
+ update_and_chmod 755 ${LD_MAIN} .build_ld_main
}
update_file() {
diff --git a/ic3/.ic3_history b/ic3/.ic3_history
index d046941..1755c4b 100644
--- a/ic3/.ic3_history
+++ b/ic3/.ic3_history
@@ -1,4 +1,3 @@
- x = unquote x
def dt = macro (x) do
quote do
x = unquote(x)
@@ -97,3 +96,4 @@ quote_cfn Plop
(Sym) "Abc"
defmodule Plop do end
defmodule Plop do def a = 1 end
+quote_cfn Plop
diff --git a/libc3/c3.c b/libc3/c3.c
index ba65158..62ac697 100644
--- a/libc3/c3.c
+++ b/libc3/c3.c
@@ -50,8 +50,7 @@ s_tag * c3_def (const s_call *call, s_tag *dest)
return env_def(&g_c3_env, call, dest);
}
-const s_sym ** c3_defmodule (const s_sym **name, const s_block *block,
- const s_sym **dest)
+s_tag * c3_defmodule (const s_sym **name, const s_block *block, s_tag *dest)
{
return env_defmodule(&g_c3_env, name, block, dest);
}
@@ -77,9 +76,10 @@ uw * c3_facts_next_id (uw *dest)
return dest;
}
-s_tag * c3_quote_cfn (const s_sym *sym, s_tag *dest)
+s_tag * c3_quote_cfn (const s_sym **sym, s_tag *dest)
{
- return tag_init_sym(dest, sym);
+ assert(sym);
+ return tag_init_sym(dest, *sym);
}
s_str * c3_getenv (const s_str *name, s_str *dest)
diff --git a/libc3/c3_main.h b/libc3/c3_main.h
index f78bd1d..357db11 100644
--- a/libc3/c3_main.h
+++ b/libc3/c3_main.h
@@ -35,12 +35,11 @@ s_str * c3_getenv (const s_str *name, s_str *dest);
void c3_license (void);
/* Operators. */
-s_tag * c3_def (const s_call *call, s_tag *dest);
-const s_sym ** c3_defmodule (const s_sym **name, const s_block *block,
- const s_sym **dest);
-void ** c3_dlopen (const s_str *path, void **dest);
-void c3_exit (sw code);
-s_tag * c3_pin (const s_tag *a, s_tag *dest);
+s_tag * c3_def (const s_call *call, s_tag *dest);
+s_tag * c3_defmodule (const s_sym **name, const s_block *block, s_tag *dest);
+void ** c3_dlopen (const s_str *path, void **dest);
+void c3_exit (sw code);
+s_tag * c3_pin (const s_tag *a, s_tag *dest);
/* Special operators. */
s_tag * c3_if_then_else (const s_tag *cond, const s_tag *then,
diff --git a/libc3/cfn.c b/libc3/cfn.c
index 3b75c88..7ada8fa 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -26,6 +26,7 @@ static s_tag * cfn_tag_init (s_tag *tag, const s_sym *type);
s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
{
s_list *a;
+ void **arg_pointer_result = NULL;
void **arg_pointers = NULL;
void **arg_values = NULL;
void **result_pointer = NULL;
@@ -75,15 +76,12 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
while (cfn_arg_types) {
assert(cfn_arg_types->tag.type == TAG_SYM);
if (cfn_arg_types->tag.data.sym == &g_sym_Result) {
+ assert(cfn->cif.rtype == &ffi_type_pointer);
cfn_tag_init(&tmp2, cfn->result_type);
- if (cfn->cif.rtype == &ffi_type_pointer) {
- if (! tag_to_ffi_pointer(&tmp2, cfn->result_type, arg_pointers + i))
- goto ko;
- arg_values[i] = &arg_pointers[i];
- }
- else
- if (! tag_to_ffi_pointer(&tmp2, cfn->result_type, arg_values + i))
- goto ko;
+ if (! tag_to_ffi_pointer(&tmp2, cfn->result_type, arg_pointers + i))
+ goto ko;
+ arg_values[i] = &arg_pointers[i];
+ arg_pointer_result = arg_pointers[i];
}
else {
if (cfn->cif.arg_types[i] == &ffi_type_pointer) {
@@ -105,6 +103,17 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
if (cfn->ptr.f) {
ffi_call(&cfn->cif, cfn->ptr.f, result, arg_values);
if (cfn->arg_result) {
+ if (result_pointer != arg_pointer_result) {
+ err_write_1("cfn_apply: ");
+ err_inspect_str(&cfn->name->str);
+ err_write_1(": ");
+ err_inspect_ptr(result_pointer);
+ err_write_1(": ");
+ err_inspect_ptr(arg_pointer_result);
+ err_write_1("\n");
+ assert(! "cfn_apply: error");
+ goto ko;
+ }
*dest = tmp2;
}
else
diff --git a/libc3/env.c b/libc3/env.c
index c8e92e0..dd7ff02 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -89,8 +89,9 @@ s_tag * env_def (s_env *env, const s_call *call, s_tag *dest)
assert(! "env_def: invalid assignment: expected Ident = value");
return NULL;
}
- tag_init_ident(&tag_ident, &call->arguments->tag.data.ident);
- env_ident_resolve_module(env, &tag_ident.data.ident);
+ tag_ident.type = TAG_IDENT;
+ env_ident_resolve_module(env, &call->arguments->tag.data.ident,
+ &tag_ident.data.ident);
tag_init_sym(&tag_module, tag_ident.data.ident.module);
tag_init_sym(&tag_symbol, &g_sym_symbol);
tag_init_sym(&tag_symbol_value, &g_sym_symbol_value);
@@ -106,11 +107,11 @@ s_tag * env_def (s_env *env, const s_call *call, s_tag *dest)
return dest;
}
-const s_sym ** env_defmodule (s_env *env, const s_sym **name,
- const s_block *block, const s_sym **dest)
+s_tag * env_defmodule (s_env *env, const s_sym **name,
+ const s_block *block, s_tag *dest)
{
const s_sym *module;
- const s_sym **result = NULL;
+ s_tag *result = NULL;
s_tag tmp = {0};
assert(env);
assert(name);
@@ -121,12 +122,12 @@ const s_sym ** env_defmodule (s_env *env, const s_sym **name,
env_module_is_loading_set(env, *name, true);
env->current_module = *name;
if (env_eval_block(env, block, &tmp)) {
- *dest = *name;
+ tag_clean(&tmp);
+ tag_init_sym(dest, *name);
result = dest;
}
env->current_module = module;
env_module_is_loading_set(env, *name, false);
- tag_clean(&tmp);
return result;
}
@@ -330,10 +331,12 @@ bool env_eval_call_fn (s_env *env, const s_call *call, s_tag *dest)
bool env_eval_call_resolve (s_env *env, s_call *call)
{
+ s_ident tmp_ident;
const s_tag *value;
assert(env);
assert(call);
- if ((value = env_frames_get(env, call->ident.sym))) {
+ if (call->ident.module == NULL &&
+ (value = env_frames_get(env, call->ident.sym))) {
if (value->type == TAG_CFN) {
call->cfn = cfn_new_copy(&value->data.cfn);
return true;
@@ -343,11 +346,12 @@ bool env_eval_call_resolve (s_env *env, s_call *call)
return true;
}
}
- if (! ident_resolve_module(&call->ident, env))
+ ident_init_copy(&tmp_ident, &call->ident);
+ if (! env_ident_resolve_module(env, &tmp_ident, &call->ident) ||
+ ! module_ensure_loaded(call->ident.module, &env->facts) ||
+ ! call_get(call, &env->facts))
return false;
- if (! module_ensure_loaded(call->ident.module, &env->facts))
- return false;
- return call_get(call, &env->facts);
+ return true;
}
bool env_eval_complex (s_env *env, const s_complex *c, s_tag *dest)
@@ -739,8 +743,7 @@ bool env_eval_ident (s_env *env, const s_ident *ident, s_tag *dest)
s_ident tmp_ident;
assert(env);
assert(ident);
- ident_init_copy(&tmp_ident, ident);
- ident_resolve_module(&tmp_ident, env);
+ env_ident_resolve_module(env, ident, &tmp_ident);
if (! ((tag = env_frames_get(env, tmp_ident.sym)) ||
(tag = ident_get(&tmp_ident, &env->facts, &tmp)))) {
err_write_1("env_eval_ident: unbound ident: ");
@@ -760,8 +763,7 @@ bool env_eval_ident_is_bound (s_env *env, const s_ident *ident)
assert(ident);
if (env_frames_get(env, ident->sym))
return true;
- ident_init_copy(&tmp_ident, ident);
- ident_resolve_module(&tmp_ident, env);
+ env_ident_resolve_module(env, ident, &tmp_ident);
if (ident_get(&tmp_ident, &env->facts, &tmp)) {
tag_clean(&tmp);
return true;
@@ -1324,8 +1326,8 @@ bool env_ident_is_special_operator (s_env *env,
s_tag tag_special_operator;
assert(env);
assert(ident);
- tag_init_ident(&tag_ident, ident);
- env_ident_resolve_module(env, &tag_ident.data.ident);
+ tag_ident.type = TAG_IDENT;
+ env_ident_resolve_module(env, ident, &tag_ident.data.ident);
tag_init_sym(&tag_is_a, &g_sym_is_a);
tag_init_sym(&tag_special_operator, &g_sym_special_operator);
if (facts_find_fact_by_tags(&env->facts, &tag_ident, &tag_is_a,
@@ -1334,19 +1336,24 @@ bool env_ident_is_special_operator (s_env *env,
return false;
}
-bool env_ident_resolve_module (const s_env *env, const s_ident *ident,
- s_ident *dest)
+s_ident * env_ident_resolve_module (const s_env *env,
+ const s_ident *ident,
+ s_ident *dest)
{
+ s_ident tmp;
assert(env);
assert(ident);
- if (! ident->module) {
+ ident_init_copy(&tmp, ident);
+ if (! tmp.module) {
if (! env->current_module) {
err_puts("env_ident_resolve_module: env current module is NULL");
assert(! "env_ident_resolve_module: env current module is NULL");
- return false;
+ return NULL;
}
- ident->module = env->current_module;
+ tmp.module = env->current_module;
}
+ *dest = tmp;
+ return dest;
}
s_env * env_init (s_env *env, int argc, char **argv)
@@ -1663,8 +1670,7 @@ s_ident * env_operator_resolve (s_env *env, const s_ident *op,
s_tag tag_sym;
s_tag tag_symbol;
s_ident tmp;
- tmp = *op;
- ident_resolve_module(&tmp, env);
+ env_ident_resolve_module(env, op, &tmp);
tag_init_sym(&tag_arity, &g_sym_arity);
tag_init_u8( &tag_arity_u8, arity);
tag_init_sym(&tag_is_a, &g_sym_is_a);
@@ -1754,8 +1760,8 @@ u8 env_special_operator_arity (s_env *env, const s_ident *ident)
s_tag tag_var;
assert(env);
assert(ident);
- tag_init_ident(&tag_ident, ident);
- env_ident_resolve_module(env, &tag_ident.data.ident);
+ tag_ident.type = TAG_IDENT;
+ env_ident_resolve_module(env, ident, &tag_ident.data.ident);
tag_init_sym( &tag_arity, &g_sym_arity);
tag_init_var( &tag_var);
facts_with_tags(&env->facts, &cursor,
diff --git a/libc3/env.h b/libc3/env.h
index 7fa3e3c..992c616 100644
--- a/libc3/env.h
+++ b/libc3/env.h
@@ -23,125 +23,126 @@ s_env * env_init (s_env *env, int argc, char **argv);
/* Observers. */
const s_tag * env_frames_get (const s_env *env, const s_sym *name);
-void env_ident_resolve_module (const s_env *env,
- s_ident *ident);
+s_ident * env_ident_resolve_module (const s_env *env,
+ const s_ident *ident,
+ s_ident *dest);
/* Operators. */
-s_tag * env_def (s_env *env, const s_call *call, s_tag *dest);
-const s_sym ** env_defmodule (s_env *env, const s_sym **name,
- const s_block *block, const s_sym **dest);
-bool env_eval_array (s_env *env, const s_array *array,
- s_array *dest);
-bool env_eval_array_tag (s_env *env, const s_array *array,
- s_tag *dest);
-bool env_eval_block (s_env *env, const s_block *block,
- s_tag *dest);
-bool env_eval_call (s_env *env, const s_call *call,
- s_tag *dest);
-bool env_eval_call_arguments (s_env *env, const s_list *args,
- s_list **dest);
-bool env_eval_call_cfn (s_env *env, const s_call *call,
+s_tag * env_def (s_env *env, const s_call *call, s_tag *dest);
+s_tag * env_defmodule (s_env *env, const s_sym **name,
+ const s_block *block, s_tag *dest);
+bool env_eval_array (s_env *env, const s_array *array,
+ s_array *dest);
+bool env_eval_array_tag (s_env *env, const s_array *array,
s_tag *dest);
-bool env_eval_call_fn (s_env *env, const s_call *call,
- s_tag *dest);
-bool env_eval_call_resolve (s_env *env, s_call *call);
-bool env_eval_complex (s_env *env, const s_complex *c,
+bool env_eval_block (s_env *env, const s_block *block,
+ s_tag *dest);
+bool env_eval_call (s_env *env, const s_call *call,
+ s_tag *dest);
+bool env_eval_call_arguments (s_env *env, const s_list *args,
+ s_list **dest);
+bool env_eval_call_cfn (s_env *env, const s_call *call,
s_tag *dest);
-bool env_eval_equal_block (s_env *env, bool macro,
- const s_block *a, const s_block *b,
- s_block *dest);
-bool env_eval_equal_list (s_env *env, bool macro,
- const s_list *a, const s_list *b,
- s_list **dest);
-bool env_eval_equal_struct (s_env *env, bool macro,
- const s_struct *a,
- const s_struct *b,
- s_struct *dest);
-bool env_eval_equal_tag (s_env *env, bool macro,
- const s_tag *a, const s_tag *b,
- s_tag *dest);
-bool env_eval_equal_tuple (s_env *env, bool macro,
- const s_tuple *a, const s_tuple *b,
- s_tuple *dest);
-bool env_eval_fn (s_env *env, const s_fn *fn, s_tag *dest);
-bool env_eval_fn_call (s_env *env, const s_fn *fn,
- const s_list *arguments, s_tag *dest);
-bool env_eval_ident (s_env *env, const s_ident *ident,
- s_tag *dest);
-bool env_eval_ident_is_bound (s_env *env,
- const s_ident *ident);
-bool env_eval_list (s_env *env, const s_list *list,
+bool env_eval_call_fn (s_env *env, const s_call *call,
+ s_tag *dest);
+bool env_eval_call_resolve (s_env *env, s_call *call);
+bool env_eval_complex (s_env *env, const s_complex *c,
+ s_tag *dest);
+bool env_eval_equal_block (s_env *env, bool macro,
+ const s_block *a, const s_block *b,
+ s_block *dest);
+bool env_eval_equal_list (s_env *env, bool macro,
+ const s_list *a, const s_list *b,
+ s_list **dest);
+bool env_eval_equal_struct (s_env *env, bool macro,
+ const s_struct *a,
+ const s_struct *b,
+ s_struct *dest);
+bool env_eval_equal_tag (s_env *env, bool macro,
+ const s_tag *a, const s_tag *b,
+ s_tag *dest);
+bool env_eval_equal_tuple (s_env *env, bool macro,
+ const s_tuple *a, const s_tuple *b,
+ s_tuple *dest);
+bool env_eval_fn (s_env *env, const s_fn *fn, s_tag *dest);
+bool env_eval_fn_call (s_env *env, const s_fn *fn,
+ const s_list *arguments, s_tag *dest);
+bool env_eval_ident (s_env *env, const s_ident *ident,
s_tag *dest);
-bool env_eval_map (s_env *env, const s_map *map,
+bool env_eval_ident_is_bound (s_env *env,
+ const s_ident *ident);
+bool env_eval_list (s_env *env, const s_list *list,
s_tag *dest);
-bool env_eval_progn (s_env *env, const s_list *program,
- s_tag *dest);
-bool env_eval_quote (s_env *env, const s_quote *quote,
- s_tag *dest);
-bool env_eval_quote_array (s_env *env, const s_array *array,
- s_tag *dest);
-bool env_eval_quote_block (s_env *env, const s_block *block,
- s_tag *dest);
-bool env_eval_quote_call (s_env *env, const s_call *call,
+bool env_eval_map (s_env *env, const s_map *map,
+ s_tag *dest);
+bool env_eval_progn (s_env *env, const s_list *program,
+ s_tag *dest);
+bool env_eval_quote (s_env *env, const s_quote *quote,
+ s_tag *dest);
+bool env_eval_quote_array (s_env *env, const s_array *array,
s_tag *dest);
-bool env_eval_quote_list (s_env *env, const s_list *list,
+bool env_eval_quote_block (s_env *env, const s_block *block,
s_tag *dest);
-bool env_eval_quote_map (s_env *env, const s_map *map,
+bool env_eval_quote_call (s_env *env, const s_call *call,
s_tag *dest);
-bool env_eval_quote_quote (s_env *env, const s_quote *quote,
- s_tag *dest);
-bool env_eval_quote_struct (s_env *env, const s_struct *s,
- s_tag *dest);
-bool env_eval_quote_tag (s_env *env, const s_tag *tag,
+bool env_eval_quote_list (s_env *env, const s_list *list,
s_tag *dest);
-bool env_eval_quote_tuple (s_env *env, const s_tuple *tuple,
+bool env_eval_quote_map (s_env *env, const s_map *map,
+ s_tag *dest);
+bool env_eval_quote_quote (s_env *env, const s_quote *quote,
+ s_tag *dest);
+bool env_eval_quote_struct (s_env *env, const s_struct *s,
s_tag *dest);
-bool env_eval_quote_unquote (s_env *env,
- const s_unquote *unquote,
- s_tag *dest);
-bool env_eval_struct (s_env *env, const s_struct *s,
- s_tag *dest);
-bool env_eval_tag (s_env *env, const s_tag *tag,
- s_tag *dest);
-bool env_eval_tuple (s_env *env, const s_tuple *tuple,
+bool env_eval_quote_tag (s_env *env, const s_tag *tag,
+ s_tag *dest);
+bool env_eval_quote_tuple (s_env *env, const s_tuple *tuple,
+ s_tag *dest);
+bool env_eval_quote_unquote (s_env *env,
+ const s_unquote *unquote,
+ s_tag *dest);
+bool env_eval_struct (s_env *env, const s_struct *s,
s_tag *dest);
-bool env_eval_void (s_env *env, const void *_, s_tag *dest);
-bool env_ident_is_special_operator (s_env *env,
- const s_ident *ident);
-bool env_module_is_loading (s_env *env, const s_sym *module);
-bool env_module_is_loading_set (s_env *env,
- const s_sym *module,
- bool value);
-bool env_module_load (s_env *env, const s_sym *module,
- s_facts *facts);
-bool env_module_maybe_reload (s_env *env,
- const s_sym *module,
- s_facts *facts);
-s8 env_operator_arity (s_env *env, const s_ident *op);
-bool env_operator_find (s_env *env, const s_ident *op);
-s_ident * env_operator_ident (s_env *env, const s_ident *op,
- s_ident *dest);
-bool env_eval_integer (s_env *env, const s_integer *integer,
- s_integer *dest);
-bool env_operator_is_right_associative (s_env *env,
- const s_ident *op);
-s8 env_operator_precedence (s_env *env, const s_ident *op);
-s_ident * env_operator_resolve (s_env *env, const s_ident *op,
- u8 arity, s_ident *dest);
-const s_sym * env_operator_symbol (s_env *env, const s_ident *op);
-u8 env_special_operator_arity (s_env *env,
- const s_ident *ident);
-bool env_struct_type_exists (s_env *env,
- const s_sym *module);
-const s_struct_type *
- env_struct_type_find (s_env *env, const s_sym *module);
-f_clean env_struct_type_get_clean (s_env *env,
- const s_sym *module);
-s_list ** env_struct_type_get_spec (s_env *env, const s_sym *module,
- s_list **dest);
-bool env_tag_ident_is_bound (const s_env *env,
- const s_tag *tag,
+bool env_eval_tag (s_env *env, const s_tag *tag,
+ s_tag *dest);
+bool env_eval_tuple (s_env *env, const s_tuple *tuple,
+ s_tag *dest);
+bool env_eval_void (s_env *env, const void *_, s_tag *dest);
+bool env_ident_is_special_operator (s_env *env,
+ const s_ident *ident);
+bool env_module_is_loading (s_env *env, const s_sym *module);
+bool env_module_is_loading_set (s_env *env,
+ const s_sym *module,
+ bool value);
+bool env_module_load (s_env *env, const s_sym *module,
+ s_facts *facts);
+bool env_module_maybe_reload (s_env *env,
+ const s_sym *module,
s_facts *facts);
+s8 env_operator_arity (s_env *env, const s_ident *op);
+bool env_operator_find (s_env *env, const s_ident *op);
+s_ident * env_operator_ident (s_env *env, const s_ident *op,
+ s_ident *dest);
+bool env_eval_integer (s_env *env, const s_integer *integer,
+ s_integer *dest);
+bool env_operator_is_right_associative (s_env *env,
+ const s_ident *op);
+s8 env_operator_precedence (s_env *env, const s_ident *op);
+s_ident * env_operator_resolve (s_env *env, const s_ident *op,
+ u8 arity, s_ident *dest);
+const s_sym * env_operator_symbol (s_env *env, const s_ident *op);
+u8 env_special_operator_arity (s_env *env,
+ const s_ident *ident);
+bool env_struct_type_exists (s_env *env,
+ const s_sym *module);
+const s_struct_type *
+ env_struct_type_find (s_env *env, const s_sym *module);
+f_clean env_struct_type_get_clean (s_env *env,
+ const s_sym *module);
+s_list ** env_struct_type_get_spec (s_env *env, const s_sym *module,
+ s_list **dest);
+bool env_tag_ident_is_bound (const s_env *env,
+ const s_tag *tag,
+ s_facts *facts);
/* Control structures. */
void env_error_f (s_env *env, const char *fmt, ...);
diff --git a/libc3/ident.c b/libc3/ident.c
index 00259c4..b4c3a1a 100644
--- a/libc3/ident.c
+++ b/libc3/ident.c
@@ -201,9 +201,9 @@ bool ident_is_special_operator (const s_ident *ident)
return env_ident_is_special_operator(&g_c3_env, ident);
}
-void ident_resolve_module (s_ident *ident)
+s_ident * ident_resolve_module (const s_ident *ident, s_ident *dest)
{
- env_ident_resolve_module(&g_c3_env, ident);
+ return env_ident_resolve_module(&g_c3_env, ident, dest);
}
bool ident_to_tag_type (const s_ident *ident, e_tag_type *dest)
diff --git a/libc3/ident.h b/libc3/ident.h
index 91d7633..0c5b9cb 100644
--- a/libc3/ident.h
+++ b/libc3/ident.h
@@ -27,7 +27,7 @@ s_ident * ident_init_cast (s_ident *ident, const s_tag *tag);
s_ident * ident_init_copy (s_ident *ident, const s_ident *src);
/* Modifiers */
-s_ident * ident_resolve_module (s_ident *ident, const s_env *env);
+s_ident * ident_resolve_module (const s_ident *ident, s_ident *dest);
/* Observers */
bool ident_character_is_reserved (character c);
diff --git a/libc3/io.c b/libc3/io.c
index 3e6c104..2811b9b 100644
--- a/libc3/io.c
+++ b/libc3/io.c
@@ -113,6 +113,7 @@ DEF_ERR_IO_INSPECT(fn_pattern, const s_list *)
DEF_ERR_IO_INSPECT(ident, const s_ident *)
DEF_ERR_IO_INSPECT(list, const s_list * const *)
DEF_ERR_IO_INSPECT(map, const s_map *)
+DEF_ERR_IO_INSPECT(ptr, const u_ptr_w *)
DEF_ERR_IO_INSPECT(s8, const s8 *)
DEF_ERR_IO_INSPECT(s16, const s16 *)
DEF_ERR_IO_INSPECT(s32, const s32 *)
diff --git a/libc3/io.h b/libc3/io.h
index 1efeb27..e5b0a73 100644
--- a/libc3/io.h
+++ b/libc3/io.h
@@ -50,6 +50,7 @@ PROTOTYPES_ERR_IO_INSPECT(ident, const s_ident *);
PROTOTYPES_ERR_IO_INSPECT(integer, const s_integer *);
PROTOTYPES_ERR_IO_INSPECT(list, const s_list * const *);
PROTOTYPES_ERR_IO_INSPECT(map, const s_map *);
+PROTOTYPES_ERR_IO_INSPECT(ptr, const u_ptr_w *);
PROTOTYPES_ERR_IO_INSPECT(s8, const s8 *);
PROTOTYPES_ERR_IO_INSPECT(s16, const s16 *);
PROTOTYPES_ERR_IO_INSPECT(s32, const s32 *);
diff --git a/libtommath b/libtommath
index 59726bc..1957d6f 160000
--- a/libtommath
+++ b/libtommath
@@ -1 +1 @@
-Subproject commit 59726bc470de4397f425fec64652832b0aecdee1
+Subproject commit 1957d6f6c57aded3da4721067f175f9f8e0cd6da