Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@nwellnhof nwellnhof authored
Showing with 6,018 additions and 5,535 deletions.
  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
View
2  .gitignore
@@ -37,6 +37,7 @@
/blib
/config_lib.pir
/cover_db
+/generated_hello.pbc
/install_config.fpmc
/installable*
/libparrot.def
@@ -443,6 +444,7 @@
/t/src/*_*
/t/src/*.gcov
/t/src/*.gcdada
+/t/src/embed/*.c
/t/stress/*.out
/t/stress/*.pasm
/t/stress/*.pbc
View
19 CREDITS
@@ -57,7 +57,7 @@ U: heimdall
E: Nattfodd@gmail.com
N: Allison Randal
-D: Architect (0.4.6...) & Lead Developer
+D: Architect (0.4.6 - 2.8.0) & Lead Developer
E: allison@parrot.org
U: allison
@@ -224,8 +224,8 @@ U: creiss
E: creiss@cc.gatech.edu
N: Chip Salzenberg
-D: Release manager emeritus (0.4.6-0.4.7)
-D: Architect emeritus (0.1.2-0.4.5)
+D: Release manager emeritus (0.4.6 - 0.4.7)
+D: Architect emeritus (0.1.2 - 0.4.5)
U: chip
E: chip@pobox.com
@@ -243,12 +243,11 @@ D: Rakudo patches
N: Christoph Otto
U: cotto
-D: Patch for key flags in pdd08
+D: Architect (2.9.0 - current)
D: Range check in Env PMC
A: christoph_googleacct@mksig.org
A: christop...@mksig.org
A: Christoph Otto
-D: Pipp, Lorito taskmaster
E: christoph@mksig.org
N: chromatic
@@ -299,9 +298,13 @@ N: Damian Miles Knopp
U: dmknopp
E: dmknopp@loyola.edu
+N: Daniel Kang
+U: jumpyshoes
+D: improve pbc_disassemble's test coverage
+
N: Dan Sugalski
U: dan
-D: Architect emeritus (0.0.1-0.1.1)
+D: Architect emeritus (0.0.1 - 0.1.1)
E: dan@sidhe.org
W: http://www.sidhe.org/~dan/blog/
@@ -679,6 +682,10 @@ U: LylePerl
D: Win32 and CGI testing
W: http://perl.bristolbath.org/blog/lyle/
+N: Mariano Wahlmann
+E: dichoso@gmail.com
+A: bluescreen
+
N: Marcelo Serra Castilhos
E: mhelix@terra.com.br
D: Bug fix
View
8 ChangeLog
@@ -1,8 +1,12 @@
#1 $Id$
+2011.01.18 cotto
+ * Released 3.0.0
+ See NEWS for more.
+
2010.12.21 Whiteknight
- * Released 2.11.0
- See NEWS for more.
+ * Released 2.11.0
+ See NEWS for more.
2010.11.16 tcurtis
* Released 2.10.0
View
17 DEPRECATED.pod
@@ -141,6 +141,23 @@ to work on this type.
L<http://trac.parrot.org/parrot/ticket/1904>
+=item The Eval PMC [eligible in 3.1]
+
+The Eval PMC will be removed. Uses of it returned from compilers will be
+replaced with PackFile PMCs instead.
+
+L<http://trac.parrot.org/parrot/ticket/1969>
+
+=item The PIR and PASM compreg PMCs [eligible in 3.1]
+
+The PMC returned by C<compreg "PIR"> is not going to be an NCI PMC any longer,
+it will be a new type of PMC which conforms to PDD31 and will be similar to
+HLLCompiler.
+
+There will not be a PASM compreg anymore.
+
+L<http://trac.parrot.org/parrot/ticket/1967>
+
=back
=head1 Opcodes
View
3  MANIFEST
@@ -399,7 +399,6 @@ docs/pdds/draft/pdd01_overview.pod [doc]
docs/pdds/draft/pdd05_opfunc.pod [doc]
docs/pdds/draft/pdd06_pasm.pod [doc]
docs/pdds/draft/pdd08_keys.pod [doc]
-docs/pdds/draft/pdd10_embedding.pod [doc]
docs/pdds/draft/pdd11_extending.pod [doc]
docs/pdds/draft/pdd14_numbers.pod [doc]
docs/pdds/draft/pdd16_native_call.pod [doc]
@@ -409,6 +408,7 @@ docs/pdds/pdd00_pdd.pod [doc]
docs/pdds/pdd03_calling_conventions.pod [doc]
docs/pdds/pdd07_codingstd.pod [doc]
docs/pdds/pdd09_gc.pod [doc]
+docs/pdds/pdd10_embedding.pod [doc]
docs/pdds/pdd13_bytecode.pod [doc]
docs/pdds/pdd15_object_metamodel.png [doc]
docs/pdds/pdd15_object_metamodel.svg [doc]
@@ -952,7 +952,6 @@ include/parrot/global_setup.h [main]include
include/parrot/hash.h [main]include
include/parrot/hll.h [main]include
include/parrot/imageio.h [main]include
-include/parrot/imcc.h [main]include
include/parrot/interpreter.h [main]include
include/parrot/io.h [main]include
include/parrot/io_portable.h [main]include
View
4 MANIFEST.SKIP
@@ -350,6 +350,8 @@
^/frontend/pbc_merge/.*\.gcov/
^/frontend/pbc_merge/main\.o$
^/frontend/pbc_merge/main\.o/
+^/generated_hello\.pbc$
+^/generated_hello\.pbc/
^/include/parrot/.*\.tmp$
^/include/parrot/.*\.tmp/
^/include/parrot/config\.h$
@@ -980,6 +982,8 @@
^/t/src/.*\.gcov/
^/t/src/.*_.*$
^/t/src/.*_.*/
+^/t/src/embed/.*\.c$
+^/t/src/embed/.*\.c/
^/t/stress/.*\.out$
^/t/stress/.*\.out/
^/t/stress/.*\.pasm$
View
4 MANIFEST.generated
@@ -1,11 +1,11 @@
# See tools/dev/install_files.pl for documentation on the
# format of this file.
# Please re-sort this file after *EVERY* modification
-blib/lib/libparrot.2.11.0.dylib [main]lib
+blib/lib/libparrot.3.0.0.dylib [main]lib
blib/lib/libparrot.a [main]lib
blib/lib/libparrot.dylib [main]lib
blib/lib/libparrot.so [main]lib
-blib/lib/libparrot.so.2.11.0 [main]lib
+blib/lib/libparrot.so.3.0.0 [main]lib
compilers/data_json/data_json.pbc [data_json]
config/gen/call_list/opengl.in []
docs/ops/bit.pod [doc]
View
42 NEWS
@@ -1,10 +1,42 @@
New in 3.0.0
- Core
- + Added a new embedding API in "parrot/api.h"
- + Removed autovivification behavior from ResizablePMCArray
- + Packfile manipulation functions now throw exceptions on error instead of printing error details directly to stderr
- + Test coverage for several PMC types has been significantly increased
- + Test coverage for several internal subsystems has been increased
+ + A new embedding API is available in "parrot/api.h" and documented in
+ docs/pdd/pdd10_embedding.pod .
+ + Packfile PMCs were refactored and can now be used to produce runnable bytecode.
+ + Packfile manipulation code now throws embedder-friendly exceptions rather
+ than printing error details directly to stderr.
+ + Unicode support for file IO, environment variables, program names, and
+ command-line parameters was improved.
+ + An experimental gdb pretty-printers in tools/dev for Parrot STRINGs and
+ PMCs is now available. (gdb 7.2 or later and Python are required)
+ + c2str.pl and pmc2c.pl improvements result in a noticably faster build.
+ + Bugs in our Digest::sha256 library and bit-related dynamic ops were fixed
+ by GCI student Nolan Lum. Both now work correctly on 32 and 64 bit systems.
+- Languages
+ + Ωη;)XD - OMeta for Winxed https://github.com/plobsing/ohm-eta-wink-kzd
+- Community
+ + tree-optimization by GSoC student Tyler L. Curtis joined the nest and now
+ lives at http://github.com/parrot/tree-optimization .
+ + Plumage now lives at http://github.com/parrot/plumage and is installable.
+ + Christmas proceeded as scheduled. The Parrot team does not take credit for
+ this event.
+- Documentation
+ + HTML documentation generation has been rewritten and greatly simplified.
+ + We have improved documentation in docs/project/git_workflow.pod about
+ keeping a fork of parrot.git in sync.
+ + Translations of our README in various languages are now in the
+ docs/translation directory, thanks to Google Code-In students.
+- Tests
+ + A better way to write "todo" tests with Parrot's Test::More was implemented
+ by GCI student Fernando Brito.
+ + Major increases in test coverage of many core PMCs, dynamic PMCs and
+ dynamic opcodes resulted from GCI and the interpid students it attracted.
+ + Jonathan "Duke" Leto set up Debian Linux x86_64 and sparc32 smokers
+ in the GCC Compile Farm, which continually submit smoke reports with
+ a variety of configuration options and compilers. Thanks, GCC!
+ + Makefile dependency checking is now automatically tested, resulting in a
+ more reliable parallel build.
+ + Coverage tests were improved for platforms with and without Devel::Cover.
New in 2.11.0
- Core
View
5 PBC_COMPAT
@@ -28,10 +28,7 @@
# please insert tab separated entries at the top of the list
-9.4 2011.1.2 plobsing track :main subs in packfiles
-9.3 2010.11.24 NotFound move op find_codepoint out of experimental TT #1629
-9.2 2010.11.21 plobsing remove CodeString PMC
-9.1 2010.10.27 nwellnhof remove charset ops
+10.0 2011.01.18 cotto released 3.0.0
9.0 2010.10.19 gerd released 2.9.0
8.0 2010.07.20 coke released 2.6.0
7.0 2010.04.20 gerd released 2.3.0 (version # added ex post facto, as all previous version #s were published)
View
2  PLATFORMS
@@ -12,6 +12,7 @@ Supported platforms:
Platform B8 Runloops Feature Comp Test Inst YYYYMMDD
CGoto EXEC Thr Sig
--------------------------------------------------------------------------------
+linux-sparc64-gcc-4.3.2 ? Y Y 20110114
cygwin1.5.25-x86-gcc3.4.4 4 Y - - - Y Y Y 20090315
darwin8.11.1-x86-gcc4.0.1 ?? Y ? ? ? Y Y N 20091020
linux-x86-gcc4.1.2 Y ? Y Y Y Y ? 20090419
@@ -83,7 +84,6 @@ B ... Processor is big endian
4 ... opcode_t is 4 byte, --m=32 on a 64 bit machine
CGoto ... CGoto runloop is supported
-JIT ... JIT core is supported
EXEC ... compiling to native executables is supported
Thr ... Parrot is multi-threaded
Sig ... Parrot catches a SIGHUP signal
View
2  README
@@ -1,4 +1,4 @@
-This is Parrot, version 2.11.0
+This is Parrot, version 3.0.0
------------------------------
Parrot is Copyright (C) 2001-2011, Parrot Foundation.
View
2  VERSION
@@ -1 +1 @@
-2.11.0
+3.0.0
View
3  compilers/imcc/Rules.in
@@ -148,17 +148,18 @@ compilers/imcc/main$(O) : \
compilers/imcc/imc.h \
compilers/imcc/imcparser.h \
compilers/imcc/instructions.h \
+ compilers/imcc/optimizer.h \
compilers/imcc/parser.h \
compilers/imcc/pbc.h \
compilers/imcc/sets.h \
compilers/imcc/symreg.h \
compilers/imcc/unit.h \
$(INC_DIR)/embed.h \
- $(INC_DIR)/imcc.h \
$(INC_DIR)/oplib/ops.h \
$(INC_DIR)/runcore_api.h \
$(INC_DIR)/api.h \
$(INC_DIR)/longopt.h \
+ include/pmc/pmc_sub.h \
$(PARROT_H_HEADERS)
## SUFFIX OVERRIDE - Warnings (This is generated code)
View
3  compilers/imcc/debug.c
@@ -115,9 +115,6 @@ IMCC_warning(PARROT_INTERP, ARGIN(const char *fmt), ...)
{
ASSERT_ARGS(IMCC_warning)
va_list ap;
- if (IMCC_INFO(interp)->imcc_warn)
- return;
-
va_start(ap, fmt);
imcc_vfprintf(interp, Parrot_io_STDERR(interp), fmt, ap);
va_end(ap);
View
217 compilers/imcc/imc.h
@@ -61,6 +61,114 @@ enum {
#define N_ELEMENTS(x) (sizeof (x)/sizeof ((x)[0]))
+/* HEADERIZER BEGIN: compilers/imcc/main.c */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+void * imcc_compile_file(PARROT_INTERP,
+ ARGIN(STRING *fullname),
+ ARGOUT(STRING **error_message))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(*error_message);
+
+PARROT_EXPORT
+int imcc_run_api(
+ ARGMOD(PMC * interp_pmc),
+ ARGIN(STRING *sourcefile),
+ int argc,
+ ARGIN_NULLOK(const char **argv),
+ ARGOUT(PMC **pbcpmc))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(5)
+ FUNC_MODIFIES(* interp_pmc)
+ FUNC_MODIFIES(*pbcpmc);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC * imcc_compile(PARROT_INTERP,
+ ARGIN(const char *s),
+ int pasm_file,
+ ARGOUT(STRING **error_message))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(4)
+ FUNC_MODIFIES(*error_message);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC * imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC * IMCC_compile_pasm_s(PARROT_INTERP,
+ ARGIN(const char *s),
+ ARGOUT(STRING **error_message))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(*error_message);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC * imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC * IMCC_compile_pir_s(PARROT_INTERP,
+ ARGIN(const char *s),
+ ARGOUT(STRING **error_message))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(*error_message);
+
+void imcc_destroy(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
+void imcc_init(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
+#define ASSERT_ARGS_imcc_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(fullname) \
+ , PARROT_ASSERT_ARG(error_message))
+#define ASSERT_ARGS_imcc_run_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp_pmc) \
+ , PARROT_ASSERT_ARG(sourcefile) \
+ , PARROT_ASSERT_ARG(pbcpmc))
+#define ASSERT_ARGS_imcc_compile __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(s) \
+ , PARROT_ASSERT_ARG(error_message))
+#define ASSERT_ARGS_imcc_compile_pasm_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(s))
+#define ASSERT_ARGS_IMCC_compile_pasm_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(s) \
+ , PARROT_ASSERT_ARG(error_message))
+#define ASSERT_ARGS_imcc_compile_pir_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(s))
+#define ASSERT_ARGS_IMCC_compile_pir_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(s) \
+ , PARROT_ASSERT_ARG(error_message))
+#define ASSERT_ARGS_imcc_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_imcc_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+/* HEADERIZER END: compilers/imcc/main.c */
+
/* HEADERIZER BEGIN: compilers/imcc/imcc.y */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
@@ -183,16 +291,6 @@ Instruction * INS_LABEL(PARROT_INTERP,
/* HEADERIZER BEGIN: compilers/imcc/parser_util.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-PARROT_EXPORT
-PARROT_CANNOT_RETURN_NULL
-void * imcc_compile_file(PARROT_INTERP,
- ARGIN(STRING *fullname),
- ARGOUT(STRING **error_message))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- FUNC_MODIFIES(*error_message);
-
void check_op(PARROT_INTERP,
ARGOUT(op_info_t **op_info),
ARGOUT(char *fullname),
@@ -208,67 +306,6 @@ void check_op(PARROT_INTERP,
FUNC_MODIFIES(*op_info)
FUNC_MODIFIES(*fullname);
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC * imcc_compile(PARROT_INTERP,
- ARGIN(const char *s),
- int pasm_file,
- ARGOUT(STRING **error_message))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(4)
- FUNC_MODIFIES(*error_message);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC * imcc_compile_pasm(PARROT_INTERP, ARGIN(const char *s))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC * imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC * IMCC_compile_pasm_s(PARROT_INTERP,
- ARGIN(const char *s),
- ARGOUT(STRING **error_message))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- FUNC_MODIFIES(*error_message);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC * imcc_compile_pir(PARROT_INTERP, ARGIN(const char *s))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC * imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC * IMCC_compile_pir_s(PARROT_INTERP,
- ARGIN(const char *s),
- ARGOUT(STRING **error_message))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- FUNC_MODIFIES(*error_message);
-
-void imcc_destroy(PARROT_INTERP)
- __attribute__nonnull__(1);
-
-void imcc_init(PARROT_INTERP)
- __attribute__nonnull__(1);
-
int imcc_string_ends_with(PARROT_INTERP,
ARGIN(const STRING *str),
ARGIN(const char *ext))
@@ -319,47 +356,12 @@ void op_fullname(
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
-void register_compilers(PARROT_INTERP)
- __attribute__nonnull__(1);
-
-#define ASSERT_ARGS_imcc_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(fullname) \
- , PARROT_ASSERT_ARG(error_message))
#define ASSERT_ARGS_check_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(op_info) \
, PARROT_ASSERT_ARG(fullname) \
, PARROT_ASSERT_ARG(name) \
, PARROT_ASSERT_ARG(r))
-#define ASSERT_ARGS_imcc_compile __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s) \
- , PARROT_ASSERT_ARG(error_message))
-#define ASSERT_ARGS_imcc_compile_pasm __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
-#define ASSERT_ARGS_imcc_compile_pasm_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
-#define ASSERT_ARGS_IMCC_compile_pasm_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s) \
- , PARROT_ASSERT_ARG(error_message))
-#define ASSERT_ARGS_imcc_compile_pir __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
-#define ASSERT_ARGS_imcc_compile_pir_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
-#define ASSERT_ARGS_IMCC_compile_pir_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s) \
- , PARROT_ASSERT_ARG(error_message))
-#define ASSERT_ARGS_imcc_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_imcc_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_imcc_string_ends_with __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(str) \
@@ -380,8 +382,6 @@ void register_compilers(PARROT_INTERP)
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(name) \
, PARROT_ASSERT_ARG(args))
-#define ASSERT_ARGS_register_compilers __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: compilers/imcc/parser_util.c */
@@ -559,7 +559,6 @@ typedef struct _imc_info_t {
int emitter;
int error_code; /* The Error code. */
int expect_pasm;
- int gc_off;
int imcc_warn;
int in_pod;
int ins_line;
View
2  compilers/imcc/imcparser.c
@@ -12,8 +12,6 @@
/* A Bison parser, made by GNU Bison 2.4.1. */
-/* A Bison parser, made by GNU Bison 2.4.1. */
-
/* Skeleton implementation for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
View
2  compilers/imcc/imcparser.h
@@ -12,8 +12,6 @@
/* A Bison parser, made by GNU Bison 2.4.1. */
-/* A Bison parser, made by GNU Bison 2.4.1. */
-
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
View
660 compilers/imcc/main.c
@@ -31,15 +31,20 @@ IMCC helpers.
#include "imc.h"
#include "parrot/embed.h"
#include "parrot/longopt.h"
-#include "parrot/imcc.h"
#include "parrot/runcore_api.h"
#include "pmc/pmc_callcontext.h"
+#include "pmc/pmc_sub.h"
#include "pbc.h"
#include "parser.h"
+#include "optimizer.h"
extern int yydebug;
-/* HEADERIZER HFILE: none */
+/* XXX non-reentrant */
+static Parrot_mutex eval_nr_lock;
+static INTVAL eval_nr = 0;
+
+/* HEADERIZER HFILE: compilers/imcc/imc.h */
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
@@ -55,12 +60,10 @@ static PackFile * compile_to_bytecode(PARROT_INTERP,
__attribute__nonnull__(3)
__attribute__nonnull__(4);
-static void determine_input_file_type(PARROT_INTERP,
- ARGIN(STRING *sourcefile),
- ARGIN(yyscan_t yyscanner))
+static PIOHANDLE determine_input_file_type(PARROT_INTERP,
+ ARGIN(STRING *sourcefile))
__attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3);
+ __attribute__nonnull__(2);
static void determine_output_file_type(PARROT_INTERP,
ARGIN(STRING *output_file))
@@ -70,6 +73,10 @@ static void determine_output_file_type(PARROT_INTERP,
static void do_pre_process(PARROT_INTERP, yyscan_t yyscanner)
__attribute__nonnull__(1);
+static void imcc_destroy_macro_values(ARGMOD(void *value))
+ __attribute__nonnull__(1)
+ FUNC_MODIFIES(*value);
+
static void imcc_get_optimization_description(
const PARROT_INTERP,
int opt_level,
@@ -77,11 +84,20 @@ static void imcc_get_optimization_description(
__attribute__nonnull__(3)
FUNC_MODIFIES(*opt_desc);
-static void imcc_parseflags(PARROT_INTERP,
+static STRING * imcc_parseflags(PARROT_INTERP,
int argc,
- ARGIN(const char **argv))
+ ARGIN_NULLOK(const char **argv))
+ __attribute__nonnull__(1);
+
+static int imcc_run(PARROT_INTERP,
+ ARGIN(STRING *sourcefile),
+ ARGIN(STRING *output_file),
+ ARGOUT(PMC **pbcpmc))
__attribute__nonnull__(1)
- __attribute__nonnull__(3);
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ __attribute__nonnull__(4)
+ FUNC_MODIFIES(*pbcpmc);
static void imcc_write_pbc(PARROT_INTERP, ARGIN(STRING *output_file))
__attribute__nonnull__(1)
@@ -103,19 +119,24 @@ static const struct longopt_opt_decl * Parrot_cmd_options(void);
, PARROT_ASSERT_ARG(yyscanner))
#define ASSERT_ARGS_determine_input_file_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(sourcefile) \
- , PARROT_ASSERT_ARG(yyscanner))
+ , PARROT_ASSERT_ARG(sourcefile))
#define ASSERT_ARGS_determine_output_file_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(output_file))
#define ASSERT_ARGS_do_pre_process __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_imcc_destroy_macro_values __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(value))
#define ASSERT_ARGS_imcc_get_optimization_description \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(opt_desc))
#define ASSERT_ARGS_imcc_parseflags __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_imcc_run __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(argv))
+ , PARROT_ASSERT_ARG(sourcefile) \
+ , PARROT_ASSERT_ARG(output_file) \
+ , PARROT_ASSERT_ARG(pbcpmc))
#define ASSERT_ARGS_imcc_write_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(output_file))
@@ -213,7 +234,8 @@ Parrot_cmd_options(void)
/*
-=item C<static void imcc_parseflags(PARROT_INTERP, int argc, const char **argv)>
+=item C<static STRING * imcc_parseflags(PARROT_INTERP, int argc, const char
+**argv)>
Parse flags ans set approptiate state(s)
@@ -221,14 +243,17 @@ Parse flags ans set approptiate state(s)
*/
-static void
-imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
+static STRING *
+imcc_parseflags(PARROT_INTERP, int argc, ARGIN_NULLOK(const char **argv))
{
ASSERT_ARGS(imcc_parseflags)
struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
+ STRING *output_file = STRINGNULL;
/* default state: run pbc */
SET_STATE_RUN_PBC(interp);
+ if (!argv)
+ return STRINGNULL;
while (longopt_get(argc, argv, Parrot_cmd_options(), &opt) > 0) {
switch (opt.opt_id) {
@@ -240,25 +265,9 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
IMCC_INFO(interp)->debug++;
}
break;
- case 'w':
- /* FIXME It's not best way to set warnings... */
- Parrot_setwarnings(interp, PARROT_WARNINGS_ALL_FLAG);
- IMCC_INFO(interp)->imcc_warn = 1;
- break;
- case 'G':
- IMCC_INFO(interp)->gc_off = 1;
- break;
case 'a':
SET_STATE_PASM_FILE(interp);
break;
- case 'r':
- if (STATE_RUN_PBC(interp))
- SET_STATE_RUN_FROM_FILE(interp);
- SET_STATE_RUN_PBC(interp);
- break;
- case 'c':
- SET_STATE_LOAD_PBC(interp);
- break;
case 'v':
IMCC_INFO(interp)->verbose++;
break;
@@ -270,15 +279,14 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
break;
case 'o':
UNSET_STATE_RUN_PBC(interp);
- interp->output_file = Parrot_str_from_platform_cstring(interp,
- opt.opt_arg);
+ output_file = Parrot_str_from_platform_cstring(interp, opt.opt_arg);
break;
case OPT_PBC_OUTPUT:
UNSET_STATE_RUN_PBC(interp);
SET_STATE_WRITE_PBC(interp);
- if (!interp->output_file)
- interp->output_file = Parrot_str_new(interp, "-", 1);
+ if (!STRING_IS_NULL(output_file))
+ output_file = Parrot_str_new(interp, "-", 1);
break;
case 'O':
@@ -305,6 +313,7 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
break;
}
}
+ return output_file;
}
/*
@@ -454,31 +463,6 @@ imcc_get_optimization_description(const PARROT_INTERP, int opt_level, ARGMOD(cha
/*
-=item C<void imcc_run_pbc(PARROT_INTERP, STRING *output_file, int argc, const
-char **argv)>
-
-Write out or run Parrot bytecode.
-
-=cut
-
-*/
-
-void
-imcc_run_pbc(PARROT_INTERP, SHIM(STRING *output_file),
- int argc, ARGIN(const char **argv))
-{
- /* ASSERT_ARGS(imcc_run_pbc) */
-
- IMCC_info(interp, 1, "Running...\n");
-
- /* runs :init functions */
- PackFile_fixup_subs(interp, PBC_MAIN, NULL);
-
- Parrot_runcode(interp, argc, argv);
-}
-
-/*
-
=item C<static void imcc_write_pbc(PARROT_INTERP, STRING *output_file)>
Output packed bytecode file.
@@ -494,10 +478,11 @@ imcc_write_pbc(PARROT_INTERP, ARGIN(STRING *output_file))
size_t size;
opcode_t *packed;
PIOHANDLE fp;
+ PackFile_ByteCode * const interp_code = Parrot_pf_get_current_code_segment(interp);
IMCC_info(interp, 1, "Writing %Ss\n", output_file);
- size = PackFile_pack_size(interp, interp->code->base.pf) *
+ size = PackFile_pack_size(interp, interp_code->base.pf) *
sizeof (opcode_t);
IMCC_info(interp, 1, "packed code %d bytes\n", size);
packed = (opcode_t*) mem_sys_allocate(size);
@@ -523,49 +508,29 @@ imcc_write_pbc(PARROT_INTERP, ARGIN(STRING *output_file))
/*
-=item C<static void determine_input_file_type(PARROT_INTERP, STRING *sourcefile,
-yyscan_t yyscanner)>
+=item C<static PIOHANDLE determine_input_file_type(PARROT_INTERP, STRING
+*sourcefile)>
-Read in the source and determine whether it's Parrot bytecode or PASM
+Determine whether the sourcefile is a .pir or .pasm file. Sets the appropriate
+flags and returns a C<FILE*> to the opened file.
=cut
*/
-static void
-determine_input_file_type(PARROT_INTERP, ARGIN(STRING *sourcefile),
- ARGIN(yyscan_t yyscanner))
+static PIOHANDLE
+determine_input_file_type(PARROT_INTERP, ARGIN(STRING *sourcefile))
{
ASSERT_ARGS(determine_input_file_type)
- /* Read in the source and check the file extension for the input type;
- a file extension .pbc means it's parrot bytecode;
- a file extension .pasm means it's parrot assembly (PASM);
- otherwise, it's assumed to be PIR.
- */
if (STRING_length(sourcefile) == 1
&& STRING_ord(interp, sourcefile, 0) == '-') {
- imc_yyin_set(PIO_STDHANDLE(interp, PIO_STDIN_FILENO), yyscanner);
+ return PIO_STDHANDLE(interp, PIO_STDIN_FILENO);
}
else {
- if (imcc_string_ends_with(interp, sourcefile, ".pbc")) {
- /* a PBC file */
- SET_STATE_LOAD_PBC(interp);
- UNSET_STATE_WRITE_PBC(interp);
- }
- else if (!STATE_LOAD_PBC(interp)) {
- PIOHANDLE file = PIO_OPEN(interp, sourcefile, PIO_F_READ);
-
- if (file == PIO_INVALID_HANDLE)
- IMCC_fatal_standalone(interp, EXCEPTION_EXTERNAL_ERROR,
- "Error reading source file %Ss.\n",
- sourcefile);
-
- imc_yyin_set(file, yyscanner);
-
- if (imcc_string_ends_with(interp, sourcefile, ".pasm"))
- SET_STATE_PASM_FILE(interp);
- }
+ if (imcc_string_ends_with(interp, sourcefile, ".pasm"))
+ SET_STATE_PASM_FILE(interp);
+ return PIO_OPEN(interp, sourcefile, PIO_F_READ);
}
}
@@ -622,7 +587,10 @@ compile_to_bytecode(PARROT_INTERP,
opt_desc, opt_level);
pf = PackFile_new(interp, 0);
- Parrot_pbc_load(interp, pf);
+ Parrot_pf_set_current_packfile(interp, pf);
+ /* If I comment out the above two lines and replace with this one below,
+ Parrot builds and all tests pass. */
+ /*pf = Parrot_pf_get_current_packfile(interp);*/
IMCC_push_parser_state(interp);
IMCC_INFO(interp)->state->file = sourcefile;
@@ -669,19 +637,20 @@ PMC interpreter.
*/
-PARROT_API
+PARROT_EXPORT
int
imcc_run_api(ARGMOD(PMC * interp_pmc), ARGIN(STRING *sourcefile), int argc,
- ARGIN(const char **argv), ARGOUT(PMC **pbcpmc))
+ ARGIN_NULLOK(const char **argv), ARGOUT(PMC **pbcpmc))
{
Interp * interp = (Interp *)VTABLE_get_pointer(NULL, interp_pmc);
- return imcc_run(interp, sourcefile, argc, argv, pbcpmc);
+ STRING *output_file = imcc_parseflags(interp, argc, argv);
+ return imcc_run(interp, sourcefile, output_file, pbcpmc);
}
/*
-=item C<int imcc_run(PARROT_INTERP, STRING *sourcefile, int argc, const char
-**argv, PMC **pbcpmc)>
+=item C<static int imcc_run(PARROT_INTERP, STRING *sourcefile, STRING
+*output_file, PMC **pbcpmc)>
Entry point of IMCC, as invoked by Parrot's main function.
Compile source code (if required), write bytecode file (if required)
@@ -691,38 +660,33 @@ and run. This function always returns 0.
*/
-int
-imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile), int argc,
- ARGIN(const char **argv), ARGOUT(PMC **pbcpmc))
+static int
+imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile),
+ ARGIN(STRING *output_file), ARGOUT(PMC **pbcpmc))
{
- yyscan_t yyscanner;
- STRING *output_file = interp->output_file;
- PackFile *pf_raw = NULL;
+ yyscan_t yyscanner;
+ PackFile * pf_raw = NULL;
int is_stdin;
int is_stdout;
*pbcpmc = PMCNULL;
- if (!output_file)
- output_file = STRINGNULL;
-
- imcc_parseflags(interp, argc, argv);
-
- /* PMCs in IMCC_INFO won't get marked */
- Parrot_block_GC_mark(interp);
- Parrot_block_GC_sweep(interp);
-
yylex_init_extra(interp, &yyscanner);
/* Figure out what kind of source file we have -- if we have one */
if (!STRING_length(sourcefile))
IMCC_fatal_standalone(interp, 1, "main: No source file specified.\n");
- else
- determine_input_file_type(interp, sourcefile, yyscanner);
+ else {
+ PIOHANDLE in_file = determine_input_file_type(interp, sourcefile);
+ if (in_file == PIO_INVALID_HANDLE)
+ IMCC_fatal_standalone(interp, EXCEPTION_EXTERNAL_ERROR,
+ "Error reading source file %s.\n",
+ sourcefile);
+ imc_yyin_set(in_file, yyscanner);
+ }
if (STATE_PRE_PROCESS(interp)) {
do_pre_process(interp, yyscanner);
- Parrot_destroy(interp);
yylex_destroy(yyscanner);
return 0;
@@ -757,7 +721,7 @@ imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile), int argc,
pf_raw = PackFile_read_pbc(interp, sourcefile, 0);
if (!pf_raw)
IMCC_fatal_standalone(interp, 1, "main: Packfile loading failed\n");
- Parrot_pbc_load(interp, pf_raw);
+ Parrot_pf_set_current_packfile(interp, pf_raw);
}
else
pf_raw = compile_to_bytecode(interp, sourcefile, output_file, yyscanner);
@@ -776,22 +740,11 @@ imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile), int argc,
pf_raw = PackFile_read_pbc(interp, output_file, 0);
if (!pf_raw)
IMCC_fatal_standalone(interp, 1, "Packfile loading failed\n");
- Parrot_pbc_load(interp, pf_raw);
+ Parrot_pf_set_current_packfile(interp, pf_raw);
SET_STATE_LOAD_PBC(interp);
}
}
- /* tear down the compilation context */
- if (IMCC_INFO(interp)->imcc_warn)
- PARROT_WARNINGS_on(interp, PARROT_WARNINGS_ALL_FLAG);
- else
- PARROT_WARNINGS_off(interp, PARROT_WARNINGS_ALL_FLAG);
-
- if (!IMCC_INFO(interp)->gc_off) {
- Parrot_unblock_GC_mark(interp);
- Parrot_unblock_GC_sweep(interp);
- }
-
yylex_destroy(yyscanner);
if (pf_raw) {
@@ -801,14 +754,457 @@ imcc_run(PARROT_INTERP, ARGIN(STRING *sourcefile), int argc,
}
/* should the bytecode be run */
- if (STATE_RUN_PBC(interp))
- return 1;
+ return STATE_RUN_PBC(interp) ? 1 : 0;
+}
+
+/*
+
+=item C<PMC * imcc_compile(PARROT_INTERP, const char *s, int pasm_file, STRING
+**error_message)>
+
+Compile a pasm or imcc string
+
+FIXME as we have separate constants, the old constants in ghash must be deleted.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC *
+imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file,
+ ARGOUT(STRING **error_message))
+{
+ ASSERT_ARGS(imcc_compile)
+ /* imcc always compiles to interp->code
+ * XXX: This is EXTREMELY bad. IMCC should not write to interp->code
+ * save old cs, make new
+ */
+ STRING *name;
+ PackFile_ByteCode *old_cs, *new_cs;
+ PMC *eval_pmc = NULL;
+ struct _imc_info_t *imc_info = NULL;
+ struct parser_state_t *next;
+ void *yyscanner;
+ PMC *ignored;
+ UINTVAL regs_used[4] = {3, 3, 3, 3};
+ INTVAL eval_number;
+
+ yylex_init_extra(interp, &yyscanner);
+
+ /* we create not yet anchored PMCs - e.g. Subs: turn off GC */
+ Parrot_block_GC_mark(interp);
+
+ if (IMCC_INFO(interp)->last_unit) {
+ /* a reentrant compile */
+ imc_info = mem_gc_allocate_zeroed_typed(interp, imc_info_t);
+ imc_info->ghash = IMCC_INFO(interp)->ghash;
+ imc_info->prev = IMCC_INFO(interp);
+ IMCC_INFO(interp) = imc_info;
+ }
+
+ ignored = Parrot_push_context(interp, regs_used);
+ UNUSED(ignored);
+
+ if (eval_nr == 0)
+ MUTEX_INIT(eval_nr_lock);
+
+ LOCK(eval_nr_lock);
+ eval_number = ++eval_nr;
+ UNLOCK(eval_nr_lock);
+
+ name = Parrot_sprintf_c(interp, "EVAL_" INTVAL_FMT, eval_number);
+ new_cs = PF_create_default_segs(interp, name, 0, 0);
+ old_cs = Parrot_switch_to_cs(interp, new_cs, 0);
+
+ IMCC_INFO(interp)->cur_namespace = NULL;
+
+ /* spit out the sourcefile */
+ if (Interp_debug_TEST(interp, PARROT_EVAL_DEBUG_FLAG)) {
+ char *buf = Parrot_str_to_cstring(interp, name);
+ FILE * const fp = fopen(buf, "w");
+ Parrot_str_free_cstring(buf);
+ if (fp) {
+ fputs(s, fp);
+ fclose(fp);
+ }
+ }
+
+ IMCC_push_parser_state(interp);
+ next = IMCC_INFO(interp)->state->next;
+
+ if (imc_info)
+ IMCC_INFO(interp)->state->next = NULL;
+
+ IMCC_INFO(interp)->state->pasm_file = pasm_file;
+ IMCC_INFO(interp)->state->file = name;
+ IMCC_INFO(interp)->expect_pasm = 0;
+
+ compile_string(interp, s, yyscanner);
+
+ Parrot_pop_context(interp);
+
+ /*
+ * compile_string NULLifies frames->next, so that yywrap
+ * doesn't try to continue compiling the previous buffer
+ * This OTOH prevents pop_parser-state ->
+ *
+ * set next here and pop
+ */
+ IMCC_INFO(interp)->state->next = next;
+ IMCC_pop_parser_state(interp, yyscanner);
+
+ if (!IMCC_INFO(interp)->error_code) {
+ Parrot_Sub_attributes *sub_data;
+
+ /*
+ * create sub PMC
+ *
+ * TODO if a sub was denoted :main return that instead
+ */
+ eval_pmc = Parrot_pmc_new(interp, enum_class_Eval);
+ PMC_get_sub(interp, eval_pmc, sub_data);
+ sub_data->seg = new_cs;
+ sub_data->start_offs = 0;
+ sub_data->end_offs = new_cs->base.size;
+ sub_data->name = name;
+
+ *error_message = NULL;
+ }
+ else {
+ PackFile_Segment_destroy(interp, (PackFile_Segment *)new_cs);
+ *error_message = IMCC_INFO(interp)->error_message;
+ }
+
+ if (imc_info) {
+ SymReg *ns = IMCC_INFO(interp)->cur_namespace;
+ IMCC_INFO(interp) = imc_info->prev;
+ mem_sys_free(imc_info);
+ imc_info = IMCC_INFO(interp);
+ IMCC_INFO(interp)->cur_unit = imc_info->last_unit;
+
+ if (ns && ns != imc_info->cur_namespace)
+ free_sym(ns);
+
+ IMCC_INFO(interp)->cur_namespace = imc_info->cur_namespace;
+ }
else
- return 0;
+ imc_cleanup(interp, yyscanner);
+
+ Parrot_unblock_GC_mark(interp);
+
+ yylex_destroy(yyscanner);
+
+ /* Now run any :load/:init subs. */
+ if (!*error_message)
+ PackFile_fixup_subs(interp, PBC_MAIN, eval_pmc);
+
+ /* restore old byte_code, */
+ if (old_cs)
+ (void)Parrot_switch_to_cs(interp, old_cs, 0);
+
+ return eval_pmc;
+}
+
+/*
+
+=item C<PMC * IMCC_compile_pir_s(PARROT_INTERP, const char *s, STRING
+**error_message)>
+
+Compile PIR code from a C string. Returns errors in the <STRING> provided.
+
+Called only from src/embed.c:Parrot_compile_string().
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC *
+IMCC_compile_pir_s(PARROT_INTERP, ARGIN(const char *s),
+ ARGOUT(STRING **error_message))
+{
+ ASSERT_ARGS(IMCC_compile_pir_s)
+ return imcc_compile(interp, s, 0, error_message);
+}
+
+/*
+
+=item C<PMC * IMCC_compile_pasm_s(PARROT_INTERP, const char *s, STRING
+**error_message)>
+
+Compile PASM code from a C string. Returns errors in the <STRING> provided.
+
+Called only from src/embed.c:Parrot_compile_string().
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC *
+IMCC_compile_pasm_s(PARROT_INTERP, ARGIN(const char *s),
+ ARGOUT(STRING **error_message))
+{
+ ASSERT_ARGS(IMCC_compile_pasm_s)
+ return imcc_compile(interp, s, 1, error_message);
+}
+
+/*
+
+=item C<PMC * imcc_compile_pasm_ex(PARROT_INTERP, const char *s)>
+
+Compile PASM code from a C string. Throws an exception upon errors.
+
+Called only from the PASM compreg
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC *
+imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s))
+{
+ ASSERT_ARGS(imcc_compile_pasm_ex)
+ STRING *error_message;
+
+ PMC * const sub = imcc_compile(interp, s, 1, &error_message);
+
+ if (sub)
+ return sub;
+
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_SYNTAX_ERROR, "%Ss",
+ error_message);
+}
+
+/*
+
+=item C<PMC * imcc_compile_pir_ex(PARROT_INTERP, const char *s)>
+
+Compile PIR code from a C string. Throws an exception upon errors.
+
+Called only from the PIR compreg
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC *
+imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s))
+{
+ ASSERT_ARGS(imcc_compile_pir_ex)
+ STRING *error_message;
+ PMC *sub;
+
+ sub = imcc_compile(interp, s, 0, &error_message);
+ if (sub)
+ return sub;
+
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_SYNTAX_ERROR, "%Ss",
+ error_message);
+}
+
+/*
+
+=item C<void * imcc_compile_file(PARROT_INTERP, STRING *fullname, STRING
+**error_message)>
+
+Compile a file by filename (can be either PASM or IMCC code)
+
+Called only from src/interp/inter_misc.c:Parrot_compile_file
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+void *
+imcc_compile_file(PARROT_INTERP, ARGIN(STRING *fullname),
+ ARGOUT(STRING **error_message))
+{
+ ASSERT_ARGS(imcc_compile_file)
+ PackFile_ByteCode * const cs_save = Parrot_pf_get_current_code_segment(interp);
+ PackFile_ByteCode *cs = NULL;
+ struct _imc_info_t *imc_info = NULL;
+ const char *ext;
+ PIOHANDLE fp;
+ PMC *newcontext;
+
+ /* need at least 3 regs for compilation of constant math e.g.
+ * add_i_ic_ic - see also IMCC_subst_constants() */
+ UINTVAL regs_used[4] = {3, 3, 3, 3};
+
+ if (IMCC_INFO(interp)->last_unit) {
+ /* a reentrant compile */
+ imc_info = mem_gc_allocate_zeroed_typed(interp, imc_info_t);
+ imc_info->prev = IMCC_INFO(interp);
+ imc_info->ghash = IMCC_INFO(interp)->ghash;
+ IMCC_INFO(interp) = imc_info;
+ }
+
+ if (Parrot_stat_info_intval(interp, fullname, STAT_ISDIR))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXTERNAL_ERROR,
+ "imcc_compile_file: '%Ss' is a directory\n", fullname);
+
+ fp = PIO_OPEN(interp, fullname, PIO_F_READ);
+ if (fp == PIO_INVALID_HANDLE)
+ IMCC_fatal(interp, EXCEPTION_EXTERNAL_ERROR,
+ "imcc_compile_file: couldn't open '%Ss'\n", fullname);
+
+ IMCC_push_parser_state(interp);
+ IMCC_INFO(interp)->state->file = fullname;
+
+ /* start over; let the start of line rule increment this to 1 */
+ IMCC_INFO(interp)->line = 0;
+
+ /*
+ * the Parrot_str_compare() called from pmc_type() triggers GC
+ * which can destroy packfiles under construction
+ */
+ Parrot_block_GC_mark(interp);
+
+ /* Activate a new context and reset it to initial values */
+ newcontext = Parrot_push_context(interp, regs_used);
+ Parrot_pcc_set_HLL(interp, newcontext, 0);
+ Parrot_pcc_set_sub(interp, newcontext, 0);
+ IMCC_INFO(interp)->cur_namespace = NULL;
+ interp->code = NULL;
+
+ if (imcc_string_ends_with(interp, fullname, ".pasm")) {
+ void *yyscanner;
+ yylex_init_extra(interp, &yyscanner);
+
+ IMCC_INFO(interp)->state->pasm_file = 1;
+ /* see imcc.l */
+ compile_file(interp, fp, yyscanner);
+
+ yylex_destroy(yyscanner);
+ }
+ else {
+ void *yyscanner;
+ yylex_init_extra(interp, &yyscanner);
+
+ IMCC_INFO(interp)->state->pasm_file = 0;
+ compile_file(interp, fp, yyscanner);
+
+ yylex_destroy(yyscanner);
+ }
+
+ Parrot_unblock_GC_mark(interp);
+ Parrot_pop_context(interp);
+
+ imc_cleanup(interp, NULL);
+ PIO_CLOSE(interp, fp);
+
+ if (!IMCC_INFO(interp)->error_code)
+ cs = Parrot_pf_get_current_code_segment(interp);
+ else
+ *error_message = IMCC_INFO(interp)->error_message;
+
+ if (cs_save)
+ (void)Parrot_switch_to_cs(interp, cs_save, 0);
+
+ if (imc_info) {
+ IMCC_INFO(interp) = imc_info->prev;
+ if (imc_info->globals)
+ mem_sys_free(imc_info->globals);
+
+ mem_sys_free(imc_info);
+ }
+
+ return cs;
+}
+
+/*
+
+=item C<void imcc_init(PARROT_INTERP)>
+
+Initialize IMCC with Parrot by registering it as a PIR and PASM compiler.
+
+=cut
+
+*/
+
+void
+imcc_init(PARROT_INTERP)
+{
+ ASSERT_ARGS(imcc_init)
+ PARROT_ASSERT(IMCC_INFO(interp) != NULL);
+
+ /* register PASM and PIR compilers to parrot core */
+ Parrot_compreg(interp, Parrot_str_new_constant(interp, "PASM"), imcc_compile_pasm_ex);
+ Parrot_compreg(interp, Parrot_str_new_constant(interp, "PIR"), imcc_compile_pir_ex);
}
/*
+=item C<void imcc_destroy(PARROT_INTERP)>
+
+Deallocate memory associated with IMCC.
+
+=cut
+
+*/
+
+void
+imcc_destroy(PARROT_INTERP)
+{
+ ASSERT_ARGS(imcc_destroy)
+ Hash * const macros = IMCC_INFO(interp)->macros;
+
+ if (macros)
+ Parrot_hash_chash_destroy_values(interp, macros, imcc_destroy_macro_values);
+
+ if (IMCC_INFO(interp)->globals)
+ mem_sys_free(IMCC_INFO(interp)->globals);
+
+ mem_sys_free(IMCC_INFO(interp));
+ IMCC_INFO(interp) = NULL;
+
+ if (eval_nr != 0)
+ MUTEX_DESTROY(eval_nr_lock);
+}
+
+/*
+
+=item C<static void imcc_destroy_macro_values(void *value)>
+
+A callback for Parrot_hash_chash_destroy_values() to free all macro-allocated memory.
+
+=cut
+
+*/
+
+static void
+imcc_destroy_macro_values(ARGMOD(void *value))
+{
+ ASSERT_ARGS(imcc_destroy_macro_values)
+ macro_t * const m = (macro_t *)value;
+ params_t * const params = &m->params;
+
+ int i;
+
+ for (i = 0; i < params->num_param; ++i) {
+ char * const name = params->name[i];
+ if (name)
+ mem_sys_free(name);
+ }
+
+ mem_sys_free(m->expansion);
+ mem_sys_free(m);
+}
+
+
+/*
+
=back
=cut
View
515 compilers/imcc/parser_util.c
@@ -57,10 +57,6 @@ static int change_op_arg_to_num(PARROT_INTERP,
FUNC_MODIFIES(*unit)
FUNC_MODIFIES(*r);
-static void imcc_destroy_macro_values(ARGMOD(void *value))
- __attribute__nonnull__(1)
- FUNC_MODIFIES(*value);
-
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static op_info_t * try_find_op(PARROT_INTERP,
@@ -104,8 +100,6 @@ static Instruction * var_arg_ins(PARROT_INTERP,
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(unit) \
, PARROT_ASSERT_ARG(r))
-#define ASSERT_ARGS_imcc_destroy_macro_values __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(value))
#define ASSERT_ARGS_try_find_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(unit) \
@@ -128,9 +122,6 @@ static Instruction * var_arg_ins(PARROT_INTERP,
* absolutely global to prevent the files from being overwritten.
*
*/
-/* XXX non-reentrant */
-static Parrot_mutex eval_nr_lock;
-static INTVAL eval_nr = 0;
/*
@@ -456,10 +447,6 @@ INS(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGIN(const char *name),
if (STREQ(name, "end") || STREQ(name, "ret")) {
ins->type |= ITBRANCH | IF_goto;
}
- else if (STREQ(name, "warningson")) {
- /* emit a debug seg, if this op is seen */
- PARROT_WARNINGS_on(interp, PARROT_WARNINGS_ALL_FLAG);
- }
else if (STREQ(name, "yield")) {
if (!IMCC_INFO(interp)->cur_unit->instructions->symregs[0])
IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR,
@@ -505,427 +492,6 @@ INS(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGIN(const char *name),
}
}
-extern void* yy_scan_string(const char *);
-
-/*
-
-=item C<PMC * imcc_compile(PARROT_INTERP, const char *s, int pasm_file, STRING
-**error_message)>
-
-Compile a pasm or imcc string
-
-FIXME as we have separate constants, the old constants in ghash must be deleted.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC *
-imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file,
- ARGOUT(STRING **error_message))
-{
- ASSERT_ARGS(imcc_compile)
- /* imcc always compiles to interp->code
- * save old cs, make new
- */
- STRING *name;
- PackFile_ByteCode *old_cs, *new_cs;
- PMC *sub = NULL;
- struct _imc_info_t *imc_info = NULL;
- struct parser_state_t *next;
- void *yyscanner;
- PMC *ignored;
- UINTVAL regs_used[4] = {3, 3, 3, 3};
- INTVAL eval_number;
-
- yylex_init_extra(interp, &yyscanner);
-
- /* we create not yet anchored PMCs - e.g. Subs: turn off GC */
- Parrot_block_GC_mark(interp);
-
- if (IMCC_INFO(interp)->last_unit) {
- /* a reentrant compile */
- imc_info = mem_gc_allocate_zeroed_typed(interp, imc_info_t);
- imc_info->ghash = IMCC_INFO(interp)->ghash;
- imc_info->prev = IMCC_INFO(interp);
- IMCC_INFO(interp) = imc_info;
- }
-
- ignored = Parrot_push_context(interp, regs_used);
- UNUSED(ignored);
-
- if (eval_nr == 0)
- MUTEX_INIT(eval_nr_lock);
-
- LOCK(eval_nr_lock);
- eval_number = ++eval_nr;
- UNLOCK(eval_nr_lock);
-
- name = Parrot_sprintf_c(interp, "EVAL_" INTVAL_FMT, eval_number);
- new_cs = PF_create_default_segs(interp, name, 0);
- old_cs = Parrot_switch_to_cs(interp, new_cs, 0);
-
- IMCC_INFO(interp)->cur_namespace = NULL;
-
- /* spit out the sourcefile */
- if (Interp_debug_TEST(interp, PARROT_EVAL_DEBUG_FLAG)) {
- char *buf = Parrot_str_to_cstring(interp, name);
- FILE * const fp = fopen(buf, "w");
- Parrot_str_free_cstring(buf);
- if (fp) {
- fputs(s, fp);
- fclose(fp);
- }
- }
-
- IMCC_push_parser_state(interp);
- next = IMCC_INFO(interp)->state->next;
-
- if (imc_info)
- IMCC_INFO(interp)->state->next = NULL;
-
- IMCC_INFO(interp)->state->pasm_file = pasm_file;
- IMCC_INFO(interp)->state->file = name;
- IMCC_INFO(interp)->expect_pasm = 0;
-
- compile_string(interp, s, yyscanner);
-
- Parrot_pop_context(interp);
-
- /*
- * compile_string NULLifies frames->next, so that yywrap
- * doesn't try to continue compiling the previous buffer
- * This OTOH prevents pop_parser-state ->
- *
- * set next here and pop
- */
- IMCC_INFO(interp)->state->next = next;
- IMCC_pop_parser_state(interp, yyscanner);
-
- if (!IMCC_INFO(interp)->error_code) {
- Parrot_Sub_attributes *sub_data;
-
- /*
- * create sub PMC
- *
- * TODO if a sub was denoted :main return that instead
- */
- sub = Parrot_pmc_new(interp, enum_class_Eval);
- PMC_get_sub(interp, sub, sub_data);
- sub_data->seg = new_cs;
- sub_data->start_offs = 0;
- sub_data->end_offs = new_cs->base.size;
- sub_data->name = name;
-
- *error_message = NULL;
- }
- else {
- PackFile_Segment_destroy(interp, (PackFile_Segment *)new_cs);
- *error_message = IMCC_INFO(interp)->error_message;
- }
-
- if (imc_info) {
- SymReg *ns = IMCC_INFO(interp)->cur_namespace;
- IMCC_INFO(interp) = imc_info->prev;
- mem_sys_free(imc_info);
- imc_info = IMCC_INFO(interp);
- IMCC_INFO(interp)->cur_unit = imc_info->last_unit;
-
- if (ns && ns != imc_info->cur_namespace)
- free_sym(ns);
-
- IMCC_INFO(interp)->cur_namespace = imc_info->cur_namespace;
- }
- else
- imc_cleanup(interp, yyscanner);
-
- Parrot_unblock_GC_mark(interp);
-
- yylex_destroy(yyscanner);
-
- /* Now run any :load/:init subs. */
- if (!*error_message)
- PackFile_fixup_subs(interp, PBC_MAIN, sub);
-
- /* restore old byte_code, */
- if (old_cs)
- (void)Parrot_switch_to_cs(interp, old_cs, 0);
-
- return sub;
-}
-
-/*
-
-=item C<PMC * imcc_compile_pasm(PARROT_INTERP, const char *s)>
-
-Note: This function is provided for backward compatibility. This
-function can go away in future.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC *
-imcc_compile_pasm(PARROT_INTERP, ARGIN(const char *s))
-{
- ASSERT_ARGS(imcc_compile_pasm)
- STRING *error_message;
- return imcc_compile(interp, s, 1, &error_message);
-}
-
-/*
-
-=item C<PMC * imcc_compile_pir(PARROT_INTERP, const char *s)>
-
-Note: This function is provided for backward compatibility. This
-function can go away in future.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC *
-imcc_compile_pir(PARROT_INTERP, ARGIN(const char *s))
-{
- ASSERT_ARGS(imcc_compile_pir)
- STRING *error_message;
- return imcc_compile(interp, s, 0, &error_message);
-}
-
-/*
-
-=item C<PMC * IMCC_compile_pir_s(PARROT_INTERP, const char *s, STRING
-**error_message)>
-
-Compile PIR code from a C string. Returns errors in the <STRING> provided.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC *
-IMCC_compile_pir_s(PARROT_INTERP, ARGIN(const char *s),
- ARGOUT(STRING **error_message))
-{
- ASSERT_ARGS(IMCC_compile_pir_s)
- return imcc_compile(interp, s, 0, error_message);
-}
-
-/*
-
-=item C<PMC * IMCC_compile_pasm_s(PARROT_INTERP, const char *s, STRING
-**error_message)>
-
-Compile PASM code from a C string. Returns errors in the <STRING> provided.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC *
-IMCC_compile_pasm_s(PARROT_INTERP, ARGIN(const char *s),
- ARGOUT(STRING **error_message))
-{
- ASSERT_ARGS(IMCC_compile_pasm_s)
- return imcc_compile(interp, s, 1, error_message);
-}
-
-/*
-
-=item C<PMC * imcc_compile_pasm_ex(PARROT_INTERP, const char *s)>
-
-Compile PASM code from a C string. Throws an exception upon errors.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC *
-imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s))
-{
- ASSERT_ARGS(imcc_compile_pasm_ex)
- STRING *error_message;
-
- PMC * const sub = imcc_compile(interp, s, 1, &error_message);
-
- if (sub)
- return sub;
-
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_SYNTAX_ERROR, "%Ss",
- error_message);
-}
-
-/*
-
-=item C<PMC * imcc_compile_pir_ex(PARROT_INTERP, const char *s)>
-
-Compile PIR code from a C string. Throws an exception upon errors.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-PMC *
-imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s))
-{
- ASSERT_ARGS(imcc_compile_pir_ex)
- STRING *error_message;
- PMC *sub;
-
- sub = imcc_compile(interp, s, 0, &error_message);
- if (sub)
- return sub;
-
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_SYNTAX_ERROR, "%Ss",
- error_message);
-}
-
-/*
-
-=item C<void * imcc_compile_file(PARROT_INTERP, STRING *fullname, STRING
-**error_message)>
-
-Compile a file by filename (can be either PASM or IMCC code)
-
-=cut
-
-*/
-
-PARROT_EXPORT
-PARROT_CANNOT_RETURN_NULL
-void *
-imcc_compile_file(PARROT_INTERP, ARGIN(STRING *fullname),
- ARGOUT(STRING **error_message))
-{
- ASSERT_ARGS(imcc_compile_file)
- PackFile_ByteCode * const cs_save = interp->code;
- PackFile_ByteCode *cs = NULL;
- struct _imc_info_t *imc_info = NULL;
- PIOHANDLE fp;
- PMC *newcontext;
-
- /* need at least 3 regs for compilation of constant math e.g.
- * add_i_ic_ic - see also IMCC_subst_constants() */
- UINTVAL regs_used[4] = {3, 3, 3, 3};
-
- if (IMCC_INFO(interp)->last_unit) {
- /* a reentrant compile */
- imc_info = mem_gc_allocate_zeroed_typed(interp, imc_info_t);
- imc_info->prev = IMCC_INFO(interp);
- imc_info->ghash = IMCC_INFO(interp)->ghash;
- IMCC_INFO(interp) = imc_info;
- }
-
- if (Parrot_stat_info_intval(interp, fullname, STAT_ISDIR))
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXTERNAL_ERROR,
- "imcc_compile_file: '%Ss' is a directory\n", fullname);
-
- fp = PIO_OPEN(interp, fullname, PIO_F_READ);
- if (fp == PIO_INVALID_HANDLE)
- IMCC_fatal(interp, EXCEPTION_EXTERNAL_ERROR,
- "imcc_compile_file: couldn't open '%Ss'\n", fullname);
-
- IMCC_push_parser_state(interp);
- IMCC_INFO(interp)->state->file = fullname;
-
- /* start over; let the start of line rule increment this to 1 */
- IMCC_INFO(interp)->line = 0;
-
- /*
- * the Parrot_str_compare() called from pmc_type() triggers GC
- * which can destroy packfiles under construction
- */
- Parrot_block_GC_mark(interp);
-
- /* Activate a new context and reset it to initial values */
- newcontext = Parrot_push_context(interp, regs_used);
- Parrot_pcc_set_HLL(interp, newcontext, 0);
- Parrot_pcc_set_sub(interp, newcontext, 0);
- IMCC_INFO(interp)->cur_namespace = NULL;
- interp->code = NULL;
-
- if (imcc_string_ends_with(interp, fullname, ".pasm")) {
- void *yyscanner;
- yylex_init_extra(interp, &yyscanner);
-
- IMCC_INFO(interp)->state->pasm_file = 1;
- /* see imcc.l */
- compile_file(interp, fp, yyscanner);
-
- yylex_destroy(yyscanner);
- }
- else {
- void *yyscanner;
- yylex_init_extra(interp, &yyscanner);
-
- IMCC_INFO(interp)->state->pasm_file = 0;
- compile_file(interp, fp, yyscanner);
-
- yylex_destroy(yyscanner);
- }
-
- Parrot_unblock_GC_mark(interp);
- Parrot_pop_context(interp);
-
- imc_cleanup(interp, NULL);
- PIO_CLOSE(interp, fp);
-
- if (!IMCC_INFO(interp)->error_code)
- cs = interp->code;
- else
- *error_message = IMCC_INFO(interp)->error_message;
-
- if (cs_save)
- (void)Parrot_switch_to_cs(interp, cs_save, 0);
-
- if (imc_info) {
- IMCC_INFO(interp) = imc_info->prev;
- if (imc_info->globals)
- mem_sys_free(imc_info->globals);
-
- mem_sys_free(imc_info);
- }
-
- return cs;
-}
-
-/*
-
-=item C<void register_compilers(PARROT_INTERP)>
-
-Register additional compilers with the interpreter
-
-=cut
-
-*/
-
-void
-register_compilers(PARROT_INTERP)
-{
- ASSERT_ARGS(register_compilers)
- Parrot_compreg(interp, Parrot_str_new_constant(interp, "PASM"), imcc_compile_pasm_ex);
- Parrot_compreg(interp, Parrot_str_new_constant(interp, "PIR"), imcc_compile_pir_ex);
-
- /* It looks like this isn't used anywhere yet */
- /* TODO: return a Eval PMC, instead of a packfile */
- /* Parrot_compreg(interp,
- Parrot_str_new_constant(interp, "FILE"),
- imcc_compile_file ); */
-}
/*
@@ -1115,87 +681,6 @@ imcc_vfprintf(PARROT_INTERP, ARGMOD(PMC *io), ARGIN(const char *format), va_list
return Parrot_io_putps(interp, io, Parrot_vsprintf_c(interp, format, ap));
}
-/* Utility functions */
-
-/*
-
-=item C<void imcc_init(PARROT_INTERP)>
-
-Initialize IMCC with Parrot by registering it as a PIR and PASM compiler.
-
-=cut
-
-*/
-
-void
-imcc_init(PARROT_INTERP)
-{
- ASSERT_ARGS(imcc_init)
- PARROT_ASSERT(IMCC_INFO(interp) != NULL);
-
- /* register PASM and PIR compilers to parrot core */
- register_compilers(interp);
-}
-
-/*
-
-=item C<static void imcc_destroy_macro_values(void *value)>
-
-A callback for Parrot_hash_chash_destroy_values() to free all macro-allocated memory.
-
-=cut
-
-*/
-
-static void
-imcc_destroy_macro_values(ARGMOD(void *value))
-{
- ASSERT_ARGS(imcc_destroy_macro_values)
- macro_t * const m = (macro_t *)value;
- params_t * const params = &m->params;
-
- int i;
-
- for (i = 0; i < params->num_param; ++i) {
- char * const name = params->name[i];
- if (name)
- mem_sys_free(name);
- }
-
- mem_sys_free(m->expansion);
- mem_sys_free(m);
-}
-
-
-/*
-
-=item C<void imcc_destroy(PARROT_INTERP)>
-
-Deallocate memory associated with IMCC.
-
-=cut
-
-*/
-
-void
-imcc_destroy(PARROT_INTERP)
-{
- ASSERT_ARGS(imcc_destroy)
- Hash * const macros = IMCC_INFO(interp)->macros;
-
- if (macros)
- Parrot_hash_chash_destroy_values(interp, macros, imcc_destroy_macro_values);
-
- if (IMCC_INFO(interp)->globals)
- mem_sys_free(IMCC_INFO(interp)->globals);
-
- mem_sys_free(IMCC_INFO(interp));
- IMCC_INFO(interp) = NULL;
-
- if (eval_nr != 0)
- MUTEX_DESTROY(eval_nr_lock);
-}
-
/*
=item C<int imcc_string_ends_with(PARROT_INTERP, const STRING *str, const char
View
257 compilers/imcc/pbc.c
@@ -52,14 +52,22 @@ TODO memory clean up
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-static void add_1_const(PARROT_INTERP, ARGMOD(SymReg *r))
+static void add_1_const(PARROT_INTERP,
+ ARGMOD(SymReg *r),
+ ARGMOD(PackFile_ByteCode * bc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
- FUNC_MODIFIES(*r);
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(*r)
+ FUNC_MODIFIES(* bc);
PARROT_WARN_UNUSED_RESULT
-static int add_const_num(PARROT_INTERP, ARGIN_NULLOK(const char *buf))
- __attribute__nonnull__(1);
+static int add_const_num(PARROT_INTERP,
+ ARGIN_NULLOK(const char *buf),
+ ARGMOD(PackFile_ByteCode * bc))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(* bc);
PARROT_IGNORABLE_RESULT
static int /*@alt void@*/
@@ -72,32 +80,46 @@ add_const_pmc_sub(PARROT_INTERP,
FUNC_MODIFIES(*r);
PARROT_WARN_UNUSED_RESULT
-static int add_const_str(PARROT_INTERP, ARGIN(STRING *s))
+static int add_const_str(PARROT_INTERP,
+ ARGIN(STRING *s),
+ ARGIN(PackFile_ByteCode * const bc))
__attribute__nonnull__(1)
- __attribute__nonnull__(2);
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
static int add_const_table_pmc(PARROT_INTERP, ARGIN(PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
-static opcode_t build_key(PARROT_INTERP, ARGIN(SymReg *key_reg))
+static opcode_t build_key(PARROT_INTERP,
+ ARGIN(SymReg *key_reg),
+ ARGMOD(PackFile_ByteCode * bc))
__attribute__nonnull__(1)
- __attribute__nonnull__(2);
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(* bc);
-static void constant_folding(PARROT_INTERP, ARGIN(const IMC_Unit *unit))
+static void constant_folding(PARROT_INTERP,
+ ARGIN(const IMC_Unit *unit),
+ ARGMOD(PackFile_ByteCode * bc))
__attribute__nonnull__(1)
- __attribute__nonnull__(2);
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(* bc);
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
static PMC* create_lexinfo(PARROT_INTERP,
ARGMOD(IMC_Unit *unit),
ARGIN(PMC *sub_pmc),
- int need_lex)
+ int need_lex,
+ ARGMOD(PackFile_ByteCode * bc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
- FUNC_MODIFIES(*unit);
+ __attribute__nonnull__(5)
+ FUNC_MODIFIES(*unit)
+ FUNC_MODIFIES(* bc);
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
@@ -142,9 +164,12 @@ static size_t get_code_size(PARROT_INTERP,
FUNC_MODIFIES(*src_lines);
PARROT_WARN_UNUSED_RESULT
-static int get_old_size(PARROT_INTERP, ARGOUT(int *ins_line))
+static int get_old_size(PARROT_INTERP,
+ ARGIN(PackFile_ByteCode * bc),
+ ARGOUT(int *ins_line))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
+ __attribute__nonnull__(3)
FUNC_MODIFIES(*ins_line);
static void imcc_globals_destroy(PARROT_INTERP,
@@ -170,9 +195,13 @@ static void make_pmc_const(PARROT_INTERP, ARGMOD(SymReg *r))
PARROT_CANNOT_RETURN_NULL
PARROT_MALLOC
-static PMC* mk_multi_sig(PARROT_INTERP, ARGIN(const SymReg *r))
+static PMC* mk_multi_sig(PARROT_INTERP,
+ ARGIN(const SymReg *r),
+ ARGMOD(PackFile_ByteCode * bc))
__attribute__nonnull__(1)
- __attribute__nonnull__(2);
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(* bc);
static void store_fixup(PARROT_INTERP,
ARGIN(const SymReg *r),
@@ -190,35 +219,44 @@ static void store_sub_size(PARROT_INTERP, size_t size, size_t ins_line)
static void verify_signature(PARROT_INTERP,
ARGIN(const Instruction *ins),
- ARGIN(opcode_t *pc))
+ ARGIN(opcode_t *pc),
+ ARGMOD(PackFile_ByteCode * bc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
- __attribute__nonnull__(3);
+ __attribute__nonnull__(3)
+ __attribute__nonnull__(4)
+ FUNC_MODIFIES(* bc);
#define ASSERT_ARGS_add_1_const __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(r))
+ , PARROT_ASSERT_ARG(r) \
+ , PARROT_ASSERT_ARG(bc))
#define ASSERT_ARGS_add_const_num __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp))
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(bc))
#define ASSERT_ARGS_add_const_pmc_sub __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(r))
#define ASSERT_ARGS_add_const_str __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
+ , PARROT_ASSERT_ARG(s) \
+ , PARROT_ASSERT_ARG(bc))
#define ASSERT_ARGS_add_const_table_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pmc))
#define ASSERT_ARGS_build_key __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(key_reg))
+ , PARROT_ASSERT_ARG(key_reg) \
+ , PARROT_ASSERT_ARG(bc))
#define ASSERT_ARGS_constant_folding __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(unit))
+ , PARROT_ASSERT_ARG(unit) \
+ , PARROT_ASSERT_ARG(bc))
#define ASSERT_ARGS_create_lexinfo __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(unit) \
- , PARROT_ASSERT_ARG(sub_pmc))
+ , PARROT_ASSERT_ARG(sub_pmc) \
+ , PARROT_ASSERT_ARG(bc))
#define ASSERT_ARGS_find_global_label __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(name) \
@@ -240,6 +278,7 @@ static void verify_signature(PARROT_INTERP,
, PARROT_ASSERT_ARG(src_lines))
#define ASSERT_ARGS_get_old_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(bc) \
, PARROT_ASSERT_ARG(ins_line))
#define ASSERT_ARGS_imcc_globals_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
@@ -256,7 +295,8 @@ static void verify_signature(PARROT_INTERP,
, PARROT_ASSERT_ARG(r))
#define ASSERT_ARGS_mk_multi_sig __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(r))
+ , PARROT_ASSERT_ARG(r) \
+ , PARROT_ASSERT_ARG(bc))
#define ASSERT_ARGS_store_fixup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(r))
@@ -268,7 +308,8 @@ static void verify_signature(PARROT_INTERP,
#define ASSERT_ARGS_verify_signature __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(ins) \
- , PARROT_ASSERT_ARG(pc))
+ , PARROT_ASSERT_ARG(pc) \
+ , PARROT_ASSERT_ARG(bc))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
@@ -326,7 +367,8 @@ static int
add_const_table_pmc(PARROT_INTERP, ARGIN(PMC *pmc))
{
ASSERT_ARGS(add_const_table_pmc)
- PackFile_ConstTable *ct = interp->code->const_table;
+ PackFile_ByteCode * const bc = Parrot_pf_get_current_code_segment(interp);
+ PackFile_ConstTable * const ct = bc->const_table;
if (!ct->pmc.constants)
ct->pmc.constants =
@@ -357,6 +399,7 @@ int
e_pbc_open(PARROT_INTERP, SHIM(const char *param))
{
ASSERT_ARGS(e_pbc_open)
+ PackFile_ByteCode * const current_bc = Parrot_pf_get_current_code_segment(interp);
code_segment_t * const cs = mem_gc_allocate_zeroed_typed(interp, code_segment_t);
if (!IMCC_INFO(interp)->globals)
@@ -384,11 +427,11 @@ e_pbc_open(PARROT_INTERP, SHIM(const char *param))
cs->prev->next = cs;
/* we need some segments */
- if (!interp->code) {
+ if (!current_bc) {
STRING *name = IMCC_INFO(interp)->state->file;
PMC *self;
- cs->seg = interp->code = PF_create_default_segs(interp, name, 1);
+ cs->seg = PF_create_default_segs(interp, name, 1, 1);
}
IMCC_INFO(interp)->globals->cs = cs;
@@ -430,7 +473,8 @@ make_new_sub(PARROT_INTERP, ARGIN(IMC_Unit *unit))