skip to main content

kiesler.at

Boundary Checks with gforth
updated by rck, 2004-05-21

Forth is a fascinating language. I've been hunting a bug in definition of mere 5 words for quite some weeks now. Now that I know, why things are the way the are, it seems quite trivial. I'm documenting the definition of check-range ( u lower-bound upper-bound -- ), while I still know about it.
                     
1 | 2 | 3

Preface

I'm currently writing on a assembler and disassembler for gforth for the SPARC-Platform. Currently, as in 1.5 years more or less hard work.

There are some finished assemblers / disassemblers for gforth already and I have access to their sourcecode. Thus, my spasm, as I call it, is based on the MIPS-Assembler/Disassembler

Checking Bounds in C

checking bounds is kind of a trivial task, or so it seems. Imagine a C-Function like the following:

check_bounds(int val, int lower, int upper) {
  return((lower <= val) && (val <= upper));
}

Checking Bound with Exceptionhandling

The forth-word I need behaves a little different. Written down in pseudo-code, it would be:

check_bounds(int val, int lower, int upper) {
  if((lower > val) || (upper < val))
    throw(new index_out_of_bounds_exception());
}

                     
1 | 2 | 3



RSSComments - Make a comment
The comments are owned by the poster. We are not responsible for its content.
RSSAll Articles
2008, 2007, 2006, 2005, 2004

What's Related

Link Manager

Forth

Article Manager

Forth

FAQ

Forth

Latest Updates

AdministrativeTexts
updated by freddiemac1993, 2013-06-14
wiki

Re: adventures
created by brittdavis10, 2012-02-23 (1 rply, 3 views)
thread

Re: how to run phpwebsite...
created by alexander, 2011-08-25 (2 rpls, 3607 views)
thread

Re: Forum tags
created by HaroldFaragher, 2011-08-22 (3 rpls, 8488 views)
thread


Zu den KO2100 Foren