1. OSX platform code

What platform() code do you plan to use on OSX?

I don't know this system.

Is this system so similar to Linux-BSD that we can use the same code? or is better assign a new code?

new topic     » topic index » view message » categorize

2. Re: OSX platform code

Marco A. Achury P. said...

What platform() code do you plan to use on OSX?

I don't know this system.

Is this system so similar to Linux-BSD that we can use the same code? or is better assign a new code?

I believe it is set up to return a 3. They are all UNIX.

It is highly recommended to use the new ifdef system instead of platform(). platform() is now decapricated.

new topic     » goto parent     » topic index » view message » categorize

3. Re: OSX platform code

Marco A. Achury P. said...

What platform() code do you plan to use on OSX?

It is different enough that a new code should be returned, but IMHO, a new code should be returned for FreeBSD as well, but it's too late for that. platform() returns 3 for Linux and FreeBSD and returns 4 for OS X. However, as Jim said, I would not use platform() any more. The new ifdef system is much better in almost all ways as it removes any run time check. It is only a parse time check. ifdef has a few predefined words thus far:

  • DOS32
  • WIN32
  • LINUX
  • FREEBSD
  • OSX
  • UNIX
  • EU400

UNIX is true when LINUX, FREEBSD or OSX is true. FREEBSD is only true on a legitimate FreeBSD machine. It is not true on Linux machines.

You can also define your own words at runtime by:

C:\EUPHORIA > exwc -D MYWORD myapp.ex 

or in code:

with define=MYWORD 

Now, you can do things such as:

while get_line() do 
    ifdef DEBUG then  
        printf(1, "Line='%s'\n", {line}) 
    end ifdef 
    -- process code 
end while 

The above is where the real power of the ifdef system comes in, because, let's say that you run the above program with DEBUG defined, i.e.:

$ exu -D DEBUG myprog.ex 

The parser comes across the ifdef word, and makes a decision at parse time. Should this code be included? Oh, yes, it should, DEBUG is defined. So, the parser then only emits IL code for the contents of the ifdef, not the ifdef itself. So, the interpreter when it hit's this portion of code, actually sees:

while get_line() do 
    printf(1, "Line='%s'\n", {line}) 
    -- process code 
end while 

Notice, there is no logic decision in the code. That loop could loop 10,000,000,000,000,000 times w/no performance hit what-so-ever for deciding if it is DEBUG or not. Now, let's say you are done with your app and you run it without define DEBUG. Now the interpreter will see:

while get_line() do 
    -- process code 
end while 

Notice, all DEBUG code is gone, the interpreter sees none of it.

This is the same for any platform check. For instance, when wrapping a library:

ifdef WIN32 then 
    constant lib = open_dll("mylib.dll") 
elsifdef OSX then 
    constant lib = open_dll("mylib.dylib") 
elsifdef UNIX then 
    constant lib = open_dll("mylib.so") 
elsifdef DOS32 then 
    puts(1, "Please upgrade finally!? grin") 
    abort(1) 
else 
    puts(1, "Hm, what platform is this? Please email me!") 
    abort(2) 
end ifdef 

Notice how we can benefit from using a constant here. There is no redefinition of the lib constant because only 1 of those blocks is emitted. Also notice a trick I did with OSX and UNIX. When opening a library, Linux and FreeBSD are enough alike to support the same open_dll call, however, OS X is not, notice the .dylib extension. Thus, I checked for OSX first, then for UNIX (in which is true for FreeBSD, Linux and OSX but the OSX target would have already been tripped if it were OSX).

So, the long story is, platform() returns 4, but you should use ifdef. smile

Jeremy

new topic     » goto parent     » topic index » view message » categorize

4. Re: OSX platform code

Jeremy Cowgar said...
Marco A. Achury P. said...

What platform() code do you plan to use on OSX?

So, the long story is, platform() returns 4, but you should use ifdef. smile

Jeremy

I recall that platform() once returned 4 for FreeBSD, but Rob got so many complaints over it that he changed it to return 3 for FreeBSD.k

Also, the builtin platform() returns a 4 for OSX but the machine function (machine_func(53, {}) ) returns a 3 on OSX. So there is somewhat of an inconsistency here, but probably not a big deal since both are now decapricated.

Another reason to move to the ifdef system. :p

new topic     » goto parent     » topic index » view message » categorize

5. Re: OSX platform code

Jim C. Brown said...
Marco A. Achury P. said...

What platform() code do you plan to use on OSX?

I don't know this system.

Is this system so similar to Linux-BSD that we can use the same code? or is better assign a new code?

I believe it is set up to return a 3. They are all UNIX.

It is highly recommended to use the new ifdef system instead of platform(). platform() is now decapricated.

If you eliminate platform() shrouded programs will no longer be platform independant. Shrouded programs are pre-parsed il code. ifdef is a compile time function and can't be used to make decisions based on the platform with shrouded programs. Daryl

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu