idea for pre-processing
[1/11] from: anton::lexicon::net at: 20-Jun-2002 13:50
The following two lines work the same:
do %demo-trapezoid-morph.r
do read %demo-trapezoid-morph.r
This means that you can make a wrapper around
'do which will allow you to pre-process the file
before it is run.
Why?
I want to optionally strip debugging lines in my
programs, so that they run at top speed without
them. There will be no overhead of, eg:
if debug [print "inner loop"]
which could occur multiple times in a program,
and within tight, inner loops, impacting
performance.
The reason I have come to this idea was in
image processing.
Has anyone done something like this?
Anton.
[2/11] from: robert:muench:robertmuench at: 20-Jun-2002 11:33
> -----Original Message-----
> From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]On Behalf Of
<<quoted lines omitted: 8>>
> 'do which will allow you to pre-process the file
> before it is run.
Hi, just to be sure I understand this. You want to make an own 'read or use the
system 'read?
> I want to optionally strip debugging lines in my
> programs, so that they run at top speed without
> them.
Yes, good idea. I would like to have such a thing as well. How about a more
generic way:
set-version [debug 1.01 beta]
version debug [print "debug output"]
version 1.01 [<normal-rebol-code>]
With this you could easly configure the behaviour of your program. Don't know if
this will lead to context problems. But something like a pre-processor etc.
would be nice. This could even be expanded into a linker.
> Has anyone done something like this?
No, sorry but I'm interested. Robert
[3/11] from: greggirwin:mindspring at: 20-Jun-2002 11:09
Hi Anton,
<< I want to optionally strip debugging lines in my programs, so that they
run at top speed without them. >>
Should be DOable. ;) I haven't tackled it in REBOL, but have in another
language. There it was fairly simple to do it in line oriented fashion, and
the stuff I was processing all started with a specific object method call.
E.g.
Assert.Require ...
Assert.Ensure ...
In your example, looking for "if debug ["... would be similar, but then
you'd have to actually parse things to find the end of the block if you want
to handle debug code that spans more than one line.
If you're building a deployment tool, writing it as a real parser might be a
good way to go, maybe even if it's a runtime tool. A line-oriented approach
would probably be too limiting, though it's easy to do.
--Gregg
[4/11] from: sunandadh:aol at: 20-Jun-2002 13:51
Anton:
> I want to optionally strip debugging lines in my
> programs, so that they run at top speed without
<<quoted lines omitted: 4>>
> performance.
> Has anyone done something like this?
Here's something I picked up off this list a year or so ago. Put this in the
User.r or initialisation code:
either system/user/email = _my-email-address_ ;;; or some such test/prod
test
[d-print: :print]
[d-print: func [whatever [any-type!]] [] ]
That defines d-print as either 'print or nothing. Debugging code can then
stay in:
d-print "inner loop"
It doesn't _quite_ give you top speed as 'd-print will be evaluated -- here's
a test of the overhead:
d-print: func [whatever [any-type!]] []
loops: 100000000
Start-time: now/time/precise
loop loops [d-print "inner-loop"]
print ["d-print test " now/time/precise - start-time]
Start-time: now/time/precise
loop loops []
print ["null loop " now/time/precise - start-time]
Results on my machine:
d-print test 0:00:39.82
null loop 0:00:02.85
Other uses: I have system where d-print is turned on/off if an obscure button
is right-clicked when an input field contains an unlikely value. That's
invaluable for over-the-phone debugging.
Sunanda.
[5/11] from: nitsch-lists:netcologne at: 20-Jun-2002 20:16
Am Donnerstag, 20. Juni 2002 05:50 schrieb Anton:
> The following two lines work the same:
> do %demo-trapezoid-morph.r
<<quoted lines omitted: 13>>
> image processing.
> Has anyone done something like this?
another option could be
;when debugging
debug: :do
debug [print "inner loop"]
;when released
debug: none
debug [print "inner loop"]
could be a little bit faster.
or you could process the loaded source with
src: copy/deep orig: [a b debug [c] [1 2 debug [3 4] 5 6] [debug [?]] e f]
no-debug: func [src] [
rule: [
any [
begin: 'debug block! :begin (remove remove begin)
| into rule
| skip
]
]
parse src rule
src
]
no-debug src
? src
? orig
and
do no-debug load %file.r
[6/11] from: ammon:rcslv at: 20-Jun-2002 15:19
Hi,
What I beleive Anton is talking about is something more like a compiler than
anything. I think that he wants to be able to automatically remove debugging
lines from his code so that they don't even add the overhead of an if
statement. He is talking about stablizing, enhancing, speeding up his app
*after* debugging is done, and he is ready to release a final product to his
customers... ;-)
Enjoy!!
Ammon
On Thursday 20 June 2002 02:16 pm, Volker Nitsch wrote:
[7/11] from: robert:muench:robertmuench at: 21-Jun-2002 15:58
> -----Original Message-----
> From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]On Behalf Of
<<quoted lines omitted: 7>>
> *after* debugging is done, and he is ready to release a final product to his
> customers... ;-)
Hi, yep that's what I mean too. The 'if or 'version etc. would be removed after
the script was send to the pre-processor/linker. The linker could include all
functions used from external files through do %XYZ.r as well. This will result
in one script file for distribution. Robert
[8/11] from: nitsch-lists:netcologne at: 21-Jun-2002 17:07
Am Freitag, 21. Juni 2002 15:58 schrieb Robert M. Muench:
> > -----Original Message-----
> > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]On Behalf Of
<<quoted lines omitted: 12>>
> include all functions used from external files through do %XYZ.r as well.
> This will result in one script file for distribution. Robert
thats what this snippet does.
use it like
save %release.r no-debug load/all %with-debug.r
kills comments too.
define
debug: :do
and each block prefixed with 'debug will be done in the debug-version
and removed in the release.
no-debug: func [src] [
rule: [
any [
begin: 'debug block! :begin (remove remove
begin)
| into rule
| skip
]
]
parse src rule
src
]
src: copy/deep orig: [a b debug [c] [1 2 debug [3 4] 5 6] [debug [?]]
e f]
no-debug src
? src
? orig
and
do no-debug load %file.r
[9/11] from: ammon:rcslv at: 21-Jun-2002 9:04
Hi,
So you want a full blown linker? ;-) You will of course create some sort of
dialect for declaring exactly which functions you want from the library?
that would be much nicer than just including the file, unless of course the
developer specifies that he wants the whole file. ;-) Sounds like power to
me. ;-)
Enjoy!!
Ammon
On Friday 21 June 2002 09:58 am, Robert M. Muench wrote:
[10/11] from: robert:muench:robertmuench at: 21-Jun-2002 19:46
> -----Original Message-----
> From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]On Behalf Of
<<quoted lines omitted: 4>>
> So you want a full blown linker? ;-) You will of course create
> some sort of dialect for declaring exactly which functions you want from the
library?
Of course! That's a full blown linker to me ;-)).
> that would be much nicer than just including the file, unless of course the
> developer specifies that he wants the whole file. ;-) Sounds like power to
> me. ;-)
Right. Selective linking. Only what is needed. But this can get tricky, as Rebol
allows dynamic creation etc. But hey, we don't need to handle every case. Just
normal source scan for used functions and than one assemble pass to create one
file. Robert
[11/11] from: ammon:rcslv at: 21-Jun-2002 13:19
Hi,
I would recomend that you don't do a source scan for used functions, that
would get tricky, but rather have something like a header field:
REBOL[
Author: "Yoda"
email: [yoda--starwars--com]
purpose: {To demonstrate the linker}
import-functions:[%my-library.r [this-func that-func]]
]
this-func
that-func
print 'wonderful example! ;-)"
Enjoy!!
Ammon
On Friday 21 June 2002 01:46 pm, Robert M. Muench wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted