Forums

Using Cobra from the lastest source code

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

Using Cobra from the lastest source code

Postby Charles » Thu Sep 18, 2008 10:48 am

It's been awhile since the last release of Cobra, but not due to lack of progress. I've often been obsessing over getting another refinement or bugfix in for the next release. In this post, I'd like to point out that it's very easy to use Cobra out of the source code repository. Upon doing so, you'll get the additional features and fixes described below. Plus you can provide feedback for the upcoming release. The repository is usually quite stable due to the automated regression test suite.

See http://cobra-language.com/source/

Building Cobra is very easy. See the instructions in cobra-workspace\Developer\ImplementationNotes.text

Here I have pasted in the IntermediateReleaseNotes.text file found in the Developer directory:

* Added support for "extended initializers" which allow you to set properties of the object in the same call being used to create the object:
r = Rectangle(p1=Point(x=0, y=1), p2=Point(x=2, y=3))
c = Customer('Acme, Inc.', region=Regions.South)

* Added partial classes, a la C# and VB. This enables class (and struct) declarations to be split across files. This can be useful for organizing generated code or even manually written code based on purpose. ticket:10
# file Foo.cobra
class Foo
is partial

var _name as String

pro name from var

# file Foo.gen.cobra
class Foo
is partial

def generatedMethod
pass

* Added new comment markers /# ... #/ which can be used for block comments and inline comments. Block comments must start at the beginning of a line and can be used to comment out multiple lines of source. They can be nested. Inline comments also start with /# and end with #/, but within the same line. They can be used to comment out a portion of a line. Regular end of line comments are still available and still the norm.
class Example

def main is shared
# an end-of-line comment
t = [1, 2, 3] # a list of numbers

# an inline comment
print t, /#t[0],#/ t.count

# a block comment
/#
def foo
print 'bar'
#/

* Added support for warning suppression on arbitrary lines by placing a trailing comment containing `.no-warnings.` after the `#`
.code
this.call() # .no-warnings.

* Added support for a Cobra compiler directive to specify the type for `number`
type of number and integer literals same as command line -number option
%% number 'decimal' | 'float' | 'float32' | 'float64'

* Added support for implicit line continuation for items in parentheses.
i.e method call argument lists, method declaration parameters and
parenthesised expressions.

* Added a new built-in doc tool accessible via "cobra -doc ...". The documentation is generated to local HTML files using your declarations, doc strings, contracts, etc.

* Added support for declaring and raising events. When raising events, passing "this" is implied (e.g., not required) since that is the normal behavior for events. Also, if the events argument has a default constructor, it too can be omitted.

* Add support for specifying unsigned integers as Hex literals
e.g. 0x7f 0x7f_8 0x7Fu16 0x7F_u32

* The default type for vars, properties and method arguments is now `dynamic?`. Also the result type for `d.foo` where `d` is dynamic is now `dynamic?` instead of `dynamic`. These changes reflect the flexibility that was originally intended with default types and dynamic typing.

* Added new `all` and `any` unary operators that take something enumerable (such as a list, set or generator) and return a boolean (true or false) indicating if all or any of the elements are true. These operators increase expressiveness in conditions. For example, a contract might use these operators:
.code
def foo(items as IList<of Item>)
require all for item in items get item.name.trim.length > 0

* Added generic methods.

* Added new Visitor class to the Cobra standard library. Subclasses can easily implement the visitor pattern and the classes being visited require no additional modification. See the doc string of `Visitor` in CobraLang.cobra for details.

* Added support for attributes on class/object variables (also know as "fields").

* Cobra now prints '[1, 2, 3]' for a list of integers rather than 'System.Collections.Generic.List`1[System.Int32]'. It still uses the standard List<of> class.

Added new Cobra library classes StringMaker (abstract), PrintStringMaker and TechStringMaker and associated properties CobraCore.printStringMaker and CobraCore.techStringMaker. Through those properties, you can customize the output of `print` statements and string substitution (.printStringMaker), and assert failures and `trace` statements (.techStringMaker).

For convenience, the extension methods .toPrintString and .toTechString have been added to System.Object.

* You can now say `get foo from var is override`. In other words, you can add "is names" after a "from var" property declaration.

* The backend C# compiler is now invoked via .NET's CSharpCodeProvider (also tested on Mono). This eliminates problems with locating the installed C# compiler and speeds up the regression tests. You can still use the -sharp-compiler option to dictate the backend C# compiler if you desire.

* The Cobra run-time will no longer throw IndexOutOfRangeException for slicing. At worst, you will get an empty list. This is more convenient and matches Python's semantics. Thanks to "hopscc" in New Zealand.

* There are three places where non-nil is verified at run-time: class variables at the end of an initializer, arguments at the beginning of a method and "to !" casts. Added new -include-nil-checks:yes|no option which includes or excludes these checks. Default is 'yes'. Using -turbo will set to 'no'.

* Renamed CobraCore.willCheckNonNilClassVars to CobraCore.willCheckNil

* Integer literals can now be suffixed to indicate their type such as `1_u64` and `7_i8`. The underscore is optional and valid sizes include 8, 16, 32 and 64. There is no reason to ever suffix zero (0). Credit: hopscc

* In string literals, square brackets can be escaped with a backslash to prevent expression substitution. ticket:15

* A single underscore marks a class member as `protected` (or a struct member as `private`). Previously, this behavior only took place for variables, but now takes place for all types of members including properties and methods. Also, two underscores now implies `private`.

* (minor) Fix BinaryOp.writeSharpBreakdownItems to indent and outdent around its subexpressions.

* Added keyword `each`, reserved for future use. Removed keywords `down`, `global`, `instance` and `step`.

* Fixed: The Cobra command line compiler throws an exception for files with an all capital extension (FOO.COBRA).

* Fixed: Using "continue" in new style numeric for loops does not increment the loop variable. ticket:9

* Fixed: Cannot access classes that start with a lower case letter such as iDB2Connection. ticket:16

* Fixed: Looping through an object that inherits IEnumerator<of T>, but with T that has constraints, does not recognize those constraints in the body of the `for` loop. For example, if T is constrained to be an ICar, the .drive method cannot be invoked.

* Fixed: Cannot assign or compare qualified types such as `System.Object` even though the same can be done with unqualified types such as `Object`.

* Fixed: Cannot implement a method whose signature is matched by an extension method of a base class.

* Fixed: Method return types from generics in DLLs are always considered nilable even if the generic parameter was not (such as `bool`). ticket:22

* Fixed: Assignments (and other side effects) can appear in assert conditions even though they might be excluded during compilation or run-time. ticket:4 (hopscc)

* Fixed: Cannot use the `branch` statement if the expression has a dynamic type.

* Fixed: Using `ref` on a variable that experienced an error causes an internal exception.

* Fixed: Some bitwise operations with integer literals of 16 or 8 bits produce invalid compilation errors.

* Fixed: Putting a comment after a doc string, but before a `test` section causes an invalid compilation error.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Using Cobra from the lastest source code

Postby relez » Fri Sep 19, 2008 4:35 pm

