Skip to content

Commit 3dc26db

Browse files
authored
Merge pull request #1028 from zickgraf/master
Support compiling CAP operations which are themselves operations or kernel functions
2 parents 3d1a62f + 72967ea commit 3dc26db

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

CompilerForCAP/PackageInfo.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SetPackageInfo( rec(
1010

1111
PackageName := "CompilerForCAP",
1212
Subtitle := "Speed up computations in CAP categories",
13-
Version := "2022.09-02",
13+
Version := "2022.09-03",
1414
Date := Concatenation( "01/", ~.Version{[ 6, 7 ]}, "/", ~.Version{[ 1 .. 4 ]} ),
1515
License := "GPL-2.0-or-later",
1616

CompilerForCAP/TODO

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Features:
99

1010
* list expressions for logic templates
1111
* do not inline variables but only a reference to them for the logic to use
12-
* support compilation of operations
1312
* For categories with finitely many objects (or morphisms): detect parts of the code which can be precomputed, e.g. hom_structure_on_basis_paths in Algebroids.
1413
* unify deduplication and hoisting: hoisting in duplicate code can lead to different variable names, so the deduplication does not match anymore (partially fixed)
1514
* hoisting in the following situation:
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#! @Chapter Examples and tests
2+
3+
#! @Section Tests
4+
5+
#! @Example
6+
7+
LoadPackage( "CompilerForCAP", false );
8+
#! true
9+
10+
dummy := DummyCategory( rec(
11+
list_of_operations_to_install := [
12+
"IdentityMorphism",
13+
],
14+
) : FinalizeCategory := false );;
15+
16+
AddIsProjective( dummy, ReturnTrue );
17+
18+
Finalize( dummy );;
19+
20+
Display( CapJitCompiledFunction(
21+
{ cat, obj } -> IsProjective( cat, obj ),
22+
dummy
23+
) );
24+
#! function ( cat_1, obj_1 )
25+
#! return RETURN_TRUE( cat_1, obj_1 );
26+
#! end
27+
28+
#! @EndExample

CompilerForCAP/gap/CompileCAPOperation.gi

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Implementations
55
#
66
InstallGlobalFunction( "CapJitCompiledCAPOperationAsEnhancedSyntaxTree", function ( cat, operation_name )
7-
local index, function_to_compile, info, filter_list, return_type;
7+
local index, function_to_compile, global_variable_name, info, return_type;
88

99
if not (IsBound( cat!.category_as_first_argument ) and cat!.category_as_first_argument = true) then
1010

@@ -41,8 +41,15 @@ InstallGlobalFunction( "CapJitCompiledCAPOperationAsEnhancedSyntaxTree", functio
4141

4242
if IsOperation( function_to_compile ) or IsKernelFunction( function_to_compile ) then
4343

44-
# COVERAGE_IGNORE_NEXT_LINE
45-
Error( "compiling operations or kernel functions is not supported." );
44+
global_variable_name := CapJitGetOrCreateGlobalVariable( function_to_compile );
45+
46+
function_to_compile := EvalString( ReplacedStringViaRecord(
47+
"{ input_arguments } -> global_variable_name( input_arguments )",
48+
rec(
49+
input_arguments := CAP_INTERNAL_METHOD_NAME_RECORD.(operation_name).input_arguments_names,
50+
global_variable_name := global_variable_name,
51+
)
52+
) );
4653

4754
fi;
4855

CompilerForCAP/gap/InferDataTypes.gi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ CapJitAddTypeSignature( "Range", [ IsCapCategoryMorphism ], function ( input_typ
876876
end );
877877

878878
# GAP operations
879+
CapJitAddTypeSignature( "RETURN_TRUE", [ IsObject, IsObject ], IsBool );
879880
CapJitAddTypeSignature( "Length", [ IsList ], IsInt );
880881
CapJitAddTypeSignature( "+", [ IsInt, IsInt ], IsInt );
881882
CapJitAddTypeSignature( "-", [ IsInt, IsInt ], IsInt );

0 commit comments

Comments
 (0)