|
|
Up |
|
|
  |
Author: The Beez'The Beez' Date: Sep 19, 2008 07:58
Krishna,
Are you SURE this is correct? I think this goes out of bounds for the
n{ array!
---8<---
3 INTEGER array n{
: LongRangeSensors ( -- )
d{ 3 } f@ f0< IF
cr ." LONG RANGE SENSORS ARE INOPERABLE"
ELSE
cr ." LONG RANGE SCAN FOR QUADRANT " q1 ? ." ," q2 ?
cr ." ------------" cr
q1 @ 2 + q1 @ 1- DO
-1 n{ 1 } !
-2 n{ 2 } !
-3 n{ 3 } !
---8<---
Hans Bezemer
|
| |
|
| | 18 Comments |
|
  |
Author: The Beez'The Beez' Date: Sep 19, 2008 08:01
For those who want to debug along, this is the underlying code:
---8<---
1 cells constant INTEGER
: ?allot here swap allot ;
: cell- ( a1 -- a2 | backup 1 cell)
[ 1 cells ] literal - ;
: matrix ( n m size -- )
create >r 2dup * r@ * 2 cells + ?allot
2dup ! cell+ r> swap ! 2drop does> [ 2 cells ] literal + ;
: }} ( addr i j -- addr[i][j] | fetch 2-D array address)
>r >r dup cell- cell- 2@ r> * r> + * + ;
9 9 INTEGER matrix g{{ \ the galaxy
4 4 INTEGER matrix k{{ \ Klingon data
9 9 INTEGER matrix z{{ \ cumulative record of galaxy
: array ( n cell_size -- | -- addr )
create 2dup swap 1+ * ?allot ! drop does> cell+ ;
: } ( addr n -- addr[n] | fetch 1-D array address)
over cell- @ * swap + ;
|
| Show full article (0.79Kb) |
|
| | no comments |
|
  |
Author: Doug HoffmanDoug Hoffman Date: Sep 19, 2008 08:51
The Beez' wrote:
> Krishna,
>
> Are you SURE this is correct? I think this goes out of bounds for the
> n{ array!
>
> ---8<---
> 3 INTEGER array n{
> : LongRangeSensors ( -- )
> d{ 3 } f@ f0< IF
> cr ." LONG RANGE SENSORS ARE INOPERABLE"
> ELSE
> cr ." LONG RANGE SCAN FOR QUADRANT " q1 ? ." ," q2 ?
> cr ." ------------" cr
> q1 @ 2 + q1 @ 1- DO
> -1 n{ 1 } !
> -2 n{ 2 } !
> -3 n{ 3 } !
> ---8<---
> ...
|
| Show full article (0.65Kb) |
| no comments |
|
  |
Author: Krishna MyneniKrishna Myneni Date: Sep 19, 2008 10:32
The Beez' wrote:
> Krishna,
>
> Are you SURE this is correct? I think this goes out of bounds for the
> n{ array!
>
> ---8<---
> 3 INTEGER array n{
> : LongRangeSensors ( -- )
> d{ 3 } f@ f0< IF
> cr ." LONG RANGE SENSORS ARE INOPERABLE"
> ELSE
> cr ." LONG RANGE SCAN FOR QUADRANT " q1 ? ." ," q2 ?
> cr ." ------------" cr
> q1 @ 2 + q1 @ 1- DO
> -1 n{ 1 } !
> -2 n{ 2 } !
> -3 n{ 3 } !
> ---8<---
> ...
|
| Show full article (0.88Kb) |
| no comments |
|
  |
Author: The Beez'The Beez' Date: Sep 19, 2008 14:03
On 19 sep, 19:32, Krishna Myneni ccreweb.org> wrote:
> I will take a closer look at the code presently. But the array/matrix
> stuff is lifted from the Forth Scientific Library (FSL). FSL arrays and
> matrices have a starting index of zero, so if I allocated an array with
> 3 elements, and used an index of 3, this would be an out of bounds
> condition. Please increase the alloted array size for the array n{.
Krishna,
I have done that already, but that doesn't seem the problem. The array
is used in this word only and you don't seem to use n{ 0 }. I think
you mixed up the Basic indexes while converting.
Hans Bezemer
|
| |
| no comments |
|
  |
Author: Krishna MyneniKrishna Myneni Date: Sep 19, 2008 16:19
The Beez' wrote:
> On 19 sep, 19:32, Krishna Myneni ccreweb.org> wrote:
>> I will take a closer look at the code presently. But the array/matrix
>> stuff is lifted from the Forth Scientific Library (FSL). FSL arrays and
>> matrices have a starting index of zero, so if I allocated an array with
>> 3 elements, and used an index of 3, this would be an out of bounds
>> condition. Please increase the alloted array size for the array n{.
> Krishna,
>
> I have done that already, but that doesn't seem the problem. The array
> is used in this word only and you don't seem to use n{ 0 }. I think
> you mixed up the Basic indexes while converting.
>
> Hans Bezemer
>
Hans,
|
| Show full article (1.28Kb) |
| no comments |
|
  |
Author: The Beez'The Beez' Date: Sep 19, 2008 16:42
On 20 sep, 01:19, Krishna Myneni bellsouth.net> wrote:
> There may be some other bug then. I remember explicitly deciding to keep the
> original Basic indices, and not subtracting 1, so that I wouldn't get confused
> between the Basic origin and the FSL array origin -- you will not find "{ 0" as
> a pattern in the file. Sacrificing one element, or one row and one column, is a
> small price to pay for avoiding confusion in the translation. There appear to be
> some instances where I initialize the 0 index elements to zero, but they should
> never be used by the actual code. Can you please send me your output, and I'll
> see if I can reproduce it?
Kris,
The program doesn't display any toxic behavior, it runs fine (after
increasing the allocation). The code just didn't look right and I
couldn't find any functional reason for the construction which made me
kind of suspicious about what I was overlooking.
No further action needed. I got my answer.
Hans Bezemer
|
| |
| no comments |
|
  |
Author: Doug HoffmanDoug Hoffman Date: Sep 19, 2008 18:55
This might be a problem:
variable d1 \ damage flag
^^^^^^^^^^^
: RepairDamage ( -- )
0 d1 !
w1 f@ d6 f!
w1 f@ 1e f>= IF 1e d6 f! THEN
9 1 DO
d{ I } f@ f0< IF
d6 f@ d{ I } f@ f+ d{ I } f!
d{ I } f@ -0.1e f> d{ I } f@ f0< and IF
-0.1e d{ I } f!
ELSE
d{ I } f@ 0e f>= IF
d1 f@ 1e f<> IF 1e d1 f! THEN
^^^^^ ^^^^^
-Doug
|
| |
| no comments |
|
  |
Author: Doug HoffmanDoug Hoffman Date: Sep 19, 2008 19:47
This might also be a problem:
fvariable x
^^^^^^^^^^^
: FirePhasers ( -- )
...
cr ." NUMBER OF UNITS TO FIRE " #in X !
^^^
e @ X @ - 0 >=
UNTIL
X @ 0> IF
X @ negate e +!
d{ 7 } f@ f0< IF X @ s>f ran0 f* fround>s X ! THEN
X @ k3 @ / h1 ! \ distribute phaser energy among klingons present
( there may be more uses of @ and ! with x )
-Doug
|
| |
| no comments |
|
  |
|
|
  |
Author: Krishna MyneniKrishna Myneni Date: Sep 19, 2008 20:09
Doug Hoffman wrote:
> This might also be a problem:
>
>
> fvariable x
> ^^^^^^^^^^^
>
>
> : FirePhasers ( -- )
>
> ...
> cr ." NUMBER OF UNITS TO FIRE " #in X !
> ^^^
> e @ X @ - 0 >=
> UNTIL
>
> X @ 0> IF
> X @ negate e +!
> d{ 7 } f@ f0< IF X @ s>f ran0 f* fround>s X ! THEN
> X @ k3 @ / h1 ! \ distribute phaser energy among klingons present ...
|
| Show full article (0.82Kb) |
| no comments |
|
|
|
|