Just to understand:
from your notes:
So at any point in time now, there is a cobra.exe living in CobraWorkspace/Source/Snapshot which is used to compile CobraWorkspace/Source/*.cobra to produce a cobra.exe in CobraWorkspace/Source that is then tested and debuggedCobra.exe produced in Source is bigger then Cobra.exe 0.8 and it doesn't run.... i generated it by using comp.bat. Have i missed anything?
relez
 
Posts: 69

Re: Using Cobra from the lastest source code

Postby Charles » Fri Sep 19, 2008 7:06 pm

The one you built in Source is bigger because the one I put in Source/Snapshot is built with "comp -turbo". The -turbo option excludes all contracts, assertions and unit tests. It also turns on optimizations. The result is a smaller .exe that runs much faster.

If you are on mono, don't forget to run with "mono cobra.exe ..."

When you attempt to run your new cobra.exe, what exactly happens? Does it return right away? Throw an exception? Hang indefinitely? Print anything out?

What platform are you on?

What does "cobra -help" do?

If you get it running at all, you can also run it with verbosity such as -v or -v:2

-Chuck
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Using Cobra from the lastest source code

Postby relez » Sat Sep 20, 2008 2:01 am

Hi Chuck
I'm developing on Windows Vista sp1
Cobra.exe is located in cobra-workspace\source
Simply, if i run that file (even if it's cobra -help) it hangs and Vista display the tipycal "Cobra.exe has stopped working"....
This is the begin of the long message:
C:\Users\RL\Cobra\workspace\cobra-workspace\Source>cobra

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has
been thrown by the target of an invocation. ---> Cobra.Lang.AssertException:
sourceSite = C:\Users\RL\Cobra\workspace\cobra-workspace\Source\Snapshot\CobraLa
ng.cobra:1956 in StringMaker.testCases for object Cobra.Lang.PrintStringMaker
info = nil
this = PrintStringMaker('Cobra.Lang.PrintStringMaker')
(.makeString(6.0, 'N2') == '6.00') = false
.makeString(6.0, 'N2') = '6,00'

at Cobra.Lang.StringMaker.TestCases(IList cases) in c:\Users\RL\Cobra\workspa
ce\cobra-workspace\Source\Snapshot\CobraLang.cobra:line 1956
at Cobra.Lang.PrintStringMaker.test_MakePrintString() in c:\Users\RL\Cobra\wo
rkspace\cobra-workspace\Source\Snapshot\CobraLang.cobra:line 2001
at Cobra.Lang.PrintStringMaker.RunTests() in c:\Users\RL\Cobra\workspace\cobr
a-workspace\Source\Snapshot\CobraLang.cobra:line 2016
at Cobra.Lang.PrintStringMaker.RunTestsIfNeeded() in c:\Users\RL\Cobra\worksp
ace\cobra-workspace\Source\Snapshot\CobraLang.cobra:line 2016
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] argum
ents, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle
typeOwner)


Of course i can wait till 0.9 version (or 0.81 will be the next?) it's just for curiosity to know waht i'm missing
relez
 
Posts: 69

Re: Using Cobra from the lastest source code

Postby Charles » Sat Sep 20, 2008 9:17 am

relez wrote:Of course i can wait till 0.9 version (or 0.81 will be the next?) it's just for curiosity to know waht i'm missing

Well since you're now connected to the repository, it would just be waiting for this specific fix instead of the next release. Anyway, based on the message you pasted in, it looks like the test is sensitive to culture info. It's the comma vs. period thing for decimal separator. And this is why it's good to have more testers! :-)

For now, try killing the test with "comp -include-tests:no".

comp is invoking Source\Snapshot\cobra.exe on the source and will pass any command line args down to it. So with that argument, the unit tests will be excluded and you should be good.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Using Cobra from the lastest source code

Postby relez » Sat Sep 20, 2008 2:36 pm

something like that happened to me with one of the first version of F#, if i remember well :)
i've tried changing settings to english/usa and all is fine
then i came back to my old settings and tried using comp -include-tests:no... cobra.exe works but hello.exe hangs again :(
so now i'm using US settings.
relez
 
Posts: 69

Re: Using Cobra from the lastest source code

Postby Charles » Sat Sep 20, 2008 5:56 pm

Does hello.exe hang when you run it directly, or when you run it via "cobra hello.cobra"?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Using Cobra from the lastest source code

Postby relez » Sun Sep 21, 2008 1:12 am

one way or the other there is no difference, It hangs....with US setting it's ok. With italian settings this is the result:

C:\Users\RL\Cobra\workspace\cobra-workspace\Source>hello
An unhandled exception has occurred.

Cobra debugging tips:
To get file name and line number information for the stack frames, use:
cobra -debug foo.cobra
To get a post-mortem, HTML-formatted report with more details about your obj
ects:
cobra -debug -exception-report foo.cobra
For even more information, try:
cobra -debug -exception-report -detailed-stack-trace foo.cobra
Or use the abbreviations:
cobra -d -er -dst foo.cobra


Unhandled Exception: System.Reflection.TargetInvocationException: Exception has
been thrown by the target of an invocation. ---> Cobra.Lang.AssertException:
sourceSite = C:\Users\RL\Cobra\workspace\cobra-workspace\Source\CobraLang.cobra:
1955 in StringMaker.testCases for object Cobra.Lang.PrintStringMaker
info = nil
this = PrintStringMaker('Cobra.Lang.PrintStringMaker')
(.makeString(6.0, 'N2') == '6.00') = false
.makeString(6.0, 'N2') = '6,00'

at Cobra.Lang.StringMaker.TestCases(IList cases)
at Cobra.Lang.PrintStringMaker.test_MakePrintString()
at Cobra.Lang.PrintStringMaker.RunTests()
at Cobra.Lang.PrintStringMaker.RunTestsIfNeeded()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] argum
ents, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle
typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] argume
nts, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwn
er)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisib
ilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture)
at Cobra.Lang.CobraCore._runAllTests(Assembly ass, Dictionary`2 found)
at Program.Main()
relez
 
Posts: 69

Re: Using Cobra from the lastest source code

Postby Charles » Sun Sep 21, 2008 9:37 am

I use "hang" to mean the program runs, but never terminates or does any visible work. I use "throws exception" to mean that it throws an uncaught exception which is subsequently displayed as an error. The two are mutually exclusive.

I think what you mean above is that it that it throws an exception with Italian settings. But this is the same exception we discussed earlier, so suppose you have Italian settings and you run it with:

cobra -c -include-tests:no hello
hello.exe

What happens then?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Using Cobra from the lastest source code

Postby Charles » Sun Sep 21, 2008 9:49 am

I've fixed the bug in development. Please update and try again.

I've also made some updates to DeveloperNotes.text regarding:

-- updating the workspace

-- using the -turbo option when building Cobra

See changeset:1625
Charles
 
Posts: 2515
Location: Los Angeles, CA

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 9 guests