Skip to content

Commit

Permalink
Seperate Info functions into new file
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Mar 31, 2019
1 parent 0ef46dc commit a174995
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 64 deletions.
1 change: 1 addition & 0 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ SOURCES += src/gap.c
SOURCES += gen/gap_version.c # generated source file
SOURCES += src/gvars.c
SOURCES += src/hookintrprtr.c
SOURCES += src/info.c
SOURCES += src/integer.c
SOURCES += src/intfuncs.c
SOURCES += src/intrprtr.c
Expand Down
140 changes: 140 additions & 0 deletions src/info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/****************************************************************************
**
** This file is part of GAP, a system for computational discrete algebra.
**
** Copyright of GAP belongs to its developers, whose names are too numerous
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** This file declares the functions handling Info statements.
*/


#include "info.h"

#include "bool.h"
#include "calls.h"
#include "gvars.h"
#include "modules.h"
#include "plist.h"

#ifdef HPCGAP
#include "hpc/aobjects.h"
#endif

enum {
INFODATA_NUM = 1,
INFODATA_CURRENTLEVEL,
INFODATA_CLASSNAME,
INFODATA_HANDLER,
INFODATA_OUTPUT,
};

static Obj InfoDecision;
static Obj IsInfoClassListRep;
static Obj DefaultInfoHandler;

void InfoDoPrint(Obj cls, Obj lvl, Obj args)
{
if (IS_PLIST(cls))
cls = ELM_PLIST(cls, 1);
#if defined(HPCGAP)
Obj fun = Elm0AList(cls, INFODATA_HANDLER);
#else
Obj fun = ELM_PLIST(cls, INFODATA_HANDLER);
#endif
if (!fun)
fun = DefaultInfoHandler;

CALL_3ARGS(fun, cls, lvl, args);
}


Obj InfoCheckLevel(Obj selectors, Obj level)
{
// Fast-path the most common failing case.
// The fast-path only deals with the case where all arguments are of the
// correct type, and were False is returned.
if (CALL_1ARGS(IsInfoClassListRep, selectors) == True) {
#if defined(HPCGAP)
Obj index = ElmAList(selectors, INFODATA_CURRENTLEVEL);
#else
Obj index = ELM_PLIST(selectors, INFODATA_CURRENTLEVEL);
#endif
if (IS_INTOBJ(index) && IS_INTOBJ(level)) {
// < on INTOBJs compares the represented integers.
if (index < level) {
return False;
}
}
}
return CALL_2ARGS(InfoDecision, selectors, level);
}

/****************************************************************************
**
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *
*/


/****************************************************************************
**
*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures
*/
static Int InitKernel (
StructInitInfo * module )
{
/* The work of handling Info messages is delegated to the GAP level */
ImportFuncFromLibrary("InfoDecision", &InfoDecision);
ImportFuncFromLibrary("DefaultInfoHandler", &DefaultInfoHandler);
ImportFuncFromLibrary("IsInfoClassListRep", &IsInfoClassListRep);

/* return success */
return 0;
}


/****************************************************************************
**
*F InitLibrary( <module> ) . . . . . . . initialise library data structures
*/
static Int InitLibrary (
StructInitInfo * module )
{
ExportAsConstantGVar(INFODATA_CURRENTLEVEL);
ExportAsConstantGVar(INFODATA_CLASSNAME);
ExportAsConstantGVar(INFODATA_HANDLER);
ExportAsConstantGVar(INFODATA_OUTPUT);
ExportAsConstantGVar(INFODATA_NUM);

/* return success */
return 0;
}

static Int InitModuleState(void)
{
// return success
return 0;
}


/****************************************************************************
**
*F InitInfoIntrprtr() . . . . . . . . . . . . . . . table of init functions
*/
static StructInitInfo module = {
// init struct using C99 designated initializers; for a full list of
// fields, please refer to the definition of StructInitInfo
.type = MODULE_BUILTIN,
.name = "info",
.initKernel = InitKernel,
.initLibrary = InitLibrary,

.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoInfo ( void )
{
return &module;
}
41 changes: 41 additions & 0 deletions src/info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/****************************************************************************
**
** This file is part of GAP, a system for computational discrete algebra.
**
** Copyright of GAP belongs to its developers, whose names are too numerous
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** This file declares the functions handling Info statements.
*/

#ifndef GAP_INFO_H
#define GAP_INFO_H

#include "system.h"
#include "gap.h"

/*
*F InfoCheckLevel( <selectors>, <level> ) . . . check if Info should output
** InfoDoPrint( <selectors>, <level>, <args> ) . . . print an Info statement
*/

Obj InfoCheckLevel(Obj selectors, Obj level);

void InfoDoPrint(Obj cls, Obj lvl, Obj args);


/****************************************************************************
**
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *
*/


/****************************************************************************
**
*F InitInfoInfo() . . . . . . . . . . . . . . . . . table of init functions
*/
StructInitInfo * InitInfoInfo ( void );

#endif
61 changes: 1 addition & 60 deletions src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "gapstate.h"
#include "gvars.h"
#include "hookintrprtr.h"
#include "info.h"
#include "integer.h"
#include "io.h"
#include "lists.h"
Expand Down Expand Up @@ -3765,55 +3766,6 @@ void IntrInfoBegin( void )

}

enum {
INFODATA_NUM = 1,
INFODATA_CURRENTLEVEL,
INFODATA_CLASSNAME,
INFODATA_HANDLER,
INFODATA_OUTPUT,
};

static Obj InfoDecision;
static Obj IsInfoClassListRep;
static Obj DefaultInfoHandler;

void InfoDoPrint(Obj cls, Obj lvl, Obj args)
{
if (IS_PLIST(cls))
cls = ELM_PLIST(cls, 1);
#if defined(HPCGAP)
Obj fun = Elm0AList(cls, INFODATA_HANDLER);
#else
Obj fun = ELM_PLIST(cls, INFODATA_HANDLER);
#endif
if (!fun)
fun = DefaultInfoHandler;

CALL_3ARGS(fun, cls, lvl, args);
}


Obj InfoCheckLevel(Obj selectors, Obj level)
{
// Fast-path the most common failing case.
// The fast-path only deals with the case where all arguments are of the
// correct type, and were False is returned.
if (CALL_1ARGS(IsInfoClassListRep, selectors) == True) {
#if defined(HPCGAP)
Obj index = ElmAList(selectors, INFODATA_CURRENTLEVEL);
#else
Obj index = ELM_PLIST(selectors, INFODATA_CURRENTLEVEL);
#endif
if (IS_INTOBJ(index) && IS_INTOBJ(level)) {
// < on INTOBJs compares the represented integers.
if (index < level) {
return False;
}
}
}
return CALL_2ARGS(InfoDecision, selectors, level);
}


void IntrInfoMiddle( void )
{
Expand Down Expand Up @@ -4026,11 +3978,6 @@ static Int InitKernel (
InitCopyGVar( "CurrentAssertionLevel", &CurrentAssertionLevel );
InitFopyGVar( "CONVERT_FLOAT_LITERAL_EAGER", &CONVERT_FLOAT_LITERAL_EAGER);

/* The work of handling Info messages is delegated to the GAP level */
ImportFuncFromLibrary("InfoDecision", &InfoDecision);
ImportFuncFromLibrary("DefaultInfoHandler", &DefaultInfoHandler);
ImportFuncFromLibrary("IsInfoClassListRep", &IsInfoClassListRep);

/* The work of handling Options is also delegated*/
ImportFuncFromLibrary( "PushOptions", &PushOptions );
ImportFuncFromLibrary( "PopOptions", &PopOptions );
Expand All @@ -4053,12 +4000,6 @@ static Int InitLibrary (
lev = GVarName("CurrentAssertionLevel");
AssGVar( lev, INTOBJ_INT(0) );

ExportAsConstantGVar(INFODATA_CURRENTLEVEL);
ExportAsConstantGVar(INFODATA_CLASSNAME);
ExportAsConstantGVar(INFODATA_HANDLER);
ExportAsConstantGVar(INFODATA_OUTPUT);
ExportAsConstantGVar(INFODATA_NUM);

/* return success */
return 0;
}
Expand Down
4 changes: 0 additions & 4 deletions src/intrprtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,15 +835,11 @@ void IntrEmpty(void);
*F IntrInfoBegin() . . . . . . . . . start interpretation of Info statement
*F IntrInfoMiddle() . . . . . . . shift to interpreting printable arguments
*F IntrInfoEnd( <narg> ) . . Info statement complete, <narg> things to print
*F InfoCheckLevel( <selectors>, <level> ) . . . check if Info should output
*/

void IntrInfoBegin(void);
void IntrInfoMiddle(void);
void IntrInfoEnd(UInt narg);
Obj InfoCheckLevel(Obj, Obj);

void InfoDoPrint(Obj cls, Obj lvl, Obj args);


/****************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions src/modules_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "compiled.h"
#include "gap.h"
#include "hookintrprtr.h"
#include "info.h"
#include "intfuncs.h"
#include "iostream.h"
#include "objccoll.h"
Expand Down Expand Up @@ -63,6 +64,7 @@ const InitInfoFunc InitFuncsBuiltinModules[] = {
InitInfoVars, /* must come after InitExpr and InitStats */
InitInfoFuncs,
InitInfoOpers,
InitInfoInfo,
InitInfoIntrprtr,
InitInfoCompiler,

Expand Down
1 change: 1 addition & 0 deletions src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "exprs.h"
#include "gvars.h"
#include "hookintrprtr.h"
#include "info.h"
#include "intrprtr.h"
#include "io.h"
#include "lists.h"
Expand Down

0 comments on commit a174995

Please sign in to comment.