Hash :
4885ef3d
Author :
Thomas de Grivel
Date :
2025-03-14T20:42:27
wip pcallable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
/* kc3
* Copyright from 2022 to 2025 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <stdlib.h>
#include "alloc.h"
#include "assert.h"
#include "callable.h"
#include "op.h"
#include "pcallable.h"
#include "sym.h"
void op_clean (s_op *op)
{
assert(op);
pcallable_clean(&op->pcallable);
}
void op_delete (s_op *op)
{
assert(op);
op_clean(op);
free(op);
}
s_op * op_init (s_op *op)
{
s_op tmp = {0};
*op = tmp;
return op;
}
s_op * op_init_copy (s_op *op, s_op *src)
{
s_op tmp = {0};
tmp.sym = src->sym;
tmp.arity = src->arity;
tmp.special = src->special;
tmp.precedence = src->precedence;
tmp.associativity = src->associativity;
pcallable_init_copy(&tmp.pcallable, &src->pcallable);
*op = tmp;
return op;
}
s_op * op_new (void)
{
s_op *op;
op = alloc(sizeof(s_op));
if (! op)
return NULL;
if (! op_init(op)) {
free(op);
return NULL;
}
return op;
}
s_op * op_new_copy (s_op *src)
{
s_op *op;
op = alloc(sizeof(s_op));
if (! op)
return NULL;
if (! op_init_copy(op, src)) {
free(op);
return NULL;
}
return op;
}
s_op * op_set_callable (s_op *op, s_callable *callable)
{
if (! pcallable_init_copy(&op->pcallable, &callable))
return NULL;
callable_set_special(op->pcallable, op->special);
return op;
}
s_op * op_set_special (s_op *op, bool special)
{
op->special = special;
callable_set_special(op->pcallable, special);
return op;
}