1. New pre-processor interface added to Euphoria

Please see the thread: http://openeuphoria.org/EUforum/index.cgi?module=forum&action=flat&id=107702 and let us know what you think.

Jeremy

new topic     » topic index » view message » categorize

2. Re: New pre-processor interface added to Euphoria

I just created the skeleton of another pre-processor. This one is a more advanced one and will not be included as a demo but hopefully it will be of use to people. It's called esql.

Here's what it does:

-- people.sql 
CREATE TABLE people ( 
  id integer primary key autoincrement, 
  first_name varchar(50) not null, 
  last_name varchar(50) not null, 
  age integer 
); 
 
CREATE INDEX people_name ON people(first_name, last_name); 
CREATE INDEX people_last_name ON people(last_name); 
CREATE INDEX people_age ON people(age); 

include esql_core.e as esql  
include people.sql as people 
 
esql:set_db("example.db") -- uses SQLite right now 
 
-- creates table if it does not already exist 
people:ensure_exists() 
 
-- automatically creates a type for the table contents and also a few creation 
-- functions 
people jim = people:empty() 
jim[people:first_name] = "Jim" 
jim[people:last_name] = "Doe" 
jim[people:age] = 30 
 
-- Saves the record to the database as automatically sets the ID 
jim = people:save(jim) 
 
people john = people:new(BLANK_ID, "John", "Doe", 33) 
john = people:save(john) 
 
-- Automatic 
object all_people = people:find_all() 
 
-- Created based on ID being a primary key 
object john_ = people:find_by_id(john[people:ID]) 
 
-- Created due to the index people_last_name 
object all_does = people:find_by_last_name("Doe") 
object all_dos = people:find_by_last_name("Do%", esql:LIKE) 
 
-- Created due to the index people_name 
object who_knows = people:find_by_name("John", "Doe") 
 
-- Automatic deleting by the primary key 
people:delete(john[people:ID]) 

All of this functionality exists right away to the Euphoria user by simply

include people.sql as people 

I'm pretty excited about all the possibilites of the pre-processor, in case you couldn't tell. Who knows what someone will come up with next.

Jeremy

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

3. Re: New pre-processor interface added to Euphoria

Ok, in regards to speed test. I've just got done benchmarking Euphoria with the new pre-processor DLL/so interface. This saves spawning a new process each time a file needs to be pre-processed. Although I did not test this on a big program, it does pre-process two files using the dot4 pre-processor, which is fairly complex.

Time to run when pre-processing is forced: 0.0630 Time to run when pre-processing is cached: 0.0621

0.0009 seconds different!

Now, obviously this will increase if you are running/compiling a 200,000 line program, but the idea is that it adds very little to the overall startup time, even when it does have to pre-process and rarely (except for the first run) will you ever have to pre-process hundreds of files. Normally, you will run eui, all the pre-processing will take place, you make a change to a file or two and re-run, so maybe 1 or 2 files will have to be processed again.

Jeremy

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

4. Re: New pre-processor interface added to Euphoria

Oh, I was going to show how to make your pre-processor a shared library pre-processor so you can benefit from it's speed as well...

Here is the simple pre-processor we made in another thread:

-- fname_preproc.ex  
-- Print the filename when the file is included  
  
include std/io.e  
  
sequence cmds = command_line()  
sequence input_filename = cmds[3]  
sequence output_filename = cmds[4]  
  
sequence content = read_file(input_filename)  
content = "puts(1, \"Filename: " & input_filename & "\")\n" & content  
  
write_file(output_filename, content)  
abort(0)  

To make it a pre-processor that can be used as a shared library pre-processor, thus avoiding spawning a new process each call, you can simply export a function named preprocess...

-- fname_preproc.ex  
-- Print the filename when the file is included  
  
include std/io.e  
 
export function preprocess(sequence input_filename, sequence output_filename)  
    sequence content = read_file(input_filename)  
    content = "puts(1, \"Filename: " & input_filename & "\")\n" & content  
  
    write_file(output_filename, content)  
     
    return 0 -- OK 
end function 

Now, just use euc to create a DLL of it:

C:\Euphoria> euc -dll fname_preproc.ex 

Then change your pre-processor definition from stating fname_preproc.ex to fname_preproc.dll

C:\Euphoria> eui -p e,ex:fname_preproc.dll test.ex 

That's it. Now your pre-processor is fully integrated with Euphoria and processes code at lightning speed due to two reasons

  1. Euphoria no longer spawns a new process for each file that has to be pre-processed.
  2. Your pre-processor has been converted into C code, then compiled into a native shared library, thus you gain a considerable performance percentage due to it being native code.

Jeremy

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

5. Re: New pre-processor interface added to Euphoria

Now you can write a preprocessor appl. that displays a menu
to the user. The user then can select the type of interpreter
(win,dos,linux) that is needed and what features they want it to support.

