SeeminglyScience / PSLambda

A runtime compiler for PowerShell ScriptBlock objects.
MIT License
61 stars 3 forks source link

about PSLambda #26

Open tylike opened 5 years ago

tylike commented 5 years ago

hi, this is a very good project. I'm a c# developer and I want to use powershell as a scripting language in my project. Powershell script has several big advantages: 1.scriptblock feature is not in c#. This feature can develop the dsl language.

  1. There is IDE support for powershell and can be personalized.
  2. Has the debugger support.
  3. Based on .net framework. So my idea is that the powershell if used to replace cmd is good enough. Performance may not be a big problem. But as a scripting language, the performance requirements are higher, so I want to compile the power scriptshell to .net dll. I see you're trying to be compatible with all the original powershell commands, and what I'm trying to say is, don't you need these? Thank you!
SeeminglyScience commented 5 years ago

hi, this is a very good project.

Thank you! ❤️

But as a scripting language, the performance requirements are higher, so I want to compile the power scriptshell to .net dll.

PSLambda can't compile to a DLL unfortunately. It's all done via System.Linq.Expressions.Expression trees. While it is possible to compile those to a savable assembly, PSLambda uses too many ConstantExpression's based on the current PowerShell runspace that it's compiled in. It's possible to strip away the functionality enabled by those constants, but that hasn't been a goal of this project.

I see you're trying to be compatible with all the original powershell commands, and what I'm trying to say is, don't you need these?

It actually can't run any PowerShell commands (commands in this case referring to functions/cmdlets/etc). Commands require a runspace, and the main reason I wrote this is so I could use PowerShell-like syntax to quickly create a delegate that could run in a thread without a runspace.

PSLambda is sort of a language on it's own that borrows the PowerShell engine's parser, and then tries to be just-similar-enough to PowerShell so that it's a bit easier to write. It has to be that way because a lot of what makes PowerShell fantastic also makes it less performant and completely reliant on the current thread for it's state.