18 #define impl_afw_value_optional_release NULL
19 #define impl_afw_value_get_reference NULL
23 #define impl_afw_value_get_evaluated_meta \
24 afw_value_internal_get_evaluated_meta_default
26 #define impl_afw_value_get_evaluated_metas \
27 afw_value_internal_get_evaluated_metas_default
30 #define AFW_IMPLEMENTATION_ID "block"
31 #define AFW_IMPLEMENTATION_INF_SPECIFIER AFW_DEFINE_CONST_DATA
32 #define AFW_IMPLEMENTATION_INF_LABEL afw_value_block_inf
35 #define IMPL_TEMP_FIX_ASSIGNS(XX) \
37 modified_x.xctx = xctx; \
38 modified_x.function = &afw_function_definition_ ## XX; \
39 modified_x.argv = argv; \
40 modified_x.argc = argc; \
42 #define IMPL_TEMP_FIX(XX) \
43 afw_function_execute_t modified_x; \
44 afw_memory_clear(&modified_x); \
45 IMPL_TEMP_FIX_ASSIGNS(XX) \
78 switch (assignment_type) {
82 case afw_compile_assignment_type_assign_only:
86 case afw_compile_assignment_type_const:
90 case afw_compile_assignment_type_loc:
94 case afw_compile_assignment_type_define_loc_if_needed:
107 impl_list_destructure(
123 "List destructure can only be performed on a list", xctx);
128 ae = ld->assignment_element,
141 if (!ae->assignment_target) {
145 v = ae->default_value;
148 impl_assign_value(ae->assignment_target, v, assignment_type,
156 if (!eol && ld->rest) {
157 for (rest = NULL;;) {
171 impl_assign_value(ld->rest, v, assignment_type, p, xctx);
179 impl_object_destructure(
197 for (ap = od->assignment_property; ap; ap = ap->next)
202 v = ap->assignment_element->default_value;
205 impl_assign_value(ap->assignment_element->assignment_target, v,
206 assignment_type, p, xctx);
214 ap->variable_reference->symbol->name, xctx);
216 v = ap->default_value;
219 impl_assign_value((
const afw_value_t *)ap->variable_reference,
220 v, assignment_type, p, xctx);
232 for (iterator = NULL;;) {
239 for (ap = od->assignment_property; ap; ap = ap->next)
243 ap->property_name, property_name))
246 ap->variable_reference->symbol->name, property_name))
257 impl_assign_value(od->rest, v, assignment_type, p, xctx);
264 impl_assignment_target(
272 target->assignment_target;
274 switch (at->target_type) {
275 case afw_compile_assignment_target_type_list_destructure:
276 impl_list_destructure(at, at->list_destructure, value,
277 assignment_type, p, xctx);
280 case afw_compile_assignment_target_type_object_destructure:
281 impl_object_destructure(at, at->object_destructure, value,
282 assignment_type, p, xctx);
285 case afw_compile_assignment_target_type_variable_reference:
286 impl_set_variable(at->variable_reference->symbol->name,
287 value, assignment_type, xctx);
290 case afw_compile_assignment_target_type_max_type:
308 if (assignment_type == afw_compile_assignment_type_use_assignment_targets)
312 assignment_type = at->assignment_target->assignment_type;
319 impl_assign_value(target, value, assignment_type, p, xctx);
336 impl_assignment_target(at, value, assignment_type, p, xctx);
343 value, assignment_type, xctx);
350 impl_set_variable(t->symbol->name, value,
351 assignment_type, xctx);
411 impl_evaluate_one_or_more_values(
421 afw_value_block_statement_type_t type;
434 false,
false, value, p, xctx);
440 false,
false, values, p, xctx);
449 afw_value_block_evaluate_block(
451 afw_value_block_statement_type_t *type,
471 for (i = 0; i <
self->argc; i++) {
473 true, is_loop, self->argv[i], p, xctx);
474 if (*type != afw_value_block_statement_type_sequential)
495 afw_value_block_evaluate_for(
497 afw_value_block_statement_type_t *type,
516 impl_evaluate_one_or_more_values(x, 1, argv[1], p, xctx);
534 if (!condition->internal) {
541 true,
true, body, p, xctx);
542 if (*type == afw_value_block_statement_type_break ||
543 *type == afw_value_block_statement_type_return)
550 impl_evaluate_one_or_more_values(x, 3, increment, p, xctx);
556 if (*type == afw_value_block_statement_type_continue ||
557 *type == afw_value_block_statement_type_break)
559 *type = afw_value_block_statement_type_sequential;
570 afw_value_block_evaluate_foreach(
572 afw_value_block_statement_type_t *type,
578 IMPL_TEMP_FIX(
foreach);
592 assignment_type = afw_compile_assignment_type_use_assignment_targets;
593 for (iterator = NULL;;) {
599 impl_assign(argv[1], value, assignment_type, p, xctx);
600 assignment_type = afw_compile_assignment_type_assign_only;
602 true,
true, argv[3], p, xctx);
603 if (*type == afw_value_block_statement_type_break ||
604 *type == afw_value_block_statement_type_return)
612 if (*type == afw_value_block_statement_type_continue ||
613 *type == afw_value_block_statement_type_break)
615 *type = afw_value_block_statement_type_sequential;
627 afw_value_block_evaluate_do_while(
629 afw_value_block_statement_type_t *type,
635 IMPL_TEMP_FIX(do_while);
642 true,
true, argv[2], p, xctx);
643 if (*type == afw_value_block_statement_type_break ||
644 *type == afw_value_block_statement_type_return)
649 if (!condition->internal) {
655 if (*type == afw_value_block_statement_type_continue ||
656 *type == afw_value_block_statement_type_break)
658 *type = afw_value_block_statement_type_sequential;
666 afw_value_block_evaluate_if(
668 afw_value_block_statement_type_t *type,
684 if (condition->internal) {
686 true, is_loop, argv[2], p, xctx);
688 else if (x->
argc == 3) {
690 true, is_loop, argv[3], p, xctx);
698 afw_value_block_evaluate_while(
700 afw_value_block_statement_type_t *type,
706 IMPL_TEMP_FIX(
while);
714 if (!condition->internal) {
718 true,
true, argv[2], p, xctx);
719 if (*type == afw_value_block_statement_type_break ||
720 *type == afw_value_block_statement_type_return)
727 if (*type == afw_value_block_statement_type_continue ||
728 *type == afw_value_block_statement_type_break)
730 *type = afw_value_block_statement_type_sequential;
740 afw_value_block_statement_type_t *type,
756 modified_x.
xctx = xctx;
762 *type = afw_value_block_statement_type_sequential;
766 result = afw_value_block_evaluate_block(x, type,
777 (call->function_value);
778 switch (function->scriptSupportNumber) {
780 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_ASSIGN:
782 saved_contextual = xctx->error->contextual;
783 xctx->error->contextual = call->args.
contextual;
791 impl_assign(modified_x.
argv[1], statement,
792 afw_compile_assignment_type_assign_only,
797 xctx->error->contextual = saved_contextual;
800 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_BREAK:
808 *type = afw_value_block_statement_type_break;
811 &modified_x, 1, NULL);
815 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_CONST:
817 saved_contextual = xctx->error->contextual;
818 xctx->error->contextual = call->args.
contextual;
828 impl_assign(modified_x.
argv[1], statement,
829 afw_compile_assignment_type_const,
834 xctx->error->contextual = saved_contextual;
837 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_CONTINUE:
845 *type = afw_value_block_statement_type_continue;
848 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_DO_WHILE:
850 saved_contextual = xctx->error->contextual;
851 xctx->error->contextual = call->args.
contextual;
853 result = afw_value_block_evaluate_do_while(x, type,
858 xctx->error->contextual = saved_contextual;
861 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_FOR:
863 saved_contextual = xctx->error->contextual;
864 xctx->error->contextual = call->args.
contextual;
866 result = afw_value_block_evaluate_for(x, type,
871 xctx->error->contextual = saved_contextual;
874 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_FOREACH:
876 saved_contextual = xctx->error->contextual;
877 xctx->error->contextual = call->args.
contextual;
879 result = afw_value_block_evaluate_foreach(x, type,
884 xctx->error->contextual = saved_contextual;
887 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_IF:
889 saved_contextual = xctx->error->contextual;
890 xctx->error->contextual = call->args.
contextual;
892 result = afw_value_block_evaluate_if(x, type,
893 call->args.
argc, call->args.
argv, is_loop,
897 xctx->error->contextual = saved_contextual;
900 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_LOC:
902 saved_contextual = xctx->error->contextual;
903 xctx->error->contextual = call->args.
contextual;
915 impl_assign(modified_x.
argv[1], statement,
916 afw_compile_assignment_type_loc,
921 xctx->error->contextual = saved_contextual;
924 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_RETURN:
925 *type = afw_value_block_statement_type_return;
940 case AFW_VALUE_SCRIPT_SUPPORT_NUMBER_WHILE:
942 saved_contextual = xctx->error->contextual;
943 xctx->error->contextual = call->args.
contextual;
945 result = afw_value_block_evaluate_while(x, type,
950 xctx->error->contextual = saved_contextual;
979 if (compiled_value->top_block &&
980 !compiled_value->current_block)
997 block->contextual = contextual;
999 if (!compiled_value->top_block) {
1000 compiled_value->top_block = block;
1003 block->parent_block = compiled_value->current_block;
1004 block->depth = block->parent_block->depth + 1;
1006 block->number = *block_count;
1007 if (!block->parent_block->first_child_block) {
1008 block->parent_block->first_child_block = block;
1011 block->parent_block->final_child_block->next_sibling_block = block;
1013 block->parent_block->final_child_block = block;
1015 compiled_value->current_block = block;
1049 afw_value_block_statement_type_t type;
1057 result = afw_value_block_evaluate_block(&x, &type,
1067 impl_afw_value_get_data_type(
1078 impl_afw_value_get_evaluated_data_type(
1090 impl_afw_value_get_evaluated_data_type_parameter(
1102 impl_afw_value_produce_compiler_listing(
1111 afw_value_compiler_listing_begin_value(writer, instance,
1112 self->contextual, xctx);
1121 AFW_VALUE_COMPILER_LISTING_IF_NOT_LIMIT_EXCEEDED
1122 for (i = 0; i <
self->argc; i++) {
1138 impl_afw_value_decompile(
1160 impl_afw_value_get_info(
1170 info->value_inf_id = &instance->inf->rti.implementation_id;
1171 info->contextual =
self->contextual;
AFW_DEFINE(const afw_object_t *)
#define AFW_DEFINE_INTERNAL(type)
Define an internal function for /src/afw/ source*.c files.
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
#define afw_value_is_integer(A_VALUE)
Macro to determine if value is evaluated integer.
afw_value_create_list(const afw_list_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type list value.
#define afw_value_is_list(A_VALUE)
Macro to determine if value is evaluated list.
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated object.
afw_value_create_object(const afw_object_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type object value.
afw_value_as_object(const afw_value_t *value, afw_xctx_t *xctx)
Typesafe cast of data type object.
#define afw_value_is_string(A_VALUE)
Macro to determine if value is evaluated string.
struct afw_iterator_s afw_iterator_t
apr_size_t afw_size_t
size_t.
afw_compile_internal_assignment_type_t
Enum for assignment types.
#define AFW_FINALLY
Always executed regardless of error.
#define AFW_ENDTRY
Ends an AFW try block.
#define AFW_TRY
Begin an AFW TRY block.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_FUNCTION_EVALUATE_REQUIRED_CONDITION_PARAMETER(A_RESULT, A_N)
Evaluate an arg that is a required condition.
afw_function_evaluate_required_parameter(afw_function_execute_t *x, afw_size_t parameter_number, const afw_data_type_t *data_type)
Evaluate an required parameter and convert if necessary.
#define AFW_FUNCTION_EVALUATE_REQUIRED_DATA_TYPE_PARAMETER(A_RESULT, A_N, A_TYPE)
Evaluate an arg for a particular data type.
#define AFW_FUNCTION_ASSERT_PARAMETER_COUNT_MIN(n)
Assert that argc is at least a specific number.
#define AFW_FUNCTION_PARAMETER_IS_PRESENT(A_N)
Determine if a specific parameter value is present.
#define AFW_FUNCTION_EVALUATE_PARAMETER(A_RESULT, A_N)
Evaluate a parameter.
#define AFW_FUNCTION_ASSERT_PARAMETER_COUNT_MAX(n)
Assert that argc is no more than specific number.
afw_function_evaluate_parameter(afw_function_execute_t *x, afw_size_t parameter_number, const afw_data_type_t *data_type)
Evaluate a parameter and convert if necessary.
#define AFW_FUNCTION_ASSERT_PARAMETER_COUNT_IS(n)
Assert that argc is a specific number.
afw_function_definition_loc
Adaptive Function le<script>
afw_function_definition_const
Function definition const.
afw_function_definition_continue
Function definition continue.
afw_function_definition_assign
Function definition assign.
afw_function_definition_break
Adaptive Function bag_size<script>
afw_function_definition_return
Adaptive Function nex<script>
#define afw_list_get_next_value(instance, iterator, p, xctx)
Call method get_next_value of interface afw_list.
afw_list_set_value_by_index(const afw_list_t *instance, afw_size_t index, const afw_value_t *value, afw_xctx_t *xctx)
Call method set_value_by_index of interface afw_list_setter.
#define afw_list_is_immutable(list, xctx)
Determine if list is immutable.
#define afw_list_create_generic(p, xctx)
Create an value list in memory.
afw_list_add_value(const afw_list_t *instance, const afw_value_t *value, afw_xctx_t *xctx)
Call method add_value of interface afw_list_setter.
#define afw_memory_clear(to)
Clear preallocated memory for sizeof(*(to)).
#define afw_memory_copy(to, from)
Copy to preallocated memory of same type.
#define afw_object_get_property(instance, property_name, xctx)
Call method get_property of interface afw_object.
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
#define afw_object_is_immutable(instance, xctx)
Determine if object is immutable.
#define afw_object_create_managed(p, xctx)
Create an empty entity object in its own pool.
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
afw_boolean_t afw_utf8_equal(const afw_utf8_t *s1, const afw_utf8_t *s2)
Check to see if a string equals another string.
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_produce_compiler_listing(instance, writer, xctx)
Call method produce_compiler_listing of interface afw_value.
afw_value_block_evaluate_statement(afw_function_execute_t *x, afw_value_block_statement_type_t *type, afw_boolean_t allow_return, afw_boolean_t is_loop, const afw_value_t *statement, const afw_pool_t *p, afw_xctx_t *xctx)
#define afw_value_is_variable_reference(A_VALUE)
Macro to determine if value is a variable reference.
#define afw_value_is_block(A_VALUE)
Macro to determine if value is a block.
#define afw_value_is_reference_by_key(A_VALUE)
Macro to determine if value is a access property by index.
#define afw_value_evaluate(value, p, xctx)
Evaluate value if needed using specific pool.
#define afw_value_is_assignment_target(A_VALUE)
Macro to determine if value is an assignment target.
afw_value_as_utf8(const afw_value_t *value, const afw_pool_t *p, afw_xctx_t *xctx)
afw_value_block_inf
Value block inf.
#define afw_value_is_function_definition(A_VALUE)
Macro to determine if value is a function definition.
afw_value_block_finalize(const afw_value_block_t *block, afw_size_t argc, const afw_value_t *const *argv, afw_xctx_t *xctx)
Create and link a new block.
afw_value_block_allocated_and_link(const afw_compile_value_contextual_t *contextual, afw_value_compiled_value_t *compiled_value, afw_size_t *block_count, const afw_pool_t *p, afw_xctx_t *xctx)
Create and link a new block.
afw_value_null
Adaptive value null.
#define afw_value_is_any_call(A_VALUE)
Macro to determine if value is a call.
#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.
afw_writer_write_size(const afw_writer_t *writer, afw_size_t size, afw_xctx_t *xctx)
Call afw_writer_write() with an size.
afw_xctx_define_variable(const afw_utf8_t *name, const afw_value_t *value, afw_xctx_t *xctx)
Defined a variable in current xctx frame.
int afw_xctx_begin_stack_frame(afw_xctx_t *xctx)
Begin stack frame.
afw_xctx_set_local_variable(const afw_utf8_t *name, const afw_value_t *value, afw_xctx_t *xctx)
Set a variable then current xctx frame.
#define afw_xctx_evaluation_stack_push_value(VALUE, xctx)
Push VALUE onto execution stack.
#define afw_xctx_evaluation_stack_pop_value(xctx)
Pop top VALUE off execution stack.
void afw_xctx_end_stack_frame(int top, afw_xctx_t *xctx)
Set stack top.
afw_xctx_set_defined_variable(const afw_utf8_t *name, const afw_value_t *value, afw_xctx_t *xctx)
Set a defined variable in xctx.
Contextual information provided in some values.
Interface afw_data_type public struct.
const afw_compile_value_contextual_t * contextual
Contextual information or NULL.
Function execute parameter.
const afw_value_t *const * argv
This is the function parameters.
afw_xctx_t * xctx
The execution context (xctx) of caller.
const afw_value_function_definition_t * function
The evaluated function definition.
const afw_pool_t * p
Pool for result.
afw_size_t argc
This is the argv count not counting argv[0].
Interface afw_list public struct.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Struct for assignment target value.
struct for afw_value_block_t
struct for data type boolean values.
const afw_value_t *const * argv
const afw_compile_value_contextual_t * contextual
Struct for function value.
Filled in by afw_value get_info method.
struct for data type integer values.
Struct for compiled value value.
struct for data type list values.
struct for data type object values.
Struct for reference_by_key value.
Interface afw_value public struct.
struct for data type string values.
Interface afw_writer public struct.
Interface afw_xctx public struct.