summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-10-14 21:10:31 +0000
committerPaul Buetow <paul@buetow.org>2008-10-14 21:10:31 +0000
commitc25ba0d8ee9e4e6a0432fba2e8606c7e0a35d1cd (patch)
treea3bc323b93acee460e8e04210062284624ecd5cf
parentd527f50159f056dc165fa7eaf7bf80425a1e758d (diff)
added a scope debug flag
-rw-r--r--docs/stats.txt4
-rw-r--r--examples/conditionals.fy2
-rw-r--r--src/build.h2
-rw-r--r--src/core/scope.c31
-rw-r--r--src/defines.h2
5 files changed, 36 insertions, 5 deletions
diff --git a/docs/stats.txt b/docs/stats.txt
index c2427da..d390ccd 100644
--- a/docs/stats.txt
+++ b/docs/stats.txt
@@ -1,4 +1,4 @@
===> Num of C source files : 42
-===> Num of C source lines : 7680
+===> Num of C source lines : 7713
===> Num of Fype source examples : 13
-===> Num of Fype source lines : 325
+===> Num of Fype source lines : 323
diff --git a/examples/conditionals.fy b/examples/conditionals.fy
index 1260ae2..2dc027f 100644
--- a/examples/conditionals.fy
+++ b/examples/conditionals.fy
@@ -37,5 +37,3 @@ assert 1 == (put 1 >= 1);
assert 1 == (put 1 >= 0);
assert 0 == (put 0 >= 1);
assert 1 == (say 0 >= 0);
-
-
diff --git a/src/build.h b/src/build.h
index bd5bc76..df9738e 100644
--- a/src/build.h
+++ b/src/build.h
@@ -35,7 +35,7 @@
#ifndef BUILD_H
#define BUILD_H
-#define BUILDNR 9596
+#define BUILDNR 9607
#define OS_FREEBSD
#endif
diff --git a/src/core/scope.c b/src/core/scope.c
index 0c65c1d..1eaac8f 100644
--- a/src/core/scope.c
+++ b/src/core/scope.c
@@ -36,6 +36,9 @@
#include "scope.h"
#include "symbol.h"
+#define _SCOPE_ERROR(m) \
+ ERROR("%s: Scope error", m)
+
Scope*
scope_new(Hash *p_hash_syms) {
Scope *p_scope = malloc(sizeof(Scope));
@@ -58,14 +61,42 @@ scope_delete(Scope *p_scope) {
void
scope_up(Scope *p_scope) {
+#ifdef EXTRA_CHECKS
+ int i_before = (int) stack_size(p_scope->p_stack_scopes);
+#elif DEBUG_SCOPE_UPDOWN
+ int i_before = (int) stack_size(p_scope->p_stack_scopes);
+#endif
stack_push(p_scope->p_stack_scopes, hash_new(24));
+#ifdef DEBUG_SCOPE_UPDOWN
+ printf("SCOPE UPPED %d => %d\n",
+ i_before,
+ (int) stack_size(p_scope->p_stack_scopes));
+#endif /* DEBUG_SCOPE_UPDOWN */
+#ifdef EXTRA_CHECKS
+ if (i_before >= (int) stack_size(p_scope->p_stack_scopes))
+ _SCOPE_ERROR("Scope should be higher");
+#endif /* EXTRA_CHECKS */
}
void
scope_down(Scope *p_scope) {
+#ifdef EXTRA_CHECKS
+ int i_before = (int) stack_size(p_scope->p_stack_scopes);
+#elif DEBUG_SCOPE_UPDOWN
+ int i_before = (int) stack_size(p_scope->p_stack_scopes);
+#endif
Hash *p_hash_syms = stack_pop(p_scope->p_stack_scopes);
hash_iterate(p_hash_syms, symbol_cleanup_hash_syms_cb);
hash_delete(p_hash_syms);
+#ifdef DEBUG_SCOPE_UPDOWN
+ printf("SCOPE DOWNED %d => %d\n",
+ i_before,
+ (int) stack_size(p_scope->p_stack_scopes));
+#endif /* DEBUG_SCOPE_UPDOWN */
+#ifdef EXTRA_CHECKS
+ if (i_before <= (int) stack_size(p_scope->p_stack_scopes))
+ _SCOPE_ERROR("Scope should be lower");
+#endif /* EXTRA_CHECKS */
}
static Hash*
diff --git a/src/defines.h b/src/defines.h
index 8cd1114..9842c4f 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -75,6 +75,8 @@
exit(1); }
#define DPRINTF(...) printf("DEBUG("); printf(__VA_ARGS__); printf(")\n");
+#define EXTRA_CHECKS
+#define DEBUG_SCOPE_UPDOWN
//#define DEBUG_TOKEN_REFCOUNT
//#define DEBUG_FUNCTION_PROCESS
//#define DEBUG_TRACK