/** * 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 * Licensed under GPL version 2.0, or, at your option, any later version. */ #include "debug.h" #include "memory/node.h" #include "memory/pointer.h" #include "memory/pso.h" #include "memory/pso2.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/function.h" #include "payloads/stack.h" /** * @brief Apply a function to arguments in an environment. * * * (apply fn args) */ struct pso_pointer apply( struct pso_pointer frame_pointer ) { // TODO. } /** * @brief Evaluate a form, in an environment * * * (eval form) */ struct pso_pointer eval( struct pso_pointer frame_pointer ) { struct pso4 *frame = pointer_to_pso4( frame_pointer ); struct pso_pointer arg = fetch_arg( frame, 0 ); struct pso_pointer result = nil; if ( !c_nilp( arg ) ) { switch ( get_tag_value( arg ) ) { // case CONSTV: // result = eval_cons( frame, frame_pointer, env); // break; case INTEGERTV: case KEYTV: case NILTV: case STRINGTV: // self evaluating result = nil; break; case SYMBOLTV: result = c_assoc( arg, fetch_env( frame_pointer ) ); 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: #ifdef DEBUG struct pso2 *object = pointer_to_object( arg ); debug_printf( DEBUG_EVAL, 0, L"Can't yet evaluate objects of type %3.3s\n", object->header.tag.bytes.mnemonic[0] ); debug_print_object( arg, DEBUG_EVAL, 2 ); debug_println( DEBUG_EVAL ); #endif result = make_exception( make_frame( 1, frame_pointer, make_cons( frame_pointer, c_string_to_lisp_string ( frame_pointer, L"Can't yet evaluate things of this type: " ), arg ), make_cons( frame_pointer, make_cons ( frame_pointer, c_string_to_lisp_keyword ( frame_pointer, L"tag" ), get_tag_string ( frame_pointer, arg ) ), nil ), nil ) ); } } if ( exceptionp( result ) ) { struct pso3 *x = ( struct pso3 * ) pointer_to_object_with_tag_value( result, EXCEPTIONTV ); if ( c_nilp( x->payload.exception.stack ) ) { x->payload.exception.stack = frame_pointer; } } return result; }