Faculty of Information Technology
Software Engineering Group

Ticket #105: regression_fix_1_of_1_rev_03c52f59f5df_Issue__105__STC_compiled_forces_result_of______________to_be_a_boolean.patch

File regression_fix_1_of_1_rev_03c52f59f5df_Issue__105__STC_compiled_forces_result_of______________to_be_a_boolean.patch, 6.7 KB (added by Jan Vrany, 5 years ago)

Testcase

  • RegressionTests__CompilerTests2.st

    # HG changeset patch
    # User Jan Vrany <jan.vrany@fit.cvut.cz>
    # Date 1471684576 -3600
    #      Sat Aug 20 10:16:16 2016 +0100
    # Branch jv
    # Node ID 03c52f59f5df8db399528d83e0a101c27e99243d
    # Parent  b711534dc296eb7579089a5a80cb2f958b3568ab
    Issue #105: STC compiled forces result of #<, #<=, ... to be a boolean
    
    Added tests for "comparing" selectors. More may be needed, based on a
    quick look to stc's `codeexpr.c`.
    
    diff -r b711534dc296 -r 03c52f59f5df RegressionTests__CompilerTests2.st
    a b  
    55TestCase subclass:#CompilerTests2
    66        instanceVariableNames:'methods enabledJIT savedContext savedContextArgAndVarNames
    77                savedContextArgAndVarValues savedContextArgAndVarValuesUsingEval
    8                 savedContextLine'
     8                savedContextLine stcGeneratedCSource'
    99        classVariableNames:''
    1010        poolDictionaries:''
    1111        category:'tests-Regression-Compilers'
     
    5858       #stc....then the method is stc-compiled.
    5959       #jit....then the method is bytecode compiled and left
    6060               to the jitter
    61        #bc.....them the method is bytecode compiled and marked
     61       #bc.....then the method is bytecode compiled and marked
    6262               as checked so JIT won't even try.
    6363    "
    6464
     
    6767    Class withoutUpdatingChangesDo:[
    6868        mode == #stc ifTrue:[
    6969            ParserFlags withSTCCompilation:#always do:[
    70                 m := self class compile: (mode, '_', source) classified: 'private - *dynamic*'.
     70                MessageTracer wrapMethod: STCCompilerInterface >> #compileToC
     71                              onEntry:[:context | "nothing" ]
     72                              onExit: [:context :retval | stcGeneratedCSource := (context receiver instVarNamed: #cFileName) asFilename contents.retval ].
     73                [
     74                    m := self class compile: (mode, '_', source) classified: 'private - *dynamic*'.
     75                ] ensure:[
     76                    MessageTracer unwrapMethod: STCCompilerInterface >> #compileToC   
     77                ].
     78
    7179            ].
    7280        ] ifFalse:[
    7381            ParserFlags withSTCCompilation:#never do:[
     
    8088    ^m
    8189
    8290    "Created: / 25-04-2013 / 15:18:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     91    "Modified: / 21-08-2016 / 08:34:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    8392!
    8493
    8594currentLineNumber
     
    650659    ^ literal.
    651660! !
    652661
     662!CompilerTests2 methodsFor:'private-mock methods-inlining / special selectors'!
     663
     664< another
     665    ^ self
     666
     667    "Created: / 20-08-2016 / 09:11:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     668!
     669
     670<= another
     671    ^ self
     672
     673    "Created: / 20-08-2016 / 09:11:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     674    "Modified: / 20-08-2016 / 10:11:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     675!
     676
     677= another
     678    ^ self
     679
     680    "Created: / 20-08-2016 / 09:11:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     681    "Modified: / 20-08-2016 / 10:11:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     682!
     683
     684> another
     685    ^ self
     686
     687    "Created: / 20-08-2016 / 09:11:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     688    "Modified: / 20-08-2016 / 10:11:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     689!
     690
     691>= another
     692   ^ self
     693
     694    "Created: / 20-08-2016 / 09:11:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     695    "Modified: / 20-08-2016 / 10:12:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     696!
     697
     698methodCallingBinaryRelopsOnObject: lhs andObject: rhs
     699    | result |
     700
     701    result := Array new: 5.
     702
     703    lhs <  rhs then:[ result at: 1 put: #<  ].
     704    lhs <= rhs then:[ result at: 2 put: #<= ].
     705    lhs =  rhs then:[ result at: 3 put: #=  ].
     706    lhs >  rhs then:[ result at: 4 put: #>  ].
     707    lhs >= rhs then:[ result at: 5 put: #>= ].
     708
     709    ^ result
     710
     711    "Created: / 20-08-2016 / 09:17:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     712!
     713
     714methodCallingBinaryRelopsOnObjectAndConstant: lhs
     715    | result |
     716
     717    result := Array new: 5.
     718
     719    lhs <  1 then:[ result at: 1 put: #<  ].
     720    lhs <= 2 then:[ result at: 2 put: #<= ].
     721    lhs =  3 then:[ result at: 3 put: #=  ].
     722    lhs >  4 then:[ result at: 4 put: #>  ].
     723    lhs >= 5 then:[ result at: 5 put: #>= ].
     724
     725    ^ result
     726
     727    "Created: / 20-08-2016 / 09:17:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     728!
     729
     730then: aBlock
     731    aBlock value
     732
     733    "Created: / 20-08-2016 / 10:09:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     734! !
     735
    653736!CompilerTests2 methodsFor:'setup'!
    654737
    655738setUp
     
    666749tearDown
    667750    savedContext := savedContextArgAndVarNames
    668751    := savedContextArgAndVarValues := savedContextArgAndVarValuesUsingEval
    669     := savedContextLine := nil.
     752    := savedContextLine := stcGeneratedCSource := nil.
    670753
    671754    ObjectMemory justInTimeCompilation: enabledJIT.
    672755    Class withoutUpdatingChangesDo:[
     
    693776    ]
    694777
    695778    "Created: / 26-10-2012 / 11:32:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    696     "Modified: / 26-09-2014 / 12:59:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     779    "Modified: / 20-08-2016 / 08:57:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    697780! !
    698781
    699782!CompilerTests2 methodsFor:'tests'!
     
    11771260    "Modified: / 26-12-2015 / 07:38:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    11781261! !
    11791262
     1263!CompilerTests2 methodsFor:'tests - inlining / special selectors'!
     1264
     1265testRelopNotReturningBoolean01
     1266    | expected returned |
     1267
     1268    expected := #( #< #<= #= #> #>= ).
     1269
     1270    #(bc stc) do:[:mode |
     1271        self compile: (self class >> #methodCallingBinaryRelopsOnObjectAndConstant:) source mode: mode.
     1272        returned := self perform: (mode , '_methodCallingBinaryRelopsOnObjectAndConstant:') asSymbol with: self.
     1273        self assert: returned = expected.
     1274    ]
     1275
     1276    "Created: / 21-08-2016 / 08:37:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     1277!
     1278
     1279testRelopNotReturningBoolean02
     1280    | expected returned |
     1281
     1282    expected := #( #< #<= #= #> #>= ).
     1283
     1284    #(bc stc) do:[:mode |
     1285        self compile: (self class >> #methodCallingBinaryRelopsOnObject:andObject:) source mode: mode.
     1286        returned := self perform: (mode , '_methodCallingBinaryRelopsOnObject:andObject:') asSymbol with: self with: self.
     1287        self assert: returned = expected.
     1288    ]
     1289
     1290    "Created: / 21-08-2016 / 09:04:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     1291! !
     1292
    11801293!CompilerTests2 methodsFor:'tests - line numbers'!
    11811294
    11821295test_lineno_01_bci
     
    12221335    m300 := self class >> #method_lineno_300.
    12231336
    12241337    self compile: m002 source mode: #stc.
     1338    "
     1339    stcGeneratedCSource asString inspect.
     1340    "
    12251341    self compile: m300 source mode: #stc.
    12261342
    12271343    self assert: (l := self stc_method_lineno_002) == 2.
     
    12291345
    12301346    "Created: / 12-04-2013 / 21:50:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    12311347    "Modified: / 25-04-2013 / 15:22:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     1348    "Modified (comment): / 20-08-2016 / 08:59:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    12321349! !
    12331350
    12341351!CompilerTests2 methodsFor:'tests - literals'!