Skip to content
This repository
Browse code

Merge branch 'master' into nwellnhof/unicode_filenames

Conflicts:
	compilers/imcc/imc.h
	compilers/imcc/imclexer.c
	compilers/imcc/imcparser.c
	compilers/imcc/imcparser.h
	compilers/imcc/main.c
	compilers/imcc/parser_util.c
	compilers/imcc/pbc.c
	frontend/parrot/main.c
	include/parrot/api.h
	include/parrot/imcc.h
	include/parrot/interpreter.h
	include/parrot/packfile.h
	src/embed/api.c
	src/packfile/api.c
  • Loading branch information...
commit adc07e53ad5e2a70e6bf094cdb7f4a3d2c1c5257 2 parents ff62b37 + a0d48ce
Nick Wellnhofer nwellnhof authored

Showing 70 changed files with 6,018 additions and 5,535 deletions. Show diff stats Hide diff stats

  1. +2 0  .gitignore
  2. +13 6 CREDITS
  3. +6 2 ChangeLog
  4. +17 0 DEPRECATED.pod
  5. +1 2  MANIFEST
  6. +4 0 MANIFEST.SKIP
  7. +2 2 MANIFEST.generated
  8. +37 5 NEWS
  9. +1 4 PBC_COMPAT
  10. +1 1  PLATFORMS
  11. +1 1  README
  12. +1 1  VERSION
  13. +2 1  compilers/imcc/Rules.in
  14. +0 3  compilers/imcc/debug.c
  15. +108 109 compilers/imcc/imc.h
  16. +0 2  compilers/imcc/imcparser.c
  17. +0 2  compilers/imcc/imcparser.h
  18. +528 132 compilers/imcc/main.c
  19. +0 515 compilers/imcc/parser_util.c
  20. +155 102 compilers/imcc/pbc.c
  21. +2 0  docs/parrothist.pod
  22. 0  docs/pdds/{draft → }/pdd10_embedding.pod
  23. +4 5 docs/project/release_manager_guide.pod
  24. +84 48 frontend/parrot/main.c
  25. +2 1  frontend/pbc_dump/main.c
  26. +12 1 frontend/pbc_merge/main.c
  27. +18 12 include/parrot/api.h
  28. +9 0 include/parrot/exceptions.h
  29. +3 2 include/parrot/imageio.h
  30. +0 18 include/parrot/imcc.h
  31. +0 2  include/parrot/interpreter.h
  32. +3 3 include/parrot/oplib/core_ops.h
  33. +1,009 1,009 include/parrot/oplib/ops.h
  34. +1,009 1,009 include/parrot/opsenum.h
  35. +65 13 include/parrot/packfile.h
  36. +14 20 include/parrot/pmc_freeze.h
  37. +1 0  lib/Parrot/Harness/DefaultTests.pm
  38. +1 0  lib/Parrot/Install.pm
  39. +8 0 runtime/parrot/library/Test/More.pir
  40. +3 18 src/embed.c
  41. +81 42 src/embed/api.c
  42. +73 5 src/exceptions.c
  43. +1 0  src/interp/inter_create.c
  44. +2 0  src/nci/libffi.c
  45. +2,123 2,125 src/ops/core_ops.c
  46. +119 58 src/packfile/api.c
  47. +7 84 src/packfile/object_serialization.c
  48. +79 4 src/packfile/output.c
  49. +3 1 src/pbc_disassemble.c
  50. +28 0 src/pmc/exception.pmc
  51. +6 2 src/pmc/float.pmc
  52. +69 39 src/pmc/imageiofreeze.pmc
  53. +74 30 src/pmc/imageiosize.pmc
  54. +7 15 src/pmc/imageiostrings.pmc
  55. +70 40 src/pmc/imageiothaw.pmc
  56. +49 1 t/compilers/imcc/syn/errors.t
  57. +10 6 t/dynoplibs/trans.t
  58. +1 1  t/manifest/01-basic.t
  59. BIN  t/native_pbc/integer.pbc
  60. BIN  t/native_pbc/integer_1.pbc
  61. BIN  t/native_pbc/number.pbc
  62. BIN  t/native_pbc/number_1.pbc
  63. BIN  t/native_pbc/string.pbc
  64. BIN  t/native_pbc/string_1.pbc
  65. +2 1  t/pmc/class.t
  66. +16 1 t/pmc/string.t
  67. +10 10 t/src/embed.t
  68. +51 9 t/src/embed/api.t
  69. +4 3 t/src/embed/strings.t
  70. +7 7 tools/release/release.json
2  .gitignore
@@ -37,6 +37,7 @@
37 37 /blib
38 38 /config_lib.pir
39 39 /cover_db
  40 +/generated_hello.pbc
40 41 /install_config.fpmc
41 42 /installable*
42 43 /libparrot.def
@@ -443,6 +444,7 @@
443 444 /t/src/*_*
444 445 /t/src/*.gcov
445 446 /t/src/*.gcdada
  447 +/t/src/embed/*.c
446 448 /t/stress/*.out
447 449 /t/stress/*.pasm
448 450 /t/stress/*.pbc
19 CREDITS
@@ -57,7 +57,7 @@ U: heimdall
57 57 E: Nattfodd@gmail.com
58 58
59 59 N: Allison Randal
60   -D: Architect (0.4.6...) & Lead Developer
  60 +D: Architect (0.4.6 - 2.8.0) & Lead Developer
61 61 E: allison@parrot.org
62 62 U: allison
63 63
@@ -224,8 +224,8 @@ U: creiss
224 224 E: creiss@cc.gatech.edu
225 225
226 226 N: Chip Salzenberg
227   -D: Release manager emeritus (0.4.6-0.4.7)
228   -D: Architect emeritus (0.1.2-0.4.5)
  227 +D: Release manager emeritus (0.4.6 - 0.4.7)
  228 +D: Architect emeritus (0.1.2 - 0.4.5)
229 229 U: chip
230 230 E: chip@pobox.com
231 231
@@ -243,12 +243,11 @@ D: Rakudo patches
243 243
244 244 N: Christoph Otto
245 245 U: cotto
246   -D: Patch for key flags in pdd08
  246 +D: Architect (2.9.0 - current)
247 247 D: Range check in Env PMC
248 248 A: christoph_googleacct@mksig.org
249 249 A: christop...@mksig.org
250 250 A: Christoph Otto
251   -D: Pipp, Lorito taskmaster
252 251 E: christoph@mksig.org
253 252
254 253 N: chromatic
@@ -299,9 +298,13 @@ N: Damian Miles Knopp
299 298 U: dmknopp
300 299 E: dmknopp@loyola.edu
301 300
  301 +N: Daniel Kang
  302 +U: jumpyshoes
  303 +D: improve pbc_disassemble's test coverage
  304 +
302 305 N: Dan Sugalski
303 306 U: dan
304   -D: Architect emeritus (0.0.1-0.1.1)
  307 +D: Architect emeritus (0.0.1 - 0.1.1)
305 308 E: dan@sidhe.org
306 309 W: http://www.sidhe.org/~dan/blog/
307 310
@@ -679,6 +682,10 @@ U: LylePerl
679 682 D: Win32 and CGI testing
680 683 W: http://perl.bristolbath.org/blog/lyle/
681 684
  685 +N: Mariano Wahlmann
  686 +E: dichoso@gmail.com
  687 +A: bluescreen
  688 +
682 689 N: Marcelo Serra Castilhos
683 690 E: mhelix@terra.com.br
684 691 D: Bug fix
8 ChangeLog
... ... @@ -1,8 +1,12 @@
1 1 #1 $Id$
2 2
  3 +2011.01.18 cotto
  4 + * Released 3.0.0
  5 + See NEWS for more.
  6 +
3 7 2010.12.21 Whiteknight
4   - * Released 2.11.0
5   - See NEWS for more.
  8 + * Released 2.11.0
  9 + See NEWS for more.
6 10
7 11 2010.11.16 tcurtis
8 12 * Released 2.10.0
17 DEPRECATED.pod
Source Rendered
@@ -141,6 +141,23 @@ to work on this type.
141 141
142 142 L<http://trac.parrot.org/parrot/ticket/1904>
143 143
  144 +=item The Eval PMC [eligible in 3.1]
  145 +
  146 +The Eval PMC will be removed. Uses of it returned from compilers will be
  147 +replaced with PackFile PMCs instead.
  148 +
  149 +L<http://trac.parrot.org/parrot/ticket/1969>
  150 +
  151 +=item The PIR and PASM compreg PMCs [eligible in 3.1]
  152 +
  153 +The PMC returned by C<compreg "PIR"> is not going to be an NCI PMC any longer,
  154 +it will be a new type of PMC which conforms to PDD31 and will be similar to
  155 +HLLCompiler.
  156 +
  157 +There will not be a PASM compreg anymore.
  158 +
  159 +L<http://trac.parrot.org/parrot/ticket/1967>
  160 +
144 161 =back
145 162
146 163 =head1 Opcodes
3  MANIFEST
@@ -399,7 +399,6 @@ docs/pdds/draft/pdd01_overview.pod [doc]
399 399 docs/pdds/draft/pdd05_opfunc.pod [doc]
400 400 docs/pdds/draft/pdd06_pasm.pod [doc]
401 401 docs/pdds/draft/pdd08_keys.pod [doc]
402   -docs/pdds/draft/pdd10_embedding.pod [doc]
403 402 docs/pdds/draft/pdd11_extending.pod [doc]
404 403 docs/pdds/draft/pdd14_numbers.pod [doc]
405 404 docs/pdds/draft/pdd16_native_call.pod [doc]
@@ -409,6 +408,7 @@ docs/pdds/pdd00_pdd.pod [doc]
409 408 docs/pdds/pdd03_calling_conventions.pod [doc]
410 409 docs/pdds/pdd07_codingstd.pod [doc]
411 410 docs/pdds/pdd09_gc.pod [doc]
  411 +docs/pdds/pdd10_embedding.pod [doc]
412 412 docs/pdds/pdd13_bytecode.pod [doc]
413 413 docs/pdds/pdd15_object_metamodel.png [doc]
414 414 docs/pdds/pdd15_object_metamodel.svg [doc]
@@ -952,7 +952,6 @@ include/parrot/global_setup.h [main]include
952 952 include/parrot/hash.h [main]include
953 953 include/parrot/hll.h [main]include
954 954 include/parrot/imageio.h [main]include
955   -include/parrot/imcc.h [main]include
956 955 include/parrot/interpreter.h [main]include
957 956 include/parrot/io.h [main]include
958 957 include/parrot/io_portable.h [main]include
4 MANIFEST.SKIP
@@ -350,6 +350,8 @@
350 350 ^/frontend/pbc_merge/.*\.gcov/
351 351 ^/frontend/pbc_merge/main\.o$
352 352 ^/frontend/pbc_merge/main\.o/
  353 +^/generated_hello\.pbc$
  354 +^/generated_hello\.pbc/
353 355 ^/include/parrot/.*\.tmp$
354 356 ^/include/parrot/.*\.tmp/
355 357 ^/include/parrot/config\.h$
@@ -980,6 +982,8 @@
980 982 ^/t/src/.*\.gcov/
981 983 ^/t/src/.*_.*$
982 984 ^/t/src/.*_.*/
  985 +^/t/src/embed/.*\.c$
  986 +^/t/src/embed/.*\.c/
983 987 ^/t/stress/.*\.out$
984 988 ^/t/stress/.*\.out/
985 989 ^/t/stress/.*\.pasm$
4 MANIFEST.generated
... ... @@ -1,11 +1,11 @@
1 1 # See tools/dev/install_files.pl for documentation on the
2 2 # format of this file.
3 3 # Please re-sort this file after *EVERY* modification
4   -blib/lib/libparrot.2.11.0.dylib [main]lib
  4 +blib/lib/libparrot.3.0.0.dylib [main]lib
5 5 blib/lib/libparrot.a [main]lib
6 6 blib/lib/libparrot.dylib [main]lib
7 7 blib/lib/libparrot.so [main]lib
8   -blib/lib/libparrot.so.2.11.0 [main]lib
  8 +blib/lib/libparrot.so.3.0.0 [main]lib
9 9 compilers/data_json/data_json.pbc [data_json]
10 10 config/gen/call_list/opengl.in []
11 11 docs/ops/bit.pod [doc]
42 NEWS
... ... @@ -1,10 +1,42 @@
1 1 New in 3.0.0
2 2 - Core
3   - + Added a new embedding API in "parrot/api.h"
4   - + Removed autovivification behavior from ResizablePMCArray
5   - + Packfile manipulation functions now throw exceptions on error instead of printing error details directly to stderr
6   - + Test coverage for several PMC types has been significantly increased
7   - + Test coverage for several internal subsystems has been increased
  3 + + A new embedding API is available in "parrot/api.h" and documented in
  4 + docs/pdd/pdd10_embedding.pod .
  5 + + Packfile PMCs were refactored and can now be used to produce runnable bytecode.
  6 + + Packfile manipulation code now throws embedder-friendly exceptions rather
  7 + than printing error details directly to stderr.
  8 + + Unicode support for file IO, environment variables, program names, and
  9 + command-line parameters was improved.
  10 + + An experimental gdb pretty-printers in tools/dev for Parrot STRINGs and
  11 + PMCs is now available. (gdb 7.2 or later and Python are required)
  12 + + c2str.pl and pmc2c.pl improvements result in a noticably faster build.
  13 + + Bugs in our Digest::sha256 library and bit-related dynamic ops were fixed
  14 + by GCI student Nolan Lum. Both now work correctly on 32 and 64 bit systems.
  15 +- Languages
  16 + + Ωη;)XD - OMeta for Winxed https://github.com/plobsing/ohm-eta-wink-kzd
  17 +- Community
  18 + + tree-optimization by GSoC student Tyler L. Curtis joined the nest and now
  19 + lives at http://github.com/parrot/tree-optimization .
  20 + + Plumage now lives at http://github.com/parrot/plumage and is installable.
  21 + + Christmas proceeded as scheduled. The Parrot team does not take credit for
  22 + this event.
  23 +- Documentation
  24 + + HTML documentation generation has been rewritten and greatly simplified.
  25 + + We have improved documentation in docs/project/git_workflow.pod about
  26 + keeping a fork of parrot.git in sync.
  27 + + Translations of our README in various languages are now in the
  28 + docs/translation directory, thanks to Google Code-In students.
  29 +- Tests
  30 + + A better way to write "todo" tests with Parrot's Test::More was implemented
  31 + by GCI student Fernando Brito.
  32 + + Major increases in test coverage of many core PMCs, dynamic PMCs and
  33 + dynamic opcodes resulted from GCI and the interpid students it attracted.
  34 + + Jonathan "Duke" Leto set up Debian Linux x86_64 and sparc32 smokers
  35 + in the GCC Compile Farm, which continually submit smoke reports with
  36 + a variety of configuration options and compilers. Thanks, GCC!
  37 + + Makefile dependency checking is now automatically tested, resulting in a
  38 + more reliable parallel build.
  39 + + Coverage tests were improved for platforms with and without Devel::Cover.
8 40
9 41 New in 2.11.0
10 42 - Core
5 PBC_COMPAT
@@ -28,10 +28,7 @@
28 28
29 29 # please insert tab separated entries at the top of the list
30 30
31   -9.4 2011.1.2 plobsing track :main subs in packfiles
32   -9.3 2010.11.24 NotFound move op find_codepoint out of experimental TT #1629
33   -9.2 2010.11.21 plobsing remove CodeString PMC
34   -9.1 2010.10.27 nwellnhof remove charset ops
  31 +10.0 2011.01.18 cotto released 3.0.0
35 32 9.0 2010.10.19 gerd released 2.9.0
36 33 8.0 2010.07.20 coke released 2.6.0
37 34 7.0 2010.04.20 gerd released 2.3.0 (version # added ex post facto, as all previous version #s were published)
2  PLATFORMS
@@ -12,6 +12,7 @@ Supported platforms:
12 12 Platform B8 Runloops Feature Comp Test Inst YYYYMMDD
13 13 CGoto EXEC Thr Sig
14 14 --------------------------------------------------------------------------------
  15 +linux-sparc64-gcc-4.3.2 ? Y Y 20110114
15 16 cygwin1.5.25-x86-gcc3.4.4 4 Y - - - Y Y Y 20090315
16 17 darwin8.11.1-x86-gcc4.0.1 ?? Y ? ? ? Y Y N 20091020
17 18 linux-x86-gcc4.1.2 Y ? Y Y Y Y ? 20090419
@@ -83,7 +84,6 @@ B ... Processor is big endian
83 84 4 ... opcode_t is 4 byte, --m=32 on a 64 bit machine
84 85
85 86 CGoto ... CGoto runloop is supported
86   -JIT ... JIT core is supported
87 87 EXEC ... compiling to native executables is supported
88 88 Thr ... Parrot is multi-threaded
89 89 Sig ... Parrot catches a SIGHUP signal
2  README
... ... @@ -1,4 +1,4 @@
1   -This is Parrot, version 2.11.0
  1 +This is Parrot, version 3.0.0
2 2 ------------------------------
3 3
4 4 Parrot is Copyright (C) 2001-2011, Parrot Foundation.
2  VERSION
... ... @@ -1 +1 @@
1   -2.11.0
  1 +3.0.0
3  compilers/imcc/Rules.in
@@ -148,17 +148,18 @@ compilers/imcc/main$(O) : \
148 148 compilers/imcc/imc.h \
149 149 compilers/imcc/imcparser.h \
150 150 compilers/imcc/instructions.h \
  151 + compilers/imcc/optimizer.h \
151 152 compilers/imcc/parser.h \
152 153 compilers/imcc/pbc.h \
153 154 compilers/imcc/sets.h \
154 155 compilers/imcc/symreg.h \
155 156 compilers/imcc/unit.h \
156 157 $(INC_DIR)/embed.h \
157   - $(INC_DIR)/imcc.h \
158 158 $(INC_DIR)/oplib/ops.h \
159 159 $(INC_DIR)/runcore_api.h \
160 160 $(INC_DIR)/api.h \
161 161 $(INC_DIR)/longopt.h \
  162 + include/pmc/pmc_sub.h \
162 163 $(PARROT_H_HEADERS)
163 164
164 165 ## SUFFIX OVERRIDE - Warnings (This is generated code)
3  compilers/imcc/debug.c
@@ -115,9 +115,6 @@ IMCC_warning(PARROT_INTERP, ARGIN(const char *fmt), ...)
115 115 {
116 116 ASSERT_ARGS(IMCC_warning)
117 117 va_list ap;
118   - if (IMCC_INFO(interp)->imcc_warn)
119   - return;
120   -
121 118 va_start(ap, fmt);
122 119 imcc_vfprintf(interp, Parrot_io_STDERR(interp), fmt, ap);
123 120 va_end(ap);
217 compilers/imcc/imc.h
@@ -61,6 +61,114 @@ enum {
61 61
62 62 #define N_ELEMENTS(x) (sizeof (x)/sizeof ((x)[0]))
63 63
  64 +/* HEADERIZER BEGIN: compilers/imcc/main.c */
  65 +/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
  66 +
  67 +PARROT_EXPORT
  68 +PARROT_CANNOT_RETURN_NULL
  69 +void * imcc_compile_file(PARROT_INTERP,
  70 + ARGIN(STRING *fullname),
  71 + ARGOUT(STRING **error_message))
  72 + __attribute__nonnull__(1)
  73 + __attribute__nonnull__(2)
  74 + __attribute__nonnull__(3)
  75 + FUNC_MODIFIES(*error_message);
  76 +
  77 +PARROT_EXPORT
  78 +int imcc_run_api(
  79 + ARGMOD(PMC * interp_pmc),
  80 + ARGIN(STRING *sourcefile),
  81 + int argc,
  82 + ARGIN_NULLOK(const char **argv),
  83 + ARGOUT(PMC **pbcpmc))
  84 + __attribute__nonnull__(1)
  85 + __attribute__nonnull__(2)
  86 + __attribute__nonnull__(5)
  87 + FUNC_MODIFIES(* interp_pmc)
  88 + FUNC_MODIFIES(*pbcpmc);
  89 +
  90 +PARROT_WARN_UNUSED_RESULT
  91 +PARROT_CANNOT_RETURN_NULL
  92 +PMC * imcc_compile(PARROT_INTERP,
  93 + ARGIN(const char *s),
  94 + int pasm_file,
  95 + ARGOUT(STRING **error_message))
  96 + __attribute__nonnull__(1)
  97 + __attribute__nonnull__(2)
  98 + __attribute__nonnull__(4)
  99 + FUNC_MODIFIES(*error_message);
  100 +
  101 +PARROT_WARN_UNUSED_RESULT
  102 +PARROT_CANNOT_RETURN_NULL
  103 +PMC * imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s))
  104 + __attribute__nonnull__(1)
  105 + __attribute__nonnull__(2);
  106 +
  107 +PARROT_WARN_UNUSED_RESULT
  108 +PARROT_CANNOT_RETURN_NULL
  109 +PMC * IMCC_compile_pasm_s(PARROT_INTERP,
  110 + ARGIN(const char *s),
  111 + ARGOUT(STRING **error_message))
  112 + __attribute__nonnull__(1)
  113 + __attribute__nonnull__(2)
  114 + __attribute__nonnull__(3)
  115 + FUNC_MODIFIES(*error_message);
  116 +
  117 +PARROT_WARN_UNUSED_RESULT
  118 +PARROT_CANNOT_RETURN_NULL
  119 +PMC * imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s))
  120 + __attribute__nonnull__(1)
  121 + __attribute__nonnull__(2);
  122 +
  123 +PARROT_WARN_UNUSED_RESULT
  124 +PARROT_CANNOT_RETURN_NULL
  125 +PMC * IMCC_compile_pir_s(PARROT_INTERP,
  126 + ARGIN(const char *s),
  127 + ARGOUT(STRING **error_message))
  128 + __attribute__nonnull__(1)
  129 + __attribute__nonnull__(2)
  130 + __attribute__nonnull__(3)
  131 + FUNC_MODIFIES(*error_message);
  132 +
  133 +void imcc_destroy(PARROT_INTERP)
  134 + __attribute__nonnull__(1);
  135 +
  136 +void imcc_init(PARROT_INTERP)
  137 + __attribute__nonnull__(1);
  138 +
  139 +#define ASSERT_ARGS_imcc_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  140 + PARROT_ASSERT_ARG(interp) \
  141 + , PARROT_ASSERT_ARG(fullname) \
  142 + , PARROT_ASSERT_ARG(error_message))
  143 +#define ASSERT_ARGS_imcc_run_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  144 + PARROT_ASSERT_ARG(interp_pmc) \
  145 + , PARROT_ASSERT_ARG(sourcefile) \
  146 + , PARROT_ASSERT_ARG(pbcpmc))
  147 +#define ASSERT_ARGS_imcc_compile __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  148 + PARROT_ASSERT_ARG(interp) \
  149 + , PARROT_ASSERT_ARG(s) \
  150 + , PARROT_ASSERT_ARG(error_message))
  151 +#define ASSERT_ARGS_imcc_compile_pasm_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  152 + PARROT_ASSERT_ARG(interp) \
  153 + , PARROT_ASSERT_ARG(s))
  154 +#define ASSERT_ARGS_IMCC_compile_pasm_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  155 + PARROT_ASSERT_ARG(interp) \
  156 + , PARROT_ASSERT_ARG(s) \
  157 + , PARROT_ASSERT_ARG(error_message))
  158 +#define ASSERT_ARGS_imcc_compile_pir_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  159 + PARROT_ASSERT_ARG(interp) \
  160 + , PARROT_ASSERT_ARG(s))
  161 +#define ASSERT_ARGS_IMCC_compile_pir_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  162 + PARROT_ASSERT_ARG(interp) \
  163 + , PARROT_ASSERT_ARG(s) \
  164 + , PARROT_ASSERT_ARG(error_message))
  165 +#define ASSERT_ARGS_imcc_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  166 + PARROT_ASSERT_ARG(interp))
  167 +#define ASSERT_ARGS_imcc_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  168 + PARROT_ASSERT_ARG(interp))
  169 +/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
  170 +/* HEADERIZER END: compilers/imcc/main.c */
  171 +
64 172 /* HEADERIZER BEGIN: compilers/imcc/imcc.y */
65 173 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
66 174
@@ -183,16 +291,6 @@ Instruction * INS_LABEL(PARROT_INTERP,
183 291 /* HEADERIZER BEGIN: compilers/imcc/parser_util.c */
184 292 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
185 293
186   -PARROT_EXPORT
187   -PARROT_CANNOT_RETURN_NULL
188   -void * imcc_compile_file(PARROT_INTERP,
189   - ARGIN(STRING *fullname),
190   - ARGOUT(STRING **error_message))
191   - __attribute__nonnull__(1)
192   - __attribute__nonnull__(2)
193   - __attribute__nonnull__(3)
194   - FUNC_MODIFIES(*error_message);
195   -
196 294 void check_op(PARROT_INTERP,
197 295 ARGOUT(op_info_t **op_info),
198 296 ARGOUT(char *fullname),
@@ -208,67 +306,6 @@ void check_op(PARROT_INTERP,
208 306 FUNC_MODIFIES(*op_info)
209 307 FUNC_MODIFIES(*fullname);
210 308
211   -PARROT_WARN_UNUSED_RESULT
212   -PARROT_CANNOT_RETURN_NULL
213   -PMC * imcc_compile(PARROT_INTERP,
214   - ARGIN(const char *s),
215   - int pasm_file,
216   - ARGOUT(STRING **error_message))
217   - __attribute__nonnull__(1)
218   - __attribute__nonnull__(2)
219   - __attribute__nonnull__(4)
220   - FUNC_MODIFIES(*error_message);
221   -
222   -PARROT_WARN_UNUSED_RESULT
223   -PARROT_CANNOT_RETURN_NULL
224   -PMC * imcc_compile_pasm(PARROT_INTERP, ARGIN(const char *s))
225   - __attribute__nonnull__(1)
226   - __attribute__nonnull__(2);
227   -
228   -PARROT_WARN_UNUSED_RESULT
229   -PARROT_CANNOT_RETURN_NULL
230   -PMC * imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s))
231   - __attribute__nonnull__(1)
232   - __attribute__nonnull__(2);
233   -
234   -PARROT_WARN_UNUSED_RESULT
235   -PARROT_CANNOT_RETURN_NULL
236   -PMC * IMCC_compile_pasm_s(PARROT_INTERP,
237   - ARGIN(const char *s),
238   - ARGOUT(STRING **error_message))
239   - __attribute__nonnull__(1)
240   - __attribute__nonnull__(2)
241   - __attribute__nonnull__(3)
242   - FUNC_MODIFIES(*error_message);
243   -
244   -PARROT_WARN_UNUSED_RESULT
245   -PARROT_CANNOT_RETURN_NULL
246   -PMC * imcc_compile_pir(PARROT_INTERP, ARGIN(const char *s))
247   - __attribute__nonnull__(1)
248   - __attribute__nonnull__(2);
249   -
250   -PARROT_WARN_UNUSED_RESULT
251   -PARROT_CANNOT_RETURN_NULL
252   -PMC * imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s))
253   - __attribute__nonnull__(1)
254   - __attribute__nonnull__(2);
255   -
256   -PARROT_WARN_UNUSED_RESULT
257   -PARROT_CANNOT_RETURN_NULL
258   -PMC * IMCC_compile_pir_s(PARROT_INTERP,
259   - ARGIN(const char *s),
260   - ARGOUT(STRING **error_message))
261   - __attribute__nonnull__(1)
262   - __attribute__nonnull__(2)
263   - __attribute__nonnull__(3)
264   - FUNC_MODIFIES(*error_message);
265   -
266   -void imcc_destroy(PARROT_INTERP)
267   - __attribute__nonnull__(1);
268   -
269   -void imcc_init(PARROT_INTERP)
270   - __attribute__nonnull__(1);
271   -
272 309 int imcc_string_ends_with(PARROT_INTERP,
273 310 ARGIN(const STRING *str),
274 311 ARGIN(const char *ext))
@@ -319,47 +356,12 @@ void op_fullname(
319 356 __attribute__nonnull__(3)
320 357 FUNC_MODIFIES(*dest);
321 358
322   -void register_compilers(PARROT_INTERP)
323   - __attribute__nonnull__(1);
324   -
325   -#define ASSERT_ARGS_imcc_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
326   - PARROT_ASSERT_ARG(interp) \
327   - , PARROT_ASSERT_ARG(fullname) \
328   - , PARROT_ASSERT_ARG(error_message))
329 359 #define ASSERT_ARGS_check_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
330 360 PARROT_ASSERT_ARG(interp) \
331 361 , PARROT_ASSERT_ARG(op_info) \
332 362 , PARROT_ASSERT_ARG(fullname) \
333 363 , PARROT_ASSERT_ARG(name) \
334 364 , PARROT_ASSERT_ARG(r))
335   -#define ASSERT_ARGS_imcc_compile __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
336   - PARROT_ASSERT_ARG(interp) \
337   - , PARROT_ASSERT_ARG(s) \
338   - , PARROT_ASSERT_ARG(error_message))
339   -#define ASSERT_ARGS_imcc_compile_pasm __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
340   - PARROT_ASSERT_ARG(interp) \
341   - , PARROT_ASSERT_ARG(s))
342   -#define ASSERT_ARGS_imcc_compile_pasm_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
343   - PARROT_ASSERT_ARG(interp) \
344   - , PARROT_ASSERT_ARG(s))
345   -#define ASSERT_ARGS_IMCC_compile_pasm_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
346   - PARROT_ASSERT_ARG(interp) \
347   - , PARROT_ASSERT_ARG(s) \
348   - , PARROT_ASSERT_ARG(error_message))
349   -#define ASSERT_ARGS_imcc_compile_pir __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
350   - PARROT_ASSERT_ARG(interp) \
351   - , PARROT_ASSERT_ARG(s))
352   -#define ASSERT_ARGS_imcc_compile_pir_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
353   - PARROT_ASSERT_ARG(interp) \
354   - , PARROT_ASSERT_ARG(s))
355   -#define ASSERT_ARGS_IMCC_compile_pir_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
356   - PARROT_ASSERT_ARG(interp) \
357   - , PARROT_ASSERT_ARG(s) \
358   - , PARROT_ASSERT_ARG(error_message))
359   -#define ASSERT_ARGS_imcc_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
360   - PARROT_ASSERT_ARG(interp))
361   -#define ASSERT_ARGS_imcc_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
362   - PARROT_ASSERT_ARG(interp))
363 365 #define ASSERT_ARGS_imcc_string_ends_with __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
364 366 PARROT_ASSERT_ARG(interp) \
365 367 , PARROT_ASSERT_ARG(str) \
@@ -380,8 +382,6 @@ void register_compilers(PARROT_INTERP)
380 382 PARROT_ASSERT_ARG(dest) \
381 383 , PARROT_ASSERT_ARG(name) \
382 384 , PARROT_ASSERT_ARG(args))
383   -#define ASSERT_ARGS_register_compilers __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
384   - PARROT_ASSERT_ARG(interp))
385 385 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
386 386 /* HEADERIZER END: compilers/imcc/parser_util.c */
387 387
@@ -559,7 +559,6 @@ typedef struct _imc_info_t {
559 559 int emitter;
560 560 int error_code; /* The Error code. */
561 561 int expect_pasm;
562   - int gc_off;
563 562 int imcc_warn;
564 563 int in_pod;
565 564 int ins_line;
2  compilers/imcc/imcparser.c
@@ -12,8 +12,6 @@
12 12
13 13 /* A Bison parser, made by GNU Bison 2.4.1. */
14 14
15   -/* A Bison parser, made by GNU Bison 2.4.1. */
16   -
17 15 /* Skeleton implementation for Bison's Yacc-like parsers in C
18 16
19 17 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
2  compilers/imcc/imcparser.h
@@ -12,8 +12,6 @@
12 12
13 13 /* A Bison parser, made by GNU Bison 2.4.1. */
14 14
15   -/* A Bison parser, made by GNU Bison 2.4.1. */
16   -
17 15 /* Skeleton interface for Bison's Yacc-like parsers in C
18 16
19 17 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
660 compilers/imcc/main.c
@@ -31,15 +31,20 @@ IMCC helpers.
31 31 #include "imc.h"
32 32 #include "parrot/embed.h"
33 33 #include "parrot/longopt.h"
34   -#include "parrot/imcc.h"
35 34 #include "parrot/runcore_api.h"
36 35 #include "pmc/pmc_callcontext.h"
  36 +#include "pmc/pmc_sub.h"
37 37 #include "pbc.h"
38 38 #include "parser.h"
  39 +#include "optimizer.h"
39 40
40 41 extern int yydebug;
41 42
42   -/* HEADERIZER HFILE: none */
  43 +/* XXX non-reentrant */
  44 +static Parrot_mutex eval_nr_lock;
  45 +static INTVAL eval_nr = 0;
  46 +
  47 +/* HEADERIZER HFILE: compilers/imcc/imc.h */
43 48
44 49 /* HEADERIZER BEGIN: static */
45 50 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
@@ -55,12 +60,10 @@ static PackFile * compile_to_bytecode(PARROT_INTERP,
55 60 __attribute__nonnull__(3)
56 61 __attribute__nonnull__(4);
57 62
58   -static void determine_input_file_type(PARROT_INTERP,
59   - ARGIN(STRING *sourcefile),
60   - ARGIN(yyscan_t yyscanner))
  63 +static PIOHANDLE determine_input_file_type(PARROT_INTERP,
  64 + ARGIN(STRING *sourcefile))
61 65 __attribute__nonnull__(1)
62   - __attribute__nonnull__(2)
63   - __attribute__nonnull__(3);
  66 + __attribute__nonnull__(2);
64 67
65 68 static void determine_output_file_type(PARROT_INTERP,
66 69 ARGIN(STRING *output_file))
@@ -70,6 +73,10 @@ static void determine_output_file_type(PARROT_INTERP,
70 73 static void do_pre_process(PARROT_INTERP, yyscan_t yyscanner)
71 74 __attribute__nonnull__(1);
72 75
  76 +static void imcc_destroy_macro_values(ARGMOD(void *value))
  77 + __attribute__nonnull__(1)
  78 + FUNC_MODIFIES(*value);
  79 +
73 80 static void imcc_get_optimization_description(
74 81 const PARROT_INTERP,
75 82 int opt_level,
@@ -77,11 +84,20 @@ static void imcc_get_optimization_description(
77 84 __attribute__nonnull__(3)
78 85 FUNC_MODIFIES(*opt_desc);
79 86
80   -static void imcc_parseflags(PARROT_INTERP,
  87 +static STRING * imcc_parseflags(PARROT_INTERP,
81 88 int argc,
82   - ARGIN(const char **argv))
  89 + ARGIN_NULLOK(const char **argv))
  90 + __attribute__nonnull__(1);
  91 +
  92 +static int imcc_run(PARROT_INTERP,
  93 + ARGIN(STRING *sourcefile),
  94 + ARGIN(STRING *output_file),
  95 + ARGOUT(PMC **pbcpmc))
83 96 __attribute__nonnull__(1)
84   - __attribute__nonnull__(3);
  97 + __attribute__nonnull__(2)
  98 + __attribute__nonnull__(3)
  99 + __attribute__nonnull__(4)
  100 + FUNC_MODIFIES(*pbcpmc);
85 101
86 102 static void imcc_write_pbc(PARROT_INTERP, ARGIN(STRING *output_file))
87 103 __attribute__nonnull__(1)
@@ -103,19 +119,24 @@ static const struct longopt_opt_decl * Parrot_cmd_options(void);
103 119 , PARROT_ASSERT_ARG(yyscanner))
104 120 #define ASSERT_ARGS_determine_input_file_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
105 121 PARROT_ASSERT_ARG(interp) \
106   - , PARROT_ASSERT_ARG(sourcefile) \
107   - , PARROT_ASSERT_ARG(yyscanner))
  122 + , PARROT_ASSERT_ARG(sourcefile))
108 123 #define ASSERT_ARGS_determine_output_file_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
109 124 PARROT_ASSERT_ARG(interp) \
110 125 , PARROT_ASSERT_ARG(output_file))
111 126 #define ASSERT_ARGS_do_pre_process __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
112 127 PARROT_ASSERT_ARG(interp))
  128 +#define ASSERT_ARGS_imcc_destroy_macro_values __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  129 + PARROT_ASSERT_ARG(value))
113 130 #define ASSERT_ARGS_imcc_get_optimization_description \
114 131 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
115 132 PARROT_ASSERT_ARG(opt_desc))
116 133 #define ASSERT_ARGS_imcc_parseflags __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  134 + PARROT_ASSERT_ARG(interp))
  135 +#define ASSERT_ARGS_imcc_run __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
117 136 PARROT_ASSERT_ARG(interp) \
118   - , PARROT_ASSERT_ARG(argv))
  137 + , PARROT_ASSERT_ARG(sourcefile) \
  138 + , PARROT_ASSERT_ARG(output_file) \
  139 + , PARROT_ASSERT_ARG(pbcpmc))
119 140 #define ASSERT_ARGS_imcc_write_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
120 141 PARROT_ASSERT_ARG(interp) \
121 142 , PARROT_ASSERT_ARG(output_file))
@@ -213,7 +234,8 @@ Parrot_cmd_options(void)
213 234
214 235 /*
215 236
216   -=item C<static void imcc_parseflags(PARROT_INTERP, int argc, const char **argv)>
  237 +=item C<static STRING * imcc_parseflags(PARROT_INTERP, int argc, const char
  238 +**argv)>
217 239
218 240 Parse flags ans set approptiate state(s)
219 241
@@ -221,14 +243,17 @@ Parse flags ans set approptiate state(s)
221 243
222 244 */
223 245
224   -static void
225   -imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
  246 +static STRING *
  247 +imcc_parseflags(PARROT_INTERP, int argc, ARGIN_NULLOK(const char **argv))
226 248 {
227 249 ASSERT_ARGS(imcc_parseflags)
228 250 struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
  251 + STRING *output_file = STRINGNULL;
229 252
230 253 /* default state: run pbc */
231 254 SET_STATE_RUN_PBC(interp);
  255 + if (!argv)
  256 + return STRINGNULL;
232 257
233 258 while (longopt_get(argc, argv, Parrot_cmd_options(), &opt) > 0) {
234 259 switch (opt.opt_id) {
@@ -240,25 +265,9 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
240 265 IMCC_INFO(interp)->debug++;
241 266 }
242 267 break;
243   - case 'w':
244   - /* FIXME It's not best way to set warnings... */
245   - Parrot_setwarnings(interp, PARROT_WARNINGS_ALL_FLAG);
246   - IMCC_INFO(interp)->imcc_warn = 1;
247   - break;
248   - case 'G':
249   - IMCC_INFO(interp)->gc_off = 1;
250   - break;
251 268 case 'a':
252 269 SET_STATE_PASM_FILE(interp);
253 270 break;
254   - case 'r':
255   - if (STATE_RUN_PBC(interp))
256   - SET_STATE_RUN_FROM_FILE(interp);
257   - SET_STATE_RUN_PBC(interp);
258   - break;
259   - case 'c':
260   - SET_STATE_LOAD_PBC(interp);
261   - break;
262 271 case 'v':
263 272 IMCC_INFO(interp)->verbose++;
264 273 break;
@@ -270,15 +279,14 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
270 279 break;
271 280 case 'o':
272 281 UNSET_STATE_RUN_PBC(interp);
273   - interp->output_file = Parrot_str_from_platform_cstring(interp,
274   - opt.opt_arg);
  282 + output_file = Parrot_str_from_platform_cstring(interp, opt.opt_arg);
275 283 break;
276 284
277 285 case OPT_PBC_OUTPUT:
278 286 UNSET_STATE_RUN_PBC(interp);
279 287 SET_STATE_WRITE_PBC(interp);
280   - if (!interp->output_file)
281   - interp->output_file = Parrot_str_new(interp, "-", 1);
  288 + if (!STRING_IS_NULL(output_file))
  289 + output_file = Parrot_str_new(interp, "-", 1);
282 290 break;
283 291
284 292 case 'O':
@@ -305,6 +313,7 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
305 313 break;
306 314 }
307 315 }
  316 + return output_file;
308 317 }
309 318
310 319 /*
@@ -454,31 +463,6 @@ imcc_get_optimization_description(const PARROT_INTERP, int opt_level, ARGMOD(cha
454 463
455 464 /*
456 465
457   -=item C<void imcc_run_pbc(PARROT_INTERP, STRING *output_file, int argc, const
458   -char **argv)>
459   -
460   -Write out or run Parrot bytecode.
461   -
462   -=cut
463   -
464   -*/
465   -
466   -void
467   -imcc_run_pbc(PARROT_INTERP, SHIM(STRING *output_file),
468   - int argc, ARGIN(const char **argv))
469   -{
470   - /* ASSERT_ARGS(imcc_run_pbc) */
471   -
472   - IMCC_info(interp, 1, "Running...\n");
473   -
474   - /* runs :init functions */
475   - PackFile_fixup_subs(interp, PBC_MAIN, NULL);
476   -
477   - Parrot_runcode(interp, argc, argv);
478   -}
479   -
480   -/*
481   -
482 466 =item C<static void imcc_write_pbc(PARROT_INTERP, STRING *output_file)>
483 467
484 468 Output packed bytecode file.
@@ -494,10 +478,11 @@ imcc_write_pbc(PARROT_INTERP, ARGIN(STRING *output_file))
494 478 size_t size;
495 479 opcode_t *packed;
496 480 PIOHANDLE fp;
  481 + PackFile_ByteCode * const interp_code = Parrot_pf_get_current_code_segment(interp);
497 482
498 483 IMCC_info(interp, 1, "Writing %Ss\n", output_file);
499 484
500   - size = PackFile_pack_size(interp, interp->code->base.pf) *
  485 + size = PackFile_pack_size(interp, interp_code->base.pf) *
501 486 sizeof (opcode_t);
502 487 IMCC_info(interp, 1, "packed code %d bytes\n", size);
503 488 packed = (opcode_t*) mem_sys_allocate(size);
@@ -523,49 +508,29 @@ imcc_write_pbc(PARROT_INTERP, ARGIN(STRING *output_file))
523 508
524 509 /*
525 510
526   -=item C<static void determine_input_file_type(PARROT_INTERP, STRING *sourcefile,
527   -yyscan_t yyscanner)>
  511 +=item C<static PIOHANDLE determine_input_file_type(PARROT_INTERP, STRING
  512 +*sourcefile)>
528 513
529   -Read in the source and determine whether it's Parrot bytecode or PASM
  514 +Determine whether the sourcefile is a .pir or .pasm file. Sets the appropriate
  515 +flags and returns a C<FILE*> to the opened file.
530 516
531 517 =cut
532 518
533 519 */
534 520
535   -static void
536   -determine_input_file_type(PARROT_INTERP, ARGIN(STRING *sourcefile),
537   - ARGIN(yyscan_t yyscanner))
  521 +static PIOHANDLE
  522 +determine_input_file_type(PARROT_INTERP, ARGIN(STRING *sourcefile))
538 523 {
539 524 ASSERT_ARGS(determine_input_file_type)
540 525
541   - /* Read in the source and check the file extension for the input type;
542   - a file extension .pbc means it's parrot bytecode;
543   - a file extension .pasm means it's parrot assembly (PASM);
544   - otherwise, it's assumed to be PIR.
545   - */
546 526 if (STRING_length(sourcefile) == 1
547 527 && STRING_ord(interp, sourcefile, 0) == '-') {
548   - imc_yyin_set(PIO_STDHANDLE(interp, PIO_STDIN_FILENO), yyscanner);
  528 + return PIO_STDHANDLE(interp, PIO_STDIN_FILENO);
549 529 }
550 530 else {
551   - if (imcc_string_ends_with(interp, sourcefile, ".pbc")) {
552   - /* a PBC file */
553   - SET_STATE_LOAD_PBC(interp);
554   - UNSET_STATE_WRITE_PBC(interp);
555   - }
556   - else if (!STATE_LOAD_PBC(interp)) {
557   - PIOHANDLE file = PIO_OPEN(interp, sourcefile, PIO_F_READ);
558   -
559   - if (file == PIO_INVALID_HANDLE)
560   - IMCC_fatal_standalone(interp, EXCEPTION_EXTERNAL_ERROR,
561   - "Error reading source file %Ss.\n",
562   - sourcefile);
563   -
564   - imc_yyin_set(file, yyscanner);
565   -
566   - if (imcc_string_ends_with(interp, sourcefile, ".pasm"))
567   - SET_STATE_PASM_FILE(interp);
568   - }
  531 + if (imcc_string_ends_with(interp, sourcefile, ".pasm"))
  532 + SET_STATE_PASM_FILE(interp);
  533 + return PIO_OPEN(interp, sourcefile, PIO_F_READ);
569 534 }
570 535 }
571 536
@@ -622,7 +587,10 @@ compile_to_bytecode(PARROT_INTERP,
622 587 opt_desc, opt_level);
623 588
624 589 pf = PackFile_new(interp, 0);
625   - Parrot_pbc_load(interp, pf);
  590 + Parrot_pf_set_current_packfile(interp, pf);
  591 + /* If I comment out the above two lines and replace with this one below,
  592 + Parrot builds and all tests pass. */
  593 + /*pf = Parrot_pf_get_current_packfile(interp);*/
626 594
627 595 IMCC_push_parser_state(interp);
628 596 IMCC_INFO(interp)->state->file = sourcefile;
@@ -669,19 +637,20 @@ PMC interpreter.
669 637
670 638 */
671 639
672   -PARROT_API
  640 +PARROT_EXPORT
673 641 int
674 642 imcc_run_api(ARGMOD(PMC * interp_pmc), ARGIN(STRING *sourcefile), int argc,
675   - ARGIN(const char **argv), ARGOUT(PMC **pbcpmc))
  643 + ARGIN_NULLOK(const char **argv), ARGOUT(PMC **pbcpmc))
676 644 {
677 645 Interp * interp = (Interp *)VTABLE_get_pointer(NULL, interp_pmc);
678   - return imcc_run(interp, sourcefile, argc, argv, pbcpmc);
  646 + STRING *output_file = imcc_parseflags(interp, argc, argv);
  647 + return imcc_run(interp, sourcefile, output_file, pbcpmc);
679 648 }
680 649
681 650 /*
682 651
683   -=item C<int imcc_run(PARROT_INTERP, STRING *sourcefile, int argc, const char
684   -**argv, PMC **pbcpmc)>
  652 +=item C<static int imcc_run(PARROT_INTERP, STRING *sourcefile, STRING
  653 +*output_file, PMC **pbcpmc)>
685 654
686 655 Entry point of IMCC, as invoked by Parrot's main function.
687 656 Compile source code (if required), write bytecode file (if required)
@@ -691,38 +660,33 @@ and run. This function always returns 0.
691 660
692 661 */
693 662
694   -int
695   -imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile), int argc,
696   - ARGIN(const char **argv), ARGOUT(PMC **pbcpmc))
  663 +static int
  664 +imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile),
  665 + ARGIN(STRING *output_file), ARGOUT(PMC **pbcpmc))
697 666 {
698   - yyscan_t yyscanner;
699   - STRING *output_file = interp->output_file;
700   - PackFile *pf_raw = NULL;
  667 + yyscan_t yyscanner;
  668 + PackFile * pf_raw = NULL;
701 669 int is_stdin;
702 670 int is_stdout;
703 671
704 672 *pbcpmc = PMCNULL;
705 673
706   - if (!output_file)
707   - output_file = STRINGNULL;
708   -
709   - imcc_parseflags(interp, argc, argv);
710   -
711   - /* PMCs in IMCC_INFO won't get marked */
712   - Parrot_block_GC_mark(interp);
713   - Parrot_block_GC_sweep(interp);
714   -
715 674 yylex_init_extra(interp, &yyscanner);
716 675
717 676 /* Figure out what kind of source file we have -- if we have one */
718 677 if (!STRING_length(sourcefile))
719 678 IMCC_fatal_standalone(interp, 1, "main: No source file specified.\n");
720   - else
721   - determine_input_file_type(interp, sourcefile, yyscanner);
  679 + else {
  680 + PIOHANDLE in_file = determine_input_file_type(interp, sourcefile);
  681 + if (in_file == PIO_INVALID_HANDLE)
  682 + IMCC_fatal_standalone(interp, EXCEPTION_EXTERNAL_ERROR,
  683 + "Error reading source file %s.\n",
  684 + sourcefile);
  685 + imc_yyin_set(in_file, yyscanner);
  686 + }
722 687
723 688 if (STATE_PRE_PROCESS(interp)) {
724 689 do_pre_process(interp, yyscanner);
725   - Parrot_destroy(interp);
726 690 yylex_destroy(yyscanner);
727 691
728 692 return 0;
@@ -757,7 +721,7 @@ imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile), int argc,
757 721 pf_raw = PackFile_read_pbc(interp, sourcefile, 0);
758 722 if (!pf_raw)
759 723 IMCC_fatal_standalone(interp, 1, "main: Packfile loading failed\n");
760   - Parrot_pbc_load(interp, pf_raw);
  724 + Parrot_pf_set_current_packfile(interp, pf_raw);
761 725 }
762 726 else
763 727 pf_raw = compile_to_bytecode(interp, sourcefile, output_file, yyscanner);
@@ -776,22 +740,11 @@ imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile), int argc,
776 740 pf_raw = PackFile_read_pbc(interp, output_file, 0);
777 741 if (!pf_raw)
778 742 IMCC_fatal_standalone(interp, 1, "Packfile loading failed\n");
779   - Parrot_pbc_load(interp, pf_raw);
  743 + Parrot_pf_set_current_packfile(interp, pf_raw);
780 744 SET_STATE_LOAD_PBC(interp);
781 745 }
782 746 }
783 747
784   - /* tear down the compilation context */
785   - if (IMCC_INFO(interp)->imcc_warn)
786   - PARROT_WARNINGS_on(interp, PARROT_WARNINGS_ALL_FLAG);
787   - else
788   - PARROT_WARNINGS_off(interp, PARROT_WARNINGS_ALL_FLAG);
789   -
790   - if (!IMCC_INFO(interp)->gc_off) {
791   - Parrot_unblock_GC_mark(interp);
792   - Parrot_unblock_GC_sweep(interp);
793   - }
794   -
795 748 yylex_destroy(yyscanner);
796 749
797 750 if (pf_raw) {
@@ -801,14 +754,457 @@ imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile), int argc,
801 754 }
802 755
803 756 /* should the bytecode be run */
804   - if (STATE_RUN_PBC(interp))
805   - return 1;
  757 + return STATE_RUN_PBC(interp) ? 1 : 0;
  758 +}
  759 +
  760 +/*
  761 +
  762 +=item C<PMC * imcc_compile(PARROT_INTERP, const char *s, int pasm_file, STRING
  763 +**error_message)>
  764 +
  765 +Compile a pasm or imcc string
  766 +
  767 +FIXME as we have separate constants, the old constants in ghash must be deleted.
  768 +
  769 +=cut
  770 +
  771 +*/
  772 +
  773 +PARROT_WARN_UNUSED_RESULT
  774 +PARROT_CANNOT_RETURN_NULL
  775 +PMC *
  776 +imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file,
  777 + ARGOUT(STRING **error_message))
  778 +{
  779 + ASSERT_ARGS(imcc_compile)
  780 + /* imcc always compiles to interp->code
  781 + * XXX: This is EXTREMELY bad. IMCC should not write to interp->code
  782 + * save old cs, make new
  783 + */
  784 + STRING *name;
  785 + PackFile_ByteCode *old_cs, *new_cs;
  786 + PMC *eval_pmc = NULL;
  787 + struct _imc_info_t *imc_info = NULL;
  788 + struct parser_state_t *next;
  789 + void *yyscanner;
  790 + PMC *ignored;
  791 + UINTVAL regs_used[4] = {3, 3, 3, 3};
  792 + INTVAL eval_number;
  793 +
  794 + yylex_init_extra(interp, &yyscanner);
  795 +
  796 + /* we create not yet anchored PMCs - e.g. Subs: turn off GC */
  797 + Parrot_block_GC_mark(interp);
  798 +
  799 + if (IMCC_INFO(interp)->last_unit) {
  800 + /* a reentrant compile */
  801 + imc_info = mem_gc_allocate_zeroed_typed(interp, imc_info_t);
  802 + imc_info->ghash = IMCC_INFO(interp)->ghash;
  803 + imc_info->prev = IMCC_INFO(interp);
  804 + IMCC_INFO(interp) = imc_info;
  805 + }
  806 +
  807 + ignored = Parrot_push_context(interp, regs_used);
  808 + UNUSED(ignored);
  809 +
  810 + if (eval_nr == 0)
  811 + MUTEX_INIT(eval_nr_lock);
  812 +
  813 + LOCK(eval_nr_lock);
  814 + eval_number = ++eval_nr;
  815 + UNLOCK(eval_nr_lock);
  816 +
  817 + name = Parrot_sprintf_c(interp, "EVAL_" INTVAL_FMT, eval_number);
  818 + new_cs = PF_create_default_segs(interp, name, 0, 0);
  819 + old_cs = Parrot_switch_to_cs(interp, new_cs, 0);
  820 +
  821 + IMCC_INFO(interp)->cur_namespace = NULL;
  822 +
  823 + /* spit out the sourcefile */
  824 + if (Interp_debug_TEST(interp, PARROT_EVAL_DEBUG_FLAG)) {
  825 + char *buf = Parrot_str_to_cstring(interp, name);
  826 + FILE * const fp = fopen(buf, "w");
  827 + Parrot_str_free_cstring(buf);
  828 + if (fp) {
  829 + fputs(s, fp);
  830 + fclose(fp);
  831 + }
  832 + }
  833 +
  834 + IMCC_push_parser_state(interp);
  835 + next = IMCC_INFO(interp)->state->next;
  836 +
  837 + if (imc_info)
  838 + IMCC_INFO(interp)->state->next = NULL;
  839 +
  840 + IMCC_INFO(interp)->state->pasm_file = pasm_file;
  841 + IMCC_INFO(interp)->state->file = name;
  842 + IMCC_INFO(interp)->expect_pasm = 0;
  843 +
  844 + compile_string(interp, s, yyscanner);
  845 +
  846 + Parrot_pop_context(interp);
  847 +
  848 + /*
  849 + * compile_string NULLifies frames->next, so that yywrap
  850 + * doesn't try to continue compiling the previous buffer
  851 + * This OTOH prevents pop_parser-state ->
  852 + *
  853 + * set next here and pop
  854 + */
  855 + IMCC_INFO(interp)->state->next = next;
  856 + IMCC_pop_parser_state(interp, yyscanner);
  857 +
  858 + if (!IMCC_INFO(interp)->error_code) {
  859 + Parrot_Sub_attributes *sub_data;
  860 +
  861 + /*
  862 + * create sub PMC
  863 + *
  864 + * TODO if a sub was denoted :main return that instead
  865 + */
  866 + eval_pmc = Parrot_pmc_new(interp, enum_class_Eval);
  867 + PMC_get_sub(interp, eval_pmc, sub_data);
  868 + sub_data->seg = new_cs;
  869 + sub_data->start_offs = 0;
  870 + sub_data->end_offs = new_cs->base.size;
  871 + sub_data->name = name;
  872 +
  873 + *error_message = NULL;
  874 + }
  875 + else {
  876 + PackFile_Segment_destroy(interp, (PackFile_Segment *)new_cs);
  877 + *error_message = IMCC_INFO(interp)->error_message;
  878 + }
  879 +
  880 + if (imc_info) {
  881 + SymReg *ns = IMCC_INFO(interp)->cur_namespace;
  882 + IMCC_INFO(interp) = imc_info->prev;
  883 + mem_sys_free(imc_info);
  884 + imc_info = IMCC_INFO(interp);
  885 + IMCC_INFO(interp)->cur_unit = imc_info->last_unit;
  886 +
  887 + if (ns && ns != imc_info->cur_namespace)
  888 + free_sym(ns);
  889 +
  890 + IMCC_INFO(interp)->cur_namespace = imc_info->cur_namespace;
  891 + }
806 892 else
807   - return 0;
  893 + imc_cleanup(interp, yyscanner);
  894 +
  895 + Parrot_unblock_GC_mark(interp);
  896 +
  897 + yylex_destroy(yyscanner);
  898 +
  899 + /* Now run any :load/:init subs. */
  900 + if (!*error_message)
  901 + PackFile_fixup_subs(interp, PBC_MAIN, eval_pmc);
  902