-
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 #708 from zickgraf/compiler_improvements
Some improvements to the compiler
- Loading branch information
Showing
22 changed files
with
271 additions
and
206 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
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
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
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,16 @@ | ||
# 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 | ||
#! Detects statements of the form `if condition then return expr_if_true; else return expr_if_false; fi` and | ||
#! changes their representation by using a new expression type `EXPR_CONDITIONAL` with components `condition`, | ||
#! `expr_if_true`, and `expr_if_false`. This makes such statements easier to handle. | ||
#! @Returns a record | ||
#! @Arguments tree | ||
DeclareGlobalFunction( "CapJitDetectedTernaryConditionalExpressions" ); |
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,55 @@ | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
# CompilerForCAP: Speed up computations in CAP categories | ||
# | ||
# Implementations | ||
# | ||
InstallGlobalFunction( CapJitDetectedTernaryConditionalExpressions, function ( tree ) | ||
local pre_func; | ||
|
||
pre_func := function ( tree, additional_arguments ) | ||
local body_if_true, body_if_false, statement_if_true, statement_if_false; | ||
|
||
if IsRecord( tree ) then | ||
|
||
Assert( 0, IsBound( tree.type ) ); | ||
|
||
if tree.type = "STAT_IF_ELSE" then | ||
|
||
Assert( 0, Length( tree.branches ) = 2 ); | ||
Assert( 0, tree.branches[2].condition.type = "EXPR_TRUE" ); | ||
|
||
body_if_true := tree.branches[1].body; | ||
body_if_false := tree.branches[2].body; | ||
|
||
if Length( body_if_true.statements ) = 1 and Length( body_if_false.statements ) = 1 then | ||
|
||
statement_if_true := body_if_true.statements[1]; | ||
statement_if_false := body_if_false.statements[1]; | ||
|
||
if statement_if_true.type = "STAT_RETURN_OBJ" and statement_if_false.type = "STAT_RETURN_OBJ" then | ||
|
||
tree := rec( | ||
type := "STAT_RETURN_OBJ", | ||
obj := rec( | ||
type := "EXPR_CONDITIONAL", | ||
condition := tree.branches[1].condition, | ||
expr_if_true := statement_if_true.obj, | ||
expr_if_false := statement_if_false.obj, | ||
), | ||
); | ||
|
||
fi; | ||
|
||
fi; | ||
|
||
fi; | ||
|
||
fi; | ||
|
||
return tree; | ||
|
||
end; | ||
|
||
return CapJitIterateOverTree( tree, pre_func, CapJitResultFuncCombineChildren, ReturnTrue, true ); | ||
|
||
end ); |
Oops, something went wrong.