Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_value_function_thunk.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Interface afw_value Implementation for Lambda Definition
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 
15 #include "afw_internal.h"
16 
17 
18 #define impl_afw_value_optional_release NULL
19 #define impl_afw_value_get_reference NULL
20 
21 
22 /* Inf specific is always data type. */
23 #define AFW_IMPLEMENTATION_SPECIFIC (const void *)&afw_data_type_function_direct
24 
25 /* Define inf variables for data_type and fully_evaluated_data_type. */
26 #define AFW_IMPLEMENTATION_INF_VARIABLES \
27  (const void *)&afw_data_type_function_direct, \
28  NULL
29 
30 #define impl_afw_value_get_evaluated_meta \
31  afw_value_internal_get_evaluated_meta_default
32 
33 #define impl_afw_value_get_evaluated_metas \
34  afw_value_internal_get_evaluated_metas_default
35 
36 /* Declares and rti/inf defines for interface afw_value */
37 #define AFW_IMPLEMENTATION_ID "function_thunk"
38 #define AFW_IMPLEMENTATION_INF_SPECIFIER AFW_DEFINE_CONST_DATA
39 #define AFW_IMPLEMENTATION_INF_LABEL afw_value_function_thunk_inf
41 
42 
43 
44 /* Create a function thunk value. */
45 AFW_DEFINE(const afw_value_t *)
47  const afw_utf8_t *name,
48  const afw_value_t *like_function_value,
50  void *ctx,
51  const afw_utf8_z_t *source_z,
52  const afw_pool_t *p,
53  afw_xctx_t *xctx)
54 {
56 
58  self->inf = &afw_value_function_thunk_inf;
59  self->name = name;
60  self->like_function_value = like_function_value;
61  self->execute = execute;
62  self->ctx = ctx;
63  self->detail = afw_utf8_printf(p, xctx,
64  "Thunk %" AFW_UTF8_FMT " created at %s",
65  AFW_UTF8_FMT_ARG(name), source_z);
66 
67  return (const afw_value_t *)self;
68 }
69 
70 
71 
72 /*
73  * Implementation of method optional_evaluate for interface afw_value.
74  */
75 const afw_value_t *
77  const afw_value_t *instance,
78  const afw_pool_t *p,
79  afw_xctx_t *xctx)
80 {
81  return instance;
82 }
83 
84 /*
85  * Implementation of method get_data_type for interface afw_value.
86  */
87 const afw_data_type_t *
88 impl_afw_value_get_data_type(
89  const afw_value_t * instance,
90  afw_xctx_t *xctx)
91 {
92  return NULL;
93 }
94 
95 /*
96  * Implementation of method get_evaluated_data_type for interface afw_value.
97  */
98 const afw_data_type_t *
99 impl_afw_value_get_evaluated_data_type(
100  const afw_value_t * instance,
101  afw_xctx_t *xctx)
102 {
103  return afw_data_type_function;
104 }
105 
106 
107 /*
108  * Implementation of method get_evaluated_data_type_parameter for interface
109  * afw_value.
110  */
111 const afw_utf8_t *
112 impl_afw_value_get_evaluated_data_type_parameter(
113  const afw_value_t * instance,
114  afw_xctx_t *xctx)
115 {
116  return NULL;
117 }
118 
119 
120 
121 /*
122  * Implementation of method compiler_listing for interface afw_value.
123  */
124 void
125 impl_afw_value_produce_compiler_listing(
126  const afw_value_t *instance,
127  const afw_writer_t *writer,
128  afw_xctx_t *xctx)
129 {
130  const afw_value_function_thunk_t *self =
131  (const afw_value_function_thunk_t *)instance;
132 
133  afw_value_compiler_listing_begin_value(writer, instance,
134  NULL, xctx);
135  afw_writer_write_z(writer, ": [", xctx);
136  afw_writer_write_eol(writer, xctx);
137  afw_writer_increment_indent(writer, xctx);
138  afw_writer_write_z(writer, "detail: ", xctx);
139  afw_writer_write_utf8(writer, self->detail, xctx);
140  afw_writer_write_eol(writer, xctx);
141  afw_writer_decrement_indent(writer, xctx);
142  afw_writer_write_z(writer, "]", xctx);
143  afw_writer_write_eol(writer, xctx);
144 }
145 
146 
147 /*
148  * Implementation of method decompile for interface afw_value.
149  */
150 void
151 impl_afw_value_decompile(
152  const afw_value_t * instance,
153  const afw_writer_t * writer,
154  afw_xctx_t *xctx)
155 {
156 #ifdef __FIXME_REMOVE_
157  const afw_value_function_thunk_t *self =
158  (const afw_value_function_thunk_t *)instance;
159  afw_size_t i;
160 
161  afw_writer_write_z(writer, "function ", xctx);
162  impl_decompile_type(writer, self->returns, xctx);
163 
164  afw_writer_write_z(writer, "(", xctx);
165  if (writer->tab) {
166  afw_writer_write_eol(writer, xctx);
167  afw_writer_increment_indent(writer, xctx);
168  }
169 
170  for (i = 0; i < self->count; i++) {
171  if (i != 0) {
172  afw_writer_write_z(writer, ",", xctx);
173  if (writer->tab) {
174  afw_writer_write_eol(writer, xctx);
175  }
176  }
177  impl_decompile_type(writer, self->parameters[i]->type, xctx);
178  afw_writer_write_utf8(writer, self->parameters[i]->name, xctx);
179  }
180  afw_writer_write_z(writer, ")", xctx);
181 
182  if (writer->tab) {
183  afw_writer_write_eol(writer, xctx);
184  afw_writer_decrement_indent(writer, xctx);
185  }
186 
187  afw_writer_write_z(writer, "(", xctx);
188  if (writer->tab) {
189  afw_writer_write_eol(writer, xctx);
190  afw_writer_increment_indent(writer, xctx);
191  }
192  afw_value_decompile(self->body, writer, xctx);
193  if (writer->tab) {
194  afw_writer_write_eol(writer, xctx);
195  afw_writer_decrement_indent(writer, xctx);
196  }
197  afw_writer_write_z(writer, ")", xctx);
198 #endif
199 }
200 
201 
202 /*
203  * Implementation of method get_info for interface afw_value.
204  */
205 void
206 impl_afw_value_get_info(
207  const afw_value_t *instance,
208  afw_value_info_t *info,
209  const afw_pool_t *p,
210  afw_xctx_t *xctx)
211 {
212  const afw_value_function_thunk_t *self =
213  (const afw_value_function_thunk_t *)instance;
214 
215  afw_memory_clear(info);
216  info->value_inf_id = &instance->inf->rti.implementation_id;
217  info->detail = self->detail;
218 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
afw_data_type_function
Data type struct for function.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
Definition: afw_common.h:605
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
Definition: afw_common.h:588
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
Definition: afw_common.h:523
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
const afw_value_t *(* afw_function_thunk_execute_t)(const afw_value_function_thunk_t *function, afw_size_t argc, const afw_value_t *const *argv, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for function thunk execute functions.
Definition: afw_common.h:1266
#define afw_memory_clear(to)
Clear preallocated memory for sizeof(*(to)).
Definition: afw_memory.h:47
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
Definition: afw_pool.h:167
afw_utf8_printf(const afw_pool_t *p, afw_xctx_t *xctx, const afw_utf8_z_t *format,...)
Create a utf-8 string using a c format string in specified pool.
Definition: afw_utf8.c:459
const afw_value_t * impl_afw_value_optional_evaluate(const afw_value_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
#define afw_value_decompile(instance, writer, xctx)
Call method decompile of interface afw_value.
afw_value_function_thunk_inf
Value function thunk inf.
Definition: afw_value.h:267
afw_value_function_thunk_create_impl(const afw_utf8_t *name, const afw_value_t *like_function_value, afw_function_thunk_execute_t execute, void *ctx, const afw_utf8_z_t *source_z, const afw_pool_t *p, afw_xctx_t *xctx)
Create a function thunk value.
#define afw_writer_increment_indent(instance, xctx)
Call method increment_indent of interface afw_writer.
#define afw_writer_write_eol(instance, xctx)
Call method write_eol of interface afw_writer.
#define afw_writer_decrement_indent(instance, xctx)
Call method decrement_indent of interface afw_writer.
#define afw_writer_write_z(writer, s_z, xctx)
Call afw_writer_write() with zero terminated string.
Definition: afw_writer.h:35
#define afw_writer_write_utf8(writer, S, xctx)
Call afw_writer_write() with a afw_utf8_t string.
Definition: afw_writer.h:45
Interface afw_data_type public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Struct for function thunk value.
Filled in by afw_value get_info method.
Definition: afw_value.h:49
Interface afw_value public struct.
Interface afw_writer public struct.
Interface afw_xctx public struct.