Ticket #277: tt277-test_exec.patch

File tt277-test_exec.patch, 7.4 KB (added by rurban, 13 years ago)
  • config/gen/makefiles/root.in

    old new  
    21812181# 
    21822182############################################################################### 
    21832183 
    2184 exec : $(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) $(LIBPARROT) 
     2184# usage: make exec EXEC=examples/c/test_main 
     2185exec : $(SRC_DIR)/exec_start$(O) $(EXEC)$(O) $(SRC_DIR)/parrot_config$(O) $(LIBPARROT) 
    21852186        $(LINK) @ld_out@$(EXEC)$(EXE) $(EXEC)$(O) $(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) @rpath_blib@ $(ALL_PARROT_LIBS) $(LINKFLAGS) 
    21862187 
    21872188###### OS depend targets ########## 
  • examples/c/test_main.c

    old new  
    1919 
    2020*/ 
    2121 
    22 #include "parrot/embed.h" 
    23 #include "parrot/longopt.h" 
    2422#include <stdio.h> 
    2523#include <stdlib.h> 
    2624#include <string.h> 
    2725 
    28 #define setopt(flag) Parrot_setflag(interp, (flag), (*argv)[0]+2); 
    29 #define unsetopt(flag) Parrot_setflag(interp, (flag), 0) 
     26#include "parrot/embed.h" 
     27#include "parrot/longopt.h" 
     28 
     29#define SET_FLAG(flag)   Parrot_set_flag(interp, (flag)) 
     30#define SET_DEBUG(flag)  Parrot_set_debug(interp, (flag)) 
     31#define SET_TRACE(flag)  Parrot_set_trace(interp, (flag)) 
     32#define SET_CORE(core)   interp->run_core |= (core) 
     33#define UNSET_FLAG(flag) Parrot_clear_flag(interp, (flag)) 
    3034 
    3135static char *parseflags(PARROT_INTERP, int *argc, char **argv[]); 
    3236 
     
    3842    { 'd', 'd', 0,       { "--debug" } }, 
    3943    { 'h', 'h', 0,       { "--help" } }, 
    4044    { 'j', 'j', 0,       { "--jit" } }, 
    41     { 'o', 'o', 0,       { "--output-file" } }, 
     45    { 'o', 'o', 0,       { "--output" } }, 
    4246    { 'p', 'p', 0,       { "--profile" } }, 
    43     { 'P', 'P', 0, { "--prederefrenced-core" } }, 
     47    { 'P', 'P', 0, { "--predereferenced-core" } }, 
    4448    { 'S', 'S', 0,       { "--switched-core" } }, 
    4549    { 'g', 'g', 0,       { "--no-computed-goto" } }, 
    4650    { 't', 't', 0,       { "--trace" } }, 
     
    5155    {'\0',   0, 0,       { NULL } } 
    5256}; 
    5357 
    54 static void usage(void); 
     58static void usage(PARROT_INTERP); 
    5559 
    56 static void version(void); 
     60static void version(PARROT_INTERP); 
    5761 
    5862/* 
    5963 
     
    8084 
    8185    filename = parseflags(interp, &argc, &argv); 
    8286 
    83     pf = Parrot_readbc(interp, filename); 
     87    pf = Parrot_pbc_read(interp, filename, 0); 
    8488 
    8589    if (!pf) { 
    8690        return 1; 
    8791    } 
    8892 
    89     Parrot_loadbc(interp, pf); 
     93    Parrot_pbc_load(interp, pf); 
    9094    Parrot_runcode(interp, argc, argv); 
    9195    Parrot_destroy(interp); 
    9296 
     
    111115    struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; 
    112116 
    113117    if (*argc == 1) { 
    114         usage(); 
     118        usage(interp); 
    115119    } 
    116120 
    117121    ++*argv; 
     
    120124 
    121125 
    122126#ifdef HAVE_COMPUTED_GOTO 
    123     setopt(PARROT_CGOTO_FLAG); 
     127    SET_CORE(PARROT_CGOTO_CORE); 
    124128#endif 
    125129 
    126     while (longopt_get(interp, *argc, *argv, options, &opt)) { 
     130    while (longopt_get(interp, *argc, (const char **)*argv, options, &opt)) { 
    127131        if (opt.opt_id == -1) { 
    128             fprintf(stderr, "parrot: %s\n", opt.opt_error); 
     132            fprintf(stderr, "main: %s\n", opt.opt_error); 
    129133            Parrot_exit(interp, 1); 
    130134        } 
    131135 
    132136        switch (opt.opt_id) { 
    133137        case 'b': 
    134             setopt(PARROT_BOUNDS_FLAG); 
     138            SET_FLAG(PARROT_BOUNDS_FLAG); 
    135139            break; 
    136140        case 'j': 
    137             setopt(PARROT_JIT_FLAG); 
     141            SET_CORE(PARROT_JIT_CORE); 
    138142            break; 
    139143        case 'o': 
    140             setopt(PARROT_EXEC_FLAG); 
     144            interp->output_file = opt.opt_arg; 
    141145            break; 
    142146        case 'p': 
    143             setopt(PARROT_PROFILE_FLAG); 
     147            SET_FLAG(PARROT_PROFILE_FLAG); 
    144148            break; 
    145149        case 'P': 
    146             setopt(PARROT_PREDEREF_FLAG); 
     150            SET_CORE(PARROT_SWITCH_CORE); 
     151            /*SET_FLAG(PARROT_PREDEREF_FLAG);*/ 
    147152            break; 
    148153        case 'S': 
    149             setopt(PARROT_SWITCH_FLAG); 
     154            SET_CORE(PARROT_SWITCH_CORE); 
    150155            break; 
    151156        case 'g': 
    152             unsetopt(PARROT_CGOTO_FLAG); 
     157            SET_CORE(PARROT_CGOTO_CORE); 
    153158            break; 
    154159        case 't': 
    155             setopt(PARROT_TRACE_FLAG); 
     160            SET_TRACE(1); 
     161            SET_CORE(PARROT_SWITCH_CORE); 
     162#ifdef HAVE_COMPUTED_GOTO 
     163            SET_CORE(PARROT_CGP_CORE); 
     164#endif 
     165#ifdef JIT_CAPABLE 
     166            SET_CORE(PARROT_JIT_CORE); 
     167#endif 
    156168            break; 
    157169        case 'd': 
    158             setopt(PARROT_DEBUG_FLAG); 
     170            SET_DEBUG(1); 
    159171            break; 
    160172        case 'h': 
    161             usage(); 
     173            usage(interp); 
    162174            break; 
    163175        case 'v': 
    164             version(); 
     176            version(interp); 
    165177            break; 
    166178        case 'w': 
    167179            Parrot_setwarnings(interp, PARROT_WARNINGS_ALL_FLAG); 
     
    172184            fgetc(stdin); 
    173185            break; 
    174186        case OPT_GC_DEBUG: 
    175 #if DISABLE_GC_DEBUG 
     187#ifdef DISABLE_GC_DEBUG 
    176188            Parrot_warn(interp, PARROT_WARNINGS_ALL_FLAG, 
    177189                        "PARROT_GC_DEBUG is set but the binary was " 
    178190                        "compiled with DISABLE_GC_DEBUG."); 
    179191#endif 
    180             setopt(PARROT_GC_DEBUG_FLAG); 
     192            SET_FLAG(PARROT_GC_DEBUG_FLAG); 
    181193            break; 
    182194        case OPT_DESTROY_FLAG: 
    183             setopt(PARROT_DESTROY_FLAG); 
     195            SET_FLAG(PARROT_DESTROY_FLAG); 
    184196            break; 
     197        default: 
     198            fprintf(stderr, 
     199                "main: Invalid flag '%s' used.\n", 
     200                (*argv)[0]); 
    185201        } 
    186202    } 
    187203    *argv += opt.opt_index; 
     
    190206    if ((*argv)[0]) 
    191207        return (*argv)[0]; 
    192208    else { 
    193         usage(); 
     209        usage(interp); 
    194210        return 0;   /* This won't happen */ 
    195211    } 
    196212} 
     
    198214/* 
    199215 
    200216=item C<static void 
    201 usage(void)> 
     217usage(PARROT_INTERP)> 
    202218 
    203219Returns the user help. 
    204220 
     
    207223*/ 
    208224 
    209225static void 
    210 usage(void) 
     226usage(PARROT_INTERP) 
    211227{ 
    212228#ifdef HAVE_COMPUTED_GOTO 
    213229    const char* cgoto_info = "Deactivate computed goto"; 
     
    230246  -v  --version                 Display version information\n\ 
    231247  -.  --wait                    Wait for a keypress (gives Windows users\n\ 
    232248                                    time to attach a debugger)\n\ 
     249  -o  --output=FILE             Output to file\n\ 
    233250      --gc-debug\n\ 
    234251        Enable garbage collection debugging mode. This may also be enabled\n\ 
    235252        by setting the environment variable $PARROT_GC_DEBUG to 1.\n\ 
    236253\n", 
    237254            cgoto_info); 
    238  
    239255    Parrot_exit(interp, 0); 
    240256} 
    241257 
    242258/* 
    243259 
    244260=item C<static void 
    245 version(void)> 
     261version(PARROT_INTERP)> 
    246262 
    247263Returns the version information. 
    248264 
     
    251267*/ 
    252268 
    253269static void 
    254 version(void) 
     270version(PARROT_INTERP) 
    255271{ 
    256272    fprintf(stderr, 
    257273            "This is parrot version " PARROT_VERSION " built for " 
    258274            PARROT_ARCHNAME "\n\ 
    259 Copyright (C) 2001-2003, The Perl Foundation.\n\ 
     275Copyright (C) 2001-2009, The Perl Foundation.\n\ 
    260276\n\ 
    261277Parrot may be copied only under the terms of either the Artistic License or the\ 
    262278\n\