Skip to content

Commit

Permalink
Compile functions to Syntax Trees
Browse files Browse the repository at this point in the history
Adds a kernel function SYNTAX_TREE that translates a previously coded GAP
function into a syntax tree by using GAP records.
  • Loading branch information
markuspf authored and Markus Pfeiffer committed Nov 20, 2018
1 parent d87ce06 commit 6dd2fc0
Show file tree
Hide file tree
Showing 10 changed files with 996 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ SOURCES += src/set.c
SOURCES += src/stats.c
SOURCES += src/streams.c
SOURCES += src/stringobj.c
SOURCES += src/syntaxtree.c
SOURCES += src/sysfiles.c
SOURCES += src/sysmem.c
SOURCES += src/system.c
Expand Down
11 changes: 11 additions & 0 deletions doc/ref/language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,17 @@ For examples of <K>return</K> statements, see the functions <C>fib</C> and

</Section>

<Section>
<Heading>Syntax Trees</Heading>

This section describes the tools available to manipulate &GAP; syntax
programmatically.

<#Include Label="SyntaxTree">
<#Include Label="CleanupCompiler">
<#Include Label="PrintCompiler">
</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!--
Expand Down
1 change: 1 addition & 0 deletions doc/ref/makedocreldata.g
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ GAPInfo.ManualDataRef:= rec(
"../../lib/string.g",
"../../lib/string.gd",
"../../lib/system.g",
"../../lib/syntaxtree.gd",
"../../lib/teaching.g",
"../../lib/tcsemi.gd",
"../../lib/test.gi",
Expand Down
3 changes: 3 additions & 0 deletions lib/read8.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ ReadLib( "overload.g" );
##
ReadLib( "compiler.g" );

ReadLib( "syntaxtree.gd" );
ReadLib( "syntaxtree.gi" );

#############################################################################
##
#X Teaching functionality
Expand Down
17 changes: 17 additions & 0 deletions lib/syntaxtree.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## syntaxtree.gd

DeclareCategory("IsSyntaxTree", IsObject);
BindGlobal("SyntaxTreeType", NewType( NewFamily( "SyntaxTreeFamily" )
, IsSyntaxTree and IsComponentObjectRep ) );

## <#GAPDoc Label="SyntaxTree">
## <ManSection>
## <Func Name="SyntaxTree" Arg='f'/>
##
## <Description>
## Takes a GAP function <A>f</A> and returns its syntax tree.
##
## </Description>
## </ManSection>
## <#/GAPDoc>
DeclareGlobalFunction("SyntaxTree");
15 changes: 15 additions & 0 deletions lib/syntaxtree.gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# syntaxtree.gi

InstallGlobalFunction( SyntaxTree,
function(f)
if (not IsFunction(f)) or IsOperation(f) or IsKernelFunction(f) then
Error("SyntaxTree: <f> must be a plain GAP function, not a ", TNAM_OBJ(f));
fi;
return Objectify( SyntaxTreeType, rec( file := FilenameFunc(f)
, line := StartlineFunc(f)
, tree := SYNTAX_TREE(f) ) );
end);

InstallMethod( ViewString, "for a syntax tree"
, [ IsSyntaxTree ]
, t -> "<syntax tree>" );
4 changes: 4 additions & 0 deletions src/modules-builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "objccoll.h"
#include "objset.h"
#include "profile.h"
#include "syntaxtree.h"
#include "vec8bit.h"
#include "vecffe.h"
#include "vecgf2.h"
Expand Down Expand Up @@ -103,6 +104,9 @@ const InitInfoFunc InitFuncsBuiltinModules[] = {
InitInfoWeakPtr,
InitInfoSaveLoad,

/* syntax and parser tools */
InitInfoSyntaxTree,

/* input and output */
InitInfoStreams,
InitInfoSysFiles,
Expand Down
Loading

0 comments on commit 6dd2fc0

Please sign in to comment.