Beispiel #1
0
void simon(void)
{
  int returnValue = 0;
  char buffer[256];
  ficlVm *vm;
  int led_id;

  if (simon_system == NULL)
    simon_boot(NULL);

  vm = ficlSystemCreateVm(simon_system);

  led_id = ledOpen(fileno(stdin),fileno(stdout),100);

  while (returnValue != FICL_VM_STATUS_USER_EXIT)
    {
      fputs(FICL_PROMPT, stdout);
      fflush(stdout);
      ledRead(led_id,buffer,sizeof(buffer));
      returnValue = ficlVmEvaluate(vm, buffer);
    }

  ledClose(led_id);

  ficlSystemDestroyVm(vm);
}
Beispiel #2
0
static int spawn_helper
(
 int arg0,
 int arg1,
 int arg2,
 int arg3,
 int arg4,
 int arg5,
 int arg6,
 int arg7,
 int arg8,
 int arg9
 )
{
  unsigned command = arg0;
  char *taskName = (char *)arg1;
  ficlVm *vm;
  char eval[20];
  sprintf(eval,"0x%x execute\n",command);
  
  vm = ficlSystemCreateVm(simon_system);
  ficlVmEvaluate(vm,eval);
  ficlSystemDestroyVm(vm);
  free(taskName);
  return 0;
}
Beispiel #3
0
int main(int argc, char **argv)
{
    int returnValue = 0;
    char buffer[256];
    char *gotline;
    ficlVm *vm;
	ficlSystem *system;

    system = ficlSystemCreate(NULL);
    ficlSystemCompileExtras(system);
    vm = ficlSystemCreateVm(system);

    returnValue = ficlVmEvaluate(vm, ".ver .( " __DATE__ " ) cr quit");

    /*
    ** load files specified on command-line
    */
    if (argc  > 1)
    {
        sprintf(buffer, ".( loading %s ) cr load %s\n cr", argv[1], argv[1]);
        returnValue = ficlVmEvaluate(vm, buffer);
    }

    while (returnValue != FICL_VM_STATUS_USER_EXIT)
    {
	    fputs(FICL_PROMPT, stdout);
        gotline = fgets(buffer, sizeof(buffer), stdin);
        returnValue = ficlVmEvaluate(vm, gotline);
    }

    ficlSystemDestroy(system);
    return 0;
}
Beispiel #4
0
/*
 * Initialise the Forth interpreter, create all our commands as words.
 */
