Next: Adding The Specific Functions, Previous: The Library Object Constructors, Up: Executive Assembler Introduction [Index]
Three aime functions are introduced: the first indicating the number of program arguments, the second picking one of the arguments and the third terminating program execution.
See Function Definition Example.
static const int c_____m__[] = {
X1f4_E4_MODE
};
static const struct x1f4_function_type here_set[] = {
{ "argc", mode_argc,
X1f4_E4_MODE, NULL, 0,
X1f4_E4_KEEP_CALL, 4 },
{ "argv", text_argv,
X1f4_E4_TEXT, c_____m__, 1,
X1f4_E4_KEEP_CALL, 4 },
{ "exit", exit_mode,
X1f4_E4_VOID, c_____m__, 1,
X1f4_E4_KEEP_CALL, 4 },
{ NULL, NULL,
0, NULL, 0,
0, 1 }
};
The argc function:
static int
mode_argc(void *context, void *output, void **input)
{
X1f4_E4_C_MODE *l;
l = (void *) (output);
*l = ((struct context_type *) context)->argc;
return 0;
}
#define I_MODE(i) (*((X1f4_E4_C_MODE *) (i)))
The argv function:
static int
text_argv(void *context, void *output, void **input)
{
X1f4_E4_C_MODE index;
int status = 0;
struct context_type *context_data;
context_data = context;
index = I_MODE(input[0]);
if (index < 0 || context_data->argc < index + 1) {
Described the error if any and set the status to some non zero value (the aime interpreter will stop the program execution for non zero returns):
status = stat_argv(context, index);
} else {
X1f4_E4_C_TEXT *l;
l = (void *) (output);
if (index) {
*l = context_data->argv[index];
} else {
char *program;
program = (char *) context_data->program;
*l = program ? program : (char *) x1f4_c1_empty_string;
}
}
return status;
}
See The Error Reporters.
static int
stat_argv(void *context, int index)
{
line_flat(context);
Construct the error message over push_flat calls (not shown).
post_flat(context);
return -1;
}
The exit function:
static int
exit_mode(void *context, void *output, void **input)
{
((struct context_type *) context)->exit = I_MODE(input[0]) << 1 | 1;
return 1;
}