1. preprocessor

------=_NextPart_000_0008_01C01520.CE70A740
        charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

The soulution to your problems with lack of language features and coding =
shorcuts is to write your own preprocessor. Then you can have C-like =
#define macros, you can have object programming, you can even solve the =
problem that the functions you use must be before you, you can customize =
the language the way you want to.
I am surprised that noone is working on a *good fast* preprocessor and =
nobody seems to be using the existing ones, like david cuny's. Maybe if =
you added some more documentation help files of all new freatures i =
would use it, and some example code along.

------=_NextPart_000_0008_01C01520.CE70A740
        charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-2" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3401" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DVerdana size=3D2>The soulution to your problems with =
lack of=20
language features and coding shorcuts is to write your own preprocessor. =
Then=20
you can have&nbsp;C-like #define macros, you can have object=20
programming,&nbsp;you can even&nbsp;solve the problem that the functions =
you use=20
must be before you, you can customize the language the way you want=20
to.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>I am surprised that noone is working =
on a *good=20
fast* preprocessor and nobody seems to be using the existing ones, like =
david=20
cuny's. Maybe if you added some more documentation help files of all new =

freatures i would use it, and some example&nbsp;code=20

------=_NextPart_000_0008_01C01520.CE70A740--

new topic     » topic index » view message » categorize

2. preprocessor

I have a lot of "assert()" and "if Debug" statements in my code, for debugging.
They catch a lot of bugs. But I'm sometimes affraid they'll slow my code down. So
I would like to have preprocessor which would comment out these debug lines.

If I'm already "compiling" my code then I would also like this preprocessor to
support some other things. Structures is one of them. I'm not sure how to handle
array of structures though. Nothing complicated, something like this:

-- Rectangle structure.
structure RECT
	-- left point of rectangle
	integer left
	-- top point of rectangle
	integer top
	-- right point of rectangle
	integer right
	integer bottom -- bottom point of rectangle
end structure

RECT rect
rect = new (RECT)
rect.left = 66

RECT *rects
rects = repeat (0, 100)
for i = 1 to length (rects) do
	rects [i] = new (RECT)
	rects [i].left = i
end for

would translate to this:

-- Rectangle structure.

-- left point of rectangle
constant RECT_LEFT = 1
-- top point of rectangle
constant RECT_TOP = 2
-- right point of rectangle
constant RECT_RIGHT = 3
-- bottom point of rectangle
constant RECT_BOTTOM = 4
constant RECT_SIZEOF = 4
type RECT (object rect)
	if not sequence (rect) then
		return false
	end if
	if not integer (rect [RECT_LEFT]) then
		return false
	end if
	if not integer (rect [RECT_TOP]) then
		return false
	end if
	if not integer (rect [RECT_RIGHT]) then
		return false
	end if
	if not integer (rect [RECT_BOTTOM]) then
		return false
	end if
	return true
end type

function new_rect ()
	return repeat (0, RECT_SIZEOF)
end function

RECT rect
rect = new_rect ()
rect [RECT_LEFT] = 66

sequence rects
rects = repeat (0, 100)
for i = 1 to length (rects) do
	rects [i] = new_rect ()
	rects [i] [RECT_LEFT] = i
end for

Here comes another problem: every line in translated file should have same line
number as it had it in source file, so that you can know where error happened in
source file when it's reported by euphoria interpreter.
So that means that all code within RECT type should fit into one line. But I
know that euphoria interpreter complaints pretty quick if line is too long. So
that wouldn't work. I don't know for any workaround for this problem.

It's got to be fast, so you don't wait long to "compile". 

It has to check all included files and translate them if needed.
For each file that it would translate it would save this info into database:
date and time when it was last translated. So when file needs to be translated
check this info if we can use already translated file. This is to speed up
translation. Because I really don't want trnslation to take more than a few
seconds.

I'm too lazy to do it and it's a lot of work. But it would be good if it would
be done.

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

3. Re: preprocessor

Tone, you're far from the first person to ask about this...

Have a look on empire (empire.iwireweb.com) ... Eulex has built a pre
processor that you might be interested in..


