rick_o_max
rick_o_max
CC#
Created by rick_o_max on 5/17/2023 in #help
❔ Can't catch Unity Coroutine (IEnumerator) error
Hi! I'm running some Func inside a Unity Coroutine. I'm using an approach I've used before to get the errors the code might throw and handle them, but by some reason, I can't catch the errors. You guys have any idea why?
7 replies
CC#
Created by rick_o_max on 2/20/2023 in #help
❔ System.Linq.Expressions custom expression
Hi guys! I'm parsing a custom language and building an Expression Tree based on it, but I came into an issue: My language can use Labels, but since I parse the file line by line, I can't reference a label that hasn't been parsed yet when creating a Goto expression. So parsing something like that would give issues:
IFEQUALS var1, 10;
GOTO label;
END;
label:
PRINT "HELLO WORLD";
IFEQUALS var1, 10;
GOTO label;
END;
label:
PRINT "HELLO WORLD";
So, my idea was to inherit the Expression class to create a kind of LazyGotoExpression, where the LabelTarget would be evaluated by the time the expression is compiled, but I have no clue how to do that. Could you guys give me a hand? Current parsing code:
private Expression ParseExpression(List<string> tokens, Func<List<string>> parseNextStatement)
{
switch (tokens[0])
{
case "LABEL":
{
var label = tokens[1];
var labelTarget = Expression.Label(label);
_labels.Add(label, labelTarget);
return Expression.Label(labelTarget);
}
case "GOTO":
{
//I MIGHT NOT HAVE THE LABEL REFERENCE HERE, SO I NEED A WAY TO LAZY EVALUATE IT
var label = tokens[1];
var expression = Expression.Empty();
_goto.Add(expression, label);
return expression;
}
private Expression ParseExpression(List<string> tokens, Func<List<string>> parseNextStatement)
{
switch (tokens[0])
{
case "LABEL":
{
var label = tokens[1];
var labelTarget = Expression.Label(label);
_labels.Add(label, labelTarget);
return Expression.Label(labelTarget);
}
case "GOTO":
{
//I MIGHT NOT HAVE THE LABEL REFERENCE HERE, SO I NEED A WAY TO LAZY EVALUATE IT
var label = tokens[1];
var expression = Expression.Empty();
_goto.Add(expression, label);
return expression;
}
If there is a way to make a custom Expression return another Expression instance, that would be perfect.
140 replies
CC#
Created by rick_o_max on 2/15/2023 in #help
❔ Generator setting wrong (not existing) source path in the PDB file
Hi! I'm generating some classes with a custom generator (Roslyn). When the PDB file is generated, the path to the generated document is wrong, making impossible to debug it. In the PDB file, the path to the generated source is relative to the generator project, and not to the project that is consuming the generator:
<Document Index="8" DocumentType="Text" Language="C#" LanguageVendor="Microsoft" ChecksumAlgorithm="SHA-1" Checksum="2d 0c 35 89 df cf b0 cf 65 1b a6 52 70 b7 94 c4 6e 29 7c cc ">C:\Repos\trilib-core\TriLibCore.Obj\TriLibCore.Generators\TriLibCore.Generators.CoroutineGenerator\CoroutineGenerated.cs</Document>
<Document Index="8" DocumentType="Text" Language="C#" LanguageVendor="Microsoft" ChecksumAlgorithm="SHA-1" Checksum="2d 0c 35 89 df cf b0 cf 65 1b a6 52 70 b7 94 c4 6e 29 7c cc ">C:\Repos\trilib-core\TriLibCore.Obj\TriLibCore.Generators\TriLibCore.Generators.CoroutineGenerator\CoroutineGenerated.cs</Document>
Also, this file doesn't seem to exist. Enabling the EmitCompilerGeneratedFiles project option and setting the path manually will generate the file inside the current project path, and not the generator project path. Also, changing the CompilerGeneratedFilesOutputPath does not change the PDB document path.
4 replies
CC#
Created by rick_o_max on 2/1/2023 in #help
❔ Alternatives to Antlr for C#
Antlr needs a runtime library, and the parsing is veeery slow. Any good alternative?
87 replies
CC#
Created by rick_o_max on 1/18/2023 in #help
❔ Best strategy to move methods to IEnumerator
Hi guys! I appreciate the help you have been giving on this server. You guys rock! I'm trying to tackle down an architecture issue this time. I have a big codebase (approx. 100k lines of code) which contains processing-intensive methods that might halt the main thread (I'm using Unity). The issue is not Unity specific, as it is a feature from the .NET Framework. On Unity, one can spread large processing across various frames on the main thread by using Couroutines (https://docs.unity3d.com/Manual/Coroutines.html). Inside a Coroutine, the code can suspend it until the yield instruction is accepted. I'm looking for ways to convert my codebase to IEnumerator, so I can make use of Coroutines, but I think putting lots of conditional compilation stuff like #ifs will make the library management almost impossible. (The conditional compilation is meant to keep compatibility with the current userbase) Unity has this helper class as well, that allows suspending a Coroutine using any custom logic: https://docs.unity3d.com/ScriptReference/CustomYieldInstruction.html I can definetely take the most processing-intensive methods and convert them to Coroutines, but because all the Coroutine chain is made using IEnumerators, that would require converting all methods on the stack as well. What would you guys use to handle such situation? Something that injects code or dependencies came to my mind, but I'm not sure, as I haven't made anything like that yet.
4 replies
CC#
Created by rick_o_max on 12/9/2022 in #help
✅ Interoperability between incompatible types
Hi! I'm trying to pass a class back-and-forth from C# to CPP. This class contains some members that I can't and don't need to translate to CPP types, but when I add these members to my interop classes, the application exits with a fatal error.
67 replies
CC#
Created by rick_o_max on 12/8/2022 in #help
Interoperability issues (PInvoke)
Hi! I'm calling a native CPP library and retrieving a struct by reference which returns a struct containing some pointers.
143 replies