예제 #1
0
/*
 *   terminate the error subsystem for the compiler 
 */
void CTcMain::tc_err_term()
{
    /* reduce the reference count */
    --err_refs_;

    /* delete the error stack */
    err_terminate();

    /* if this is the last reference, clean things up */
    if (err_refs_ == 0)
    {
        /* if we loaded an external message file, unload it */
        err_delete_message_array(&tc_messages, &tc_message_count,
                                 &tc_messages_english[0],
                                 tc_message_count_english);
    }
}
예제 #2
0
int main(int argc, char **argv)
{
    CVmFile *fp = 0;
    CVmImageWriter *volatile iw = 0;

    /* initialize for testing */
    test_init();

    /* initialize error stack */
    err_init(1024);

    /* check arguments */
    if (argc != 2)
        errexit("usage: test_write <output-file>");

    /* open the file */
    fp = new CVmFile();

    err_try
    {
        static const char *meta[] =
        {
            "tads-object"
        };
        static const char *bif[] =
        {
            "tads/030000"
        };
        static const unsigned char code0[] =
        {
            /* 
             *   method header 
             */
            0x00,                                        /* parameter count */
            0x00,                                               /* reserved */
            0x02, 0x00,                             /* local variable count */
            0x20, 0x00,                              /* maximum stack usage */
            0x00, 0x00,                           /* exception table offset */
            0x00, 0x00,                         /* debugging records offset */
            0x00, 0x00, 0x00, 0x00,                      /* defining object */

            /*
             *   code 
             */

            // local i;   // -> local #0
            // local j;   // -> local #1
            //
            // say('hello, world!\n');
            0x05, 0x00, 0x00, 0x00, 0x00, // pushstr  0x00000000
            0xB1, 0x00, 0x01,         //    builtin_a 0
            
            // for (i := 1 ; i < 100 ; ++i)
            // {
            0xDA, 0x00,               //    onelcl1   0
                                      // $1:
            0x80, 0x00,               //    getlcl1   0
            0x03, 0x64,               //    pushint8  100
            0x96, 0x29, 0x00,         //    jgt       $2  ; +41

            //   j := i*3;
            0x80, 0x00,               //    getlcl1   0
            0x03, 0x03,               //    pushint8  3
            0x24,                     //    mul
            0xE0, 0x01,               //    setlcl1   1

            //   say('i = ' + i + ', j = ' + j + '\n');
            0x05, 0x10, 0x00, 0x00, 0x00, // pushstr  0x00000010
            0x80, 0x00,               //    getlcl1   0
            0x22,                     //    add
            0x05, 0x16, 0x00, 0x00, 0x00, // pushstr  0x00000016
            0x22,                     //    add
            0x80, 0x01,               //    getlcl1   1
            0x22,                     //    add
            0x05, 0x1E, 0x00, 0x00, 0x00, // pushstr  0x0000001E
            0x22,                     //    add
            0xB1, 0x00, 0x01,         //    builtin_a 0
            
            // } // end of for
            0xD0, 0x00, 0x00,         //    inclcl    0
            0x91, 0xD4, 0xFF,         //    jmp       $1  ; -44
                                      // $2:

            // END OF FUNCTION
            0x51                      //    retnil
        };
        static const unsigned char const0[] =
        {
            /* 0 = 0x0000 */
            /* string "hello, world!\n" */
            0x0E, 0x00,  // length = 14
            'h', 'e', 'l', 'l', 'o', ',', ' ',
            'w', 'o', 'r', 'l', 'd', '!', 0x0A,

            /* 16 = 0x0010 */
            /* string "i = " */
            0x04, 0x00,  // length = 4
            'i', ' ', '=', ' ',

            /* 22 = 0x0016 */
            /* string ", j = " */
            0x06, 0x00,  // length = 6
            ',', ' ', 'j', ' ', '=', ' ',

            /* 30 = 0x001E */
            /* string "\n" */
            0x01, 0x00,  // length = 1
            0x0A
        };
        static const char tool_data[4] = { 't', 'e', 's', 't' };
        
        /* open the output file */
        fp->open_write(argv[1], OSFTT3IMG);

        /* create an image writer */
        iw = new CVmImageWriter(fp);

        /* start the file */
        iw->prepare(1, tool_data);

        /* write the entrypoint - enter at code offset zero */
        iw->write_entrypt(0, 14, 10, 10, 2, 6, 4, 1);

        /* write an empty function set dependency table */
        iw->write_func_dep(bif, sizeof(bif)/sizeof(bif[0]));

        /* write our metaclass dependency table */
        iw->write_meta_dep(meta, sizeof(meta)/sizeof(meta[0]));

        /* write our code pool definition and pages */
        iw->write_pool_def(1, 1, 4096, TRUE);
        iw->write_pool_page(1, 0, (const char *)code0, sizeof(code0),
                            TRUE, 0);

        /* write the constant pool definition and pages */
        iw->write_pool_def(2, 1, 4096, TRUE);
        iw->write_pool_page(2, 0, (const char *)const0, sizeof(const0),
                            TRUE, 0);

        /* finish the image file data */
        iw->finish();
    }
    err_catch(exc)
    {
        printf("exception caught: %d\n", exc->get_error_code());
    }
    err_end;

    /* delete the image writer */
    if (iw != 0)
        delete iw;
    
    /* release our file object */
    if (fp != 0)
        delete fp;

    /* delete the error context */
    err_terminate();

    /* done */
    return 0;
}
예제 #3
0
int main(int argc, char **argv)
{
    osfildef *fpin;
    osfildef *fpout;
    CVmFile *file_in;
    CVmFile *file_out;
    int status;
    CVmHostIfc *hostifc;
    CVmMainClientConsole clientifc;
    int curarg;

    /* initialize for testing */
    test_init();

    /* initialize the error stack */
    err_init(1024);
    
    /* start at the first argument */
    curarg = 1;

    /* check usage */
    if (curarg + 2 > argc)
    {
        printf("usage: t3pre <original-image> <new-image> [program-args]\n"
               "\n"
               "Runs preinitialization on the image file, writing a new "
               "image file\n"
               "with the state of the program after preinitialization.\n");
        return OSEXFAIL;
    }

    /* open the files */
    if ((fpin = osfoprb(argv[curarg], OSFTT3IMG)) == 0)
    {
        printf("Error opening original image file \"%s\"\n", argv[1]);
        return OSEXFAIL;
    }

    if ((fpout = osfopwb(argv[curarg + 1], OSFTT3IMG)) == 0)
    {
        printf("Error opening new image file \"%s\"\n", argv[2]);
        return OSEXFAIL;
    }

    /* create the CVmFile objects */
    file_in = new CVmFile();
    file_in->set_file(fpin, 0);
    file_out = new CVmFile();
    file_out->set_file(fpout, 0);

    /* create our host interface */
    hostifc = new CVmHostIfcStdio(argv[0]);

    /* run preinit and write the new image file */
    err_try
    {
        /* load, run, and write */
        vm_run_preinit(file_in, argv[1], file_out, hostifc, &clientifc,
                       argv + curarg + 1, argc - curarg - 1, 0);
        
        /* note the success status */
        status = OSEXSUCC;
    }
    err_catch(exc)
    {
        const char *msg;
        char buf[128];

        /* look up the message */
        msg = err_get_msg(vm_messages, vm_message_count,
                          exc->get_error_code(), FALSE);

        /* if that failed, just show the error number */
        if (msg == 0)
        {
            sprintf(buf, "[no message: code %d]", exc->get_error_code());
            msg = buf;
        }

        /* show the message */
        printf("VM Error: %s\n", msg);

        /* note the failure status */
        status = OSEXFAIL;
    }
    err_end;

    /* delete the file objects, which will close the files */
    delete file_in;
    delete file_out;

    /* terminate the error mechanism */
    err_terminate();

    /* delete our host interface object */
    delete hostifc;

    /* log any memory leaks */
    t3_list_memory_blocks(0);

    /* exit with appropriate results */
    return status;
}
예제 #4
0
파일: vminit.cpp 프로젝트: tags07/gpm-maze
/*
 *   Terminate the VM 
 */
void vm_terminate(vm_globals *vmg__, CVmMainClientIfc *clientifc)
{
    /* tell the debugger to shut down, if necessary */
    vm_terminate_debug_shutdown(vmg0_);
    
    /* drop all undo information */
    G_undo->drop_undo(vmg0_);

    /* delete the main console */
    clientifc->delete_console(VMGLOB_ADDR, G_console);

    /* release references on the character mappers */
    G_cmap_from_fname->release_ref();
    G_cmap_to_fname->release_ref();
    G_cmap_from_ui->release_ref();
    G_cmap_to_ui->release_ref();
    G_cmap_from_file->release_ref();
    G_cmap_to_file->release_ref();
    G_cmap_to_log->release_ref();

    /* delete the saved UI character set name, if any */
    lib_free_str(G_disp_cset_name);

    /* delete the BigNumber register cache */
    delete G_bignum_cache;

    /* delete the TADS intrinsic function set's globals */
    delete G_bif_tads_globals;

    /* delete the predefined object table */
    VM_IF_ALLOC_PRE_GLOBAL(delete G_predef);

    /* delete the interpreter */
    VM_IFELSE_ALLOC_PRE_GLOBAL(delete G_interpreter,
                               G_interpreter->terminate());

    /* terminate the TadsObject class */
    CVmObjTads::class_term(vmg0_);

    /* delete the source file table */
    delete G_srcf_table;

    /* delete debugger objects */
    vm_terminate_debug_delete(vmg0_);

    /* delete dynamic compilation objects */
    if (G_dyncomp != 0)
    {
        delete G_dyncomp;
        G_dyncomp = 0;
    }

    /* delete the constant pools */
    VM_IFELSE_ALLOC_PRE_GLOBAL(delete G_code_pool,
                               G_code_pool->terminate());
    VM_IFELSE_ALLOC_PRE_GLOBAL(delete G_const_pool,
                               G_const_pool->terminate());

    /* delete the object table */
    G_obj_table->delete_obj_table(vmg0_);
    VM_IF_ALLOC_PRE_GLOBAL(delete G_obj_table);

    /* delete the dependency tables */
    G_bif_table->clear(vmg0_);
    delete G_meta_table;
    delete G_bif_table;

    /* delete the undo manager */
    delete G_undo;

    /* delete the memory manager and heap manager */
    delete G_mem;
    delete G_varheap;

    /* delete the error context */
    err_terminate();

    /* delete the globals */
    vmglob_delete(vmg__);
}