Forums

Operator overloading support?

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

Operator overloading support?

Postby melger » Thu Nov 24, 2011 11:35 am

I just recently discovered Cobra, and I really like the syntax/speed trade-off. One question I have is if operator overloading support is planned anytime soon? I realize that full support would be a large undertaking, but just the ability to consume C# classes with operators defined (i.e. issue #69 from 2008) would be very useful for people doing numerical-oriented applications.
melger
 
Posts: 6

Re: Operator overloading support?

Postby Charles » Thu Nov 24, 2011 11:42 am

It wasn't already high on my list as I usually get by using the various methods like:
start = DateTime.now
...
duration = DateTime.now.subtract(start)

But I realize there are libraries out there that violate the CLS/CTS standards and do not provide named methods for their operators which can be a bummer. I'll take a closer look in December. After all, I'm heading out for some turkey today. :D

Btw if you get in a jam, you can use the sharp "escape hatch":
start = DateTime.now
...
duration = sharp'DateTime.Now - start' to TimeSpan
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Operator overloading support?

Postby melger » Thu Nov 24, 2011 12:01 pm

Thanks for the quick reply! That looks interesting... Is the sharp escape hatch just quoted C# code?
melger
 
Posts: 6

Re: Operator overloading support?

Postby Charles » Fri Nov 25, 2011 2:29 am

Re: the "sharp string", yes. Only works for expressions and statements, not declarations such as methods and classes.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Operator overloading support?

Postby DelphiGuy » Fri Jan 25, 2013 12:26 pm

charles, just curious: has there been any further activity on providing operator overload support? thanks.
DelphiGuy
 
Posts: 116

Re: Operator overloading support?

Postby Charles » Fri Jan 25, 2013 5:25 pm

No. I have been focused on bug fixing and supporting the IDE effort (specifically optimizing Cobra.Compiler.dll).
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Operator overloading support?

Postby torial » Tue Jan 29, 2013 8:10 am

What kinds of changes have you been making for IDE support? I noticed a lot of optimization changes. Are you adding hooks into the compilation mechanism?
torial
 
Posts: 229
Location: IA

Re: Operator overloading support?

Postby nerdzero » Wed Jan 30, 2013 10:20 am

Charles did a lot of work on the performance of the Tokenizer which means less time waiting between entering some text in MonoDevelop and seeing the completion data.
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: Operator overloading support?

Postby torial » Wed Jan 30, 2013 10:38 am

How are you getting access to the tokenizer info? I took a quick look at the code in GitHub but couldn't figure out where autocomplete logic was being handled.
torial
 
Posts: 229
Location: IA

Re: Operator overloading support?

Postby nerdzero » Wed Jan 30, 2013 12:48 pm

Yeah, the code isn't very easy to understand at this point. I'm working on making it prettier. Also, if you were looking at the 'master' branch there is no autocomplete logic in there, it's in the 'completion' branch.

I'm not using the tokenizer output directly, but I am using the output of the parser which is fed by the tokenizer. Here's a simplified example program:

use Cobra.Compiler

class AstDemo

def main

# set some default options for the compiler
options = OptionValues()
options.add("compile", true)
options.add("back-end", "clr")
options.add("turbo", true)
options.add("number", decimal)

# create an instance of the Cobra Compiler
verbosity = 0
compiler = Compiler(verbosity)
compiler.options = options
compiler.initBackEnd

# set some shared variables on the Node class
Node.setCompiler(compiler)
Node.typeProvider = compiler

# create an instance of the Cobra Parser
parser = CobraParser()
parser.typeProvider = compiler
parser.warningRecorder = compiler
parser.errorRecorder = compiler
parser.globalNS = compiler.globalNS
parser.backEnd = compiler.backEnd

# create a Cobra source "file", you could also read this from the disk
fileName = "example.cobra"

sourceCode = _
"class A\n" +
" var b as int\n" +
" var c as int\n" +
" def add as int\n" +
" return .b + .c"

# parse the source code and get a prelimary AST
module as CobraModule? = nil

try
module = parser.parseSource(fileName, sourceCode)
compiler.modules.add(module)
catch ex as SourceException
print "Parser error: [ex.toString]"

if module <> nil
# print the nodes in the abstract syntax tree
for syntaxNode in module.topNameSpace.declsInOrder
if syntaxNode inherits Box
print syntaxNode.name
for member in syntaxNode.declsInOrder
print "\t[member.name]"


Output:

Code: Select all
A
   b
   c
   add
nerdzero
 
Posts: 286
Location: Chicago, IL

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 17 guests

cron