summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-10-19 17:48:21 +0000
committerPaul Buetow <paul@buetow.org>2008-10-19 17:48:21 +0000
commit3d7b35bb37c066489546751e100c2c2b823ccba3 (patch)
treea507be11afc3c55807e254ce5b24c5412367aa46 /src/core
parentd4657a5d7029ea66d19a5d238a9dd6bf75fe5bb0 (diff)
refs and syms
Diffstat (limited to 'src/core')
-rw-r--r--src/core/function.c11
-rw-r--r--src/core/interpret.c21
-rw-r--r--src/core/token.c2
-rw-r--r--src/core/token.h1
4 files changed, 35 insertions, 0 deletions
diff --git a/src/core/function.c b/src/core/function.c
index fda40b8..c25834d 100644
--- a/src/core/function.c
+++ b/src/core/function.c
@@ -575,6 +575,9 @@ function_is_buildin(Token *p_token_ident) {
if (strcmp("not", token_get_val(p_token_ident)) == 0)
return (true);
+ if (strcmp("refs", token_get_val(p_token_ident)) == 0)
+ return (true);
+
return (false);
}
@@ -812,6 +815,14 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident,
break;
NO_DEFAULT;
}
+
+ } else if (strcmp("refs", token_get_val(p_token_ident)) == 0) {
+ if (0 == stack_size(p_stack_args))
+ _FUNCTION_ERROR("No argument given", p_token_ident);
+
+ Token *p_token_top = stack_pop(p_stack_args);
+ Token *p_token = token_new_integer(p_token_top->i_ref_count);
+ stack_push(p_stack_args, p_token);
}
}
diff --git a/src/core/interpret.c b/src/core/interpret.c
index 2c80163..9dbd7df 100644
--- a/src/core/interpret.c
+++ b/src/core/interpret.c
@@ -927,6 +927,27 @@ _term(Interpret *p_interpret) {
}
break;
+ case TT_SYMS:
+ {
+ _NEXT
+ if (p_interpret->tt != TT_IDENT)
+ _INTERPRET_ERROR("Expexted identifier for 'syms'",
+ p_interpret->p_token);
+
+ char *c_name = token_get_val(p_interpret->p_token);
+ Symbol *p_symbol = scope_get(p_interpret->p_scope, c_name);
+ if (p_symbol == NULL)
+ _INTERPRET_ERROR("No such symbol", p_interpret->p_token);
+
+
+ Token *p_token_num_refs = token_new_integer(p_symbol->i_refs);
+ stack_push(p_interpret->p_stack, p_token_num_refs);
+
+ _NEXT;
+ return (1);
+ }
+ break;
+
/*
case TT_PARANT_AL:
{
diff --git a/src/core/token.c b/src/core/token.c
index 4626e5a..2f08097 100644
--- a/src/core/token.c
+++ b/src/core/token.c
@@ -52,6 +52,7 @@ get_tt(char *c_token) {
CHECK("next") TT_NEXT;
CHECK("defined") TT_DEFINED;
CHECK("undef") TT_UNDEF;
+ CHECK("syms") TT_SYMS;
CHECK("ret") TT_RET;
CHECK("const") TT_CONST;
CHECK("proc") TT_PROC;
@@ -129,6 +130,7 @@ tt_get_name(TokenType tt_cur) {
CASE(TT_NEXT,"TT_NEXT")
CASE(TT_DEFINED,"TT_DEFINED")
CASE(TT_UNDEF,"TT_UNDEF")
+ CASE(TT_SYMS,"TT_SYMS")
CASE(TT_INT,"TT_INT")
CASE(END_KEYWORDS, "END_KEYWORDS")
diff --git a/src/core/token.h b/src/core/token.h
index caf4854..2107dd2 100644
--- a/src/core/token.h
+++ b/src/core/token.h
@@ -110,6 +110,7 @@ typedef enum {
TT_INT,
TT_DEFINED,
TT_UNDEF,
+ TT_SYMS,
END_KEYWORDS,
START_PARANTS,