Ticket #21: numberDirective1.patch

File numberDirective1.patch, 3.9 kB (added by hopscc, 6 months ago)

new patch

  • Source/Compiler.cobra

     
    515515                                on 'float64', _numberType = .floatType(64) 
    516516                                else, throw FallThroughException(.options['number']) 
    517517                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) 
    518527                 
    519528        get passThroughType as PassThroughType 
    520529                if _passThroughType is nil 
  • Source/CobraParser.cobra

     
    521521                                        else 
    522522                                                isGood = false 
    523523                                if not isGood 
    524                                         sugg = Compiler.suggestionFor(tok.text) 
     524                                        sugg = nil 
     525                                        if tok.text.length 
     526                                                sugg = Compiler.suggestionFor(tok.text) 
    525527                                        sugg = if(sugg, ' Try "[sugg]".', '') 
    526528                                        .throwError('Expecting use, assembly, namespace, class, interface or enum, but got [tok].[sugg]') 
    527529                                if what 
     
    542544                                .expect('EOL') 
    543545                                # TODO: throw AssertException(SourceSite sourceSite, object[] expressions, object thiss, object info) 
    544546                                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 
    545556                        else 
    546557                                .throwError('Unknown compiler directive.') 
    547558 
  • 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 
     5class 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 
     22class 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 
     29class 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 
     36class 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 
     43class 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

     
    11Post 0.8 
    22 
     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     
    37* 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. 
    48 
    59* Add support for specifying unsigned integers as Hex literals