Ticket #21: numberDirective1.patch
File numberDirective1.patch, 3.9 KB (added by hopscc, 16 years ago) |
---|
new patch |
-
Source/Compiler.cobra
515 515 on 'float64', _numberType = .floatType(64) 516 516 else, throw FallThroughException(.options['number']) 517 517 return _numberType to ! 518 519 # set _numberType from a string rep 520 set numberTypeFmStr as String 521 branch value 522 on 'decimal', _numberType = .decimalType 523 on 'float', _numberType = .floatType 524 on 'float32', _numberType = .floatType(32) 525 on 'float64', _numberType = .floatType(64) 526 else, throw FallThroughException(value) 518 527 519 528 get passThroughType as PassThroughType 520 529 if _passThroughType is nil -
Source/CobraParser.cobra
521 521 else 522 522 isGood = false 523 523 if not isGood 524 sugg = Compiler.suggestionFor(tok.text) 524 sugg = nil 525 if tok.text.length 526 sugg = Compiler.suggestionFor(tok.text) 525 527 sugg = if(sugg, ' Try "[sugg]".', '') 526 528 .throwError('Expecting use, assembly, namespace, class, interface or enum, but got [tok].[sugg]') 527 529 if what … … 542 544 .expect('EOL') 543 545 # TODO: throw AssertException(SourceSite sourceSite, object[] expressions, object thiss, object info) 544 546 assert false, IdentifierExpr(token, 'throw') 547 # number 'decimal' | 'float' | 'float32' | 'float64' 548 on 'number' 549 typeId = .grab #.typeId # or subset thereof 550 if typeId.text not in ['decimal', 'float', 'float32', 'float64'] 551 .throwError("Compiler directive 'number': unrecognised arg '[typeId.text]'. Must be one of 'decimal' | 'float' | 'float32' | 'float64'.") 552 .expect('EOL') 553 cc = .typeProvider to Compiler? 554 if cc 555 cc.numberTypeFmStr = typeId.text 545 556 else 546 557 .throwError('Unknown compiler directive.') 547 558 -
Tests/200-misc/900-number-directive.cobra
1 # test the new number compiler directive 2 #%% number float32 | decimal | float | float32 | float64 3 %% number float32 4 5 class CompDir 6 def main is shared 7 n as number = 44 8 #print '[n.getType] n=[n]' 9 assert n.getType is Single 10 m as number = 45 11 #print '[m.getType] m=[m]' 12 assert m.getType is Single 13 14 CDDec.x 15 CDF.x 16 CDF32.x 17 CDF64.x 18 #print 'end' 19 20 21 %% number decimal 22 class CDDec 23 def x is shared 24 m as number = 46 25 #print '[m.getType] m=[m]' 26 assert m.getType is Decimal 27 28 %% number float 29 class CDF 30 def x is shared 31 m as number = 47 32 #print '[m.getType] m=[m]' 33 assert m.getType is Double 34 35 %% number float32 36 class CDF32 37 def x is shared 38 m as number = 48 39 #print '[m.getType] m=[m]' 40 assert m.getType is Single 41 42 %% number float64 43 class CDF64 44 def x is shared 45 m as number = 49 46 #print '[m.getType] m=[m]' 47 assert m.getType is Double 48 -
Developer/IntermediateReleaseNotes.text
1 1 Post 0.8 2 2 3 * Add support for a cobra compiler Directive specifying default numeric 4 type of number and integer literals same as command line -number option 5 %% number 'decimal' | 'float' | 'float32' | 'float64' 6 3 7 * 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. 4 8 5 9 * Add support for specifying unsigned integers as Hex literals