107 lines
3.1 KiB
C
107 lines
3.1 KiB
C
/**
|
|
* ops/apply.c
|
|
*
|
|
* Post Scarcity Software Environment: apply.
|
|
*
|
|
* Add a applying for a key/value pair to a store -- at this stage, just an
|
|
* association list.
|
|
*
|
|
* (c) 2026 Simon Brooke <simon@journeyman.cc>
|
|
* Licensed under GPL version 2.0, or, at your option, any later version.
|
|
*/
|
|
|
|
#include "memory/node.h"
|
|
#include "memory/pointer.h"
|
|
#include "memory/pso.h"
|
|
#include "memory/pso3.h"
|
|
#include "memory/pso4.h"
|
|
#include "memory/tags.h"
|
|
|
|
#include "ops/assoc.h"
|
|
#include "ops/stack_ops.h"
|
|
#include "ops/string_ops.h"
|
|
#include "ops/truth.h"
|
|
|
|
#include "payloads/cons.h"
|
|
#include "payloads/stack.h"
|
|
|
|
/**
|
|
* @brief Apply a function to arguments in an environment.
|
|
*
|
|
* * (apply fn args)
|
|
*/
|
|
struct pso_pointer apply(
|
|
#ifndef MANAGED_POINTER_ONLY
|
|
struct pso4 *frame,
|
|
#endif
|
|
struct pso_pointer frame_pointer,
|
|
struct pso_pointer env ) {
|
|
#ifdef MANAGED_POINTER_ONLY
|
|
struct pso4 *frame = pointer_to_pso4( frame_pointer );
|
|
#endif
|
|
|
|
// TODO.
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief Evaluate a form, in an environment
|
|
*
|
|
* * (eval form)
|
|
*/
|
|
struct pso_pointer eval(
|
|
#ifndef MANAGED_POINTER_ONLY
|
|
struct pso4 *frame,
|
|
#endif
|
|
struct pso_pointer frame_pointer,
|
|
struct pso_pointer env ) {
|
|
#ifdef MANAGED_POINTER_ONLY
|
|
struct pso4 *frame = pointer_to_pso4( frame_pointer );
|
|
#endif
|
|
struct pso_pointer result = fetch_arg( frame, 0 );
|
|
|
|
switch ( get_tag_value( result ) ) {
|
|
// case CONSTV:
|
|
// result = eval_cons( frame, frame_pointer, env);
|
|
// break;
|
|
case INTEGERTV:
|
|
case KEYTV:
|
|
case STRINGTV:
|
|
// self evaluating
|
|
break;
|
|
case SYMBOLTV:
|
|
result = c_assoc( result, env );
|
|
break;
|
|
// case LAMBDATV:
|
|
// result = eval_lambda( frame, frame_pointer, env);
|
|
// break;
|
|
// case NLAMBDATV:
|
|
// result = eval_nlambda( frame, frame_pointer, env);
|
|
// break;
|
|
// case SPECIALTV:
|
|
// result = eval_special( frame, frame_pointer, env);
|
|
// break;
|
|
default:
|
|
result =
|
|
make_exception( c_cons
|
|
( c_string_to_lisp_string
|
|
( L"Can't yet evaluate things of this type: " ),
|
|
result ), frame_pointer,
|
|
c_cons( c_cons( c_string_to_lisp_keyword(L"tag"),
|
|
get_tag_string(result)), nil), nil );
|
|
}
|
|
|
|
if ( exceptionp( result ) ) {
|
|
struct pso3 *x =
|
|
( struct pso3 * ) pointer_to_object_with_tag_value( result,
|
|
EXCEPTIONTV );
|
|
|
|
if ( nilp( x->payload.exception.stack ) ) {
|
|
result =
|
|
make_exception( x->payload.exception.message, frame_pointer, nil,
|
|
result );
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|