Skip to content

Commit

Permalink
kernel: remove FEXS_FUNC
Browse files Browse the repository at this point in the history
Function expressions logically belong to the function body, not the
function object. Hence FEXS_FUNC should be in the body, not the
function. But in the body, we already have the `values` plist, which is
used to so to store all other kinds of expression objects. Hence we can
simply get rid of FEXS_FUNC, and store function expressions in the
`values` plist.
  • Loading branch information
fingolfin committed Feb 8, 2019
1 parent 114e510 commit 2fdb8b1
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 54 deletions.
2 changes: 0 additions & 2 deletions src/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,6 @@ static void SaveFunction(Obj func)
SaveSubObj(header->nloc);
SaveSubObj(header->body);
SaveSubObj(header->envi);
SaveSubObj(header->fexs);
if (IS_OPERATION(func))
SaveOperationExtras( func );
}
Expand All @@ -1603,7 +1602,6 @@ static void LoadFunction(Obj func)
header->nloc = LoadSubObj();
header->body = LoadSubObj();
header->envi = LoadSubObj();
header->fexs = LoadSubObj();
if (IS_OPERATION(func))
LoadOperationExtras( func );
}
Expand Down
15 changes: 0 additions & 15 deletions src/calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ typedef Obj (* ObjFunc_6ARGS) (Obj self, Obj a1, Obj a2, Obj a3, Obj a4, Obj a5,
*F NLOC_FUNC(<func>) . . . . . . . . . . . . number of locals of a function
*F BODY_FUNC(<func>) . . . . . . . . . . . . . . . . . . body of a function
*F ENVI_FUNC(<func>) . . . . . . . . . . . . . . . environment of a function
*F FEXS_FUNC(<func>) . . . . . . . . . . . . func. expr. list of a function
**
** These macros make it possible to access the various components of a
** function.
Expand All @@ -96,9 +95,6 @@ typedef Obj (* ObjFunc_6ARGS) (Obj self, Obj a1, Obj a2, Obj a3, Obj a4, Obj a5,
** 'ENVI_FUNC(<func>)' is the environment (i.e., the local variables bag)
** that was current when <func> was created.
**
** 'FEXS_FUNC(<func>)' is the function expressions list (i.e., the list of
** the function expressions of the functions defined inside of <func>).
**
** 'LCKS_FUNC(<func>)' is a string that contains the lock mode for the
** arguments of <func>. Each byte corresponds to the mode for an argument:
** 0 means no lock, 1 means a read-only lock, 2 means a read-write lock.
Expand All @@ -114,7 +110,6 @@ typedef struct {
Obj nloc;
Obj body;
Obj envi;
Obj fexs;
#ifdef HPCGAP
Obj locks;
#endif
Expand Down Expand Up @@ -177,11 +172,6 @@ EXPORT_INLINE Obj ENVI_FUNC(Obj func)
return CONST_FUNC(func)->envi;
}

EXPORT_INLINE Obj FEXS_FUNC(Obj func)
{
return CONST_FUNC(func)->fexs;
}

#ifdef HPCGAP
EXPORT_INLINE Obj LCKS_FUNC(Obj func)
{
Expand Down Expand Up @@ -229,11 +219,6 @@ EXPORT_INLINE void SET_ENVI_FUNC(Obj func, Obj envi)
FUNC(func)->envi = envi;
}

EXPORT_INLINE void SET_FEXS_FUNC(Obj func, Obj fexs)
{
FUNC(func)->fexs = fexs;
}

#ifdef HPCGAP
EXPORT_INLINE void SET_LCKS_FUNC(Obj func, Obj locks)
{
Expand Down
13 changes: 1 addition & 12 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,6 @@ void CodeFuncExprBegin (
Int startLine)
{
Obj fexp; /* function expression bag */
Obj fexs; /* function expressions list */
Bag body; /* function body */
Bag old; /* old frame */
Stat stat1; /* first statement in body */
Expand All @@ -830,11 +829,6 @@ void CodeFuncExprBegin (
#endif
CHANGED_BAG( fexp );

/* give it a functions expressions list */
fexs = NEW_PLIST( T_PLIST, 0 );
SET_FEXS_FUNC( fexp, fexs );
CHANGED_BAG( fexp );

/* give it a body */
body = NewBag( T_BODY, 1024*sizeof(Stat) );
SET_BODY_FUNC( fexp, body );
Expand Down Expand Up @@ -864,7 +858,6 @@ void CodeFuncExprEnd(UInt nr)
Expr expr; /* function expression, result */
Stat stat1; /* single statement of body */
Obj fexp; /* function expression bag */
Obj fexs; /* funct. expr. list of outer func */
UInt len; /* length of func. expr. list */
UInt i; /* loop variable */

Expand Down Expand Up @@ -906,9 +899,6 @@ void CodeFuncExprEnd(UInt nr)
WRITE_STAT(OFFSET_FIRST_STAT, nr - i, stat1);
}

// make the function expression list immutable
MakeImmutable( FEXS_FUNC( fexp ) );

// make the body values list (if any) immutable
Obj values = ((BodyHeader *)STATE(PtrBody))->values;
if (values)
Expand All @@ -927,8 +917,7 @@ void CodeFuncExprEnd(UInt nr)
/* if this was inside another function definition, make the expression */
/* and store it in the function expression list of the outer function */
if (STATE(CurrLVars) != CS(CodeLVars)) {
fexs = FEXS_FUNC( CURR_FUNC() );
len = PushPlist( fexs, fexp );
len = PushValue(fexp);
expr = NewExpr( T_FUNC_EXPR, sizeof(Expr) );
WRITE_EXPR(expr, 0, len);
PushExpr( expr );
Expand Down
4 changes: 4 additions & 0 deletions src/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ void SET_ENDLINE_BODY(Obj body, UInt val);

Obj GET_VALUE_FROM_CURRENT_BODY(Int ix);

EXPORT_INLINE Obj VALUES_BODY(Obj body)
{
return BODY_HEADER(body)->values;
}

/****************************************************************************
**
Expand Down
18 changes: 10 additions & 8 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,13 +1117,11 @@ static CVar CompFuncExpr(Expr expr)
CVar func; /* function, result */
CVar tmp; /* dummy body */

Obj fexs; /* function expressions list */
Obj fexp; /* function expression */
Int nr; /* number of the function */

/* get the number of the function */
fexs = FEXS_FUNC( CURR_FUNC() );
fexp = ELM_PLIST(fexs, READ_EXPR(expr, 0));
fexp = GET_VALUE_FROM_CURRENT_BODY(READ_EXPR(expr, 0));
nr = NR_INFO( INFO_FEXP( fexp ) );

/* allocate a new temporary for the function */
Expand Down Expand Up @@ -5034,7 +5032,6 @@ static void CompFunc(Obj func)
Bag info; /* info bag for this function */
Int narg; /* number of arguments */
Int nloc; /* number of locals */
Obj fexs; /* function expression list */
Bag oldFrame; /* old frame */
Int i; /* loop variable */
Int prevarargs; /* we have varargs with a prefix */
Expand Down Expand Up @@ -5073,10 +5070,15 @@ static void CompFunc(Obj func)
/* get the info bag */
info = INFO_FEXP( CURR_FUNC() );

/* compile the innner functions */
fexs = FEXS_FUNC(func);
for ( i = 1; i <= LEN_PLIST(fexs); i++ ) {
CompFunc( ELM_PLIST( fexs, i ) );
/* compile the inner functions */
Obj values = VALUES_BODY(BODY_FUNC(func));
if (values) {
UInt len = LEN_PLIST(values);
for (i = 1; i <= len; i++) {
Obj val = ELM_PLIST(values, i);
if (IS_FUNC(val))
CompFunc(val);
}
}

/* emit the code for the function header and the arguments */
Expand Down
14 changes: 2 additions & 12 deletions src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ Obj MakeFunction (
#ifdef HPCGAP
SET_LCKS_FUNC( func, LCKS_FUNC( fexp ) );
#endif
SET_FEXS_FUNC( func, FEXS_FUNC( fexp ) );

/* return the function */
return func;
Expand All @@ -675,12 +674,8 @@ Obj MakeFunction (
*/
static Obj EvalFuncExpr(Expr expr)
{
Obj fexs; /* func. expr. list of curr. func. */
Obj fexp; /* function expression bag */

/* get the function expression bag */
fexs = FEXS_FUNC( CURR_FUNC() );
fexp = ELM_PLIST(fexs, READ_EXPR(expr, 0));
Obj fexp = GET_VALUE_FROM_CURRENT_BODY(READ_EXPR(expr, 0));

/* and make the function */
return MakeFunction( fexp );
Expand All @@ -695,14 +690,9 @@ static Obj EvalFuncExpr(Expr expr)
*/
static void PrintFuncExpr(Expr expr)
{
Obj fexs; /* func. expr. list of curr. func. */
Obj fexp; /* function expression bag */

/* get the function expression bag */
fexs = FEXS_FUNC( CURR_FUNC() );
fexp = ELM_PLIST(fexs, READ_EXPR(expr, 0));
Obj fexp = GET_VALUE_FROM_CURRENT_BODY(READ_EXPR(expr, 0));
PrintFunction( fexp );
/* Pr("function ... end",0L,0L); */
}


Expand Down
6 changes: 1 addition & 5 deletions src/syntaxtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ static Obj SyntaxTreeFunccall(Obj result, Expr expr)

static Obj SyntaxTreeFuncExpr(Obj result, Expr expr)
{
Obj fexs;
Obj fexp;

fexs = FEXS_FUNC(CURR_FUNC());
fexp = ELM_PLIST(fexs, READ_EXPR(expr, 0));
Obj fexp = GET_VALUE_FROM_CURRENT_BODY(READ_EXPR(expr, 0));

SyntaxTreeFunc(result, fexp);

Expand Down

0 comments on commit 2fdb8b1

Please sign in to comment.