diff options
57 files changed, 2201 insertions, 2489 deletions
@@ -1,22 +1,27 @@ -Fype (http://fype.buetow.org) is ... -... Copyright (c) 2005 2006 2007 2008 by Dipl.-Inf. (FH) Paul C. Buetow -All rights reserved. +File: ./COPYING +A simple Fype interpreter -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of buetow.org nor the names of its contributors may - be used to endorse or promote products derived from this software - without specific prior written permission. +WWW: http://fype.buetow.org +AUTHOR: http://paul.buetow.org +E-Mail: fype at dev.buetow.org -THIS SOFTWARE IS PROVIDED BY Paul Buetow ``AS IS'' AND ANY EXPRESS OR +The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + +Redistribution and use in source and binary forms, with or without modi- +fication, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of buetow.org nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, +DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -6,6 +6,6 @@ How to install fype: How to read the docu: - man fype + man pbsc Examples can be found in the ./examples directory. @@ -13,7 +13,6 @@ OSYSTEM!=uname PREFIX=/usr/local all: build $(OBJS) newline stats-tofile @$(CC) -lm -o $(BIN) $(OBJS) $(LDADD) - @if test -z '$(DEBUG)'; then strip $(BIN) ; fi @awk '$$2 == "BUILDNR" { printf("===> Fype build number % 13s :% 6s%d\n", \ "", "", $$3); exit(0); }' src/build.h @echo "===> Fype binary size : `du -hs $(BIN)`" @@ -41,7 +40,7 @@ printbuild: @awk '$$2 == "BUILDNR" { printf("%d\n", \ $$3); exit(0); }' src/build.h ctags: - @# Generating Source-Tags for Vim + # Generating Source-Tags for Vim ctags `find . -name '*.c'` style: astyle check astyle: @@ -59,30 +58,31 @@ stats: grep -E \"\\.(c|h)$$\" | wc -l`"; \ echo "===> Num of C source lines : `echo \"$$wc\" | \ tail -n 1 | sed s/total//`"' - @sh -c 'wc=`find ./examples -name "*.fy" | xargs wc -l`; \ + @sh -c 'wc=`find ./examples -name "*.fype" | xargs wc -l`; \ echo "===> Num of Fype source examples : `echo \"$$wc\" | \ - grep -E \"\\.fy$$\" | wc -l`"; \ + grep -E \"\\.fype$$\" | wc -l`"; \ echo "===> Num of Fype source lines : `echo \"$$wc\" | \ tail -n 1 | sed s/total//`"' stats-tofile: make stats | tee ./docs/stats.txt testrun: - cat ./test.fy > ./test.out - ./$(BIN) -V ./test.fy | tee -a ./test.out + cat ./test.fype > ./test.out + ./$(BIN) -V ./test.fype | tee -a ./test.out tr: testrun test: all testrun t: test run: - ./$(BIN) ./test.fy + ./$(BIN) ./test.fype core: - gdb $(BIN) $(BIN).core + #gdb $(BIN) $(BIN).core + gdb $(BIN) core gdb: - gdb --args $(BIN) .//test.fy + gdb --args $(BIN) .// newline: @echo examples: all echo > ./examples/all-examples.txt - for i in ./examples/*.fy; do \ + for i in ./examples/*.fype; do \ echo "===> Running $$i"; \ ./$(BIN) $$i; \ cat $$i >> ./examples/all-examples.txt; \ @@ -94,6 +94,10 @@ replace: headers: @find ./src -name '*.[ch]' -exec sh -c 'export FILE={}; \ make header' \; + @sh -c '> ./COPYING;export FILE=./COPYING; make header' + @# BSD sed does not support the -i (inplace) switch + @sed -n '1d;$$d;s/....//; w .tmp' ./COPYING && mv .tmp ./COPYING + header: @echo "===> Processing $(FILE)" @sed -n '/*:/d; w .tmp' $(FILE) @@ -112,4 +116,3 @@ deinstall: uninstall: deinstall pod: @cd ./docs/pod; make clean all - @cp ./docs/pod/fype.pod README.pod diff --git a/docs/header.txt b/docs/header.txt index 88c96c2..83638b8 100644 --- a/docs/header.txt +++ b/docs/header.txt @@ -1,12 +1,11 @@ File: ${FILE} -A simple interpreter +A simple Fype interpreter -WWW : http://fype.buetow.org -AUTHOR : http://paul.buetow.org -E-Mail : fype at dev.buetow.org +WWW: http://fype.buetow.org +AUTHOR: http://paul.buetow.org +E-Mail: fype at dev.buetow.org -Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow -All rights reserved. +The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow Redistribution and use in source and binary forms, with or without modi- fication, are permitted provided that the following conditions are met: diff --git a/docs/help.txt b/docs/help.txt index 545eda4..0033293 100644 --- a/docs/help.txt +++ b/docs/help.txt @@ -1,5 +1,5 @@ -Fype0 Alpha Build 9669 -(c) Paul C. Buetow (2005 - 2008) <fype@dev.buetow.org> +Fype2 Alpha Build 10387 +(c) Paul C. Buetow (2005 - 2010) <fype@dev.buetow.org> -e Executes given code string (see synopses) -h Prints this help -s Prints the synopsis diff --git a/docs/pbsc.txt b/docs/pbsc.txt new file mode 100644 index 0000000..3a2726c --- /dev/null +++ b/docs/pbsc.txt @@ -0,0 +1,43 @@ +Global Frame + +v?: Variables +p?: Parameters +b?: Boolean expression (Returns #t or #f) +t?: Term +f: Function +l?: List + +(f p1 p2 ...) + +(define v1 t1) + +(lambda (v1 v2 ...) t1) + +(define foo (lambda (v1 v2 ...) t1)) +(define (foo (v1 v2 ...) t1)) + +(if b1 t1 t2) +(unless b1 t1 t2) +(eq? t1 t2) +(neq? t1 t2) +(and b1 b2) +(or b1 b2) +(xor b1 b2) +(not b1) + +(cond ((b1 t1) + (b2 t2) + ... + (else tn))) + +(let ((v1 t1) + (v2 t2) + ...) + t3) + +(cons t1 l1) +(car l1) +(cdr l1) +(set-car l1 t1) +(set-cdr l1 t1) +(list p1 p2 ...) diff --git a/docs/stats.txt b/docs/stats.txt index b44c232..50cbda1 100644 --- a/docs/stats.txt +++ b/docs/stats.txt @@ -1,4 +1,4 @@ -===> Num of C source files : 46 -===> Num of C source lines : 8227 -===> Num of Fype source examples : 15 -===> Num of Fype source lines : 376 +===> Num of C source files : 44 +===> Num of C source lines : 5740 +===> Num of Fype source examples : 2 +===> Num of Fype source lines : 18 diff --git a/docs/version.txt b/docs/version.txt index dd836b0..d2c768b 100644 --- a/docs/version.txt +++ b/docs/version.txt @@ -1 +1 @@ -Fype0 Alpha Build 9669 +Fype2 Alpha Build 10387 diff --git a/examples/netsted.fype b/examples/netsted.fype new file mode 100644 index 0000000..2ddf89f --- /dev/null +++ b/examples/netsted.fype @@ -0,0 +1,11 @@ +(def (test) + (say "This is test") + (def (test2) + (say "I am in test2" "And test3 will be defined next!") + (def (test3) + (say "Displaying all frames now:") + (show-frames)) + (test3)) + (test2)) +(test) + diff --git a/examples/reverse.fype b/examples/reverse.fype new file mode 100644 index 0000000..a4384b6 --- /dev/null +++ b/examples/reverse.fype @@ -0,0 +1,7 @@ +(def (reverse x) + (def (my-reverse x y) + (if (null? x) + y + (my-reverse (cdr x) (cons (car x) y)))) + (my-reverse x '())) +(reverse (list 1 2 3)) @@ -1,14 +1,13 @@ /*:* *: File: ./src/argv.c - *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow - *: All rights reserved. - *: + *: A simple Fype interpreter + *: + *: WWW: http://fype.buetow.org + *: AUTHOR: http://paul.buetow.org + *: E-Mail: fype at dev.buetow.org + *: + *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -16,20 +15,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of buetow.org nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of buetow.org nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ @@ -47,7 +46,7 @@ char *BINARY; void -argv_run(Fype *p_fype, int i_argc, char **pc_argv) { +argv_run(PBSc *p_fype, int i_argc, char **pc_argv) { Dat *p_dat_string = dat_new(); BINARY = pc_argv[0]; @@ -1,14 +1,13 @@ /*:* *: File: ./src/argv.h - *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow - *: All rights reserved. - *: + *: A simple Fype interpreter + *: + *: WWW: http://fype.buetow.org + *: AUTHOR: http://paul.buetow.org + *: E-Mail: fype at dev.buetow.org + *: + *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -16,20 +15,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of buetow.org nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of buetow.org nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ @@ -39,7 +38,7 @@ #include "data/tupel.h" #include "fype.h" -void argv_run(Fype *p_fype, int i_argc, char **pc_argv); +void argv_run(PBSc *p_fype, int i_argc, char **pc_argv); void argv_switch(char c_arg, Tupel *p_tupel_argv, unsigned i_argc_left); void argv_synopsis(Tupel *p_tupel_argv); void argv_help(); diff --git a/src/build.h b/src/build.h index 27dbb5c..1e6006e 100644 --- a/src/build.h +++ b/src/build.h @@ -1,14 +1,13 @@ /*:* *: File: ./src/build.h - *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow - *: All rights reserved. - *: + *: A simple Fype interpreter + *: + *: WWW: http://fype.buetow.org + *: AUTHOR: http://paul.buetow.org + *: E-Mail: fype at dev.buetow.org + *: + *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -16,27 +15,27 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of buetow.org nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of buetow.org nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ #ifndef BUILD_H #define BUILD_H -#define BUILDNR 9669 +#define BUILDNR 10388 #define OS_LINUX #endif diff --git a/src/core/frame.c b/src/core/frame.c new file mode 100644 index 0000000..9143a0d --- /dev/null +++ b/src/core/frame.c @@ -0,0 +1,152 @@ +/*:* + *: File: ./src/core/frame.c + *: A simple Fype interpreter + *: + *: WWW: http://fype.buetow.org + *: AUTHOR: http://paul.buetow.org + *: E-Mail: fype at dev.buetow.org + *: + *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: + *: Redistribution and use in source and binary forms, with or without modi- + *: fication, are permitted provided that the following conditions are met: + *: * Redistributions of source code must retain the above copyright + *: notice, this list of conditions and the following disclaimer. + *: * Redistributions in binary form must reproduce the above copyright + *: notice, this list of conditions and the following disclaimer in the + *: documentation and/or other materials provided with the distribution. + *: * Neither the name of buetow.org nor the names of its contributors may + *: be used to endorse or promote products derived from this software + *: without specific prior written permission. + *: + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: POSSIBILITY OF SUCH DAMAGE. + *:*/ + +#include "frame.h" +#include "lambda.h" +#include "variable.h" + +unsigned _I_FRAME_ID_COUNT = 0; + +Symbol* +symbol_new(SymbolType st, void *p_val) { + Symbol *p_symbol = malloc(sizeof(Symbol)); + + p_symbol->st = st; + p_symbol->p_val = p_val; + + return (p_symbol); +} + +void +symbol_delete(Symbol *p_symbol) { + switch (p_symbol->st) { + case ST_LAMBDA: + lambda_delete(p_symbol->p_val); + break; + case ST_VARIABLE: + variable_delete(p_symbol->p_val); + break; + } + + free(p_symbol); +} + +void +symbol_delete_cb(void *p_symbol) { + symbol_delete(p_symbol); +} + +char* +symbol_get_type_name(Symbol *p_symbol) { + switch (p_symbol->st) { + case ST_LAMBDA: + return ("ST_LAMBDA"); + case ST_VARIABLE: + return ("ST_VARIABLE"); + } + + return ("ST_UNKNOWN"); +} + +Frame* +frame_new(Frame *p_parent_frame) { + Frame *p_frame = malloc(sizeof(Frame)); + + p_frame->p_parent_frame = p_parent_frame; + p_frame->p_hash_symbols = hash_new(8); + p_frame->i_frame_id = _I_FRAME_ID_COUNT++; + + return (p_frame); +} + +void +frame_delete(Frame *p_frame) { + Hash *p_hash_symbols = p_frame->p_hash_symbols; + + hash_iterate(p_hash_symbols, symbol_delete_cb); + hash_delete(p_hash_symbols); +} + +_Bool +frame_add_symbol(Frame *p_frame, char *c_name, SymbolType st, void *p_val) { + Hash *p_hash_symbols = p_frame->p_hash_symbols; + + if (hash_key_exists(p_hash_symbols, c_name)) + return (false); + + + Symbol *p_symbol = symbol_new(st, p_val); + hash_insert(p_hash_symbols, c_name, p_symbol); + + return (true); +} + +Symbol* +frame_get_symbol(Frame *p_frame, char *c_name) { + void *p_val = hash_get(p_frame->p_hash_symbols, c_name); + + if (!p_val && p_frame->p_parent_frame) + return (frame_get_symbol(p_frame->p_parent_frame, c_name)); + + return (p_val); +} + +void +_symbol_print_cb(void *p_val, char *c_name) { + Symbol *p_symbol = p_val; + switch (p_symbol->st) { + case ST_LAMBDA: + lambda_print(p_symbol->p_val); + break; + case ST_VARIABLE: + variable_print(p_symbol->p_val); + break; + } +} + +void +_frame_print(Frame *p_frame, int i_frame_nr) { + printf("FRAME(id=%u) %d:\n", p_frame->i_frame_id, i_frame_nr); + + Hash *p_hash_symbols = p_frame->p_hash_symbols; + hash_iterate_key(p_hash_symbols, _symbol_print_cb); + + if (p_frame->p_parent_frame) + _frame_print(p_frame->p_parent_frame, i_frame_nr + 1); +} + +void +frame_print(Frame *p_frame) { + _frame_print(p_frame, 0); +} diff --git a/src/core/frame.h b/src/core/frame.h new file mode 100644 index 0000000..d1e01f5 --- /dev/null +++ b/src/core/frame.h @@ -0,0 +1,68 @@ +/*:* + *: File: ./src/core/frame.h + *: A simple Fype interpreter + *: + *: WWW: http://fype.buetow.org + *: AUTHOR: http://paul.buetow.org + *: E-Mail: fype at dev.buetow.org + *: + *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: + *: Redistribution and use in source and binary forms, with or without modi- + *: fication, are permitted provided that the following conditions are met: + *: * Redistributions of source code must retain the above copyright + *: notice, this list of conditions and the following disclaimer. + *: * Redistributions in binary form must reproduce the above copyright + *: notice, this list of conditions and the following disclaimer in the + *: documentation and/or other materials provided with the distribution. + *: * Neither the name of buetow.org nor the names of its contributors may + *: be used to endorse or promote products derived from this software + *: without specific prior written permission. + *: + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: POSSIBILITY OF SUCH DAMAGE. + *:*/ + +#ifndef FRAME_H +#define FRAME_H + +#include "../defines.h" +#include "../data/hash.h" + +typedef enum { + ST_LAMBDA, + ST_VARIABLE, +} SymbolType; |
