Comments and renaming in evalDefArgs()
This commit is contained in:
parent
8c71fd2242
commit
a39c6b2c53
|
@ -9,24 +9,38 @@
|
||||||
#define printf(...) APP_LOG(APP_LOG_LEVEL_DEBUG, __VA_ARGS__)
|
#define printf(...) APP_LOG(APP_LOG_LEVEL_DEBUG, __VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a variable into the environment with a given name and value.
|
||||||
|
*
|
||||||
|
* If `argForms` (symbol) and `argForms->forward` (value) are lists of the same
|
||||||
|
* length, define each symbol element with the corresponding value element.
|
||||||
|
* I.e. `(def (a b) (5 20))` would store `a` as `5` and `b` as `20`.
|
||||||
|
*
|
||||||
|
* @param argForms The symbol(s) and value(s) to define in the environment
|
||||||
|
* @param env The environment to add the new definition to
|
||||||
|
* @return The symbol(s) defined
|
||||||
|
*/
|
||||||
Object evalDefArgs(const Object *argForms, struct Environment *env)
|
Object evalDefArgs(const Object *argForms, struct Environment *env)
|
||||||
{
|
{
|
||||||
const Object *newSymbol = argForms;
|
const Object *newSymbol = argForms;
|
||||||
|
const Object *newValue = argForms->forward;
|
||||||
const char *name = newSymbol->string;
|
const char *name = newSymbol->string;
|
||||||
|
|
||||||
if(argForms->type == TYPE_LIST && argForms->forward->type == TYPE_LIST) {
|
// Handles multi-definitions
|
||||||
FOR_POINTERS_IN_LISTS(argForms, argForms->forward) {
|
if(newSymbol->type == TYPE_LIST && newValue->type == TYPE_LIST
|
||||||
Object newValue = eval(P2, env);
|
&& listLength(newSymbol) == listLength(newValue)) {
|
||||||
addToEnv(env, P1->string, newValue);
|
FOR_POINTERS_IN_LISTS(newSymbol, newValue) {
|
||||||
cleanObject(&newValue);
|
Object finalValue = eval(P2, env);
|
||||||
|
addToEnv(env, P1->string, finalValue);
|
||||||
|
cleanObject(&finalValue);
|
||||||
}
|
}
|
||||||
return cloneObject(*newSymbol);
|
return cloneObject(*newSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object newValue = eval(newSymbol->forward, env);
|
Object finalValue = eval(newSymbol->forward, env);
|
||||||
|
|
||||||
addToEnv(env, name, newValue);
|
addToEnv(env, name, finalValue);
|
||||||
cleanObject(&newValue);
|
cleanObject(&finalValue);
|
||||||
|
|
||||||
return cloneObject(*newSymbol);
|
return cloneObject(*newSymbol);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue