Forums
Operator overloading support?
11 posts
• Page 1 of 2 • 1, 2
Operator overloading support?
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?
It wasn't already high on my list as I usually get by using the various methods like:
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.
Btw if you get in a jam, you can use the sharp "escape hatch":
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.
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?
Thanks for the quick reply! That looks interesting... Is the sharp escape hatch just quoted C# code?
- melger
- Posts: 6
Re: Operator overloading support?
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?
charles, just curious: has there been any further activity on providing operator overload support? thanks.
- DelphiGuy
- Posts: 116
Re: Operator overloading support?
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?
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?
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?
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?
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:
Output:
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
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 26 guests