[Mono-dev] [PATCH] [VBNC] Treat AscW as CInt with /novbruntimeref

Rolf Bjarne rolfbasura at ya.com
Wed Sep 6 07:48:12 EDT 2006


Hello,

Commenting code inline:

+        If Info.Compiler.CommandLine.NoVBRuntimeRef AndAlso  
Info.Compiler.Assembly.IsDefinedHere(Method.DeclaringType) AndAlso  
Method.IsStatic AndAlso CompareNameOrdinal(Method.Name, "AscW") Then
+            Dim methodParameters() As ParameterInfo =  
Method.GetParameters()
You might want to use Helper.GetParameters(Info.Compiler, Method), since  
this will fail if a MethodBuilder is passed in instead of a  
MethodDescriptor.
+
+            If methodParameters.Length <> 0 AndAlso  
Helper.CompareType(methodParameters(0).ParameterType, TypeCache.Char) Then
To compare types use Helper.CompareType(type1, type2), I have found that  
comparing type instances at the same time as using Reflection.Emit is very  
unreliable.
+                If Arguments.Count <> 0 Then
This pushes a Char on the stack:
+                    result = Arguments(0).GenerateCode(Info.Clone(True,  
False, TypeCache.Char), methodParameters(0)) AndAlso result
Always put a 'AndAlso result' after assigning to result, this will ensure  
that a False result value earlier on won't get lost. I know there is no  
earlier assignment right now to result, but when the code changes it is  
very easy to forget this.
+                Else
+                    Helper.Assert(methodParameters(0).IsOptional)
This also pushes a Char on the stack:
+                    Emitter.EmitLoadValue(Info.Clone(TypeCache.Char),  
methodParameters(0).DefaultValue)
+                End If
If you now push an integer on the stack you'll have the char and the  
integer there. I suggest using this:
			Info.Stack.SwitchHead(TypeCache.Char, TypeCache.Integer)
+                Info.Stack.Push(TypeCache.Integer)
+
+                Return result
+            End If
+        End If
+

> Hi,
>
> I added a hack to EmitArgumentsAndCallOrCallVirt to support the  
> previously
> discussed functionality.
>
> I don't know how exactly the stack evaluation in vbnc works and I keep
> getting ...  reached, but stack is not empty.
The stack evaluation is only for debug purposes and is anyway flawed, so  
you can safely ignore these warnings if the resulting assembly works.

> Another missing functionality is that the return value of this replaced  
> AscW
> should be treated as Integer regardless of the return type of the  
> replaced
> AscW function.
In order for this to work correctly you would have to insert the hack  
earlier on in the compiler, probably in the Resolve phase, when during  
resolution a call to AscW is detected the parse tree is modified to just  
load the char/integer value on the stack. Error checking would have to be  
bypassed since it is now allowed in VB to treat a Char value as any other  
int value (this error isn't reported now anyway though). Having in mind  
that this is a hack to support a feature of an unsupported commandline  
option your hack might be just good enough.

> Kornél

Rolf


-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.7/438 - Release Date: 05/09/2006




More information about the Mono-devel-list mailing list