Then the end user executes the preprocessor which automatically
compiles the defined interpreter and downloads it to the end user.

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

6. Re: New pre-processor interface added to Euphoria

I don't think that is possible as by the time the pre-processor is running, many files may have already been parsed and the interpreter/translator has already been called. It's the interpreter and translator that manages the pre-processor, not the other way around. However, maybe I misunderstood the intention, but it seems like you want to change the way that the interpreter/translator is called via the pre-processor?

It might be better to write a little program that provides these options, then calls the interpreter/translator binary accordingly.

Also, you do not need to put \\ at the end of each line. Just type away and put a blank line in between paragraphs.

Jeremy

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

7. Re: New pre-processor interface added to Euphoria

jeremy said...

Also, you do not need to put \\ at the end of each line. Just type away and put a blank line in between paragraphs.

Jeremy

When I type in the text area the lines wrap and become all messed up when I Preview what I typed.

Why don't carriage returns always wrap the text ?

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

8. Re: New pre-processor interface added to Euphoria

bernie said...
jeremy said...

Also, you do not need to put \\ at the end of each line. Just type away and put a blank line in between paragraphs.

Jeremy

When I type in the text area the lines wrap and become all messed up when I Preview what I typed.

Why don't carriage returns always wrap the text ?

By "messed up" do you mean that the lines do not break at the same place you pressed 'Enter'?

That is the way that HTML works. The Space and NewLine character are ignored when it comes to formatting lines. Lines will extend to the edge of your viewing area and this is the way that nearly everyone wants it to work.

However, if you really must have 
fixed-length lines, enclose your 
text in triple-braces, as this 
paragraph has. 

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

9. Re: New pre-processor interface added to Euphoria

It just dawned on me. If someone wants to take on a little project, it would be easy to use euphoria/tokenize.e to tokenize Euphoria source and provide a 3.0 compatability pre-processor. For instance, we have a new keyword named entry. The pre-processor would read in 3.x a variable name "entry" and change it to, say, "entry". Thus, 4.0 could be made to run 3.x apps w/no change what-so-ever.

Jeremy

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

10. Re: New pre-processor interface added to Euphoria

DerekParnell said...
bernie said...
jeremy said...

Also, you do not need to put \\ at the end of each line. Just type away and put a blank line in between paragraphs.

Jeremy

When I type in the text area the lines wrap and become all messed up when I Preview what I typed.

Why don't carriage returns always wrap the text ?

By "messed up" do you mean that the lines do not break at the same place you pressed 'Enter'?

That is the way that HTML works. The Space and NewLine character are ignored when it comes to formatting lines. Lines will extend to the edge of your viewing area and this is the way that nearly everyone wants it to work.

However, if you really must have 
fixed-length lines, enclose your 
text in triple-braces, as this 
paragraph has. 

The problem is that the web text area that I see when I am entering text is only 68 characters wide.

When I am reading messages on the euforum web text is over 100 characters.

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

11. Re: New pre-processor interface added to Euphoria

bernie said...

The problem is that the web text area that I see when I am entering text is only 68 characters wide.

When I am reading messages on the euforum web text is over 100 characters.

Same with me, but why is that a problem?

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

12. Re: New pre-processor interface added to Euphoria

jeremy said...

It just dawned on me. If someone wants to take on a little project, it would be easy to use euphoria/tokenize.e to tokenize Euphoria source and provide a 3.0 compatability pre-processor. For instance, we have a new keyword named entry. The pre-processor would read in 3.x a variable name "entry" and change it to, say, "entry". Thus, 4.0 could be made to run 3.x apps w/no change what-so-ever.

Jeremy

I think what was meant was changing

entry 

into

__entry 

which is guarranteed to be unique since 4.0 allows variables to start with an underscore but earlier versions of euphoria do not, so the older 3.0 code can't possibly have another variable with the same name that'd cause a conflict.

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

13. Re: New pre-processor interface added to Euphoria

For the fun of it, I browsed through the archives and found the first OO pre-processor that I came by. It was o4 by Karl Bochert, http://www.rapideuphoria.com/o4_32.zip ... It was written for 3.x and it used a variable "switch" which is a new 4.x keyword. I changed that to _switch, I then changed the command line parameters to accept -i input_filename -o output_filename and then gave it a try with 4.0...

--_def.eo4		test dot notation 
-- 
include o4runtm.e 
 
:Class  A extends NONE 
:Public sequence s 
:Endclass	A 
 
:Class B extends A			-- An effective class 
:Public sequence s 
:Public procedure set() 
	this.s = "Hi "			-- local member 
	..s = "Bye"				-- parent's member 
	puts (2, .s)		-- alternate local reference 
	puts (2, ..s) 
	end procedure 
:Endclass 
 
:Instance x of B 
x.set () 
 
	include get.e 
	puts (2, "\n--Press Any Key to Exit--") 
	abort (wait_key ()) 

C:\Euphoria> eui -p eo4:eo4.ex _dot.eo4 
Hi Bye 

Pretty exciting, I think.

Jeremy

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

14. Re: New pre-processor interface added to Euphoria

jeremy said...

For the fun of it, I browsed through the archives and found the first OO pre-processor that I came by...

--_def.eo4		test dot notation 

Can you post the contents of _def_post.eo4? Just curious...

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

15. Re: New pre-processor interface added to Euphoria

euphoric said...

Can you post the contents of _def_post.eo4? Just curious...

--_def.eo4              test dot notation 
-- 
include o4runtm.e 
 
--O4:Class  A extends NONE 
--O4:Public sequence s 
--:Endclass     A 
 
--O4:Class B extends A                  -- An effective class 
--O4:Public sequence s 
procedure O42set(sequence this) 
        this[3] = "Hi "                 -- local member 
        this[2] = "Bye"                         -- parent's member 
        puts (2, this[3])               -- alternate local reference 
        puts (2, this[2]) 
o4r=this end procedure o4m=append(o4m,routine_id("O42set"))--1 
--:Endclass 
 
sequence x x=o4i(2,0,{})--:Instance x of B 
call_proc(o4m[1],{x})  x=o4r 
 
        include get.e 
        puts (2, "\n--Press Any Key to Exit--") 
        abort (wait_key ()) 

Jeremy

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

16. Re: New pre-processor interface added to Euphoria

I've update the online manual and in it is a mini-guide about using the pre-processor and creating your own pre-processor.

http://openeuphoria.org/docs/eu400_0036.html

Jeremy

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

17. Re: New pre-processor interface added to Euphoria

jeremy said...

I've update the online manual and in it is a mini-guide about using the pre-processor and creating your own pre-processor.

http://openeuphoria.org/docs/eu400_0036.html

Jeremy

If someone is interested in 'Preprocessor for OOP' there is one written by Karl Bochert in the a archive.

It uses regex which is now built-in to euphoria ver 4.0 so it might be fun for someone to write an updated version of it for 4.0.

Maybe Karl could do it if he's is still out there.

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

18. Re: New pre-processor interface added to Euphoria

bernie said...

If someone is interested in 'Preprocessor for OOP' there is one written by Karl Bochert in the a archive.

It uses regex which is now built-in to euphoria ver 4.0 so it might be fun for someone to write an updated version of it for 4.0.

Maybe Karl could do it if he's is still out there.

Bernie, grin ... Read up a few messages, or just read this one: http://openeuphoria.org/EUforum/index.cgi?module=forum&action=message&id=107744#107744

Jeremy

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

19. Re: New pre-processor interface added to Euphoria

jeremy said...
bernie said...

If someone is interested in 'Preprocessor for OOP' there is one written by Karl Bochert in the a archive.

It uses regex which is now built-in to euphoria ver 4.0 so it might be fun for someone to write an updated version of it for 4.0.

Maybe Karl could do it if he's is still out there.

Bernie, grin ... Read up a few messages, or just read this one: http://openeuphoria.org/EUforum/index.cgi?module=forum&action=message&id=107744#107744

Jeremy

Oh, however, I do not have intentions on supporting, or even releasing my changes. The changes I made took about 3 minutes and it worked like a charm.

Jeremy

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

20. Re: New pre-processor interface added to Euphoria

Hey all. Just my two cents.

Would it be possible to make a preprocessor to make including shared librarys a bit easier? The ideal would be to pass it C-style headers with associated library names or wildcards and have it produce an include file containing define_c_* calls only for the corresponding method names used in the Euphoria code. The intention would be to make using shared libraries as easy as it is with C, and transparently cross-platform if at all possible.

Cheers,

Nick

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

21. Re: New pre-processor interface added to Euphoria

prickle said...

Hey all. Just my two cents.

Would it be possible to make a preprocessor to make including shared librarys a bit easier? The ideal would be to pass it C-style headers with associated library names or wildcards and have it produce an include file containing define_c_* calls only for the corresponding method names used in the Euphoria code. The intention would be to make using shared libraries as easy as it is with C, and transparently cross-platform if at all possible.

Nick,

What a wonderful idea! Some great things are going to come out of this pre-processor, I know. With your idea it would be fully possible to:

// greeter.h 
//... 
// amongst the other defs in a C header file 
 
#define DEFAULT_GREETING "Hello" 
 
void say_hello(char *name); 
char *get_greeting(); 
//... 

include greeter.h as greeter 
 
printf(1, "Default greeting is: %s\n", { greeter:DEFAULT_GREETING }) 
greeter:say_hello("World") 
sequence greeting = greeter:get_greeting() 

i.e. using a C library such as libdspam, Iup, GTK, etc... by simply including it's .h header file. How briliant!

Jeremy

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

Search



Quick Links

User menu

Not signed in.

Misc Menu