No more platform(), conditional includes, conditional functions, conditional compilation, all done!

new topic     » topic index » view thread      » older message » newer message

Wow, I am pumped... Look at this code:

with define=debug
atom lib

ifdef debug then
    include safe.e
else
    include machine.e
end ifdef


ifdef LINUX then

    lib = open_dll("hello.so")
    global function say_hello()
        puts(1, "Hello from Linux!\n")
    end function

elsifdef WIN32 then

    lib = open_dll("hello.dll")
    global function say_hello()
        puts(1, "Hello from Windows!\n")
    end function

elsifdef DOS32 then
    
    lib = -1
    global function say_hello()
        puts(1, "Hello from DOS!\n")
    end function

end ifdef

say_hello()


This all works and this works at the parsing level. What this means is:

for i = 1 to length(lines) do
    ifdef debug then
        printf(1, "Line: %s\n", {lines[i]})
    end ifdef
    
    -- real code
end for


During the parse, the ifdef is translated at parse/compile time. Not runtime.
This means that the decision "ifdef debug" is made once, not every iteration of
the loop. Therefore, if debug is defined, then this is *exactly* what the code
looks like to the runtime or in the C code translated:

for i = 1 to length(lines) do
    printf(1, "Line: %s\n", {lines[i]})
    -- real code
end for


Notice, no decision logic! If debug is not defined, then in both the interpreter
and C code translated, you only see:

for i = 1 to length(lines) do
    -- real code
end for


This is exciting!

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu