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 2181 2181 # 2182 2182 ############################################################################### 2183 2183 2184 exec : $(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) $(LIBPARROT) 2184 # usage: make exec EXEC=examples/c/test_main 2185 exec : $(SRC_DIR)/exec_start$(O) $(EXEC)$(O) $(SRC_DIR)/parrot_config$(O) $(LIBPARROT) 2185 2186 $(LINK) @ld_out@$(EXEC)$(EXE) $(EXEC)$(O) $(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) @rpath_blib@ $(ALL_PARROT_LIBS) $(LINKFLAGS) 2186 2187 2187 2188 ###### OS depend targets ########## -
examples/c/test_main.c
old new 19 19 20 20 */ 21 21 22 #include "parrot/embed.h"23 #include "parrot/longopt.h"24 22 #include <stdio.h> 25 23 #include <stdlib.h> 26 24 #include <string.h> 27 25 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)) 30 34 31 35 static char *parseflags(PARROT_INTERP, int *argc, char **argv[]); 32 36 … … 38 42 { 'd', 'd', 0, { "--debug" } }, 39 43 { 'h', 'h', 0, { "--help" } }, 40 44 { 'j', 'j', 0, { "--jit" } }, 41 { 'o', 'o', 0, { "--output -file" } },45 { 'o', 'o', 0, { "--output" } }, 42 46 { 'p', 'p', 0, { "--profile" } }, 43 { 'P', 'P', 0, { "--prederef renced-core" } },47 { 'P', 'P', 0, { "--predereferenced-core" } }, 44 48 { 'S', 'S', 0, { "--switched-core" } }, 45 49 { 'g', 'g', 0, { "--no-computed-goto" } }, 46 50 { 't', 't', 0, { "--trace" } }, … … 51 55 {'\0', 0, 0, { NULL } } 52 56 }; 53 57 54 static void usage( void);58 static void usage(PARROT_INTERP); 55 59 56 static void version( void);60 static void version(PARROT_INTERP); 57 61 58 62 /* 59 63 … … 80 84 81 85 filename = parseflags(interp, &argc, &argv); 82 86 83 pf = Parrot_ readbc(interp, filename);87 pf = Parrot_pbc_read(interp, filename, 0); 84 88 85 89 if (!pf) { 86 90 return 1; 87 91 } 88 92 89 Parrot_ loadbc(interp, pf);93 Parrot_pbc_load(interp, pf); 90 94 Parrot_runcode(interp, argc, argv); 91 95 Parrot_destroy(interp); 92 96 … … 111 115 struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; 112 116 113 117 if (*argc == 1) { 114 usage( );118 usage(interp); 115 119 } 116 120 117 121 ++*argv; … … 120 124 121 125 122 126 #ifdef HAVE_COMPUTED_GOTO 123 setopt(PARROT_CGOTO_FLAG);127 SET_CORE(PARROT_CGOTO_CORE); 124 128 #endif 125 129 126 while (longopt_get(interp, *argc, *argv, options, &opt)) {130 while (longopt_get(interp, *argc, (const char **)*argv, options, &opt)) { 127 131 if (opt.opt_id == -1) { 128 fprintf(stderr, " parrot: %s\n", opt.opt_error);132 fprintf(stderr, "main: %s\n", opt.opt_error); 129 133 Parrot_exit(interp, 1); 130 134 } 131 135 132 136 switch (opt.opt_id) { 133 137 case 'b': 134 setopt(PARROT_BOUNDS_FLAG);138 SET_FLAG(PARROT_BOUNDS_FLAG); 135 139 break; 136 140 case 'j': 137 setopt(PARROT_JIT_FLAG);141 SET_CORE(PARROT_JIT_CORE); 138 142 break; 139 143 case 'o': 140 setopt(PARROT_EXEC_FLAG);144 interp->output_file = opt.opt_arg; 141 145 break; 142 146 case 'p': 143 setopt(PARROT_PROFILE_FLAG);147 SET_FLAG(PARROT_PROFILE_FLAG); 144 148 break; 145 149 case 'P': 146 setopt(PARROT_PREDEREF_FLAG); 150 SET_CORE(PARROT_SWITCH_CORE); 151 /*SET_FLAG(PARROT_PREDEREF_FLAG);*/ 147 152 break; 148 153 case 'S': 149 setopt(PARROT_SWITCH_FLAG);154 SET_CORE(PARROT_SWITCH_CORE); 150 155 break; 151 156 case 'g': 152 unsetopt(PARROT_CGOTO_FLAG);157 SET_CORE(PARROT_CGOTO_CORE); 153 158 break; 154 159 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 156 168 break; 157 169 case 'd': 158 setopt(PARROT_DEBUG_FLAG);170 SET_DEBUG(1); 159 171 break; 160 172 case 'h': 161 usage( );173 usage(interp); 162 174 break; 163 175 case 'v': 164 version( );176 version(interp); 165 177 break; 166 178 case 'w': 167 179 Parrot_setwarnings(interp, PARROT_WARNINGS_ALL_FLAG); … … 172 184 fgetc(stdin); 173 185 break; 174 186 case OPT_GC_DEBUG: 175 #if DISABLE_GC_DEBUG187 #ifdef DISABLE_GC_DEBUG 176 188 Parrot_warn(interp, PARROT_WARNINGS_ALL_FLAG, 177 189 "PARROT_GC_DEBUG is set but the binary was " 178 190 "compiled with DISABLE_GC_DEBUG."); 179 191 #endif 180 setopt(PARROT_GC_DEBUG_FLAG);192 SET_FLAG(PARROT_GC_DEBUG_FLAG); 181 193 break; 182 194 case OPT_DESTROY_FLAG: 183 setopt(PARROT_DESTROY_FLAG);195 SET_FLAG(PARROT_DESTROY_FLAG); 184 196 break; 197 default: 198 fprintf(stderr, 199 "main: Invalid flag '%s' used.\n", 200 (*argv)[0]); 185 201 } 186 202 } 187 203 *argv += opt.opt_index; … … 190 206 if ((*argv)[0]) 191 207 return (*argv)[0]; 192 208 else { 193 usage( );209 usage(interp); 194 210 return 0; /* This won't happen */ 195 211 } 196 212 } … … 198 214 /* 199 215 200 216 =item C<static void 201 usage( void)>217 usage(PARROT_INTERP)> 202 218 203 219 Returns the user help. 204 220 … … 207 223 */ 208 224 209 225 static void 210 usage( void)226 usage(PARROT_INTERP) 211 227 { 212 228 #ifdef HAVE_COMPUTED_GOTO 213 229 const char* cgoto_info = "Deactivate computed goto"; … … 230 246 -v --version Display version information\n\ 231 247 -. --wait Wait for a keypress (gives Windows users\n\ 232 248 time to attach a debugger)\n\ 249 -o --output=FILE Output to file\n\ 233 250 --gc-debug\n\ 234 251 Enable garbage collection debugging mode. This may also be enabled\n\ 235 252 by setting the environment variable $PARROT_GC_DEBUG to 1.\n\ 236 253 \n", 237 254 cgoto_info); 238 239 255 Parrot_exit(interp, 0); 240 256 } 241 257 242 258 /* 243 259 244 260 =item C<static void 245 version( void)>261 version(PARROT_INTERP)> 246 262 247 263 Returns the version information. 248 264 … … 251 267 */ 252 268 253 269 static void 254 version( void)270 version(PARROT_INTERP) 255 271 { 256 272 fprintf(stderr, 257 273 "This is parrot version " PARROT_VERSION " built for " 258 274 PARROT_ARCHNAME "\n\ 259 Copyright (C) 2001-200 3, The Perl Foundation.\n\275 Copyright (C) 2001-2009, The Perl Foundation.\n\ 260 276 \n\ 261 277 Parrot may be copied only under the terms of either the Artistic License or the\ 262 278 \n\