Page 1 of 1

(global) bug and question

Posted: Sat Apr 08, 2006 3:27 pm
by Dmi
First, the bug:

Code: Select all

dmi@dc:dmi$ newlisp
newLISP v.8.8.0-p2 on linux, execute 'newlisp -h' for more info.

> (global)
Segmentation fault
Second, a question:
How can I get a list of symbos of MAIN, that are maden global (either by
default or through (global sym))?

Posted: Sat Apr 08, 2006 3:57 pm
by Lutz
There is no streight way to get a list of all global symbols, but you could do the following hack for a 'global?' predicate which you could 'map' on to (symbols) and filter for not primitive?:

Code: Select all

(define (global? s)
        (let (mask (if (= (pack "d" 1) "\000\001") 0x02000000 0x00000200))
                (= (& (get-int (last (dump s))) mask) mask)))

> (global? 'x)
nil
> (global 'x)
x
> (global? 'x)
true
> 
This tests the global bit of a symbol type field and works on both: big-endian and little-endia systems.

Lutz

Posted: Sat Apr 08, 2006 4:01 pm
by newdep
aaaaaaaa....your on the right track ;-)

Posted: Sat Apr 08, 2006 4:52 pm
by Dmi
Thanks!

Posted: Sat Apr 08, 2006 8:18 pm
by Dmi
Hmm... on my little endian (i belive ;-) Intel Celeron the test shows following:

Code: Select all

> (pack "\d" 1)
"\001\000"
so the rule for mask should be inversed:

Code: Select all

(let (mask (if (= (pack ">d" 1) "\000\001") 0x00000200 0x02000000))

Posted: Sat Apr 08, 2006 8:28 pm
by Lutz
actually it should be like this:

Code: Select all

define (global? s)
        (let (mask (if (= (pack "d" 1) "\000\001") 0x02000000 0x00000200))
                (= (& (get-int (last (dump s))) mask) mask)))
The '>' would always produce bigh-endian and the '<' always little-endian. So when testing for endianess, no '<' or '>' should be put. This should work for you.

Lutz

Posted: Sat Apr 08, 2006 8:39 pm
by Dmi
It does. Thanks again.