📄 prccode.c
字号:
value of an argument passed to
a procedure
INPUTS : 1) Expression to evaluate
(PROC_PARAM index)
2) Caller's result value buffer
RETURNS : Nothing useful
SIDE EFFECTS : Caller's buffer set to specified
node of ProcParamArray
NOTES : None
***************************************************/
static intBool RtnProcParam(
void *theEnv,
void *value,
DATA_OBJECT *result)
{
register DATA_OBJECT *src;
src = &ProceduralPrimitiveData(theEnv)->ProcParamArray[*((int *) ValueToBitMap(value)) - 1];
result->type = src->type;
result->value = src->value;
result->begin = src->begin;
result->end = src->end;
return(TRUE);
}
/**************************************************************
NAME : GetProcBind
DESCRIPTION : Internal function for looking up the
values of parameters or bound variables
within procedures
INPUTS : 1) Expression to evaluate
(PROC_GET_BIND index)
2) Caller's result value buffer
RETURNS : Nothing useful
SIDE EFFECTS : Caller's buffer set to parameter value in
ProcParamArray or the value in LocalVarArray
NOTES : None
**************************************************************/
static intBool GetProcBind(
void *theEnv,
void *value,
DATA_OBJECT *result)
{
register DATA_OBJECT *src;
PACKED_PROC_VAR *pvar;
pvar = (PACKED_PROC_VAR *) ValueToBitMap(value);
src = &ProceduralPrimitiveData(theEnv)->LocalVarArray[pvar->first - 1];
if (src->supplementalInfo == EnvTrueSymbol(theEnv))
{
result->type = src->type;
result->value = src->value;
result->begin = src->begin;
result->end = src->end;
return(TRUE);
}
if (GetFirstArgument()->nextArg != NULL)
{
EvaluateExpression(theEnv,GetFirstArgument()->nextArg,result);
return(TRUE);
}
if (pvar->second == 0)
{
PrintErrorID(theEnv,"PRCCODE",5,FALSE);
SetEvaluationError(theEnv,TRUE);
EnvPrintRouter(theEnv,WERROR,"Variable ");
EnvPrintRouter(theEnv,WERROR,ValueToString(GetFirstArgument()->value));
if (ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc != NULL)
{
EnvPrintRouter(theEnv,WERROR," unbound in ");
(*ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc)(theEnv);
}
else
EnvPrintRouter(theEnv,WERROR," unbound.\n");
result->type = SYMBOL;
result->value = EnvFalseSymbol(theEnv);
return(TRUE);
}
if (pvar->secondFlag == 0)
{
src = &ProceduralPrimitiveData(theEnv)->ProcParamArray[pvar->second - 1];
result->type = src->type;
result->value = src->value;
result->begin = src->begin;
result->end = src->end;
}
else
GrabProcWildargs(theEnv,result,(int) pvar->second);
return(TRUE);
}
/**************************************************************
NAME : PutProcBind
DESCRIPTION : Internal function for setting the values of
of locally bound variables within procedures
INPUTS : 1) Expression to evaluate
(PROC_PARAM index)
2) Caller's result value buffer
RETURNS : Nothing useful
SIDE EFFECTS : Bound variable in LocalVarArray set to
value in caller's buffer.
NOTES : None
**************************************************************/
static intBool PutProcBind(
void *theEnv,
void *value,
DATA_OBJECT *result)
{
register DATA_OBJECT *dst;
dst = &ProceduralPrimitiveData(theEnv)->LocalVarArray[*((int *) ValueToBitMap(value)) - 1];
if (GetFirstArgument() == NULL)
{
if (dst->supplementalInfo == EnvTrueSymbol(theEnv))
ValueDeinstall(theEnv,dst);
dst->supplementalInfo = EnvFalseSymbol(theEnv);
result->type = SYMBOL;
result->value = EnvFalseSymbol(theEnv);
}
else
{
if (GetFirstArgument()->nextArg != NULL)
StoreInMultifield(theEnv,result,GetFirstArgument(),TRUE);
else
EvaluateExpression(theEnv,GetFirstArgument(),result);
if (dst->supplementalInfo == EnvTrueSymbol(theEnv))
ValueDeinstall(theEnv,dst);
dst->supplementalInfo = EnvTrueSymbol(theEnv);
dst->type = result->type;
dst->value = result->value;
dst->begin = result->begin;
dst->end = result->end;
ValueInstall(theEnv,dst);
}
return(TRUE);
}
/****************************************************************
NAME : RtnProcWild
DESCRIPTION : Groups a portion of the ProcParamArray
into a multi-field variable
INPUTS : 1) Starting index in ProcParamArray
for grouping of arguments into
multi-field variable (expression value)
2) Caller's result value buffer
RETURNS : Nothing useful
SIDE EFFECTS : Multi-field variable allocated and set
with corresponding values of ProcParamArray
NOTES : Multi-field is NOT on list of ephemeral segments
****************************************************************/
static intBool RtnProcWild(
void *theEnv,
void *value,
DATA_OBJECT *result)
{
GrabProcWildargs(theEnv,result,*(int *) ValueToBitMap(value));
return(TRUE);
}
#if (! BLOAD_ONLY) && (! RUN_TIME)
/***************************************************
NAME : FindProcParameter
DESCRIPTION : Determines the relative position in
an n-element list of a certain
parameter. The index is 1..n.
INPUTS : 1) Parameter name
2) Parameter list
3) Wildcard symbol (NULL if none)
RETURNS : Index of parameter in list, 0 if
not found
SIDE EFFECTS : None
NOTES : None
***************************************************/
static int FindProcParameter(
SYMBOL_HN *name,
EXPRESSION *parameterList,
SYMBOL_HN *wildcard)
{
int i = 1;
while (parameterList != NULL)
{
if (parameterList->value == (void *) name)
return(i);
i++;
parameterList = parameterList->nextArg;
}
/* ===================================================================
Wildcard may not be stored in actual list but know is always at end
=================================================================== */
if (name == wildcard)
return(i);
return(0);
}
/*************************************************************************
NAME : ReplaceProcBinds
DESCRIPTION : Examines an expression and replaces calls to the
"bind" function which are specially recognized
For example, in a message-handler,
(bind ?self <value>) would be illegal
and
(bind ?self:<slot-name> <value>) would be
replaced with
(put <slot-name> <value>)
INPUTS : 1) The actions in which to replace special binds
2) A pointer to a function to handle binds in a
special way. The function should accept the
bind function call expression and a specialized
data buffer (can be NULL) as arguments.
If the variable is recognized and treated specially,
the function should modify the expression
appropriately (including attaching/removing
any necessary argument expressions). Return 1
if recognized, 0 if not, -1 on errors.
This argument CANNOT be NULL.
3) Specialized user data buffer
RETURNS : FALSE if OK, TRUE on errors
SIDE EFFECTS : Some binds replaced with specialized calls
NOTES : Local variable binds are replaced in ReplaceProcVars
(after this routine has had a chance to replace all
special binds and remove the names from the parsed
bind list)
*************************************************************************/
static int ReplaceProcBinds(
void *theEnv,
EXPRESSION *actions,
int (*altbindfunc)(void *,EXPRESSION *,void *),
void *userBuffer)
{
int bcode;
SYMBOL_HN *bname;
while (actions != NULL)
{
if (actions->argList != NULL)
{
if (ReplaceProcBinds(theEnv,actions->argList,altbindfunc,userBuffer))
return(TRUE);
if ((actions->value == (void *) FindFunction(theEnv,"bind")) &&
(actions->argList->type == SYMBOL))
{
bname = (SYMBOL_HN *) actions->argList->value;
bcode = (*altbindfunc)(theEnv,actions,userBuffer);
if (bcode == -1)
return(TRUE);
if (bcode == 1)
RemoveParsedBindName(theEnv,bname);
}
}
actions = actions->nextArg;
}
return(FALSE);
}
/*****************************************************
NAME : CompactActions
DESCRIPTION : Examines a progn expression chain,
and if there is only one action,
the progn header is deallocated and
the action is returned. If there are
no actions, the progn expression is
modified to be the FALSE symbol
and returned. Otherwise, the progn
is simply returned.
INPUTS : The action expression
RETURNS : The compacted expression
SIDE EFFECTS : Some expressions possibly deallocated
NOTES : Assumes actions is a progn expression
and actions->nextArg == NULL
*****************************************************/
static EXPRESSION *CompactActions(
void *theEnv,
EXPRESSION *actions)
{
register struct expr *tmp;
if (actions->argList == NULL)
{
actions->type = SYMBOL;
actions->value = EnvFalseSymbol(theEnv);
}
else if (actions->argList->nextArg == NULL)
{
tmp = actions;
actions = actions->argList;
rtn_struct(theEnv,expr,tmp);
}
return(actions);
}
#endif
#if (! DEFFUNCTION_CONSTRUCT) || (! DEFGENERIC_CONSTRUCT)
/******************************************************
NAME : EvaluateBadCall
DESCRIPTION : Default evaluation function for
deffunctions and gneric functions
in configurations where either
capability is not present.
INPUTS : 1) The function (ignored)
2) A data object buffer for the result
RETURNS : FALSE
SIDE EFFECTS : Data object buffer set to the
symbol FALSE and evaluation error set
NOTES : Used for binary images which
contain deffunctions and generic
functions which cannot be used
******************************************************/
#if IBM_TBC
#pragma argsused
#endif
static intBool EvaluateBadCall(
void *theEnv,
void *value,
DATA_OBJECT *result)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(value)
#endif
PrintErrorID(theEnv,"PRCCODE",1,FALSE);
EnvPrintRouter(theEnv,WERROR,"Attempted to call a deffunction/generic function ");
EnvPrintRouter(theEnv,WERROR,"which does not exist.\n");
SetEvaluationError(theEnv,TRUE);
SetpType(result,SYMBOL);
SetpValue(result,EnvFalseSymbol(theEnv));
return(FALSE);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -