Comments (11)
@weichx Back to looking into it.
from fastexpressioncompiler.
What do you mean here by ref locals
.
Could provide an example/pseudocode?
Regarding memory usage, are you using LightExpressions?
from fastexpressioncompiler.
Sure, here is the C# I'd like to emulate
Vector3[] array = new Vector3[100]; // struct btw
for(int i = 0; i < array.Length; i++) {
ref Vector3 v = ref array[i];
// do stuff with v and have the array[i] value updated (because its a reference)
v.x += 12;
v.Normalize();
}
from fastexpressioncompiler.
I'm not currently, I'm not that worried about memory usage at expression compile time (which happens once on startup), but I care a lot about this stuff while the game is running
from fastexpressioncompiler.
Sure, here is the C# I'd like to emulate
Thanks.. So you want to be able to turn this code into expression and compile it?
from fastexpressioncompiler.
yes exactly, right now the ref
keyword cannot be used with ParameterExpression and I think thats just because the expression tree API got frozen before c# 7 when ref
locals were introduced to the language. I would imagine this is possible to implement in IL, just nobody has done it yet. We can't change the Microsoft compiler to support this, but since you generate IL yourself I figured it might be a. possible and b. pretty useful for a lot of people using your library
from fastexpressioncompiler.
Yes it should be possible, just get the address instead.
But do you need to put all that code into expression or for instance only the body of the loop and convert the ref var to ref parameter?
Vector3[] array = new Vector3[100]; // struct btw
for(int i = 0; i < array.Length; i++) {
DoStuff(ref array[i]);
}
static void DoStuff(ref Vector3 v)
{
// do stuff with v and have the array[i] value updated (because its a reference)
v.x += 12;
v.Normalize();
}
Then make lambda expression representing the DoStuff
with the Parameter(typeof(Vector3).MakeByRef(), "v")
.
Does this work?
from fastexpressioncompiler.
It would need to behave identically to the C# compiler's behavior. The example above is contrived. I'm building a language for people to write game code in that compiles to C# at production time and to IL (via expression trees) during runtime so I can support hot reloading. the syntax is 90% identical to C# to the point where you can basically copy + paste C# code into my script language it will run. Ref locals are the one thing I can't work around in my compiler via lowering and so I'd like to find a way to implement it for real.
from fastexpressioncompiler.
Yes it should be possible, just get the address instead. But do you need to put all that code into expression or for instance only the body of the loop and convert the ref var to ref parameter?
Vector3[] array = new Vector3[100]; // struct btw for(int i = 0; i < array.Length; i++) { DoStuff(ref array[i]); } static void DoStuff(ref Vector3 v) { // do stuff with v and have the array[i] value updated (because its a reference) v.x += 12; v.Normalize(); }Then make lambda expression representing the
DoStuff
with theParameter(typeof(Vector3).MakeByRef(), "v")
.Does this work?
No, this won't work, since I'm making a scripting language, I don't know the input ahead of time and can't make that transformation work in all cases.
from fastexpressioncompiler.
@weichx Just updated my prev answer with code.
Ok. I need to experiment with by-ref locals and ref assignments then.
I'll keep you posted.
from fastexpressioncompiler.
@weichx Just updated my prev answer with code.
Ok. I need to experiment with by-ref locals and ref assignments then. I'll keep you posted.
Awesome, thanks a lot!
from fastexpressioncompiler.
Related Issues (20)
- EmitCall is for the varargs method and should not be used for normal convention
- InvalidProgramException on compiling an expression that returns a record which implements IList HOT 4
- Make cast to target type controlled in config flags instead for diagnostics HOT 2
- Error when loading struct parameters closed by the nested lambda e.g. predicate in Linq
- Optimize nested lambdas with closures
- Hack DynamicMethod HOT 9
- xxxAssign doesn't work with MemberAccess HOT 2
- NullReferenceException when calling CompileFast() results HOT 4
- Error with converting to/from signed/unsigned integers HOT 6
- Invalid program exception HOT 8
- Improve the performance of variable lookup HOT 1
- Add RequiresUnreferencedCode attribute to types HOT 1
- Add support for up to 16 parameter Func<>/Action<> to LightExpression HOT 1
- Working with ref return values HOT 2
- FastExpressionCompiler[v3.3.4] gives incorrect results in some linq operations HOT 3
- Better diagnostics and debugging with error codes from Collect and Compile rounds HOT 2
- Fix duplicate nested lambda compilation HOT 1
- Decrease memory occupied by the LightExpression Block by storing Expression in SmallList (partly on stack) HOT 1
- Optimize any nested lambda compilation (LINQ) by compiling right after collect one-by-one HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastexpressioncompiler.