commit e3618036685989c204a24a874858fa40bff6775b
parent 504ffa97f0f1545ee54a2891b53b90b885c3ece0
Author: Andres Navarro <canavarro82@gmail.com>
Date: Mon, 12 Dec 2011 02:34:31 -0300
Added module constructor, type predicate, and field getters to the ground environment.
Diffstat:
5 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/Makefile b/src/Makefile
@@ -37,7 +37,7 @@ CORE_O= kobject.o ktoken.o kpair.o kstring.o ksymbol.o kread.o \
kencapsulation.o kpromise.o kport.o kinteger.o krational.o ksystem.o \
kreal.o ktable.o kgc.o imath.o imrat.o kbytevector.o kvector.o \
kchar.o kkeyword.o kmodule.o \
- kground.o kghelpers.o kgbooleans.o kgeqp.o \
+ kground.o kghelpers.o kgbooleans.o kgeqp.o kgmodules.o \
kgequalp.o kgsymbols.o kgcontrol.o kgpairs_lists.o kgpair_mut.o \
kgenvironments.o kgenv_mut.o kgcombiners.o kgcontinuations.o \
kgencapsulations.o kgpromises.o kgkd_vars.o kgks_vars.o kgports.o \
@@ -221,6 +221,10 @@ kgpromises.o: kgpromises.c kstate.h klimits.h klisp.h kobject.h \
klispconf.h ktoken.h kmem.h kpromise.h kpair.h kgc.h kapplicative.h \
koperative.h kcontinuation.h kerror.h kghelpers.h kenvironment.h \
ksymbol.h kstring.h ktable.h kgpromises.h
+kgmodules.o: kgmodules.c kstate.h klimits.h klisp.h kobject.h \
+ klispconf.h ktoken.h kmem.h kmodule.h kpair.h kgc.h kapplicative.h \
+ koperative.h kcontinuation.h kerror.h kghelpers.h kenvironment.h \
+ ksymbol.h kstring.h ktable.h kgmodules.h kpair.h
kground.o: kground.c kstate.h klimits.h klisp.h kobject.h klispconf.h \
ktoken.h kmem.h kground.h kghelpers.h kerror.h kpair.h kgc.h \
kapplicative.h koperative.h kcontinuation.h kenvironment.h ksymbol.h \
@@ -228,7 +232,7 @@ kground.o: kground.c kstate.h klimits.h klisp.h kobject.h klispconf.h \
kgcontrol.h kgpairs_lists.h kgpair_mut.h kgenvironments.h kgenv_mut.h \
kgcombiners.h kgcontinuations.h kgencapsulations.h kgpromises.h \
kgkd_vars.h kgks_vars.h kgnumbers.h kgstrings.h kgchars.h kgports.h \
- kgbytevectors.h kgvectors.h kgsystem.h kgerrors.h \
+ kgbytevectors.h kgvectors.h kgsystem.h kgerrors.h kgmodules.h \
kgffi.h keval.h krepl.h
kgstrings.o: kgstrings.c kstate.h klimits.h klisp.h kobject.h klispconf.h \
ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h kerror.h \
diff --git a/src/kgpromises.c b/src/kgpromises.c
@@ -1,11 +1,9 @@
/*
-** kgencapsulations.c
-** Encapsulations features for the ground environment
+** kgpromises.c
+** Promises features for the ground environment
** See Copyright Notice in klisp.h
*/
-#include <assert.h>
-#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
diff --git a/src/kground.c b/src/kground.c
@@ -40,6 +40,7 @@
#include "kgsystem.h"
#include "kgerrors.h"
#include "kgkeywords.h"
+#include "kgmodules.h"
#if KUSE_LIBFFI
# include "kgffi.h"
@@ -84,6 +85,7 @@ void kinit_cont_names(klisp_State *K)
#if KUSE_LIBFFI
kinit_ffi_cont_names(K);
#endif
+ kinit_modules_cont_names(K);
}
/*
@@ -118,6 +120,7 @@ void kinit_ground_env(klisp_State *K)
kinit_system_ground_env(K);
kinit_error_ground_env(K);
kinit_keywords_ground_env(K);
+ kinit_modules_ground_env(K);
#if KUSE_LIBFFI
kinit_ffi_ground_env(K);
#endif
diff --git a/src/kmodule.c b/src/kmodule.c
@@ -18,7 +18,8 @@ TValue kmake_module(klisp_State *K, TValue env, TValue exp_list)
Module *new_mod = klispM_new(K, Module);
/* header + gc_fields */
- klispC_link(K, (GCObject *) new_mod, K_TMODULE, 0);
+ klispC_link(K, (GCObject *) new_mod, K_TMODULE,
+ K_FLAG_CAN_HAVE_NAME);
/* module specific fields */
new_mod->env = env;
diff --git a/src/kwrite.c b/src/kwrite.c
@@ -699,6 +699,15 @@ void kwrite_scalar(klisp_State *K, TValue obj)
#endif
kw_printf(K, "]");
break;
+ case K_TMODULE:
+ kw_printf(K, "#[module");
+ #if KTRACK_NAMES
+ if (khas_name(obj)) {
+ kw_print_name(K, obj);
+ }
+ #endif
+ kw_printf(K, "]");
+ break;
default:
/* shouldn't happen */
kwrite_error(K, "unknown object type");