Forums

problems with 0.7.3

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

problems with 0.7.3

Postby Dafra » Mon Feb 18, 2008 1:49 pm

:!: First, It would be fine if someone with Mono installed on a linux box could test this script, because it uses the Microsoft.CSharp namespace, which allows the compiler to have better control of C# code compilation, and I am not sure it is available on non-Microsoft systems.

The code below defines some C# code in the "source" string.
class GenHello
def main is shared
# Generate an assembly named 'hello.exe' that prints 'Hello'.

source = 'namespace N { class C { static void Main() { System.Console.WriteLine("Hello"); } } }'
provider = Microsoft.CSharp.CSharpCodeProvider()
cp = System.CodeDom.Compiler.CompilerParameters()
cp.generateExecutable = true
cp.outputAssembly = 'hello.exe'

cr = provider.compileAssemblyFromSource(cp, @[source])
if cr.errors.count
for ce in cr.errors
Console.writeLine(ce.toString)
else
Console.writeLine('OK')


The compiler yields several warnings in French which mean "the private field Cobra.Lang... is never used". The code compiled without warnings with 0.7.2.
Code: Select all
c:\Code\Cobra\bin\CobraLang.cobra(6): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.Tracer._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(85): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.CobraCore._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(794): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.Html._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(813): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.PrivateObjectViewForExceptionReport._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(911): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.SourceSite._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(996): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.CobraFrame._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(1097): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.FallThroughException._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(1120): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.DynamicOperationException._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(1132): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.UnknownMemberException._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(1148): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.CannotReadPropertyException._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(1159): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.CannotWritePropertyException._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(1170): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.CannotSliceTypeException._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(1181): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.CannotInTypeException._ih_invariantGuard" n"est jamais utilis‚
c:\Code\Cobra\bin\CobraLang.cobra(1192): warning: warning CS0169: Le champ priv‚ "Cobra.Lang.CannotCompareException._ih_invariantGuard" n"est jamais utilis‚
GenHello.cobra(1): warning: Le champ priv‚ "GenHello._ih_invariantGuard" n"est jamais utilis‚


If I try the new sharp'bla bla' feature, I get an error
Code: Select all
GenHello.cobra(5): error: Cannot infer type for "source" because the type of the right hand expression is unknown.
Dafra
 
Posts: 12

Re: problems with 0.7.3

Postby Charles » Mon Feb 18, 2008 2:28 pm

On Novell Mono on Mac OS X, your code runs without modification. There are no errors or warnings and it prints "OK". The resulting "hello.exe" exists and runs fine.

In general, there are some warnings from the C# backend code that Cobra suppresses by their textual description. These warnings are unavoidable due to code generation or embedding the run-time support. If you switch your language to English they will go away.

You might able to reduce them with "cobra -ert:no myprog.cobra" provided you have a copy of Cobra.Lang.dll in the same directory. See "cobra -help" for docs.

So Cobra needs to suppress these with the C# "nowarn" option which is language independent.

Regarding sharp'blah blah', Cobra cannot infer its type because it does not parse C# code. If you are assigning this to a variable, you need to typecast it:
t = [1, 2]
i = sharp't.Count' to int
assert i == 2

If you are using sharp'...' as an argument, you can usually skip the cast.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: problems with 0.7.3

Postby Charles » Mon Feb 18, 2008 2:51 pm

I was curious if there would be a speed difference between using the CSharpCodeProvider vs. Process. On Novell Mono there is not. On Microsoft.NET the provider is about 1.8 X faster.

Provider:
00:00:05.0372432
9.92606432026153 reps per second

Process:
00:00:09.0630320
5.51691751722823 reps per second

As long as the provider covers all the command line options, or has a general one to pass additional options, then we'll certainly switch over. Btw the original Cobra compiler was a standalone Python program and some oddities like this still exist in the new compiler that's written in Cobra.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 17 guests