コード例 #1
0
ファイル: extern.c プロジェクト: krytarowski/mindy
/* Look for an object with the given name in the named file and return a
   callable "<c-function>" object for it. */
obj_t find_c_function(obj_t /* <string> */ symbol, obj_t lookup)
{
    const char *string = string_chars(symbol);
    struct symtab *syms;
    int sym_count, i;
    obj_t retval = obj_False;

    if (lookup == obj_Unbound) {
        if (mindy_dynamic_syms == NULL)
            mindy_dynamic_syms = load_program_file();
        return find_c_function(symbol, mindy_dynamic_syms);
    } else if (lookup == obj_False)
        return obj_False;
    else if (!instancep(lookup, obj_ForeignFileClass)) {
        error("Keyword file: is not a <foreign-file>: %=", lookup);
        return retval;                /* make lint happy */
    } else if (instancep(lookup, obj_SharedFileClass)) {
        shl_t *files = obj_ptr(struct shared_file *, lookup)->handles;
        int file_count = obj_ptr(struct shared_file *, lookup)->file_count;
        void *ptr;

        for (i = 0; i < file_count; i++)
            if (shl_findsym(&files[i], string, &ptr) == 0)
                return(make_c_function(make_byte_string(string), ptr));
        return retval;
    } else {
コード例 #2
0
ファイル: extern.c プロジェクト: krytarowski/mindy
/* Reads the symtab (in some machine specific format) from the main program
   and returns a "foreign_file" object which allows access to those symbols */
obj_t  load_program_file()
{
    obj_t retval;

    retval = alloc(obj_SharedFileClass, sizeof(struct shared_file));
    obj_ptr(struct shared_file *, retval)->file_name
        = make_byte_string(exec_file_name);
    obj_ptr(struct shared_file *, retval)->file_count = 1;
    obj_ptr(struct shared_file *, retval)->handles[0] = PROG_HANDLE;
    return retval;
}
コード例 #3
0
ファイル: error.c プロジェクト: dylan-hackers/GD_2_4
static void verror(char *msg, va_list ap)
{
    int nargs = count_format_args(msg);
    int i;
    struct thread *thread = thread_current();
    
    if (error_system_enabled) {
	*thread->sp++ = error_var->value;
	*thread->sp++ = make_byte_string(msg);
	for (i = 0; i < nargs; i++)
	    *thread->sp++ = va_arg(ap, obj_t);

	invoke(thread, nargs+1);
	go_on();
    }
    else if (thread) {
	obj_t cond = make_vector(nargs+1, NULL);

	SOVEC(cond)->contents[0] = make_byte_string(msg);
	for (i = 1; i <= nargs; i++)
	    SOVEC(cond)->contents[i] = va_arg(ap, obj_t);

	thread_debuggered(thread, cond);
    }
    else {
	obj_t cond = make_vector(nargs, NULL);

	for (i = 0; i < nargs; i++)
	    SOVEC(cond)->contents[i] = va_arg(ap, obj_t);
	
	printf("error: ");
	vformat(msg, SOVEC(cond)->contents, nargs);
	putchar('\n');
	exit(1);
    }
}
コード例 #4
0
ファイル: fd.c プロジェクト: krytarowski/mindy
static obj_t fd_error_str(obj_t xerrno)
{
  return make_byte_string(strerror(fixnum_value(xerrno)));
}
コード例 #5
0
ファイル: mindy.c プロジェクト: sparkhom/mindy
int main(int argc, char *argv[])
{
    struct thread *thread;
    enum pause_reason reason;
    struct variable *var;
#if ! NO_ARGV_0
    char *argv0 = "mindy";
#endif

    exec_file_name = argv[0];

    init_color(false);

    init();

    thread = thread_make(symbol("main"));
    *thread->sp++ = make_raw_function("startup", obj_Nil,
                                      true, obj_False, false,
                                      obj_Nil, obj_ObjectClass,
                                      startup);

    while (*++argv != NULL) {
        if (strcmp(*argv, "-f") == 0) {
            if (*++argv == NULL)
                missing_arg("-f");
            load(*argv);
#if ! NO_SHARP_BANG
        } else if (strcmp(*argv, "-x") == 0) {
            if (*++argv == NULL)
                missing_arg("-f");
#if ! NO_ARGV_0
            if (strcmp(*argv, "-") != 0)
                argv0 = *argv;
#endif
            load(*argv);
            argv += 1;
            break;
#endif
#if ! NO_ARGV_0
        } else if (strcmp(*argv, "-0") == 0) {
            if (*++argv == NULL)
                missing_arg("-0");
            argv0 = *argv;
#endif
        } else {
            break;
        }
    }

#if ! NO_ARGV_0
        *thread->sp++ = make_byte_string(argv0);    /* pass command name */
#endif
    while (*argv != NULL)
        *thread->sp++ = make_byte_string(*argv++);

    finalize_modules();

    while (1) {
        thread_restart(thread);

        reason = do_stuff();
        if (reason != pause_NothingToRun)
            invoke_debugger(reason);

        var = find_variable(module_BuiltinStuff, symbol("exit"),
                            false, false);
        if (var == NULL)
            lose("main undefined?");

        thread = thread_make(symbol("exit"));
        *thread->sp++ = var->value;
    }
    return 0;
}