Ejemplo n.º 1
0
/**************************************************************************
                        f i c l C a l l b a c k E r r o r O u t
** Feeds text to the vm's error output callback
**************************************************************************/
void ficlCallbackErrorOut(ficlCallback *callback, char *text)
{
	ficlOutputFunction errorOut = NULL;

	if (callback != NULL)
	{
		if (callback->errorOut != NULL)
			errorOut = callback->errorOut;
		else if ((callback->system != NULL) && (callback != &(callback->system->callback)))
		{
			ficlCallbackErrorOut(&(callback->system->callback), text);
			return;
		}
	}

	if ((errorOut == NULL) && (ficlSystemGlobal != NULL))
	{
		callback = &(ficlSystemGlobal->callback);
		errorOut = callback->errorOut;
	}

	if (errorOut == NULL)
	{
		ficlCallbackTextOut(callback, text);
		return;
	}

    (errorOut)(callback, text);

    return;
}
Ejemplo n.º 2
0
/**************************************************************************
                        f i c l C a l l b a c k T e x t O u t
** Feeds text to the vm's output callback
**************************************************************************/
void ficlCallbackTextOut(ficlCallback *callback, char *text)
{
	ficlOutputFunction textOut = NULL;

	if (callback != NULL)
	{
		if (callback->textOut != NULL)
			textOut = callback->textOut;
		else if ((callback->system != NULL) && (callback != &(callback->system->callback)))
		{
			ficlCallbackTextOut(&(callback->system->callback), text);
			return;
		}
	}

	if ((textOut == NULL) && (ficlSystemGlobal != NULL))
	{
		callback = &(ficlSystemGlobal->callback);
		textOut = callback->textOut;
	}
	
	if (textOut == NULL)
		textOut = ficlCallbackDefaultTextOut;

    (textOut)(callback, text);

    return;
}
Ejemplo n.º 3
0
void ficlCallbackAssert(ficlCallback *callback, int expression, char *expressionString, char *filename, int line)
#if FICL_ROBUST >= 1
{
	if (!expression)
	{
		static char buffer[256];
		sprintf(buffer, "ASSERTION FAILED at %s:%d: \"%s\"\n", filename, line, expressionString);
		ficlCallbackTextOut(callback, buffer);
		exit(-1);
	}
}
Ejemplo n.º 4
0
void
ficlDictionarySee(ficlDictionary *dictionary, ficlWord *word,
    ficlCallback *callback)
{
	char *trace;
	ficlCell *cell = word->param;
	ficlCell *param0 = cell;
	char buffer[128];

	for (; cell->i != ficlInstructionSemiParen; cell++) {
		ficlWord *word = (ficlWord *)(cell->p);

		trace = buffer;
		if ((void *)cell == (void *)buffer)
			*trace++ = '>';
		else
			*trace++ = ' ';
		trace += sprintf(trace, "%3ld   ", (long)(cell - param0));

		if (ficlDictionaryIsAWord(dictionary, word)) {
			ficlWordKind kind = ficlWordClassify(word);
			ficlCell c, c2;

			switch (kind) {
			case FICL_WORDKIND_INSTRUCTION:
				(void) sprintf(trace, "%s (instruction %ld)",
				    ficlDictionaryInstructionNames[(long)word],
				    (long)word);
			break;
			case FICL_WORDKIND_INSTRUCTION_WITH_ARGUMENT:
				c = *++cell;
				(void) sprintf(trace, "%s (instruction %ld), "
				    "with argument %ld (%#lx)",
				    ficlDictionaryInstructionNames[(long)word],
				    (long)word, (long)c.i, (unsigned long)c.u);
			break;
			case FICL_WORDKIND_INSTRUCTION_WORD:
				(void) sprintf(trace,
				    "%s :: executes %s (instruction word %ld)",
				    word->name,
				    ficlDictionaryInstructionNames[
				    (long)word->code], (long)word->code);
			break;
			case FICL_WORDKIND_LITERAL:
				c = *++cell;
				if (ficlDictionaryIsAWord(dictionary, c.p) &&
				    (c.i >= ficlInstructionLast)) {
					ficlWord *word = (ficlWord *)c.p;
					(void) sprintf(trace,
					    "%.*s ( %#lx literal )",
					    word->length, word->name,
					    (unsigned long)c.u);
				} else
					(void) sprintf(trace,
					    "literal %ld (%#lx)", (long)c.i,
					    (unsigned long)c.u);
			break;
			case FICL_WORDKIND_2LITERAL:
				c = *++cell;
				c2 = *++cell;
				(void) sprintf(trace,
				    "2literal %ld %ld (%#lx %#lx)",
				    (long)c2.i, (long)c.i, (unsigned long)c2.u,
				    (unsigned long)c.u);
			break;
#if FICL_WANT_FLOAT
			case FICL_WORDKIND_FLITERAL:
				c = *++cell;
				(void) sprintf(trace, "fliteral %f (%#lx)",
				    (double)c.f, (unsigned long)c.u);
			break;
#endif /* FICL_WANT_FLOAT */
			case FICL_WORDKIND_STRING_LITERAL: {
				ficlCountedString *counted;
				counted = (ficlCountedString *)(void *)++cell;
				cell = (ficlCell *)
				    ficlAlignPointer(counted->text +
				    counted->length + 1) - 1;
				(void) sprintf(trace, "s\" %.*s\"",
				    counted->length, counted->text);
			}
			break;
			case FICL_WORDKIND_CSTRING_LITERAL: {
				ficlCountedString *counted;
				counted = (ficlCountedString *)(void *)++cell;
				cell = (ficlCell *)
				    ficlAlignPointer(counted->text +
				    counted->length + 1) - 1;
				(void) sprintf(trace, "c\" %.*s\"",
				    counted->length, counted->text);
			}
			break;
			case FICL_WORDKIND_BRANCH0:
				c = *++cell;
				(void) sprintf(trace, "branch0 %ld",
				    (long)(cell + c.i - param0));
			break;
			case FICL_WORDKIND_BRANCH:
				c = *++cell;
				(void) sprintf(trace, "branch %ld",
				    (long)(cell + c.i - param0));
			break;

			case FICL_WORDKIND_QDO:
				c = *++cell;
				(void) sprintf(trace, "?do (leave %ld)",
				    (long)((ficlCell *)c.p - param0));
			break;
			case FICL_WORDKIND_DO:
				c = *++cell;
				(void) sprintf(trace, "do (leave %ld)",
				    (long)((ficlCell *)c.p - param0));
			break;
			case FICL_WORDKIND_LOOP:
				c = *++cell;
				(void) sprintf(trace, "loop (branch %ld)",
				    (long)(cell + c.i - param0));
			break;
			case FICL_WORDKIND_OF:
				c = *++cell;
				(void) sprintf(trace, "of (branch %ld)",
				    (long)(cell + c.i - param0));
			break;
			case FICL_WORDKIND_PLOOP:
				c = *++cell;
				(void) sprintf(trace, "+loop (branch %ld)",
				    (long)(cell + c.i - param0));
			break;
			default:
				(void) sprintf(trace, "%.*s", word->length,
				    word->name);
			break;
			}
		} else {
			/* probably not a word - punt and print value */
			(void) sprintf(trace, "%ld ( %#lx )", (long)cell->i,
			    (unsigned long)cell->u);
		}

		ficlCallbackTextOut(callback, buffer);
		ficlCallbackTextOut(callback, "\n");
	}

	ficlCallbackTextOut(callback, ";\n");
}