void
bf_init(char *rc)
{
	struct bootblk_command	**cmdp;
	char create_buf[41];	/* 31 characters-long builtins */
	int fd, rv;
	ficlDictionary *dict;
	ficlDictionary *env;

	fsi = malloc(sizeof (ficlSystemInformation));
	ficlSystemInformationInitialize(fsi);
	fsi->dictionarySize = BF_DICTSIZE;

	bf_sys = ficlSystemCreate(fsi);
	bf_vm = ficlSystemCreateVm(bf_sys);

	/* Put all private definitions in a "builtins" vocabulary */
	rv = ficlVmEvaluate(bf_vm,
	    "vocabulary builtins also builtins definitions");
	if (rv != FICL_VM_STATUS_OUT_OF_TEXT) {
		panic("error interpreting forth: %d", rv);
	}

	/* Builtin constructor word  */
	rv = ficlVmEvaluate(bf_vm, BUILTIN_CONSTRUCTOR);
	if (rv != FICL_VM_STATUS_OUT_OF_TEXT) {
		panic("error interpreting forth: %d", rv);
	}

	/* make all commands appear as Forth words */
	dict = ficlSystemGetDictionary(bf_sys);
	SET_FOREACH(cmdp, Xcommand_set) {
		ficlDictionaryAppendPrimitive(dict, (char *)(*cmdp)->c_name,
		    bf_command, FICL_WORD_DEFAULT);
		rv = ficlVmEvaluate(bf_vm, "forth definitions builtins");
		if (rv != FICL_VM_STATUS_OUT_OF_TEXT) {
			panic("error interpreting forth: %d", rv);
		}
		sprintf(create_buf, "builtin: %s", (*cmdp)->c_name);
		rv = ficlVmEvaluate(bf_vm, create_buf);
		if (rv != FICL_VM_STATUS_OUT_OF_TEXT) {
			panic("error interpreting forth: %d", rv);
		}
		rv = ficlVmEvaluate(bf_vm, "builtins definitions");
		if (rv != FICL_VM_STATUS_OUT_OF_TEXT) {
			panic("error interpreting forth: %d", rv);
		}
	}
Beispiel #5
0
void full_simon(void)
{
  int returnValue = 0;
  char buffer[256];
  ficlVm *vm;
  ficlSystem *system;
  ficlSystemInformation fsi;
  ficlDictionary *dict;
  FILE *fd;
  int led_id;

  ficlSystemInformationInitialize(&fsi);
  fsi.dictionarySize = 256*1024;

  printf("creating ficl system\n");
  system = ficlSystemCreate(&fsi);

  printf("compiling ficl extras\n");
  ficlSystemCompileExtras(system);

  printf("creating ficl vm\n");
  vm = ficlSystemCreateVm(system);

  printf("initializing silkworm customizations\n");
  rf_spi_init(vm);

  printf("getting ficl version\n");
  returnValue = ficlVmEvaluate(vm, ".ver .( " __DATE__ " ) cr quit");

  simon_init(vm);
  rf_spi_init(vm);

  printf("ficl initialization complete\n");

  led_id = ledOpen(fileno(stdin),fileno(stdout),100);

  while (returnValue != FICL_VM_STATUS_USER_EXIT)
    {
      fputs(FICL_PROMPT, stdout);
      fflush(stdout);
      ledRead(led_id,buffer,sizeof(buffer));
      returnValue = ficlVmEvaluate(vm, buffer);
    }

  ledClose(led_id);

  ficlSystemDestroy(system);
}
Beispiel #6
0
int simon_boot(char *eval)
{
  ficlVm *vm;
  ficlSystemInformation fsi;

  ficlSystemInformationInitialize(&fsi);
  fsi.dictionarySize = 256*1024;

  simon_system = ficlSystemCreate(&fsi);
  ficlSystemCompileExtras(simon_system);
  vm = ficlSystemCreateVm(simon_system);
  simon_init(vm);
  rf_spi_init(vm);

  if (eval != NULL) ficlVmEvaluate(vm,eval);
  ficlSystemDestroyVm(vm);
  return 0; 
}
Beispiel #7
0
FICL_PLATFORM_EXTERN ficlVm    *ficlNewVM(ficlSystem *system)
{
	ficlVm *returnValue = ficlSystemCreateVm(system);
	if (returnValue != NULL)
	{
		if ((returnValue->callback.textOut != NULL) && (returnValue->callback.textOut != thunkTextOut))
		{
			returnValue->thunkedTextout = (ficlCompatibilityOutputFunction)returnValue->callback.textOut;
			returnValue->callback.textOut = thunkTextOut;
		}
		if ((returnValue->callback.errorOut != NULL) && (returnValue->callback.errorOut != thunkTextOut))
		{
			if (returnValue->thunkedTextout == NULL)
				returnValue->thunkedTextout = (ficlCompatibilityOutputFunction)returnValue->callback.errorOut;
			returnValue->callback.errorOut = thunkTextOut;
		}
	}
	return returnValue;
}
Beispiel #8
0
int main(int argc, char **argv) {
    int returnValue = 0;
    char buffer[256];
    ficlVm *vm;
    ficlSystem *system;

    int i=0;
    int ch;
    char *fileName=(char *)NULL;
    char *loadPath=(char *)NULL;

    strcpy(prompt, FICL_PROMPT);
    verbose=-1; // Default is to be talkative.

    i = tcgetattr( 0, &orig_termios); 

    loadPath = getenv("FICL_PATH");


    system = ficlSystemCreate(NULL);
    ficlSystemCompileExtras(system);
    vm = ficlSystemCreateVm(system);

    if(verbose !=0) {
        returnValue = ficlVmEvaluate(vm, ".ver .( " __DATE__ " ) cr quit");
        // returnValue = ficlVmEvaluate(vm, ".ver cr quit");
    }

    while (returnValue != FICL_VM_STATUS_USER_EXIT) {
        //        fputs(FICL_PROMPT, stdout);
        fputs(prompt, stdout);
        if (fgets(buffer, sizeof(buffer), stdin) == NULL) break;
        returnValue = ficlVmEvaluate(vm, buffer);
    }

    ficlSystemDestroy(system);
    return 0;
}
Beispiel #9
0
/**************************************************************************
                        f i c l I n i t S y s t e m
** Binds a global dictionary to the interpreter system. 
** You specify the address and size of the allocated area.
** After that, Ficl manages it.
** First step is to set up the static pointers to the area.
** Then write the "precompiled" portion of the dictionary in.
** The dictionary needs to be at least large enough to hold the
** precompiled part. Try 1K cells minimum. Use "words" to find
** out how much of the dictionary is used at any time.
**************************************************************************/
ficlSystem *ficlSystemCreate(ficlSystemInformation *fsi)
{
    ficlInteger dictionarySize;
    ficlInteger environmentSize;
	ficlInteger stackSize;
    ficlSystem *system;
	ficlCallback callback;
	ficlSystemInformation fauxInfo;
	ficlDictionary *environment;



	if (fsi == NULL)
	{
		fsi = &fauxInfo;
		ficlSystemInformationInitialize(fsi);
	}

	callback.context = fsi->context;
	callback.textOut = fsi->textOut;
	callback.errorOut = fsi->errorOut;
	callback.system = NULL;
	callback.vm = NULL;

    FICL_ASSERT(&callback, sizeof(ficlInteger) == sizeof(void *));
    FICL_ASSERT(&callback, sizeof(ficlUnsigned) == sizeof(void *));
#if (FICL_WANT_FLOAT)
    FICL_ASSERT(&callback, sizeof(ficlFloat) == sizeof(void *));
#endif

    system = ficlMalloc(sizeof(ficlSystem));

    FICL_ASSERT(&callback, system);

    memset(system, 0, sizeof(ficlSystem));

    dictionarySize = fsi->dictionarySize;
    if (dictionarySize <= 0)
        dictionarySize = FICL_DEFAULT_DICTIONARY_SIZE;

    environmentSize = fsi->environmentSize;
    if (environmentSize <= 0)
        environmentSize = FICL_DEFAULT_DICTIONARY_SIZE;

    stackSize = fsi->stackSize;
    if (stackSize < FICL_DEFAULT_STACK_SIZE)
        stackSize = FICL_DEFAULT_STACK_SIZE;

    system->dictionary = ficlDictionaryCreateHashed(system, (unsigned)dictionarySize, FICL_HASH_SIZE);
    system->dictionary->forthWordlist->name = "forth-wordlist";

    environment = ficlDictionaryCreate(system, (unsigned)environmentSize);
    system->environment = environment;
    system->environment->forthWordlist->name = "environment";

    system->callback.textOut = fsi->textOut;
    system->callback.errorOut = fsi->errorOut;
    system->callback.context = fsi->context;
    system->callback.system = system;
    system->callback.vm = NULL;
    system->stackSize = stackSize;

#if FICL_WANT_LOCALS
    /*
    ** The locals dictionary is only searched while compiling,
    ** but this is where speed is most important. On the other
    ** hand, the dictionary gets emptied after each use of locals
    ** The need to balance search speed with the cost of the 'empty'
    ** operation led me to select a single-threaded list...
    */
    system->locals = ficlDictionaryCreate(system, (unsigned)FICL_MAX_LOCALS * FICL_CELLS_PER_WORD);
#endif /* FICL_WANT_LOCALS */

    /*
    ** Build the precompiled dictionary and load softwords. We need a temporary
    ** VM to do this - ficlNewVM links one to the head of the system VM list.
    ** ficlCompilePlatform (defined in win32.c, for example) adds platform specific words.
    */
    ficlSystemCompileCore(system);
    ficlSystemCompilePrefix(system);

#if FICL_WANT_FLOAT
    ficlSystemCompileFloat(system);
#endif /* FICL_WANT_FLOAT */

#if FICL_WANT_PLATFORM
    ficlSystemCompilePlatform(system);
#endif /* FICL_WANT_PLATFORM */

    ficlSystemSetVersion(system);

    /*
    ** Establish the parse order. Note that prefixes precede numbers -
    ** this allows constructs like "0b101010" which might parse as a
    ** hex value otherwise.
    */
    ficlSystemAddPrimitiveParseStep(system, "?word", ficlVmParseWord);
    ficlSystemAddPrimitiveParseStep(system, "?prefix", ficlVmParsePrefix);
    ficlSystemAddPrimitiveParseStep(system, "?number", ficlVmParseNumber);
#if FICL_WANT_FLOAT
    ficlSystemAddPrimitiveParseStep(system, "?float", ficlVmParseFloatNumber);
#endif

    /*
    ** Now create a temporary VM to compile the softwords. Since all VMs are
    ** linked into the vmList of ficlSystem, we don't have to pass the VM
    ** to ficlCompileSoftCore -- it just hijacks whatever it finds in the VM list.
    ** Ficl 2.05: vmCreate no longer depends on the presence of INTERPRET in the
    ** dictionary, so a VM can be created before the dictionary is built. It just
    ** can't do much...
    */
    ficlSystemCreateVm(system);
#define ADD_COMPILE_FLAG(name) ficlDictionarySetConstant(environment, #name, name)
	ADD_COMPILE_FLAG(FICL_WANT_LZ_SOFTCORE);
	ADD_COMPILE_FLAG(FICL_WANT_FILE);
	ADD_COMPILE_FLAG(FICL_WANT_FLOAT);
	ADD_COMPILE_FLAG(FICL_WANT_DEBUGGER);
	ADD_COMPILE_FLAG(FICL_WANT_EXTENDED_PREFIX);
	ADD_COMPILE_FLAG(FICL_WANT_USER);
	ADD_COMPILE_FLAG(FICL_WANT_LOCALS);
	ADD_COMPILE_FLAG(FICL_WANT_OOP);
	ADD_COMPILE_FLAG(FICL_WANT_SOFTWORDS);
	ADD_COMPILE_FLAG(FICL_WANT_MULTITHREADED);
	ADD_COMPILE_FLAG(FICL_WANT_OPTIMIZE);
	ADD_COMPILE_FLAG(FICL_WANT_VCALL);

	ADD_COMPILE_FLAG(FICL_PLATFORM_ALIGNMENT);

	ADD_COMPILE_FLAG(FICL_ROBUST);

#define ADD_COMPILE_STRING(name) ficlDictionarySetConstantString(environment, #name, name)
	ADD_COMPILE_STRING(FICL_PLATFORM_ARCHITECTURE);
	ADD_COMPILE_STRING(FICL_PLATFORM_OS);

    ficlSystemCompileSoftCore(system);
    ficlSystemDestroyVm(system->vmList);

	if (ficlSystemGlobal == NULL)
		ficlSystemGlobal = system;

    return system;
}