Live data from Hacker News

Compiling PHP's Eval() to .NET

peachpie.io

1–10 of 11 posts

Re: Compiling PHP's Eval() to .NET

#3
We do something very similar at work, but with runtime generated Java code for an in-memory column oriented database. Our data is analyzed before being loaded and we determine the range of numbers necessary to store the data: eg. If we only have bytes incoming, we generate a class that only stores bytes etc. On top of that all our strings are interned in a trie and then represented as ints, also run through above outlined code.

This works because we are mostly interested in equality of strings and other computation with strings (mostly prefix based classific) is done ahead of time.

For debugging we emit our generated code and both eclipse and intellij picked up our generated code without configuration. It's safed us a lot of headaches.

Re: Compiling PHP's Eval() to .NET

#5
post #4

I needed the ability to safely execute formulas in my .NET app. My solution was to write a parser and interpreter. Here it is: https://github.com/Rajeev-K/formula-parser

You can do this already with DataTables, which is basically an in-memory Excel spreadsheet. Bonus is that it also supports Excel functions, and it’s completely safe/sandboxed code.

Re: Compiling PHP's Eval() to .NET

#6
post #4

I needed the ability to safely execute formulas in my .NET app. My solution was to write a parser and interpreter. Here it is: https://github.com/Rajeev-K/formula-parser

I've used FLEE for this. Compiles down to IL so it's fast, you can define your own functions, etc.

https://github.com/mparlak/Flee/wiki/Getting-Started

Re: Compiling PHP's Eval() to .NET

#8
post #4

I needed the ability to safely execute formulas in my .NET app. My solution was to write a parser and interpreter. Here it is: https://github.com/Rajeev-K/formula-parser

Do you have examples of the types of "formulas" that you wanted to execute?

Also, how would one execute said formula?

Re: Compiling PHP's Eval() to .NET

#9
post #5
post #4

I needed the ability to safely execute formulas in my .NET app. My solution was to write a parser and interpreter. Here it is: https://github.com/Rajeev-K/formula-parser

You can do this already with DataTables, which is basically an in-memory Excel spreadsheet. Bonus is that it also supports Excel functions, and it’s completely safe/sandboxed code.

e.g. https://docs.microsoft.com/en-us/dotnet/api/system.data.data...

Re: Compiling PHP's Eval() to .NET

#10
> we simply want to emit the debug information of eval() only if we are just debugging the program. Otherwise it’s just an unnecessary performance overhead.

This will not correctly handle the case when the user attaches a debugger after the eval has started, but before all execution artifacts (including callbacks/closures) are finished.

Post reply on HN