-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #724 from zickgraf/misc
Miscellaneous changes
- Loading branch information
Showing
20 changed files
with
820 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#! @Chapter Examples and tests | ||
|
||
#! @Section Tests | ||
|
||
#! @Example | ||
|
||
LoadPackage( "CompilerForCAP", false ); | ||
#! true | ||
|
||
## | ||
# duplicate code inside a function | ||
func := function( x ) | ||
return List( [ 1 .. 9 ], y -> (y + (x + 1)) + (y + (x + 1)) ); end;; | ||
|
||
tree := ENHANCED_SYNTAX_TREE( func );; | ||
tree := CapJitDeduplicatedExpressions( tree );; | ||
compiled_func := ENHANCED_SYNTAX_TREE_CODE( tree );; | ||
Display( compiled_func ); | ||
#! function ( x_1 ) | ||
#! return List( [ 1 .. 9 ], function ( y_2 ) | ||
#! local cap_jit_deduplicated_expression_1_2; | ||
#! cap_jit_deduplicated_expression_1_2 := y_2 + (x_1 + 1); | ||
#! return cap_jit_deduplicated_expression_1_2 | ||
#! + cap_jit_deduplicated_expression_1_2; | ||
#! end ); | ||
#! end | ||
|
||
## | ||
# duplicate code inside duplicate code | ||
func := function( x, y ) | ||
return (y + (x + 1) + (x + 1)) + (y + (x + 1) + (x + 1)); end;; | ||
|
||
tree := ENHANCED_SYNTAX_TREE( func );; | ||
tree := CapJitDeduplicatedExpressions( tree );; | ||
compiled_func := ENHANCED_SYNTAX_TREE_CODE( tree );; | ||
Display( compiled_func ); | ||
#! function ( x_1, y_1 ) | ||
#! local cap_jit_deduplicated_expression_1_1, | ||
#! cap_jit_deduplicated_expression_2_1; | ||
#! cap_jit_deduplicated_expression_2_1 := x_1 + 1; | ||
#! cap_jit_deduplicated_expression_1_1 | ||
#! := y_1 + cap_jit_deduplicated_expression_2_1 | ||
#! + cap_jit_deduplicated_expression_2_1; | ||
#! return cap_jit_deduplicated_expression_1_1 | ||
#! + cap_jit_deduplicated_expression_1_1; | ||
#! end | ||
|
||
## | ||
# don't deduplicate code accross functions | ||
func := function( ) | ||
return [ [ x -> (x + 1) + 2 ], [ x -> (x + 1) + 3 ] ]; end;; | ||
|
||
tree := ENHANCED_SYNTAX_TREE( func );; | ||
tree := CapJitDeduplicatedExpressions( tree );; | ||
compiled_func := ENHANCED_SYNTAX_TREE_CODE( tree );; | ||
Display( compiled_func ); | ||
#! function ( ) | ||
#! return [ [ function ( x_2 ) | ||
#! return x_2 + 1 + 2; | ||
#! end ], [ function ( x_2 ) | ||
#! return x_2 + 1 + 3; | ||
#! end ] ]; | ||
#! end | ||
|
||
## | ||
# duplicate code inside duplicate code at different function levels | ||
func := {} -> | ||
y -> [ [ y, x -> (x + 1) + (x + 1) ], [ y, x -> (x + 1) + (x + 1) ] ];; | ||
|
||
tree := ENHANCED_SYNTAX_TREE( func );; | ||
tree := CapJitDeduplicatedExpressions( tree );; | ||
compiled_func := ENHANCED_SYNTAX_TREE_CODE( tree );; | ||
Display( compiled_func ); | ||
#! function ( ) | ||
#! return function ( y_2 ) | ||
#! local cap_jit_deduplicated_expression_1_2; | ||
#! cap_jit_deduplicated_expression_1_2 := [ y_2, function ( x_3 ) | ||
#! local cap_jit_deduplicated_expression_2_3; | ||
#! cap_jit_deduplicated_expression_2_3 := x_3 + 1; | ||
#! return cap_jit_deduplicated_expression_2_3 | ||
#! + cap_jit_deduplicated_expression_2_3; | ||
#! end ]; | ||
#! return | ||
#! [ cap_jit_deduplicated_expression_1_2, | ||
#! cap_jit_deduplicated_expression_1_2 ]; | ||
#! end; | ||
#! end | ||
|
||
#! @EndExample |
24 changes: 24 additions & 0 deletions
24
CompilerForCAP/examples/CapJitIsEqualForEnhancedSyntaxTrees.g
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#! @Chapter Examples and tests | ||
|
||
#! @Section Tests | ||
|
||
#! @Example | ||
|
||
LoadPackage( "CompilerForCAP", false ); | ||
#! true | ||
|
||
# test that `CAP_JIT_NOT_RESOLVABLE` does not cause errors when comparing | ||
# syntax trees | ||
DeclareOperation( "MyNonResolvableOperation", [ ] ); | ||
|
||
func := { } -> MyNonResolvableOperation( );; | ||
|
||
tree := ENHANCED_SYNTAX_TREE( func );; | ||
|
||
tree2 := StructuralCopy( tree );; | ||
tree2.bindings.BINDING_RETURN_VALUE.funcref.CAP_JIT_NOT_RESOLVABLE := true;; | ||
|
||
CapJitIsEqualForEnhancedSyntaxTrees( tree, tree2 ); | ||
#! true | ||
|
||
#! @EndExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
# CompilerForCAP: Speed up computations in CAP categories | ||
# | ||
# Declarations | ||
# | ||
#! @Chapter Improving and extending the compiler | ||
|
||
#! @Section Compilation steps | ||
|
||
#! @Description | ||
#! Deduplicates expressions occuring at least twice in the enhanced syntax tree <A>tree</A>. | ||
#! @Returns a record | ||
#! @Arguments tree | ||
DeclareGlobalFunction( "CapJitDeduplicatedExpressions" ); |
Oops, something went wrong.