On Tue, 26 Oct 2004 12:32:08 -0700, Tone =C5=A0koda <guest at rapideuphoria.co=
m> wrote:
>
> posted by: Tone =C5=A0koda <tskoda at email.si>
>
> I have a lot of "assert()" and "if Debug" statements in my code, for debu=
gging. They catch a lot of bugs. But I'm sometimes affraid they'll slow my =
code down. So I would like to have preprocessor which would comment out the=
se debug lines.
>
> If I'm already "compiling" my code then I would also like this preprocess=
or to support some other things. Structures is one of them. I'm not sure ho=
w to handle array of structures though. Nothing complicated, something like=
 this:
>
> -- Rectangle structure.
> structure RECT
>         -- left point of rectangle
>         integer left
>         -- top point of rectangle
>         integer top
>         -- right point of rectangle
>         integer right
>         integer bottom -- bottom point of rectangle
> end structure
>
> RECT rect
> rect = new (RECT)
> rect.left = 66
>
> RECT *rects
> rects = repeat (0, 100)
> for i = 1 to length (rects) do
>         rects [i] = new (RECT)
>         rects [i].left = i
> end for
>
> would translate to this:
>
> -- Rectangle structure.
>
> -- left point of rectangle
> constant RECT_LEFT = 1
> -- top point of rectangle
> constant RECT_TOP = 2
> -- right point of rectangle
> constant RECT_RIGHT = 3
> -- bottom point of rectangle
> constant RECT_BOTTOM = 4
> constant RECT_SIZEOF = 4
> type RECT (object rect)
>         if not sequence (rect) then
>                 return false
>         end if
>         if not integer (rect [RECT_LEFT]) then
>                 return false
>         end if
>         if not integer (rect [RECT_TOP]) then
>                 return false
>         end if
>         if not integer (rect [RECT_RIGHT]) then
>                 return false
>         end if
>         if not integer (rect [RECT_BOTTOM]) then
>                 return false
>         end if
>         return true
> end type
>
> function new_rect ()
>         return repeat (0, RECT_SIZEOF)
> end function
>
> RECT rect
> rect = new_rect ()
> rect [RECT_LEFT] = 66
>
> sequence rects
> rects = repeat (0, 100)
> for i = 1 to length (rects) do
>         rects [i] = new_rect ()
>         rects [i] [RECT_LEFT] = i
> end for
>
> Here comes another problem: every line in translated file should have sam=
e line number as it had it in source file, so that you can know where error=
 happened in source file when it's reported by euphoria interpreter.
> So that means that all code within RECT type should fit into one line. Bu=
t I know that euphoria interpreter complaints pretty quick if line is too l=
ong. So that wouldn't work. I don't know for any workaround for this proble=
m.
>
> It's got to be fast, so you don't wait long to "compile".
>
> It has to check all included files and translate them if needed.
> For each file that it would translate it would save this info into databa=
se: date and time when it was last translated. So when file needs to be tra=
nslated check this info if we can use already translated file. This is to s=
peed up translation. Because I really don't want trnslation to take more th=
an a few seconds.
>
> I'm too lazy to do it and it's a lot of work. But it would be good if it =
would be done.
>
>
>
>
>


--
MrTrick
----------

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

4. Re: preprocessor

Tone Škoda wrote:
> 
> I have a lot of "assert()" and "if Debug" statements in my code, for
> debugging. They
> catch a lot of bugs. But I'm sometimes affraid they'll slow my code down. So I
> would
> like to have preprocessor which would comment out these debug lines.

I have something that can do this. I'm still documenting it but it works.

> If I'm already "compiling" my code then I would also like this preprocessor to
> support
> some other things. Structures is one of them. I'm not sure how to handle array
> of structures
> though. Nothing complicated, something like this:
> 
> -- Rectangle structure.
> structure RECT
> 	-- left point of rectangle
> 	integer left
> 	-- top point of rectangle
> 	integer top
> 	-- right point of rectangle
> 	integer right
> 	integer bottom -- bottom point of rectangle
> end structure
> 
> RECT rect
> rect = new (RECT)
> rect.left = 66
> 
> RECT *rects
> rects = repeat (0, 100)
> for i = 1 to length (rects) do
> 	rects [i] = new (RECT)
> 	rects [i].left = i
> end for
> 
> would translate to this:
> 
> -- Rectangle structure.
> 
> -- left point of rectangle
> constant RECT_LEFT = 1
> -- top point of rectangle
> constant RECT_TOP = 2
> -- right point of rectangle
> constant RECT_RIGHT = 3
> -- bottom point of rectangle
> constant RECT_BOTTOM = 4
> constant RECT_SIZEOF = 4
> type RECT (object rect)
> 	if not sequence (rect) then
> 		return false
> 	end if
> 	if not integer (rect [RECT_LEFT]) then
> 		return false
> 	end if
> 	if not integer (rect [RECT_TOP]) then
> 		return false
> 	end if
> 	if not integer (rect [RECT_RIGHT]) then
> 		return false
> 	end if
> 	if not integer (rect [RECT_BOTTOM]) then
> 		return false
> 	end if
> 	return true
> end type
> 
> function new_rect ()
> 	return repeat (0, RECT_SIZEOF)
> end function
> 
> RECT rect
> rect = new_rect ()
> rect [RECT_LEFT] = 66
> 
> sequence rects
> rects = repeat (0, 100)
> for i = 1 to length (rects) do
> 	rects [i] = new_rect ()
> 	rects [i] [RECT_LEFT] = i
> end for

This it doesn't do. This effect is no so simple to implement. 

> Here comes another problem: every line in translated file should have same
> line number
> as it had it in source file, so that you can know where error happened in
> source file
> when it's reported by euphoria interpreter.
> So that means that all code within RECT type should fit into one line. But I
> know that
> euphoria interpreter complaints pretty quick if line is too long. So that
> wouldn't
> work. I don't know for any workaround for this problem.

This is also not really possible as one line of 'macro' code can often
create multiple lines of 'source code', and may even reorder them as well.

My 'solution' is to create a third file that contains a listing of the
the output but with input line and file references embedded in it.

> It's got to be fast, so you don't wait long to "compile". 

This is fairly easy. My macro processor is very fast.

> It has to check all included files and translate them if needed.
> For each file that it would translate it would save this info into database:
> date and
> time when it was last translated. So when file needs to be translated check
> this info
> if we can use already translated file. This is to speed up translation.
> Because I really
> don't want trnslation to take more than a few seconds.

Typically its less than the time Euphoria needs to parse the generated
source.

> I'm too lazy to do it and it's a lot of work. But it would be good if it would
> be done.

Oh well, that's life for you. 

-- 
Derek Parnell
Melbourne, Australia

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

5. Re: preprocessor

Derek Parnell wrote:
> 
> Tone Škoda wrote:
> > 
> > I have a lot of "assert()" and "if Debug" statements in my code, for
> > debugging. They
> > catch a lot of bugs. But I'm sometimes affraid they'll slow my code down. So
> > I would
> > like to have preprocessor which would comment out these debug lines.
> 
> I have something that can do this. I'm still documenting it but it works.



I'm not sure I'm willing to use a preprocessor only for removing debug
statements. Using preprocessor is too much trouble. If I would go into troubule
of using preprocessor then it would have to be very good.

But I would like to see your preprocessor.

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

6. Re: preprocessor

Patrick Barnes wrote:
> 
> Tone, you're far from the first person to ask about this...
> 
> Have a look on empire (empire.iwireweb.com) ... Eulex has built a pre
> processor that you might be interested in..


I see that both Alexander Toresson and Chris Bensler are making their own
preprocessors. They both read this mailing list so they read my requests. If they
will add them into their preprocessors is up to them.

I'm not planning to do it, I think I'll just manually comment out debug
statements for really critical code. I think there are not too many places like
that.

I'll be glad if someone will make a preprocessor that I described.
I would also like // comments added, so that I won't have to use --//, because
it's ugly.

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

7. Re: preprocessor

Tone Škoda wrote:
> I have a lot of "assert()" and "if Debug" statements in my code, for
> debugging. They
> catch a lot of bugs. But I'm sometimes affraid they'll slow my code down. So I
> would
> like to have preprocessor which would comment out these debug lines.

The new 2.5 Translator will completely remove a block of code such as:
if expr then
    ...
    -- lots of statements
    ...
end if

whenever it can see at compile-time that 
expr always evaluates to 0 (FALSE). e.g.
constant DEBUG = FALSE

if DEBUG then
    ...
end if

-- or a bit more complicated:
if platform() = LINUX then 
    ...
end if


It optimizes "while expr" and "elsif expr" the same way.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

8. Re: preprocessor

Ooh, nice!

Why don't you publicise these enhancements more?

On Tue, 26 Oct 2004 19:06:14 -0700, Robert Craig
<guest at rapideuphoria.com> wrote:
> posted by: Robert Craig <rds at RapidEuphoria.com>
> The new 2.5 Translator will completely remove a block of code such as:
> }}}
<eucode>
> if expr then
>     ...
>     -- lots of statements
>     ...
> end if
> </eucode>
{{{

> whenever it can see at compile-time that
> expr always evaluates to 0 (FALSE). e.g.

- 
MrTrick

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

9. Re: preprocessor

Robert Craig wrote:

[snip]

> The new 2.5 Translator will ...

That reminds me, it must about time for one of your regular weekly
progress reports. blink

Many of us are very keen to see v2.5 make headway.

-- 
Derek Parnell
Melbourne, Australia

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

10. Re: preprocessor

Derek Parnell wrote:
> That reminds me, it must about time for one of your regular weekly
> progress reports. blink
> 
> Many of us are very keen to see v2.5 make headway.

I'm guessing it will be another 10 days, but all my previous
estimates have been wrong. So much code has been rewritten, 
it might be necessary to have two alpha releases before the 
beta release. Things look solid to me, but who knows what you 
people will find. smile

I'm using '$' wherever I can, and I'm using a crash handler 
in all my CGI programs on the Web site. The handler e-mails me
the ex.err file when a CGI program fails. I caught a few bugs 
already where people were doing weird things that I never do.

The code was frozen a while ago, but I'm going to have to do
at least one more build and test on all platforms. I 
also have to proof-read all the docs, and finish
the release notes, readme, etc., and test the install procedure.
Then there's updating the Web site ...
Then there's the stuff that I remember at the last minute...

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

11. Re: preprocessor

Robert Craig wrote:
> 
> I'm guessing it will be another 10 days, 

NNNNOOOOO!!!! That's when Halo 2 is due! Can't you delay v2.5 a week blink

> but all my previous estimates have been wrong.

I can only hope.

> So much code has been rewritten, 
> it might be necessary to have two alpha releases before the 
> beta release.

How much will it take to bribe my way on to the alpha-test team blink

> Things look solid to me, but who knows what you 
> people will find. smile

Oh yes, there's always some joker out there that finds the 'obvious' bugs,
that you know weren't there when you last checked :D

> I'm using '$' wherever I can, and I'm using a crash handler 
> in all my CGI programs on the Web site. The handler e-mails me
> the ex.err file when a CGI program fails. I caught a few bugs 
> already where people were doing weird things that I never do.

That's GREAT! Have those little changes made a difference to the
way you approach coding?
 
> The code was frozen a while ago, but I'm going to have to do
> at least one more build and test on all platforms. I 
> also have to proof-read all the docs, and finish
> the release notes, readme, etc., and test the install procedure.

Oooh, oooh! Pick me! Pick me! 
(Derek sits up straight waving his arm up high)

> Then there's updating the Web site ...
> Then there's the stuff that I remember at the last minute...

If it wasn't for the "last minute" nothing would ever get completed.

-- 
Derek Parnell
Melbourne, Australia

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

12. Re: preprocessor

Robert Craig wrote:

> I'm guessing it will be another 10 days, but all my previous
> estimates have been wrong. So much code has been rewritten, 
> it might be necessary to have two alpha releases before the 
> beta release. Things look solid to me, but who knows what you 
> people will find. smile

Nobody knows - until someone other than Rob and Junko gets to try.
I really think you are being over-cautious. Everyone understands 
that an 'alpha' release is likely to have a bug or two. That's 
the purpose of having alpha releases - to enlist help in finding the 
remaining bugs. 

Other languages I use sometimes have whole sections of code marked as 
'unstable' or 'testing', or even, 'to be replaced - do not use for 
production work'. No one complains about such things - they accept that 
as part of the alpha (and beta) testing process. If they have some 
important production work to do, there's always the previous stable 
version for that.

> I'm using '$' wherever I can, and I'm using a crash handler 
> in all my CGI programs on the Web site. The handler e-mails me
> the ex.err file when a CGI program fails. I caught a few bugs 
> already where people were doing weird things that I never do.

That's the point of releasing an alpha version - there are lots of 
'weird' but perfectly valid things which you might never try,
but other people would stumble across right away, given the opportunity. 

> The code was frozen a while ago, but I'm going to have to do
> at least one more build and test on all platforms. I 
> also have to proof-read all the docs, and finish
> the release notes, readme, etc., and test the install procedure.
> Then there's updating the Web site ...
> Then there's the stuff that I remember at the last minute...

More eyes find more typos.

Once upon a time I was an editor. Even though I and three or four others  
proof-read the copy, it was almost a sure bet that that some guy on 
a loading dock somewhere would notice an error as soon as the papers 
came off the truck. If you wait until you're sure everything is 
perfect, you'll never produce anything of interest.

Irv

Wearing both a belt and suspenders to hold up your pants is fine.
When you also insist on using thumbtacks and a stapler, people begin to 
worry.

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

13. Re: preprocessor

Hey Toni :
     you can use my mixedlib.e or w32engin.ew, which can be
     download from the links below, to do the following:

--
-- Rectangle structure.
--  structure RECT
--    -- left point of rectangle
--    integer left
--    -- top point of rectangle
--    integer top
--    -- right point of rectangle
--    integer right
--    integer bottom -- bottom point of rectangle
--  end structure
--
include mixedlib.e
--
  record("RECT", ---------- if using mixedlib.e then define RECT
    "left   : int : 1 "& -- RECT is already predefined in w32engin.ew
    "top    : int : 1 "&
    "right  : int : 1 "&
    "bottom : int : 1 ")

-- RECT rect
-- rect = new (RECT)
-- rect.left = 66
atom rect
  rect = struc("RECT") -- creates new RECT initialized to zeros.
  put(rect,"left",66)
--
-- RECT *rects
-- rects = repeat (0, 100)
-- for i = 1 to length (rects) do
--         rects [i] = new (RECT)
--         rects [i].left = i
-- end for
--
atom rects
-- create an array of
-- 100 RECT structures
rects = sArray("RECT",100)
-- set each rect.left to a value
for i = 1 to 100 do
  putsArray(rects,i,"left",i)
end for
-- print value in 25th rect.left
? grabsArray(rects,25,"left")
-- print the size of a single rect
? sizeof(rect)
-- print size of an array of rects
? sizeof(rects)
-- 


Bernie

My files in archive:

http://www.rapideuphoria.com/w32engin.zip
http://www.rapideuphoria.com/mixedlib.zip
http://www.rapideuphoria.com/eu_engin.zip
http://www.rapideuphoria.com/win32eru.zip

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

14. Re: preprocessor

Patrick Barnes wrote:
> 
> Tone, you're far from the first person to ask about this...
> 
> Have a look on empire (empire.iwireweb.com) ... Eulex has built a pre
> processor that you might be interested in..
> 

This is yet only a pre-processor that's not making any changes to the 
code, and waits for features being added.

Regards, Alexander Toresson

Shhh! Be vewy quiet! I'm hunting wuntime ewwows!

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

15. Re: preprocessor

Tone Škoda wrote:
> 
> I see that both Alexander Toresson and Chris Bensler are making their own
> preprocessors.
> They both read this mailing list so they read my requests. If they will add
> them into
> their preprocessors is up to them.
> 
> I'm not planning to do it, I think I'll just manually comment out debug
> statements
> for really critical code. I think there are not too many places like that.
> 
> I'll be glad if someone will make a preprocessor that I described.
> I would also like // comments added, so that I won't have to use --//, because
> it's
> ugly.
> 

That would be a piece of a cake to add into my pre-processor, though I do not
see the use of it.

Regards, Alexander Toresson

Shhh! Be vewy quiet! I'm hunting wuntime ewwows!

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

16. Re: preprocessor

Bernard Ryan wrote:

> include mixedlib.e
> --
>   record("RECT", ---------- if using mixedlib.e then define RECT
>     "left   : int : 1 "& -- RECT is already predefined in w32engin.ew
>     "top    : int : 1 "&
>     "right  : int : 1 "&
>     "bottom : int : 1 ")
> 
> -- RECT rect
> -- rect = new (RECT)
> -- rect.left = 66
> atom rect
>   rect = struc("RECT") -- creates new RECT initialized to zeros.
>   put(rect,"left",66)


Your definition of structure is simpler than what I do.
But using put(rect,"left",66) instead of rect[RECT_LEFT]=66? I still like the
latter more. And put(rect,"left",66) must be slower. I need all the speed I can
get. :)

I've come up with this to define "structure", it's a little prettier:

    constant RECT_LEFT = 1
    constant RECT_TOP = 2
    constant RECT_RIGHT = 3
    constant RECT_BOTTOM = 4
    type RECT (object rect)
        if not check_struct ({
            rect, "sequence",
            {RECT_LEFT, "integer"},
            {RECT_TOP, "integer"},
            {RECT_RIGHT, "integer"},
            {RECT_BOTTOM, "integer"}
            }) then
            return false
        end if
        return true
    end type

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

17. Re: preprocessor

Tone Škoda wrote:
> 
> Bernard Ryan wrote:
> 
> > include mixedlib.e
> > --
> >   record("RECT", ---------- if using mixedlib.e then define RECT
> >     "left   : int : 1 "& -- RECT is already predefined in w32engin.ew
> >     "top    : int : 1 "&
> >     "right  : int : 1 "&
> >     "bottom : int : 1 ")
> > 
> > -- RECT rect
> > -- rect = new (RECT)
> > -- rect.left = 66
> > atom rect
> >   rect = struc("RECT") -- creates new RECT initialized to zeros.
> >   put(rect,"left",66)
> 
> 
> Your definition of structure is simpler than what I do.
> But using put(rect,"left",66) instead of rect[RECT_LEFT]=66? I still like the
> latter
> more. And put(rect,"left",66) must be slower. I need all the speed I can get.
> :)
> 
> I've come up with this to define "structure", it's a little prettier:
> 
>     constant RECT_LEFT = 1
>     constant RECT_TOP = 2
>     constant RECT_RIGHT = 3
>     constant RECT_BOTTOM = 4
>     type RECT (object rect)
>         if not check_struct ({
>             rect, "sequence",
>             {RECT_LEFT, "integer"},
>             {RECT_TOP, "integer"},
>             {RECT_RIGHT, "integer"},
>             {RECT_BOTTOM, "integer"}
>             }) then
>             return false
>         end if
>         return true
>     end type
> 

Your code idea will only work if you are
using entries that are the same size.

Try mixing in fields of different sizes;
or strings, unions, and nested structures.  

Bernie

My files in archive:
http://www.rapideuphoria.com/w32engin.zip
http://www.rapideuphoria.com/mixedlib.zip
http://www.rapideuphoria.com/eu_engin.zip
http://www.rapideuphoria.com/win32eru.zip

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

18. Re: preprocessor

Bernard Ryan wrote:
> > 
> > I've come up with this to define "structure", it's a little prettier:
> > 
> >     constant RECT_LEFT = 1
> >     constant RECT_TOP = 2
> >     constant RECT_RIGHT = 3
> >     constant RECT_BOTTOM = 4
> >     type RECT (object rect)
> >         if not check_struct ({
> >             rect, "sequence",
> >             {RECT_LEFT, "integer"},
> >             {RECT_TOP, "integer"},
> >             {RECT_RIGHT, "integer"},
> >             {RECT_BOTTOM, "integer"}
> >             }) then
> >             return false
> >         end if
> >         return true
> >     end type
> > 
> 
> Your code idea will only work if you are
> using entries that are the same size.
> 
> Try mixing in fields of different sizes;
> or strings, unions, and nested structures.  


entires can be of different size, why not?

I found out my check_struct() is not possible because i found out this example
doesnt work:

include get.e

procedure call_it (sequence procname)
    call_proc (routine_id (procname), {})
end procedure

procedure i_will_be_called ()
    puts (1, "hello!\n")
end procedure

procedure main ()
    call_it ("i_will_be_called")
    if wait_key () then end if
end procedure

main ()


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

19. Re: preprocessor

Robert Craig wrote:
> The new 2.5 Translator will completely remove a block of code such as:
> }}}
<eucode>
> if expr then
>     ...
>     -- lots of statements
>     ...
> end if
> </eucode>
{{{

> whenever it can see at compile-time that 
> expr always evaluates to 0 (FALSE).

That looks good, I'll use it.

I have a question:

I use this:

integer Debug
Debug = true

global procedure assert (integer be_true)
    if Debug then
	    if be_true = false then
                ... tell user assert was called ...
	    end if
    end if
end procedure

I would prefer to use

assert (length (smth) > length (smth_else))

than

if Debug then
	assert (length (smth) > length (smth_else))
end if

So, will translator also remove calls to routines which do nothing, like
assert() in non-debug mode? assert's argument also slows things down because it
has to be evaluated.

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

20. Re: preprocessor

Tone Škoda wrote:
> 
> entires can be of different size, why not?
> 
> I found out my check_struct() is not possible because i found out this example
> doesnt
> work:
> 

My structures are created in memory, Yours are in sequences.
When you need to pass a structure to a windows or some "C"
function then you will need to calculate the size of each entry
and poke in into memory takeing in to account each entry size anc etc.

Once you do this with my structure.
atom rect
rect = struc("RECT")
put(rect,"RECT",66)
-- You can use the pointer rect to pass it to windows
  callsomefunction(rect)


Bernie

My files in archive:

http://www.rapideuphoria.com/w32engin.zip
http://www.rapideuphoria.com/mixedlib.zip
http://www.rapideuphoria.com/eu_engin.zip
http://www.rapideuphoria.com/win32eru.zip

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

21. Re: preprocessor

Bernard Ryan wrote:
> 
> My structures are created in memory, Yours are in sequences.
> When you need to pass a structure to a windows or some "C"
> function then you will need to calculate the size of each entry
> and poke in into memory takeing in to account each entry size anc etc.

Yes, I want structures for euphoria code. I'm not interested in structures which
can be used with dlls.

> >     type RECT (object rect)
> >         if not check_struct ({
> >             rect, "sequence",
> >             {RECT_LEFT, "integer"},
> >             {RECT_TOP, "integer"},
> >             {RECT_RIGHT, "integer"},
> >             {RECT_BOTTOM, "integer"}
> >             }) then
> >             return false
> >         end if
> >         return true
> >     end type

I forgot to mention that "integer" is name of existing (user defined) type and I
intended to call it with call_func (routine_id()), but in order for it to work
check_struc() would have to be placed after types it calls.

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

22. Re: preprocessor

Tone Škoda wrote:
> 
> Robert Craig wrote:
> > The new 2.5 Translator will completely remove a block of code such as:
> > }}}
<eucode>
> > if expr then
> >     ...
> >     -- lots of statements
> >     ...
> > end if
> > </eucode>
{{{

> > whenever it can see at compile-time that 
> > expr always evaluates to 0 (FALSE).
> 
> That looks good, I'll use it.
> 
> I have a question:
> 
> I use this:
> 
> integer Debug
> Debug = true
> 
> global procedure assert (integer be_true)
>     if Debug then
> 	    if be_true = false then
>                 ... tell user assert was called ...
> 	    end if
>     end if
> end procedure
> 
> I would prefer to use
> 
> assert (length (smth) > length (smth_else))
> 
> than
> 
> if Debug then
> 	assert (length (smth) > length (smth_else))
> end if
> 
> So, will translator also remove calls to routines which do nothing, like
> assert() in
> non-debug mode? assert's argument also slows things down because it has to be
> evaluated.

No, it currently won't remove calls to empty procedures.
I'll add that to my list for 2.6.

Thanks,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

23. Re: preprocessor

On Wed, 27 Oct 2004 16:12:20 -0700, Tone =8Akoda
<guest at RapidEuphoria.com> wrote:

>I found out my check_struct() is not possible because i found out this exa=
mple doesnt work:
<snip>
Try this:
>
include get.e

integer rid
procedure call_it (sequence procname)
	call_proc (call_func(rid,{procname}),{})
end procedure

procedure i_will_be_called ()
	puts (1, "hello!\n")
end procedure

procedure main ()
	call_it ("i_will_be_called")
	if wait_key () then end if
end procedure

function rtnid(sequence procname)
	return routine_id(procname)
end function
rid=routine_id("rtnid")

main ()


Regards,
Pete

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

24. Re: preprocessor

Tone Škoda wrote:
> 
> That looks good, I'll use it.
> 
> I have a question:
> 
> I use this:
> 
> integer Debug
> Debug = true
> 
> global procedure assert (integer be_true)
>     if Debug then
> 	    if be_true = false then
>                 ... tell user assert was called ...
> 	    end if
>     end if
> end procedure
> 
> I would prefer to use
> 
> assert (length (smth) > length (smth_else))
> 
> than
> 
> if Debug then
> 	assert (length (smth) > length (smth_else))
> end if
> 
> So, will translator also remove calls to routines which do nothing, like
> assert() in
> non-debug mode? assert's argument also slows things down because it has to be
> evaluated.
> 

What you could do is to add a macro to your translated files:

#define assert(x)

...and it will all go away.  It's pretty easy to do this with a 
preprocessor, and not much more of a burden than simply calling ecw.
I typically set up a batch file that calls all the preprocessors I need,
calls ecw and then makes the executable (I generally copy the contents
of emake.bat into my own batch file).

Matt Lewis

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

25. Re: preprocessor

Pete Lomax wrote:

> Try this:
> >
> }}}
<eucode>
> include get.e
> 
> integer rid
> procedure call_it (sequence procname)
> 	call_proc (call_func(rid,{procname}),{})
> end procedure
> 
> procedure i_will_be_called ()
> 	puts (1, "hello!\n")
> end procedure
> 
> procedure main ()
> 	call_it ("i_will_be_called")
> 	if wait_key () then end if
> end procedure
> 
> function rtnid(sequence procname)
> 	return routine_id(procname)
> end function
> rid=routine_id("rtnid")
> 
> main ()
> </eucode>
{{{



that works for this specific example, but now rtnid() has to be after any types
that check_struc might call, including any types i define in main .exw file.

bwt, this is how check_struc() looks:

--// returns bool
function is_var_of_type (object var, sequence type_name)
    if equal (type_name, "sequence") then
        return sequence (var)
    elsif equal (type_name, "atom") then
        return atom (var)
    elsif equal (type_name, "integer") then
        return integer (var)
    elsif equal (type_name, "object") then
        return object (var)
    else
        return call_func (routine_id (type_name), {var})
    end if
end function

--/*
-- check_struc [Created on 27. October 2004, 23:05]
-- The 'check_struc' function checks if
-- a structure-like sequence is made of right
-- types of members.
-- It is meant to be used inside types.
--
-- PARAMETERS
-- 'struc_def'
--    1. First member should be object which you wish to check
--       if it has the right structure.
--       This is 'struc'.
--    2. Of what type should be 'struc'.
--       Name of existing type. STRING.
--       Can be left out if you don't want to specify type for this member.
--    3. and all next members should have this format.
--       They can be not specified if 'struc' is not sequence
--       but atom, for example.
--      1. Structure member number. Where in 'struc' is this member.
--      2. Of what type should be the this member of structre.
--         Name of existing type. STRING.
--         Can be left out if you don't want to specify type for this member.
--
-- RETURN VALUES
-- bool.
--*/
global function check_struc (sequence struc_def)
    object struc
    if length (struc_def) < 1 then
        return true
    end if
    struc = struc_def [1]
    if length (struc_def) >= 2 then
        if not is_var_of_type (struc, struc_def [2]) then
            return false
        end if
    end if
    if length (struc_def) >= 3 then
        for i = 3 to length (struc_def) do
            if length (struc_def [i]) >= 2 then
                if not is_var_of_type (struc [struc_def [i] [1]],
                    struc_def [i] [2]) then
                    return false
                end if
            end if
        end for
    end if    
    return true
end function


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

26. Re: preprocessor

Matt Lewis wrote:
> 
> What you could do is to add a macro to your translated files:
> 
> #define assert(x)

that's good idea. i don't have much experience with translating eu to c (i never
do it), so that i cant even remember what ecw means.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu