54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
/**
|
|
* payloads/string.c
|
|
*
|
|
* A string cell.
|
|
*
|
|
* (c) 2026 Simon Brooke <simon@journeyman.cc>
|
|
* Licensed under GPL version 2.0, or, at your option, any later version.
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
* wide characters
|
|
*/
|
|
|
|
#include "memory/node.h"
|
|
#include "memory/pointer.h"
|
|
#include "memory/pso.h"
|
|
#include "memory/pso2.h"
|
|
#include "memory/pso4.h"
|
|
#include "memory/tags.h"
|
|
|
|
#include "ops/string_ops.h"
|
|
#include "payloads/cons.h"
|
|
|
|
#include "ops/stack_ops.h"
|
|
|
|
|
|
/**
|
|
* Construct a string from the character `c` and this `tail`. A string is
|
|
* implemented as a flat list of cells each of which has one character and a
|
|
* pointer to the next; in the last cell the pointer to next is NIL.
|
|
*
|
|
* @param c the character to add (prepend);
|
|
* @param tail the string which is being built.
|
|
*/
|
|
struct pso_pointer make_string( struct pso_pointer frame_pointer, wint_t c,
|
|
struct pso_pointer tail ) {
|
|
return make_string_like_thing( frame_pointer, c, tail, STRINGTAG );
|
|
}
|
|
|
|
/**
|
|
* @brief When an string is freed, its cdr pointer must be decremented.
|
|
*
|
|
* Lisp calling conventions; one expected arg, the pointer to the object to
|
|
* be destroyed.
|
|
*/
|
|
struct pso_pointer destroy_string( struct pso_pointer frame_pointer ) {
|
|
if ( stackp( frame_pointer ) ) {
|
|
dec_ref( c_cdr( fetch_arg( pointer_to_pso4( frame_pointer ), 0 ) ) );
|
|
}
|
|
|
|
return nil;
|
|
}
|