Run Time Compiler

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
swhite
Enthusiast
Enthusiast
Posts: 789
Joined: Thu May 21, 2009 6:56 pm

Run Time Compiler

Post by swhite »

Hi

I would like to request the ability to compile code at run time. I could write code using my PB application and then compile and run it from within that application. This would allow me to execute code dynamically based on conditions that arise during the execution of my application.

Thanks,
Simon
Simon White
dCipher Computing
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Run Time Compiler

Post by STARGÅTE »

I think that there will never be:
Is it allowed to use DLLs made with PureBasic in other projects ?
Generally yes. You can make DLLs including PureBasic commands for your own projects without any restrictions. But it's not allowed to release simple "wrapper" Dlls to include PureBasic commands in other programming languages.
For that is a similar resultat!

But you can use this project:
Script with PB-Syntax
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
swhite
Enthusiast
Enthusiast
Posts: 789
Joined: Thu May 21, 2009 6:56 pm

Re: Run Time Compiler

Post by swhite »

HI

I guess I was not thinking of making a simple wrapper but I see your point. I was thinking more along the lines of what you can do in dynamic languages. I often store code in a database or create scripts on the fly using Visual FoxPro which then compiles and executes the code at runtime. In fact there is a specific command called "ExecScript" which compiles and runs the program code you pass to it. This allows a high degree of customization in your application that the user can control. So I was thinking it would be nice to have some kind of compiling ability from within an application. You could even put code in web-pages and execute it on the server at runtime this way.

Simon
Simon White
dCipher Computing
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Re: Run Time Compiler

Post by X »

That looks nice :) But unlike the now defunct Dracscript, this one does not include source (?) Any english translation for it?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Run Time Compiler

Post by Trond »

If you want a dynamic language, use a dynamic language. :idea:

Or you could make your own scripting language.
swhite
Enthusiast
Enthusiast
Posts: 789
Joined: Thu May 21, 2009 6:56 pm

Re: Run Time Compiler

Post by swhite »

Hi

I do not particularly want a dynamic language but the ability to compile code at runtime opens up a lot of opportunities. So I see no reason why there should be artificial barriers in any programming language so if it is possible to compile code at runtime then why not allow it. If you are worried about someone shipping your compiler inside a small wrapper then I think you could charge extra for this function or offer a lite version of the compiler by creating some new functions in PB for this purpose. I for one would not mind paying extra for such functionality.

Simon
Simon White
dCipher Computing
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Run Time Compiler

Post by srod »

You would need to ship the compiler, the FASM assembler, POLINK and God knows how many import libs, other static libs and PB user-libs. The fact that those who purchase your application then get a copy of PB into the mix... Not going to happen imo.

Why not just tell your customers to purchase PB and have that running alongside your app and they can then compile away to their hearts content?
I may look like a mule, but I'm not a complete ass.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: Run Time Compiler

Post by Rings »

.NET has a build in compiler (as class).
try that.
SPAMINATOR NR.1
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: Run Time Compiler

Post by Thorium »

swhite wrote: You could even put code in web-pages and execute it on the server at runtime this way.
Actualy that sounds horribly unsecure.

Can you show a practical example of how this would be used?
I cant think of any situation i would need runtime compiling.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Run Time Compiler

Post by fsw »

swhite wrote:Hi

I would like to request the ability to compile code at run time. I could write code using my PB application and then compile and run it from within that application. This would allow me to execute code dynamically based on conditions that arise during the execution of my application.

Thanks,
Simon
Do you mean something like that?

Code: Select all

;your code...

PureEXE_Open("test.exe")
PureEXE_AddImport("user32.dll", "MessageBoxA", 4, "MsgBox")
PureEXE_AddConstant("MB_OK", 0)

;your code...
;bla, bla, bla

if banana
    PureEXE_AddString("title", "Message")
    PureEXE_AddString("text", "Hello User!")
else
    PureEXE_AddString("title", "Hint")
    PureEXE_AddString("text", "Go away!")
endif

;your code...
;more bla, bla, bla

PureEXE_Write("MsgBox(0,text,title,MB_OK)")

;your code...
;even more bla, bla, bla

PureEXE_Close()

;end of example...
Actually I don't know what to think of it...

fsw
swhite
Enthusiast
Enthusiast
Posts: 789
Joined: Thu May 21, 2009 6:56 pm

Re: Run Time Compiler

Post by swhite »

Hi

Here is a real example. I have an application that must get data from remote sites. The sites are serial devices which require you to login and issue commands to retrieve the data. Since I do not have access to all the various versions of the hardware there are times when the prompts received from the device are different from what I expect. So I store the code used to retrieve the information in a database. When the user uses my program to retrieve the data it copies the code from the database to a file, then compiles the file and runs it. If the hardware is based on a version that I have not seen before the code in the database can be changed to accommodate the hardware. This way I can have a standard application that can be customized to the user's situation. The users does not have to wait for me to modify my code and supply a new version of the program. Eventually if I find that this version of the hardware is used a lot by my customers I may choose to modify my application and make it part of the standard application.

I do not use the run time compiling to allow the users to generate their own code but rather as a means to customizing a standard application to specific user's environment as in the situation above.

Simon
Simon White
dCipher Computing
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Run Time Compiler

Post by fsw »

The easiest way of doing it is to create a pb inc file with some constants that are used when compiling utilizing some CompilerIf/CompilerElse/etc.

When a change is needed (automatically) write a new inc file (based on the findings) with the desired constants and (automatically) recompile the pb program on your machine.
swhite
Enthusiast
Enthusiast
Posts: 789
Joined: Thu May 21, 2009 6:56 pm

Re: Run Time Compiler

Post by swhite »

Hi

The problem with that approach is that my code becomes loaded with all kinds of customer specific customizations. If you have hundreds of clients all with customization the application code becomes bloated. So that is why I leave the customizations in the customer's database so that it does not affect my code.

Simon
Simon White
dCipher Computing
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: Run Time Compiler

Post by Thorium »

You dont need runtime compiling for that. Just store a dll in the database download it and load it. It's the same you just skip the runtime compile.
cybergeek
User
User
Posts: 33
Joined: Sat Jul 03, 2010 11:11 am

Re: Run Time Compiler

Post by cybergeek »

what about other kind of code like any code to be executed dyncamially?
PUREBASIC is AWSUM
Post Reply