Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sync branch with trunk.

git-svn-id: https://svn.parrot.org/parrot/branches/pmc_i_ops@39482 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit 6366225d19affb64a7fe442a1b0bb4d6d16d6316 1 parent 903b9b0
Vasily Chekalkin bacek authored
Showing with 2,045 additions and 1,705 deletions.
  1. +0 −13 DEPRECATED.pod
  2. +6 −3 MANIFEST
  3. +5 −0 NEWS
  4. +1 −0  PBC_COMPAT
  5. +0 −1  PLATFORMS
  6. +1 −1  README
  7. +1 −1  README_win32.pod
  8. +1 −1  compilers/imcc/imcc.l
  9. +27 −12 compilers/imcc/imcc.y
  10. +1 −1  compilers/imcc/imclexer.c
  11. +746 −726 compilers/imcc/imcparser.c
  12. +1 −1  compilers/imcc/imcparser.h
  13. +5 −10 compilers/imcc/main.c
  14. +6 −0 compilers/imcc/parser_util.c
  15. +8 −2 compilers/imcc/pcc.c
  16. +7 −2 compilers/imcc/reg_alloc.c
  17. +1 −1  compilers/imcc/symreg.c
  18. +33 −11 docs/book/appc_command_line_options.pod
  19. +1 −1  docs/pdds/pdd28_strings.pod
  20. +1 −26 docs/running.pod
  21. +0 −6 include/parrot/embed.h
  22. +9 −5 include/parrot/io.h
  23. +2 −0  include/parrot/io_portable.h
  24. +21 −0 include/parrot/io_unix.h
  25. +24 −0 include/parrot/io_win32.h
  26. +21 −21 include/parrot/library.h
  27. +14 −8 include/parrot/runcore_api.h
  28. +6 −4 lib/Parrot/Install.pm
  29. +2 −2 lib/Parrot/Ops2pm.pm
  30. +40 −0 runtime/parrot/languages/parrot/parrot.pir
  31. +48 −40 src/embed.c
  32. +1 −0  src/gc/alloc_register.c
  33. +1 −1  src/hash.c
  34. +196 −25 src/io/api.c
  35. +6 −6 src/io/buffer.c
  36. +46 −0 src/io/unix.c
  37. +43 −0 src/io/win32.c
  38. +11 −14 src/library.c
  39. +13 −13 src/oo.c
  40. +1 −1  src/ops/io.ops
  41. +8 −2 src/packfile.c
  42. +5 −4 src/pmc.c
  43. +12 −6 src/pmc/codestring.pmc
  44. +1 −1  src/pmc/coroutine.pmc
  45. +3 −3 src/pmc/eventhandler.pmc
  46. +13 −79 src/pmc/filehandle.pmc
  47. +44 −0 src/pmc/handle.pmc
  48. +0 −1  src/pmc/resizablestringarray.pmc
  49. +43 −4 src/pmc/socket.pmc
  50. +9 −58 src/pmc/stringhandle.pmc
  51. +13 −2 src/pmc/undef.pmc
  52. +4 −1 src/pmc_freeze.c
  53. +8 −8 src/runcore/main.c
  54. +1 −2  src/string/api.c
  55. +2 −1  t/compilers/imcc/syn/file.t
  56. +23 −2 t/compilers/imcc/syn/pcc.t
  57. +4 −4 t/library/pcre.t
  58. BIN  t/native_pbc/annotations.pbc
  59. BIN  t/native_pbc/integer_1.pbc
  60. BIN  t/native_pbc/integer_4.pbc
  61. BIN  t/native_pbc/number_1.pbc
  62. BIN  t/native_pbc/number_2.pbc
  63. BIN  t/native_pbc/number_4.pbc
  64. BIN  t/native_pbc/number_5.pbc
  65. BIN  t/native_pbc/string_1.pbc
  66. BIN  t/native_pbc/string_4.pbc
  67. +1 −1  t/op/arithmetics_pmc.t
  68. +0 −7 t/op/interp.t
  69. +419 −470 t/pmc/array.t
  70. +1 −53 t/pmc/io.t
  71. +1 −1  t/pmc/pmc.t
  72. +1 −1  t/steps/auto_icu-01.t
  73. +12 −12 t/steps/auto_jit-01.t
  74. +2 −2 t/steps/auto_pmc-01.t
  75. +5 −5 t/steps/gen_platform-01.t
  76. +0 −1  t/tools/install/02-install_files.t
  77. +0 −1  t/tools/install/03-lines_to_files.t
  78. +2 −1  t/tools/install/dev_overall.t
  79. +2 −1  t/tools/install/overall.t
  80. +1 −1  t/tools/ops2pm/05-renum_op_map_file.t
  81. +1 −1  t/tools/ops2pm/10-print_module.t
  82. +1 −1  t/tools/ops2pm/11-print_h.t
  83. +6 −1 tools/dev/create_language.pl
  84. +10 −3 tools/dev/fetch_languages.pl
  85. +12 −0 tools/dev/mk_native_pbc
  86. +4 −4 tools/dev/parrot-fuzzer
  87. +14 −1 tools/install/smoke_languages.pl
13 DEPRECATED.pod
View
@@ -196,13 +196,6 @@ to happen.
L<http://rt.perl.org/rt3/Ticket/Display.html?id=53302>
-=item Parrot_readbc, Parrot_loadbc. [eligible in 1.1]
-
-They have been renamed to C<Parrot_pbc_read>, C<Parrot_pbc_load>.
-C<Parrot_pbc_read> has one third int argument.
-
-L<https://trac.parrot.org/parrot/ticket/266>
-
=item C API coding standards cleanup [eligible in 1.1]
All C API functions that aren't currently named according to the
@@ -212,12 +205,6 @@ check in 1.4 or 2.0 for the new names.
L<https://trac.parrot.org/parrot/ticket/443>
-=item Parrot_add_library_path [eligible in 1.1]
-
-Will be renamed to C<Parrot_lib_add_path_from_cstring>.
-
-L<https://trac.parrot.org/parrot/ticket/455>
-
=item parrot_new_pmc_hash [eligible in 1.5]
This function will be removed. parrot_new_hash should be used in its place.
9 MANIFEST
View
@@ -1,10 +1,10 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Sun May 24 16:30:09 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Jun 4 22:51:55 2009 UT
+#
+# See below for documentation on the format of this file.
#
-# See tools/dev/install_files.pl for documentation on the
-# format of this file.
# See docs/submissions.pod on how to recreate this file after SVN
# has been told about new or deleted files.
CREDITS []
@@ -114,6 +114,7 @@ compilers/nqp/t/25-list_context.t [test]
compilers/nqp/t/26-method_ops.t [test]
compilers/nqp/t/27-ternary.t [test]
compilers/nqp/t/28-return.t [test]
+compilers/nqp/t/29-self.t [test]
compilers/nqp/t/harness [test]
compilers/pct/PCT.pir [pct]
compilers/pct/README.pod []doc
@@ -1760,6 +1761,7 @@ t/op/01-parse_ops.t [test]
t/op/64bit.t [test]
t/op/annotate.t [test]
t/op/arithmetics.t [test]
+t/op/arithmetics_pmc.t [test]
t/op/basic.t [test]
t/op/bitwise.t [test]
t/op/box.t [test]
@@ -2027,6 +2029,7 @@ t/tools/install/testlib/manifest_pseudo [test]
t/tools/install/testlib/parrot.pc [test]
t/tools/install/testlib/phony [test]
t/tools/install/testlib/phony.exe [test]
+t/tools/install/testlib/runtime/parrot/include/sockets.pasm [test]
t/tools/install/testlib/runtime/parrot/library/TGE.pbc [test]
t/tools/install/testlib/src/ops/ops.num [test]
t/tools/install/testlib/src/pmc/pmc_object.h [test]
5 NEWS
View
@@ -1,5 +1,10 @@
# $Id$
+New in 1.3.0
+- Core
+ + Optimization for parts of the IO system
+ + Fix inheritance heirarchy of FileHandle and Socket PMC types
+
New in 1.2.0
- Core
+ Fixes for pir classes inheriting from core pmcs.
1  PBC_COMPAT
View
@@ -27,6 +27,7 @@
# please insert tab separated entries at the top of the list
+4.8 2009.05.30 Infinoid Added Handle PMC
4.7 2009.05.29 cotto add cmp_pmc opcode (also, addition of setstdin and root_new in previous commits)
4.6 2009.05.18 bacek removed PackfileAnnotationKeys PMC
4.5 2009.04.10 cotto removed Ref and SharedRef PMCs
1  PLATFORMS
View
@@ -58,7 +58,6 @@ netbsd5.0-sparc-gcc-4.1.3 B Y - - Y Y Y Y ? 20090519
netbsd5.0-sparc64-gcc-4.1.3 B8 Y - - Y Y Y Y/1 ? 20090519
netbsd5.0-x86_64-gcc-4.1.3 8 Y - - Y Y Y Y ? 20090419
opensolaris-x86-gcc_4.0.3 4 Y Y ? ? ? Y Y/2 ? 20080325
-sol8-sparc-gcc_4.1.0 B - - - - - - Y/42 ? 20090317
win32-x86-mingw_gcc4.3.0 Y Y - - - Y Y/88 ? 20081203
win32-x86-msvc_6.0 4 - Y - - - Y Y/8 ? 20090315
win32-x64-msvc_9.0 8 - - - - - Y Y/51 ? 20081203
2  README
View
@@ -18,7 +18,7 @@ You need a C compiler, a linker, and a make program of course. If you will be
linking with the ICU library you have to download and install it before
configuring Parrot.
-Get it from http://www-306.ibm.com/software/globalization/icu/downloads.jsp
+Get it from http://site.icu-project.org/download
You also need Perl 5.8.4 or newer, Storable 2.12 or newer, and Bundle::Parrot
to run various configure and build scripts.
2  README_win32.pod
View
@@ -60,7 +60,7 @@ build Parrot without it, by not installing it or asking Parrot to
ignore it (C<--without-icu>).
If you want to use ICU, download it from
-L<http://www.icu-project.org/download/>.
+L<http://site.icu-project.org/download>.
If you want to use precompiled binaries, do the following.
Download the package matching your compiler, unpack it (say, into
2  compilers/imcc/imcc.l
View
@@ -505,7 +505,7 @@ SP [ ]
YYCHOP();
if (valp)
- valp->s = yytext;
+ valp->s = str_dup(yytext);
return LABEL;
}
39 compilers/imcc/imcc.y
View
@@ -800,14 +800,19 @@ IMCC_itcall_sub(PARROT_INTERP, ARGIN(SymReg *sub))
{
ASSERT_ARGS(IMCC_itcall_sub)
IMCC_INFO(interp)->cur_call->pcc_sub->sub = sub;
+
if (IMCC_INFO(interp)->cur_obj) {
if (IMCC_INFO(interp)->cur_obj->set != 'P')
IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR, "object isn't a PMC");
- IMCC_INFO(interp)->cur_call->pcc_sub->object = IMCC_INFO(interp)->cur_obj;
+
+ IMCC_INFO(interp)->cur_call->pcc_sub->object =
+ IMCC_INFO(interp)->cur_obj;
IMCC_INFO(interp)->cur_obj = NULL;
}
+
if (IMCC_INFO(interp)->cur_call->pcc_sub->sub->pmc_type == enum_class_NCI)
IMCC_INFO(interp)->cur_call->pcc_sub->flags |= isNCI;
+
if (IMCC_INFO(interp)->cur_unit->type == IMC_PCCSUB)
IMCC_INFO(interp)->cur_unit->instructions->symregs[0]->pcc_sub->calls_a_sub |= 1;
}
@@ -1407,13 +1412,13 @@ vtable:
VTABLE_METHOD
{
$$ = P_VTABLE;
- IMCC_INFO(interp)->cur_unit->vtable_name = NULL;
+ IMCC_INFO(interp)->cur_unit->vtable_name = NULL;
IMCC_INFO(interp)->cur_unit->is_vtable_method = 1;
}
| VTABLE_METHOD '(' STRINGC ')'
{
$$ = P_VTABLE;
- IMCC_INFO(interp)->cur_unit->vtable_name = $3;
+ IMCC_INFO(interp)->cur_unit->vtable_name = $3;
IMCC_INFO(interp)->cur_unit->is_vtable_method = 1;
}
;
@@ -1423,13 +1428,13 @@ method:
{
$$ = P_METHOD;
IMCC_INFO(interp)->cur_unit->method_name = NULL;
- IMCC_INFO(interp)->cur_unit->is_method = 1;
+ IMCC_INFO(interp)->cur_unit->is_method = 1;
}
| METHOD '(' any_string ')'
{
$$ = P_METHOD;
IMCC_INFO(interp)->cur_unit->method_name = $3;
- IMCC_INFO(interp)->cur_unit->is_method = 1;
+ IMCC_INFO(interp)->cur_unit->is_method = 1;
}
;
@@ -1437,7 +1442,7 @@ ns_entry_name:
NS_ENTRY
{
$$ = 0;
- IMCC_INFO(interp)->cur_unit->ns_entry_name = NULL;
+ IMCC_INFO(interp)->cur_unit->ns_entry_name = NULL;
IMCC_INFO(interp)->cur_unit->has_ns_entry_name = 1;
}
| NS_ENTRY '(' any_string ')'
@@ -1674,8 +1679,8 @@ paramtype:
| ADV_OPTIONAL { $$ = VT_OPTIONAL; }
| ADV_OPT_FLAG { $$ = VT_OPT_FLAG; }
| ADV_NAMED { $$ = VT_NAMED; }
- | ADV_NAMED '(' STRINGC ')' { adv_named_set(interp, $3); $$ = 0; }
- | ADV_NAMED '(' USTRINGC ')' { adv_named_set_u(interp, $3); $$ = 0; }
+ | ADV_NAMED '(' STRINGC ')' { adv_named_set(interp, $3); $$ = 0; mem_sys_free($3); }
+ | ADV_NAMED '(' USTRINGC ')' { adv_named_set_u(interp, $3); $$ = 0; mem_sys_free($3); }
| UNIQUE_REG { $$ = VT_UNIQUE_REG; }
;
@@ -1826,7 +1831,9 @@ _labels:
label:
LABEL
{
- $$ = iLABEL(interp, IMCC_INFO(interp)->cur_unit, mk_local_label(interp, $1));
+ Instruction *i = iLABEL(interp, IMCC_INFO(interp)->cur_unit, mk_local_label(interp, $1));
+ mem_sys_free($1);
+ $$ = i;
}
;
@@ -1899,11 +1906,13 @@ labeled_inst:
{
SymReg *n = mk_const(interp, $2, 'S');
set_lexical(interp, $4, n); $$ = 0;
+ mem_sys_free($2);
}
| LEXICAL USTRINGC COMMA target
{
SymReg *n = mk_const(interp, $2, 'U');
set_lexical(interp, $4, n); $$ = 0;
+ mem_sys_free($2);
}
| CONST { pesky_global__is_def=1; } type IDENTIFIER '=' const
{
@@ -2092,9 +2101,9 @@ func_assign:
;
the_sub:
- IDENTIFIER { $$ = mk_sub_address(interp, $1); mem_sys_free($1); }
- | STRINGC { $$ = mk_sub_address_fromc(interp, $1); mem_sys_free($1); }
- | USTRINGC { $$ = mk_sub_address_u(interp, $1); mem_sys_free($1); }
+ IDENTIFIER { $$ = mk_sub_address(interp, $1); mem_sys_free($1); }
+ | STRINGC { $$ = mk_sub_address_fromc(interp, $1); mem_sys_free($1); }
+ | USTRINGC { $$ = mk_sub_address_u(interp, $1); mem_sys_free($1); }
| target
{
$$ = $1;
@@ -2115,6 +2124,12 @@ the_sub:
IMCC_INFO(interp)->cur_obj = $1;
$$ = $3;
}
+ | target DOT USTRINGC
+ {
+ IMCC_INFO(interp)->cur_obj = $1;
+ $$ = mk_const(interp, $3, 'U');
+ mem_sys_free($3);
+ }
| target DOT STRINGC
{
IMCC_INFO(interp)->cur_obj = $1;
2  compilers/imcc/imclexer.c
View
@@ -3601,7 +3601,7 @@ YY_RULE_SETUP
YYCHOP();
if (valp)
- valp->s = yytext;
+ valp->s = str_dup(yytext);
return LABEL;
}
1,472 compilers/imcc/imcparser.c
View
746 additions, 726 deletions not shown
2  compilers/imcc/imcparser.h
View
@@ -295,7 +295,7 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 1030 "compilers/imcc/imcc.y"
+#line 1035 "compilers/imcc/imcc.y"
{
IdList * idlist;
int t;
15 compilers/imcc/main.c
View
@@ -219,14 +219,9 @@ help(void)
" -L --library add path to library search\n"
" -X --dynext add path to dynamic extension search\n"
" <Run core options>\n"
- " -R --runcore CORE\n"
- " --bounds-checks|--slow-core\n"
- " --CGP-core\n"
- " --fast-core\n"
- " --computed-goto-core\n"
- " --jit-core\n"
+ " -R --runcore slow|bounds|fast|jit|cgoto|cgp|cgp-jit\n"
+ " -R --runcore switch|switch-jit|trace|exec|gcdebug\n"
" -p --profile\n"
- " --switched-core\n"
" -t --trace [flags]\n"
" <VM options>\n"
" -D --parrot-debug[=HEXFLAGS]\n"
@@ -534,15 +529,15 @@ parseflags(PARROT_INTERP, int *argc, char **argv[])
SET_FLAG(PARROT_DESTROY_FLAG);
break;
case 'I':
- Parrot_add_library_path_from_cstring(interp, opt.opt_arg,
+ Parrot_lib_add_path_from_cstring(interp, opt.opt_arg,
PARROT_LIB_PATH_INCLUDE);
break;
case 'L':
- Parrot_add_library_path_from_cstring(interp, opt.opt_arg,
+ Parrot_lib_add_path_from_cstring(interp, opt.opt_arg,
PARROT_LIB_PATH_LIBRARY);
break;
case 'X':
- Parrot_add_library_path_from_cstring(interp, opt.opt_arg,
+ Parrot_lib_add_path_from_cstring(interp, opt.opt_arg,
PARROT_LIB_PATH_DYNEXT);
break;
default:
6 compilers/imcc/parser_util.c
View
@@ -330,6 +330,12 @@ var_arg_ins(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGIN(const char *name),
/* in constant */
int dirs = 1;
+ /* XXX: Maybe the check for n == 0 is the only one required
+ * and the other must be assertions? */
+ if (n == 0 || r[0] == NULL || r[0]->name == NULL)
+ IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR,
+ "The opcode '%s' needs arguments", name);
+
r[0] = mk_const(interp, r[0]->name, 'P');
r[0]->pmc_type = enum_class_FixedIntegerArray;
10 compilers/imcc/pcc.c
View
@@ -815,8 +815,14 @@ expand_pcc_sub_call(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGMOD(Instruction *i
if (arg->set != 'P') {
if (!(arg->type == VTIDENTIFIER
|| arg->type == VTPASM
- || arg->type == VTREG))
- meth = mk_const(interp, arg->name, 'S');
+ || arg->type == VTREG)) {
+ if (arg->type & VT_ENCODED) {
+ meth = mk_const(interp, arg->name, 'U');
+ }
+ else {
+ meth = mk_const(interp, arg->name, 'S');
+ }
+ }
}
}
9 compilers/imcc/reg_alloc.c
View
@@ -1189,8 +1189,9 @@ allocate_uniq(PARROT_INTERP, ARGMOD(IMC_Unit *unit), int usage)
&& (r->usage & usage)
&& r->use_count) {
Set *avail = sets[j];
- int first_reg = first_avail(unit, (int)r->set, &avail);
-
+ int first_reg = avail
+ ? set_first_zero(avail)
+ : first_avail(unit, (int)r->set, &avail);
set_add(avail, first_reg);
r->color = first_reg++;
@@ -1200,6 +1201,10 @@ allocate_uniq(PARROT_INTERP, ARGMOD(IMC_Unit *unit), int usage)
(int)r->set, r->name, r->color);
unit->first_avail[j] = first_reg;
+
+ /* don't lose this set; we must free it */
+ if (!sets[j])
+ sets[j] = avail;
}
}
}
2  compilers/imcc/symreg.c
View
@@ -923,7 +923,7 @@ _mk_address(PARROT_INTERP, ARGMOD(SymHash *hsh), ARGIN(const char *name), int un
char *aux_name = NULL;
const char * const sub_name = (uniq == U_add_uniq_sub)
/* remember to free this name; add_ns malloc()s it */
- ? (aux_name= add_ns(interp, name))
+ ? (aux_name = add_ns(interp, name))
: (char *)name;
r = _get_sym(hsh, sub_name);
44 docs/book/appc_command_line_options.pod
View
@@ -252,37 +252,59 @@ goto core> if it's available. Otherwise the I<fast core> is used.
=over 4
-=item --bounds-checks
+=item -R slow
+
+Run with the I<slow core>
+
+=item -R bounds
Activate bounds checking. This also runs with the I<slow core> as a
side effect.
-=item --fast-core
+=item -R fast
Run with the I<fast core>.
-=item --computed-goto-core
+=item -R cgoto
Run the I<computed goto core> (CGoto).
-=item --jit-core
+=item -R jit
Run with the I<JIT core> if available.
-=item -p,--profile
+=item -R cgp
-Activate profiling. This prints a summary of opcode usage and
-execution times after the program stops. It also runs within the
-I<slow core>.
+Run with the I<CGoto-Prederefed> core.
-=item --CGP-core
+=item -R cgp-jit
-Run with the I<CGoto-Prederefed> core.
+Run with the I<CGoto-Prederefed with jit> core.
-=item --switched-core
+=item -R switch
Run with the I<Switched core>.
+=item -R switch-jit
+
+Run with the I<Switched core with jit>.
+
+=item -R exec
+
+Run with the I<exec core>
+(uses JIT at compile time to generate native code)
+
+=item -R gcdebug
+
+Performs a full GC run before every op dispatch
+(good for debugging GC problems)
+
+=item -p,--profile
+
+Activate profiling. This prints a summary of opcode usage and
+execution times after the program stops. It also runs within the
+I<slow core>.
+
=item -t,--trace
Trace execution. This also turns on the I<slow core>.
2  docs/pdds/pdd28_strings.pod
View
@@ -39,7 +39,7 @@ given character set. So in ASCII, the character C<A> has codepoint 0x41.
An encoding determines how a codepoint is represented inside a computer.
Simple encodings like ASCII define that the codepoints 0-127 simply
live as their numeric equivalents inside an eight-bit bytes. Other
-fixed-width encodings like UTF-16 use more bytes to encode more
+fixed-width encodings like UCS-2 use more bytes to encode more
codepoints. Variable-width encodings like UTF-8 use one byte for
codepoints 0-127, two bytes for codepoints 127-2047, and so on.
27 docs/running.pod
View
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2008, Parrot Foundation.
+# Copyright (C) 2001-2009, Parrot Foundation.
# $Id$
=head1 NAME
@@ -147,35 +147,10 @@ may be available on your system:
switch-jit switch core with JIT
trace bounds checking core w/ trace info (see 'parrot --help-debug')
-=item --bounds-checks, --slow-core
-
-Select the bounds-checking slow core (default).
-
-=item --computed-goto-core
-
-Select the CGoto core (if available).
-
-=item --CGP-core
-
-Select the CGP (CGoto Predereferenced) core (if available).
-
-=item --fast-core
-
-Select the fast (or function) core. Bounds checking, profiling, and tracing
-are not available. (That's why it's so fast.)
-
-=item --jit-core
-
-Run with the JIT subsystem (if available).
-
=item -p, --profile
Run with the slow core and print an execution profile.
-=item --switched-core
-
-TODO: This needs to be documented briefly here and also in glossary.pod.
-
=item -t, --trace
Run with the slow core and print trace information to B<stderr>. See C<parrot
6 include/parrot/embed.h
View
@@ -84,12 +84,6 @@ void Parrot_set_config_hash(void);
int Parrot_revision(void);
-/* Deprecated */
-
-/* with 0.9.1 TT #266 */
-#define Parrot_readbc(i, c) Parrot_pbc_read((i), (c), 0)
-#define Parrot_loadbc(i, pf) Parrot_pbc_load((i), (pf))
-
#endif /* PARROT_EMBED_H_GUARD */
/*
14 include/parrot/io.h
View
@@ -150,6 +150,10 @@ INTVAL Parrot_io_close(PARROT_INTERP, ARGMOD(PMC *pmc))
FUNC_MODIFIES(*pmc);
PARROT_EXPORT
+INTVAL Parrot_io_close_piohandle(PARROT_INTERP, PIOHANDLE handle)
+ __attribute__nonnull__(1);
+
+PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL Parrot_io_eof(PARROT_INTERP, ARGMOD(PMC *pmc))
__attribute__nonnull__(1)
@@ -229,10 +233,9 @@ PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_io_open(PARROT_INTERP,
ARGIN_NULLOK(PMC *pmc),
- ARGIN(STRING *path),
+ ARGIN_NULLOK(STRING *path),
ARGIN_NULLOK(STRING *mode))
- __attribute__nonnull__(1)
- __attribute__nonnull__(3);
+ __attribute__nonnull__(1);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
@@ -352,6 +355,8 @@ PIOOFF_T Parrot_io_make_offset_pmc(PARROT_INTERP, ARGMOD(PMC *pmc))
#define ASSERT_ARGS_Parrot_io_close __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc)
+#define ASSERT_ARGS_Parrot_io_close_piohandle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_eof __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc)
@@ -380,8 +385,7 @@ PIOOFF_T Parrot_io_make_offset_pmc(PARROT_INTERP, ARGMOD(PMC *pmc))
#define ASSERT_ARGS_Parrot_io_new_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_open __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(path)
+ PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_peek __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc) \
2  include/parrot/io_portable.h
View
@@ -16,6 +16,8 @@
typedef FILE* PIOHANDLE;
typedef long PIOOFF_T;
+#define PIO_INVALID_HANDLE NULL
+
/* HEADERIZER BEGIN: src/io/portable.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
21 include/parrot/io_unix.h
View
@@ -18,6 +18,8 @@
typedef INTVAL PIOHANDLE;
typedef off_t PIOOFF_T;
+#define PIO_INVALID_HANDLE -1
+
/* HEADERIZER BEGIN: src/io/unix.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
@@ -28,6 +30,7 @@ INTVAL Parrot_io_async_unix(PARROT_INTERP,
__attribute__nonnull__(2)
FUNC_MODIFIES(*filehandle);
+INTVAL Parrot_io_close_piohandle_unix(SHIM_INTERP, PIOHANDLE handle);
INTVAL Parrot_io_close_unix(PARROT_INTERP, ARGMOD(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -82,6 +85,16 @@ size_t Parrot_io_peek_unix(PARROT_INTERP,
SHIM(STRING **buf))
__attribute__nonnull__(1);
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+INTVAL Parrot_io_pipe_unix(SHIM_INTERP,
+ ARGMOD(PIOHANDLE *reader),
+ ARGMOD(PIOHANDLE *writer))
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(*reader)
+ FUNC_MODIFIES(*writer);
+
size_t Parrot_io_read_unix(PARROT_INTERP,
ARGMOD(PMC *filehandle),
ARGIN(STRING **buf))
@@ -114,6 +127,8 @@ size_t Parrot_io_write_unix(PARROT_INTERP,
#define ASSERT_ARGS_Parrot_io_async_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
+#define ASSERT_ARGS_Parrot_io_close_piohandle_unix \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_Parrot_io_close_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
@@ -138,6 +153,9 @@ size_t Parrot_io_write_unix(PARROT_INTERP,
|| PARROT_ASSERT_ARG(path)
#define ASSERT_ARGS_Parrot_io_peek_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_io_pipe_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(reader) \
+ || PARROT_ASSERT_ARG(writer)
#define ASSERT_ARGS_Parrot_io_read_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle) \
@@ -269,6 +287,7 @@ INTVAL Parrot_io_socket_unix(PARROT_INTERP,
#define PIO_OPEN_PIPE(interp, pmc, file, flags) \
Parrot_io_open_pipe_unix((interp), (pmc), (file), (flags))
#define PIO_CLOSE(interp, pmc) Parrot_io_close_unix((interp), (pmc))
+#define PIO_CLOSE_PIOHANDLE(interp, handle) Parrot_io_close_piohandle_unix((interp), (handle))
#define PIO_IS_CLOSED(interp, pmc) Parrot_io_is_closed_unix((interp), (pmc))
#define PIO_READ(interp, pmc, buf) Parrot_io_read_unix((interp), (pmc), (buf))
#define PIO_WRITE(interp, pmc, str) Parrot_io_write_unix((interp), (pmc), (str))
@@ -281,6 +300,8 @@ INTVAL Parrot_io_socket_unix(PARROT_INTERP,
#define PIO_POLL(interp, pmc, which, sec, usec) \
Parrot_io_poll_unix((interp), (pmc), (which), (sec), (usec))
+#define PIO_PIPE(interp, reader, writer) \
+ Parrot_io_pipe_unix((interp), (reader), (writer))
#define PIO_SOCKET(interp, socket, fam, type, proto) \
Parrot_io_socket_unix((interp), (socket), (fam), (type), (proto))
#define PIO_RECV(interp, pmc, buf) \
24 include/parrot/io_win32.h
View
@@ -16,9 +16,14 @@
typedef Parrot_WIN32_HANDLE PIOHANDLE;
typedef Parrot_OFF_T PIOOFF_T;
+#define PIO_INVALID_HANDLE INVALID_HANDLE_VALUE
+
/* HEADERIZER BEGIN: src/io/win32.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+INTVAL Parrot_io_close_piohandle_win32(PARROT_INTERP, PIOHANDLE handle)
+ __attribute__nonnull__(1);
+
INTVAL Parrot_io_close_win32(PARROT_INTERP, ARGMOD(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -72,6 +77,16 @@ size_t Parrot_io_peek_win32(PARROT_INTERP,
SHIM(STRING **buf))
__attribute__nonnull__(1);
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+INTVAL Parrot_io_pipe_win32(SHIM_INTERP,
+ ARGMOD(PIOHANDLE *reader),
+ ARGMOD(PIOHANDLE *writer))
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(*reader)
+ FUNC_MODIFIES(*writer);
+
size_t Parrot_io_read_win32(PARROT_INTERP,
ARGMOD(PMC *filehandle),
ARGOUT(STRING **buf))
@@ -100,6 +115,9 @@ size_t Parrot_io_write_win32(PARROT_INTERP,
__attribute__nonnull__(2)
__attribute__nonnull__(3);
+#define ASSERT_ARGS_Parrot_io_close_piohandle_win32 \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_close_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
@@ -124,6 +142,9 @@ size_t Parrot_io_write_win32(PARROT_INTERP,
|| PARROT_ASSERT_ARG(path)
#define ASSERT_ARGS_Parrot_io_peek_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_io_pipe_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(reader) \
+ || PARROT_ASSERT_ARG(writer)
#define ASSERT_ARGS_Parrot_io_read_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle) \
@@ -251,6 +272,7 @@ INTVAL Parrot_io_socket_win32(PARROT_INTERP,
#define PIO_OPEN_PIPE(interp, pmc, file, flags) \
Parrot_io_open_pipe_win32((interp), (pmc), (file), (flags))
#define PIO_CLOSE(interp, pmc) Parrot_io_close_win32((interp), (pmc))
+#define PIO_CLOSE_PIOHANDLE(interp, handle) Parrot_io_close_piohandle_win32((interp), (handle))
#define PIO_IS_CLOSED(interp, pmc) Parrot_io_is_closed_win32((interp), (pmc))
#define PIO_READ(interp, pmc, buf) Parrot_io_read_win32((interp), (pmc), (buf))
#define PIO_WRITE(interp, pmc, str) Parrot_io_write_win32((interp), (pmc), (str))
@@ -263,6 +285,8 @@ INTVAL Parrot_io_socket_win32(PARROT_INTERP,
#define PIO_POLL(interp, pmc, which, sec, usec) \
Parrot_io_poll_win32((interp), (pmc), (which), (sec), (usec))
+#define PIO_PIPE(interp, reader, writer) \
+ Parrot_io_pipe_win32((interp), (reader), (writer))
#define PIO_SOCKET(interp, socket, fam, type, proto) \
Parrot_io_socket_win32((interp), (socket), (fam), (type), (proto))
#define PIO_RECV(interp, pmc, buf) \
42 include/parrot/library.h
View
@@ -39,20 +39,6 @@ typedef enum {
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
PARROT_EXPORT
-void Parrot_add_library_path(PARROT_INTERP,
- ARGIN(STRING *path),
- enum_lib_paths which)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_EXPORT
-void Parrot_add_library_path_from_cstring(PARROT_INTERP,
- ARGIN(const char *path),
- enum_lib_paths which)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_get_runtime_path(PARROT_INTERP)
__attribute__nonnull__(1);
@@ -64,6 +50,20 @@ char* Parrot_get_runtime_prefix(PARROT_INTERP)
__attribute__nonnull__(1);
PARROT_EXPORT
+void Parrot_lib_add_path(PARROT_INTERP,
+ ARGIN(STRING *path_str),
+ enum_lib_paths which)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
+void Parrot_lib_add_path_from_cstring(PARROT_INTERP,
+ ARGIN(const char *path),
+ enum_lib_paths which)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
PARROT_MALLOC
@@ -100,17 +100,17 @@ STRING * parrot_split_path_ext(PARROT_INTERP,
FUNC_MODIFIES(*wo_ext)
FUNC_MODIFIES(*ext);
-#define ASSERT_ARGS_Parrot_add_library_path __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(path)
-#define ASSERT_ARGS_Parrot_add_library_path_from_cstring \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(path)
#define ASSERT_ARGS_Parrot_get_runtime_path __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_get_runtime_prefix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_lib_add_path __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(path_str)
+#define ASSERT_ARGS_Parrot_lib_add_path_from_cstring \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(path)
#define ASSERT_ARGS_Parrot_locate_runtime_file __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(file_name)
22 include/parrot/runcore_api.h
View
@@ -25,14 +25,17 @@ PARROT_EXPORT
void enable_event_checking(PARROT_INTERP)
__attribute__nonnull__(1);
-void do_prederef(void **pc_prederef, PARROT_INTERP, int type)
+void do_prederef(ARGIN(void **pc_prederef), PARROT_INTERP, int type)
+ __attribute__nonnull__(1)
__attribute__nonnull__(2);
-void dynop_register(PARROT_INTERP, PMC *lib_pmc)
- __attribute__nonnull__(1);
+void dynop_register(PARROT_INTERP, ARGIN(PMC *lib_pmc))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
-void exec_init_prederef(PARROT_INTERP, void *prederef_arena)
- __attribute__nonnull__(1);
+void exec_init_prederef(PARROT_INTERP, ARGIN(void *prederef_arena))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
@@ -56,11 +59,14 @@ void runops_int(PARROT_INTERP, size_t offset)
#define ASSERT_ARGS_enable_event_checking __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_do_prederef __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp)
+ PARROT_ASSERT_ARG(pc_prederef) \
+ || PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_dynop_register __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp)
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(lib_pmc)
#define ASSERT_ARGS_exec_init_prederef __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp)
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(prederef_arena)
#define ASSERT_ARGS_init_jit __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_runcore_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = \
10 lib/Parrot/Install.pm
View
@@ -5,7 +5,7 @@ use strict;
use warnings;
use File::Basename qw(dirname);
use File::Copy;
-use File::Path; # mkpath
+use File::Path qw( mkpath );
use File::Spec;
use base qw( Exporter );
our @EXPORT_OK = qw(
@@ -175,9 +175,11 @@ B<Comment:>
sub create_directories {
my($destdir, $directories) = @_;
- mkpath([
- grep { ! -d } map { $destdir . $_ } keys %$directories
- ],0,0777);
+ my @dirs_created = mkpath(
+ ( grep { ! -d } map { $destdir . $_ } keys %$directories ),
+ { mode => 0777 },
+ );
+ return 1;
}
=head2 C<install_files()>
4 lib/Parrot/Ops2pm.pm
View
@@ -323,7 +323,7 @@ sub print_module {
my $cwd = cwd();
my $fulldir = File::Spec->catdir( $cwd, $self->{moddir} );
if ( !-d $fulldir ) {
- if ( !File::Path::mkpath( $fulldir, 0, 0755 ) ) {
+ if ( !File::Path::mkpath( $fulldir, { mode => 0755 } ) ) {
-d $fulldir
or die "$self->{script}: Could not mkdir $fulldir: $!!\n";
}
@@ -412,7 +412,7 @@ sub print_h {
my $cwd = cwd();
my $fulldir = File::Spec->catdir( $cwd, $self->{inc_dir} );
if ( !-d $fulldir ) {
- if ( !File::Path::mkpath( $fulldir, 0, 0755 ) ) {
+ if ( !File::Path::mkpath( $fulldir, { mode => 0755 } ) ) {
-d $fulldir
or die "$self->{script}: Could not mkdir $fulldir: $!!\n";
}
40 runtime/parrot/languages/parrot/parrot.pir
View
@@ -61,6 +61,46 @@
ns.'export_to'(exportns, syms)
.end
+.sub 'import' :method :multi(_,_)
+ .param pmc library
+ .local pmc i, targetns
+ i = getinterp
+ targetns = i['namespace';1]
+ .tailcall self.'import'('parrot',library,'targetns'=>targetns)
+.end
+
+.sub 'import' :method :multi(_,_,_)
+ .param string lang
+ .param pmc library
+ .param pmc targetns :named('targetns') :optional
+ .local pmc name, compiler, library, imports
+ $S0 = library
+ name = split '::', $S0
+ compiler = compreg lang
+ unless null targetns goto has_targetns
+ $P0 = getinterp
+ targetns = $P0['namespace';1]
+ has_targetns:
+ library = compiler.'load_library'(name)
+ imports = library['symbols']
+ imports = imports['DEFAULT']
+ .local pmc ns_iter, item
+ ns_iter = iter imports
+ import_loop:
+ unless ns_iter goto import_loop_end
+ $S0 = shift ns_iter
+ $P0 = imports[$S0]
+ targetns[$S0] = $P0
+ goto import_loop
+ import_loop_end:
+ #foreignlibns = library['namespace']
+ #if null foreignlibns goto no_foreign_ns
+ #$S0 = pop name
+ #set_hll_global name, $S0, foreignlibns
+ #no_foreign_ns:
+ .return (library)
+.end
+
# TODO Should this provide support for loading HLL libraries?
=head1 NAME
88 src/embed.c
View
@@ -106,6 +106,7 @@ Parrot_new(ARGIN_NULLOK(Parrot_Interp parent))
return make_interpreter(parent, PARROT_NO_FLAGS);
}
+
/*
=item C<void Parrot_init_stacktop(PARROT_INTERP, void *stack_top)>
@@ -388,17 +389,17 @@ PARROT_CAN_RETURN_NULL
PackFile *
Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *fullname), const int debug)
{
+ PackFile *pf;
+ char *program_code;
FILE *io = NULL;
INTVAL is_mapped = 0;
- char *program_code;
- PackFile *pf;
INTVAL program_size;
#ifdef PARROT_HAS_HEADER_SYSMMAN
int fd = -1;
#endif
- if (fullname == NULL || STREQ(fullname, "-")) {
+ if (!fullname || STREQ(fullname, "-")) {
/* read from STDIN */
io = stdin;
@@ -418,8 +419,9 @@ Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *fullname), const int deb
/* we may need to relax this if we want to read bytecode from pipes */
if (!Parrot_stat_info_intval(interp, fs, STAT_ISREG)) {
- Parrot_io_eprintf(interp, "Parrot VM: '%s', is not a regular file %i.\n",
- fullname, errno);
+ Parrot_io_eprintf(interp,
+ "Parrot VM: '%s', is not a regular file %i.\n",
+ fullname, errno);
return NULL;
}
@@ -446,17 +448,18 @@ Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *fullname), const int deb
INTVAL wanted = program_size;
size_t read_result;
- program_code = (char *)mem_sys_allocate(chunk_size);
+ program_code = mem_allocate_n_typed(chunk_size, char);
+ cursor = program_code;
program_size = 0;
- cursor = (char *)program_code;
while ((read_result = fread(cursor, 1, chunk_size, io)) > 0) {
program_size += read_result;
+
if (program_size == wanted)
break;
+
chunk_size = 1024;
- program_code =
- (char *)mem_sys_realloc(program_code, program_size + chunk_size);
+ mem_realloc_n_typed(program_code, program_size + chunk_size, char);
if (!program_code) {
Parrot_io_eprintf(interp,
@@ -466,15 +469,17 @@ Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *fullname), const int deb
return NULL;
}
- cursor = (char *)program_code + program_size;
+ cursor = (char *)(program_code + program_size);
}
if (ferror(io)) {
- Parrot_io_eprintf(interp, "Parrot VM: Problem reading packfile from PIO: code %d.\n",
+ Parrot_io_eprintf(interp,
+ "Parrot VM: Problem reading packfile from PIO: code %d.\n",
ferror(io));
mem_sys_free(program_code);
return NULL;
}
+
fclose(io);
}
else {
@@ -507,12 +512,13 @@ Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *fullname), const int deb
/* try again, now with IO reading the file */
io = fopen(fullname, "rb");
if (!io) {
- Parrot_io_eprintf(interp, "Parrot VM: Can't open %s, code %i.\n",
- fullname, errno);
+ Parrot_io_eprintf(interp,
+ "Parrot VM: Can't open %s, code %i.\n", fullname, errno);
return NULL;
}
goto again;
}
+
is_mapped = 1;
#else /* PARROT_HAS_HEADER_SYSMMAN */
@@ -539,8 +545,8 @@ Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *fullname), const int deb
return NULL;
}
+ /* Set :main routine */
if (!(pf->options & PFOPT_HEADERONLY))
- /* Set :main routine */
do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL);
/* JITting and/or prederefing the sub/the bytecode is done
@@ -573,7 +579,7 @@ PARROT_EXPORT
void
Parrot_pbc_load(PARROT_INTERP, NOTNULL(PackFile *pf))
{
- if (pf == NULL) {
+ if (!pf) {
Parrot_io_eprintf(interp, "Invalid packfile\n");
return;
}
@@ -582,6 +588,7 @@ Parrot_pbc_load(PARROT_INTERP, NOTNULL(PackFile *pf))
interp->code = pf->cur_cs;
}
+
/*
=item C<void Parrot_pbc_fixup_loaded(PARROT_INTERP)>
@@ -599,6 +606,7 @@ Parrot_pbc_fixup_loaded(PARROT_INTERP)
PackFile_fixup_subs(interp, PBC_LOADED, NULL);
}
+
/*
=item C<static PMC* setup_argv(PARROT_INTERP, int argc, char **argv)>
@@ -614,9 +622,8 @@ static PMC*
setup_argv(PARROT_INTERP, int argc, ARGIN(char **argv))
{
ASSERT_ARGS(setup_argv)
+ PMC *userargv = pmc_new(interp, enum_class_ResizableStringArray);
INTVAL i;
- PMC *userargv;
-
if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG)) {
Parrot_io_eprintf(interp,
@@ -624,14 +631,10 @@ setup_argv(PARROT_INTERP, int argc, ARGIN(char **argv))
argc);
}
- userargv = pmc_new_noinit(interp, enum_class_ResizableStringArray);
-
/* immediately anchor pmc to root set */
VTABLE_set_pmc_keyed_int(interp, interp->iglobals,
(INTVAL)IGLOBALS_ARGV_LIST, userargv);
- VTABLE_init(interp, userargv);
-
for (i = 0; i < argc; i++) {
/* Run through argv, adding everything to @ARGS. */
STRING * const arg =
@@ -726,10 +729,10 @@ static FLOATVAL
calibrate(PARROT_INTERP)
{
ASSERT_ARGS(calibrate)
- size_t count = 1000000;
- size_t n = count;
opcode_t code[] = { 1 }; /* noop */
opcode_t *pc = code;
+ size_t count = 1000000;
+ size_t n = count;
FLOATVAL start = Parrot_floatval_time();
FLOATVAL now = start;
@@ -869,7 +872,6 @@ static PMC*
set_current_sub(PARROT_INTERP)
{
ASSERT_ARGS(set_current_sub)
- opcode_t i;
Parrot_sub *sub_pmc_sub;
PMC *sub_pmc;
@@ -877,6 +879,8 @@ set_current_sub(PARROT_INTERP)
PackFile_FixupTable * const ft = cur_cs->fixups;
PackFile_ConstTable * const ct = cur_cs->const_table;
+ opcode_t i;
+
/*
* Walk the fixup table. The first Sub-like entry should be our
* entry point with the address at our resume_offset.
@@ -903,7 +907,7 @@ set_current_sub(PARROT_INTERP)
}
}
- /* if we didn't find anything put a dummy PMC into current_sub */
+ /* if we didn't find anything, put a dummy PMC into current_sub */
sub_pmc = pmc_new(interp, enum_class_Sub);
PMC_get_sub(interp, sub_pmc, sub_pmc_sub);
@@ -971,7 +975,8 @@ Parrot_runcode(PARROT_INTERP, int argc, ARGIN(char **argv))
Parrot_io_eprintf(interp, "EXEC core");
break;
default:
- Parrot_ex_throw_from_c_args(interp, NULL, 1, "Unknown run core");
+ Parrot_ex_throw_from_c_args(interp, NULL, 1,
+ "Unknown run core");
}
Parrot_io_eprintf(interp, " ***\n");
@@ -1051,11 +1056,12 @@ Parrot_debug(PARROT_INTERP, NOTNULL(Parrot_Interp debugger), opcode_t * pc)
return NULL;
}
+
/*
=item C<static void print_constant_table(PARROT_INTERP)>
-Print the contents of the constants table.
+Prints the contents of the constants table.
=cut
@@ -1087,17 +1093,20 @@ print_constant_table(PARROT_INTERP) {
break;
case PFC_PMC: {
Parrot_io_printf(interp, "PMC_CONST(%d): ", i);
+
switch (c->u.key->vtable->base_type) {
- /* each PBC file has a ParrotInterpreter, but it can't stringify by itself */
+ /* each PBC file has a ParrotInterpreter, but it can't
+ * stringify by itself */
case enum_class_ParrotInterpreter:
Parrot_io_printf(interp, "'ParrotInterpreter'");
break;
- /* FixedIntegerArrays are used for signatures, handy to print */
+ /* FixedIntegerArrays used for signatures, handy to print */
case enum_class_FixedIntegerArray: {
INTVAL n = VTABLE_elements(interp, c->u.key);
INTVAL i;
Parrot_io_printf(interp, "[");
+
for (i = 0; i < n; ++i) {
INTVAL val = VTABLE_get_integer_keyed_int(interp, c->u.key, i);
Parrot_io_printf(interp, "%d", val);
@@ -1237,9 +1246,8 @@ Parrot_disassemble(PARROT_INTERP, SHIM(const char *outfile), Parrot_disassemble_
=item C<void Parrot_run_native(PARROT_INTERP, native_func_t func)>
-Run the C function C<func> through the program C<[enternative, end]>.
-This ensures that the function is run with the same setup as in other
-run loops.
+Runs the C function C<func> through the program C<[enternative, end]>. This
+ensures that the function runs with the same setup as in other run loops.
This function is used in some of the source tests in F<t/src> which use
the interpreter outside a runloop.
@@ -1273,12 +1281,13 @@ Parrot_run_native(PARROT_INTERP, native_func_t func)
runops(interp, interp->resume_offset);
}
+
/*
=item C<Parrot_PMC Parrot_compile_string(PARROT_INTERP, Parrot_String type,
const char *code, Parrot_String *error)>
-Compile code string.
+Compiles a code string.
=cut
@@ -1289,16 +1298,14 @@ Parrot_PMC
Parrot_compile_string(PARROT_INTERP, Parrot_String type,
const char *code, Parrot_String *error)
{
+ /* For the benefit of embedders that do not load any pbc
+ * before compiling a string */
- /* For the benefit of embedders that does not load any pbc
- * before compiling a string
- */
- if (! interp->initial_pf) {
+ if (!interp->initial_pf) {
PackFile *pf = PackFile_new_dummy(interp, "compile_string");
/* Assumption: there is no valid reason to fail to create it.
- * If the assumption changes, replace the assertio with a
- * runtime check
- */
+ * If the assumption changes, replace the assertion with a
+ * runtime check */
PARROT_ASSERT(interp->initial_pf);
}
@@ -1312,6 +1319,7 @@ Parrot_compile_string(PARROT_INTERP, Parrot_String type,
return NULL;
}
+
/*
=back
1  src/gc/alloc_register.c
View
@@ -181,6 +181,7 @@ destroy_context(PARROT_INTERP)
mem_sys_free(ptr);
ptr = next;
}
+ interp->ctx_mem.free_list[slot] = NULL;
}
mem_sys_free(interp->ctx_mem.free_list);
}
2  src/hash.c
View
@@ -33,7 +33,7 @@ don't apply.
/* the number of entries above which it's faster to hash the hashval instead of
* looping over the used HashBuckets directly */
#define SMALL_HASH_SIZE 4
-#define INITIAL_BUCKETS 16
+#define INITIAL_BUCKETS 4
/* HEADERIZER HFILE: include/parrot/hash.h */
221 src/io/api.c
View
@@ -19,6 +19,10 @@ process.
The C<FileHandle> PMC provides the class-based interface for filehandles that
is used in Parrot ops.
+TODO: Where possible, extract some of the filehandle-related details into
+src/io/filehandle.c, and extract the stringhandle details into
+src/io/io_string.c.
+
=cut
*/
@@ -26,6 +30,8 @@ is used in Parrot ops.
#include "parrot/parrot.h"
#include "io_private.h"
#include "api.str"
+#include "../pmc/pmc_filehandle.h"
+#include "../pmc/pmc_stringhandle.h"
#include <stdarg.h>
@@ -111,20 +117,42 @@ PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC *
Parrot_io_open(PARROT_INTERP, ARGIN_NULLOK(PMC *pmc),
- ARGIN(STRING *path), ARGIN_NULLOK(STRING *mode))
+ ARGIN_NULLOK(STRING *path), ARGIN_NULLOK(STRING *mode))
{
ASSERT_ARGS(Parrot_io_open)
- PMC *new_filehandle;
-
- if (PMC_IS_NULL(pmc))
+ PMC *new_filehandle, *filehandle;
+ INTVAL flags;
+ if (PMC_IS_NULL(pmc)) {
+ /* TODO: We should look up the HLL mapped type, instead of always
+ using FileHandle here */
new_filehandle = pmc_new(interp, enum_class_FileHandle);
+ PARROT_ASSERT(new_filehandle->vtable->base_type == enum_class_FileHandle);
+ }
else
new_filehandle = pmc;
- Parrot_PCCINVOKE(interp, new_filehandle, CONST_STRING(interp, "open"), "SS->P",
- path, mode, &new_filehandle);
-
- return new_filehandle;
+ flags = Parrot_io_parse_open_flags(interp, mode);
+ if (new_filehandle->vtable->base_type == enum_class_FileHandle) {
+ /* TODO: StringHandle may have a null path, but a filehandle really
+ shouldn't allow that. */
+ PARROT_ASSERT(new_filehandle->vtable->base_type == enum_class_FileHandle);
+ filehandle = PIO_OPEN(interp, new_filehandle, path, flags);
+ if (PMC_IS_NULL(filehandle))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+ "Unable to open filehandle from path '%S'", path);
+ PARROT_ASSERT(filehandle->vtable->base_type == enum_class_FileHandle);
+ SETATTR_FileHandle_flags(interp, new_filehandle, flags);
+ SETATTR_FileHandle_filename(interp, new_filehandle, path);
+ SETATTR_FileHandle_mode(interp, new_filehandle, mode);
+ Parrot_io_setbuf(interp, filehandle, PIO_UNBOUND);
+ }
+ else if (new_filehandle->vtable->base_type == enum_class_StringHandle) {
+ SETATTR_StringHandle_flags(interp, pmc, flags);
+ filehandle = pmc;
+ }
+ else
+ Parrot_PCCINVOKE(interp, new_filehandle, CONST_STRING(interp, "read"), "SS->P", path, mode, &open);
+ return filehandle;
}
/*
@@ -187,16 +215,45 @@ INTVAL
Parrot_io_close(PARROT_INTERP, ARGMOD(PMC *pmc))
{
ASSERT_ARGS(Parrot_io_close)
- INTVAL result;
+ INTVAL result = 1;
if (PMC_IS_NULL(pmc))
return -1;
- Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "close"), "->I", &result);
+ if (pmc->vtable->base_type == enum_class_FileHandle) {
+ result = Parrot_io_close_filehandle(interp, pmc);
+ SETATTR_FileHandle_flags(interp, pmc, 0);
+ }
+ else if (pmc->vtable->base_type == enum_class_StringHandle) {
+ SETATTR_StringHandle_read_offset(interp, pmc, 0);
+ }
+ else
+ Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "close"), "->I", &result);
return result;
}
+
+/*
+
+=item C<INTVAL Parrot_io_close_piohandle(PARROT_INTERP, PIOHANDLE handle)>
+
+Calls close() on the given PIOHANDLE. This is the low level OS-specific close()
+function, intended to be called directly by PMC destroy() vtables.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+INTVAL
+Parrot_io_close_piohandle(PARROT_INTERP, PIOHANDLE handle)
+{
+ ASSERT_ARGS(Parrot_io_close_piohandle)
+ return PIO_CLOSE_PIOHANDLE(interp, handle);
+}
+
+
/*
=item C<INTVAL Parrot_io_is_closed(PARROT_INTERP, PMC *pmc)>
@@ -214,12 +271,20 @@ INTVAL
Parrot_io_is_closed(PARROT_INTERP, ARGMOD(PMC *pmc))
{
ASSERT_ARGS(Parrot_io_is_closed)
- INTVAL result;
+ INTVAL result = 1;
if (PMC_IS_NULL(pmc))
return 1;
+ if (pmc->vtable->base_type == enum_class_FileHandle)
+ result = Parrot_io_is_closed_filehandle(interp, pmc);
+ else if (pmc->vtable->base_type == enum_class_StringHandle) {
+ STRING *stringhandle;
+ GETATTR_StringHandle_stringhandle(interp, pmc, stringhandle);
+ result = STRING_IS_NULL(stringhandle);
+ }
+ else
+ Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "is_closed"), "->I", &result);
- Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "is_closed"), "->I", &result);
return result;
}
@@ -242,7 +307,13 @@ Parrot_io_flush(PARROT_INTERP, ARGMOD(PMC *pmc))
if (PMC_IS_NULL(pmc))
return;
- Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "flush"), "->");
+ if (pmc->vtable->base_type == enum_class_FileHandle)
+ Parrot_io_flush_filehandle(interp, pmc);
+ else if (pmc->vtable->base_type == enum_class_StringHandle) {
+ SETATTR_StringHandle_stringhandle(interp, pmc, NULL);
+ }
+ else
+ Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "flush"), "->");
}
/*
@@ -264,9 +335,57 @@ STRING *
Parrot_io_reads(PARROT_INTERP, ARGMOD(PMC *pmc), size_t length)
{
ASSERT_ARGS(Parrot_io_reads)
- STRING *result;
- Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "read"), "I->S",
- length, &result);
+ STRING *result = NULL;
+ if (PMC_IS_NULL(pmc))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+ "Attempt to read from null or invalid PMC");
+ if (pmc->vtable->base_type == enum_class_FileHandle) {
+ INTVAL ignored;
+ INTVAL flags;
+ GETATTR_FileHandle_flags(interp, pmc, flags);
+
+ if (Parrot_io_is_closed_filehandle(interp, pmc)
+ || !(flags & PIO_F_READ))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+ "Cannot read from a closed or non-readable filehandle");
+
+ result = Parrot_io_make_string(interp, &result, length);
+ result->bufused = length;
+
+ if (Parrot_io_is_encoding(interp, pmc, CONST_STRING(interp, "utf8")))
+ ignored = Parrot_io_read_utf8(interp, pmc, &result);
+ else
+ ignored = Parrot_io_read_buffer(interp, pmc, &result);
+ }
+ else if (pmc->vtable->base_type == enum_class_StringHandle) {
+ STRING *string_orig;
+ INTVAL offset;
+ /* TODO: Check that we are open for reading */
+ GETATTR_StringHandle_stringhandle(interp, pmc, string_orig);
+ if (STRING_IS_NULL(string_orig))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+ "Cannot read from a closed filehandle");
+
+ if (length == 0)
+ result = Parrot_str_copy(interp, string_orig);
+ else {
+ INTVAL orig_length, read_length;
+ read_length = length;
+ orig_length = Parrot_str_byte_length(interp, string_orig);
+
+ GETATTR_StringHandle_read_offset(interp, pmc, offset);
+
+ /* Only read to the end of the string data. */
+ if (offset + read_length > orig_length)
+ read_length = orig_length - offset;
+
+ result = Parrot_str_substr(interp, string_orig, offset,
+ read_length, NULL, 0);
+ SETATTR_StringHandle_read_offset(interp, pmc, offset + read_length);
+ }
+ }
+ else
+ Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "read"), "I->S", length, &result);
return result;
}
@@ -290,8 +409,41 @@ Parrot_io_readline(PARROT_INTERP, ARGMOD(PMC *pmc))
{
ASSERT_ARGS(Parrot_io_readline)
STRING *result;
- Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "readline"), "->S",
- &result);
+ if (pmc->vtable->base_type == enum_class_FileHandle) {
+ INTVAL flags;
+ if (Parrot_io_is_closed_filehandle(interp, pmc))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+ "Cannot read from a closed filehandle");
+ GETATTR_FileHandle_flags(interp, pmc, flags);
+ if (!(flags & PIO_F_LINEBUF))
+ Parrot_io_setlinebuf(interp, pmc);
+
+ result = Parrot_io_reads(interp, pmc, 0);
+ }
+ else if (pmc->vtable->base_type == enum_class_StringHandle) {
+ INTVAL offset, newline_pos, read_length, orig_length;
+
+ GETATTR_StringHandle_stringhandle(interp, pmc, result);
+ if (STRING_IS_NULL(result))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+ "Cannot read from a closed stringhandle");
+
+ orig_length = Parrot_str_byte_length(interp, result);
+ GETATTR_StringHandle_read_offset(interp, pmc, offset);
+ newline_pos = Parrot_str_find_index(interp, result, CONST_STRING(interp, "\n"), offset);
+
+ /* No newline found, read the rest of the string. */
+ if (newline_pos == -1)
+ read_length = orig_length - offset;
+ else
+ read_length = newline_pos - offset + 1; /* +1 to include the newline */
+
+ result = Parrot_str_substr(interp, result, offset,
+ read_length, NULL, 0);
+ SETATTR_StringHandle_read_offset(interp, pmc, newline_pos + 1);
+ }
+ else
+ Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "readline"), "->S", &result);
return result;
}
@@ -416,19 +568,24 @@ INTVAL
Parrot_io_eof(PARROT_INTERP, ARGMOD(PMC *pmc))
{
ASSERT_ARGS(Parrot_io_eof)
- INTVAL result;
+ INTVAL flags, result;
/* io could be null here, but rather than return a negative error
* we just fake EOF since eof test is usually in a boolean context.
*/
if (PMC_IS_NULL(pmc))
+ return 1;
+ if (pmc->vtable->base_type == enum_class_FileHandle) {
+ if (Parrot_io_is_closed_filehandle(interp, pmc))
return 1;
- Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "eof"), "->I",
- &result);
-
+ GETATTR_FileHandle_flags(interp, pmc, flags);
+ if (flags & PIO_F_EOF)
+ return 1;
+ return 0;
+ }
+ Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "eof"), "->I", &result);
return result;
-
}
/*
@@ -470,9 +627,23 @@ Parrot_io_putps(PARROT_INTERP, ARGMOD(PMC *pmc), ARGMOD_NULLOK(STRING *s))
if (PMC_IS_NULL(pmc))
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
"Cannot write to null PMC");
+ if (pmc->vtable->base_type == enum_class_FileHandle) {
+ INTVAL flags;
+ GETATTR_FileHandle_flags(interp, pmc, flags);
+
+ if (!(flags & PIO_F_WRITE))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+ "FileHandle is not opened for writing");
+ if (STRING_IS_NULL(s))
+ return 0;
+ if (Parrot_io_is_encoding(interp, pmc, CONST_STRING(interp, "utf8")))
+ result = Parrot_io_write_utf8(interp, pmc, s);
+ else
+ result = Parrot_io_write_buffer(interp, pmc, s);
+ }
+ else
+ Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "puts"), "S->I", s, &result);
- Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "puts"), "S->I",
- s, &result);
return result;
}
12 src/io/buffer.c
View
@@ -79,7 +79,7 @@ Parrot_io_setbuf(PARROT_INTERP, ARGMOD(PMC *filehandle), size_t bufsize)
/* If there is already a buffer, make sure we flush before modifying it. */
if (buffer_start)
- Parrot_io_flush(interp, filehandle);
+ Parrot_io_flush_buffer(interp, filehandle);
/* Choose an appropriate buffer size for caller */
switch (bufsize) {
@@ -286,7 +286,7 @@ Parrot_io_read_buffer(PARROT_INTERP, ARGMOD(PMC *filehandle),
/* write buffer flush */
if (buffer_flags & PIO_BF_WRITEBUF) {
- Parrot_io_flush(interp, filehandle);
+ Parrot_io_flush_buffer(interp, filehandle);
buffer_flags = Parrot_io_get_buffer_flags(interp, filehandle);
}
@@ -416,7 +416,7 @@ Parrot_io_peek_buffer(PARROT_INTERP, ARGMOD(PMC *filehandle),
/* write buffer flush */
if (buffer_flags & PIO_BF_WRITEBUF) {
- Parrot_io_flush(interp, filehandle);
+ Parrot_io_flush_buffer(interp, filehandle);
buffer_flags = Parrot_io_get_buffer_flags(interp, filehandle);
}
@@ -623,7 +623,7 @@ Parrot_io_write_buffer(PARROT_INTERP, ARGMOD(PMC *filehandle), ARGIN(STRING *s))
long wrote;
/* Write through, skip buffer. */
- Parrot_io_flush(interp, filehandle);
+ Parrot_io_flush_buffer(interp, filehandle);
wrote = PIO_WRITE(interp, filehandle, s);
if (wrote == (long)len) {
@@ -658,7 +658,7 @@ Parrot_io_write_buffer(PARROT_INTERP, ARGMOD(PMC *filehandle), ARGIN(STRING *s))
Parrot_io_set_buffer_next(interp, filehandle, buffer_next);
Parrot_io_set_file_position(interp, filehandle, (avail +
Parrot_io_get_file_position(interp, filehandle)));
- Parrot_io_flush(interp, filehandle);
+ Parrot_io_flush_buffer(interp, filehandle);
buffer_flags |= PIO_BF_WRITEBUF;
Parrot_io_set_buffer_flags(interp, filehandle, buffer_flags);
@@ -718,7 +718,7 @@ Parrot_io_seek_buffer(PARROT_INTERP, ARGMOD(PMC *filehandle),
if ((newpos < file_pos - (buffer_next - buffer_start))
|| (newpos >= file_pos + (buffer_end - buffer_next))) {
- Parrot_io_flush(interp, filehandle);
+ Parrot_io_flush_buffer(interp, filehandle);
newpos = PIO_SEEK(interp, filehandle, newpos, SEEK_SET);
}
else {
46 src/io/unix.c
View
@@ -35,6 +35,7 @@ APitUE - W. Richard Stevens, AT&T SFIO, Perl 5 (Nick Ing-Simmons)
# include <sys/types.h>
# include <sys/wait.h>
+# include <unistd.h> /* for pipe() */
/* HEADERIZER HFILE: include/parrot/io_unix.h */
@@ -357,6 +358,24 @@ Parrot_io_close_unix(PARROT_INTERP, ARGMOD(PMC *filehandle))
return result;
}
+
+/*
+
+=item C<INTVAL Parrot_io_close_piohandle_unix(PARROT_INTERP, PIOHANDLE handle)>
+
+Closes the given file descriptor. Returns 0 on success, -1 on error.
+
+=cut
+
+*/
+
+INTVAL
+Parrot_io_close_piohandle_unix(SHIM_INTERP, PIOHANDLE handle)
+{
+ ASSERT_ARGS(Parrot_io_close_piohandle_unix)
+ return close(handle);
+}
+
/*
=item C<INTVAL Parrot_io_is_closed_unix(PARROT_INTERP, PMC *filehandle)>
@@ -767,6 +786,33 @@ Parrot_io_peek_unix(PARROT_INTERP,
}
+/*
+
+=item C<INTVAL Parrot_io_pipe_unix(PARROT_INTERP, PIOHANDLE *reader, PIOHANDLE
+*writer)>
+
+Uses C<pipe()> to create a matched pair of pipe fds. Returns 0 on success, -1
+on failure.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+INTVAL
+Parrot_io_pipe_unix(SHIM_INTERP, ARGMOD(PIOHANDLE *reader), ARGMOD(PIOHANDLE *writer))
+{
+ ASSERT_ARGS(Parrot_io_pipe_unix)
+ int fds[2], rv;
+ rv = pipe(fds);
+ if (rv >= 0) {
+ *reader = fds[0];
+ *writer = fds[1];
+ }
+ return rv;
+}
+
#endif /* PIO_OS_UNIX */
/*
43 src/io/win32.c
View
@@ -295,6 +295,28 @@ Parrot_io_fdopen_win32(PARROT_INTERP, ARGMOD_NULLOK(PMC *filehandle),
/*
+=item C<INTVAL Parrot_io_close_piohandle_win32(PARROT_INTERP, PIOHANDLE handle)>
+
+Calls C<CloseHandle()> to close the given file descriptor. Returns 0 on
+success, -1 on error.
+
+=cut
+
+*/
+
+INTVAL
+Parrot_io_close_piohandle_win32(PARROT_INTERP, PIOHANDLE handle)
+{
+ ASSERT_ARGS(Parrot_io_close_piohandle_win32)
+
+ if (handle == INVALID_HANDLE_VALUE)
+ return -1;
+
+ return CloseHandle(handle) ? 0 : -1;
+}
+
+/*
+
=item C<INTVAL Parrot_io_close_win32(PARROT_INTERP, PMC *filehandle)>
Calls C<CloseHandle()> to close C<*io>'s file descriptor.
@@ -704,6 +726,27 @@ Parrot_io_open_pipe_win32(PARROT_INTERP, ARGMOD(PMC *filehandle),
"pipe open error");
}
+/*
+
+=item C<INTVAL Parrot_io_pipe_win32(PARROT_INTERP, PIOHANDLE *reader, PIOHANDLE
+*writer)>
+
+Uses CreatePipe() to create a matched pair of pipe handles. Returns 0 on
+success, -1 on failure.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+INTVAL
+Parrot_io_pipe_win32(SHIM_INTERP, ARGMOD(PIOHANDLE *reader), ARGMOD(PIOHANDLE *writer))
+{
+ ASSERT_ARGS(Parrot_io_pipe_win32)
+ return CreatePipe(reader, writer, NULL, 0) ? 0 : -1;
+}
+
#endif /* PIO_OS_WIN32 */
/*
25 src/library.c
View
@@ -594,10 +594,10 @@ try_bytecode_extensions(PARROT_INTERP, ARGMOD(STRING* path))
/*
-=item C<void Parrot_add_library_path(PARROT_INTERP, STRING *path, enum_lib_paths
+=item C<void Parrot_lib_add_path(PARROT_INTERP, STRING *path_str, enum_lib_paths
which)>
-Add a path to the library searchpath of the given type.
+Add a path to the library searchpath of the given type (passing in a STRING).
=cut
@@ -605,41 +605,38 @@ Add a path to the library searchpath of the given type.
PARROT_EXPORT
void
-Parrot_add_library_path(PARROT_INTERP,
- ARGIN(STRING *path),
+Parrot_lib_add_path(PARROT_INTERP,
+ ARGIN(STRING *path_str),
enum_lib_paths which)
{
- ASSERT_ARGS(Parrot_add_library_path)
+ ASSERT_ARGS(Parrot_lib_add_path)
PMC * const iglobals = interp->iglobals;
PMC * const lib_paths = VTABLE_get_pmc_keyed_int(interp, iglobals,
IGLOBALS_LIB_PATHS);
PMC * const paths = VTABLE_get_pmc_keyed_int(interp, lib_paths, which);
- VTABLE_push_string(interp, paths, path);
+ VTABLE_push_string(interp, paths, path_str);
}
/*
-=item C<void Parrot_add_library_path_from_cstring(PARROT_INTERP, const char
-*path, enum_lib_paths which)>
+=item C<void Parrot_lib_add_path_from_cstring(PARROT_INTERP, const char *path,
+enum_lib_paths which)>
Add a path to the library searchpath of the given type (passing in a C string).
-This function is just an interface to C<Parrot_add_library_path> for low-level
-code.
-
=cut
*/
PARROT_EXPORT
void
-Parrot_add_library_path_from_cstring(PARROT_INTERP,
+Parrot_lib_add_path_from_cstring(PARROT_INTERP,
ARGIN(const char *path),
enum_lib_paths which)
{
- ASSERT_ARGS(Parrot_add_library_path_from_cstring)
+ ASSERT_ARGS(Parrot_lib_add_path_from_cstring)
STRING * const path_str = Parrot_str_new(interp, path, 0);
- Parrot_add_library_path(interp, path_str, which);
+ Parrot_lib_add_path(interp, path_str, which);
}
/*
26 src/oo.c
View
@@ -265,16 +265,16 @@ that with the data.
PARROT_CANNOT_RETURN_NULL
PMC *
-Parrot_oo_clone_object(PARROT_INTERP, ARGIN(PMC * pmc),
- ARGMOD_NULLOK(PMC * class_), ARGMOD_NULLOK(PMC * dest))
+Parrot_oo_clone_object(PARROT_INTERP, ARGIN(PMC *pmc),
+ ARGMOD_NULLOK(PMC *class_), ARGMOD_NULLOK(PMC *dest))
{
ASSERT_ARGS(Parrot_oo_clone_object)
- Parrot_Object_attributes * obj;
- Parrot_Class_attributes * _class;
- INTVAL num_classes;
- PMC * cloned;
- Parrot_Object_attributes * cloned_guts;
- INTVAL i, num_attrs;
+ Parrot_Object_attributes *obj;
+ Parrot_Object_attributes *cloned_guts;
+ Parrot_Class_attributes *_class;
+ PMC *cloned;
+ INTVAL num_classes;
+ INTVAL i, num_attrs;
if (!PMC_IS_NULL(dest)) {
PARROT_ASSERT(!PMC_IS_NULL(class_));
@@ -284,9 +284,10 @@ Parrot_oo_clone_object(PARROT_INTERP, ARGIN(PMC * pmc),
cloned = dest;
}
else {
- obj = PARROT_OBJECT(pmc);
+ obj = PARROT_OBJECT(pmc);
cloned = pmc_new_noinit(interp, enum_class_Object);
}
+
_class = PARROT_CLASS(obj->_class);
PARROT_ASSERT(_class);
num_classes = VTABLE_elements(interp, _class->all_parents);
@@ -299,7 +300,7 @@ Parrot_oo_clone_object(PARROT_INTERP, ARGIN(PMC * pmc),
PObj_is_object_SET(cloned);
/* Now create the underlying structure, and clone attributes list.class. */
- cloned_guts = mem_allocate_zeroed_typed(Parrot_Object_attributes);
+ cloned_guts = mem_allocate_typed(Parrot_Object_attributes);
PMC_data(cloned) = cloned_guts;
cloned_guts->_class = obj->_class;
cloned_guts->attrib_store = VTABLE_clone(interp, obj->attrib_store);
@@ -351,7 +352,7 @@ Parrot_oo_new_object_attrs(PARROT_INTERP, ARGIN(PMC * class_))
{
ASSERT_ARGS(Parrot_oo_new_object_attrs)
Parrot_Object_attributes * const obj_guts =
- mem_allocate_zeroed_typed(Parrot_Object_attributes);
+ mem_allocate_typed(Parrot_Object_attributes);
obj_guts->_class = class_;
obj_guts->attrib_store = pmc_new(interp, enum_class_ResizablePMCArray);
return (void *)obj_guts;
@@ -1015,8 +1016,7 @@ Parrot_find_method_with_cache(PARROT_INTERP, ARGIN(PMC *_class), ARGIN(STRING *m
sizeof (Meth_cache_entry ***) * mc->mc_size);
}
else {
- mc->idx = (Meth_cache_entry ***)mem_sys_allocate_zeroed(
- sizeof (Meth_cache_entry ***) * (type + 1));
+ mc->idx = mem_allocate_n_zeroed_typed(type + 1, Meth_cache_entry**);
}
mc->mc_size = type + 1;
}
2  src/ops/io.ops
View
@@ -317,7 +317,7 @@ Print $2 on the IO stream object $1.
op print(invar PMC, in INT) :base_io {
if ($1) {
- STRING * const s = Parrot_sprintf_c(interp, INTVAL_FMT, $2);
+ STRING * const s = Parrot_str_from_int(interp, $2);
Parrot_io_putps(interp, $1, s);
}
}
10 src/packfile.c
View
@@ -4696,6 +4696,12 @@ compile_or_load_file(PARROT_INTERP, ARGIN(STRING *path),
if (!pf)
Parrot_ex_throw_from_c_args(interp, NULL, 1,
"Unable to append PBC to the current directory");
+
+ mem_sys_free(pf->header);
+ pf->header = NULL;
+ mem_sys_free(pf->dirp);
+ pf->dirp = NULL;
+
}
else {
STRING *err;
@@ -4766,9 +4772,9 @@ Parrot_load_language(PARROT_INTERP, ARGIN_NULLOK(STRING *lang_name))
parrot_split_path_ext(interp, path, &found_path, &found_ext);
name_length = Parrot_str_length(interp, lang_name);
found_path = Parrot_str_substr(interp, found_path, -name_length, name_length, NULL, 0);
- Parrot_add_library_path(interp, Parrot_str_append(interp, found_path, CONST_STRING(interp, "include/")),
+ Parrot_lib_add_path(interp, Parrot_str_append(interp, found_path, CONST_STRING(interp, "include/")),
PARROT_LIB_PATH_INCLUDE);
- Parrot_add_library_path(interp, Parrot_str_append(interp, found_path, CONST_STRING(interp, "dynext/")),
+ Parrot_lib_add_path(interp, Parrot_str_append(interp, found_path, CONST_STRING(interp, "dynext/")),
PARROT_LIB_PATH_DYNEXT);
9 src/pmc.c
View
@@ -196,13 +196,13 @@ PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_IGNORABLE_RESULT
PMC *
-pmc_reuse_by_class(PARROT_INTERP, ARGMOD(PMC * pmc), ARGIN(PMC * class_),
+pmc_reuse_by_class(PARROT_INTERP, ARGMOD(PMC *pmc), ARGIN(PMC *class_),
UINTVAL flags)
{
ASSERT_ARGS(pmc_reuse_by_class)
- const INTVAL new_type = PARROT_CLASS(class_)->id;
+ const INTVAL new_type = PARROT_CLASS(class_)->id;
VTABLE * const new_vtable = interp->vtables[new_type];
- INTVAL new_flags = flags;
+ INTVAL new_flags = flags;
if (pmc->vtable->base_type == new_type)
return pmc;
@@ -214,7 +214,8 @@ pmc_reuse_by_class(PARROT_INTERP, ARGMOD(PMC * pmc), ARGIN(PMC * class_),
if (PObj_active_destroy_TEST(pmc))
VTABLE_destroy(interp, pmc);
- new_flags = pmc_reuse_check_pmc_ext(interp, pmc, new_flags, new_vtable->flags);
+ new_flags = pmc_reuse_check_pmc_ext(interp, pmc,
+ new_flags, new_vtable->flags);
/* we are a PMC + maybe is_PMC_EXT */
PObj_flags_SETTO(pmc, PObj_is_PMC_FLAG | new_flags);
18 src/pmc/codestring.pmc
View
@@ -128,7 +128,8 @@ A newline is automatically added to the end of the fmt.
if ('\n' != Parrot_str_indexed(INTERP, fmt, Parrot_str_byte_length(interp, fmt) - 1))
fmt = Parrot_str_concat(INTERP, fmt, newline, 0);
- S1 = Parrot_str_concat(INTERP, SELF.get_string(), fmt, 0);
+ GET_ATTR_str_val(INTERP, SELF, S1);
+ S1 = Parrot_str_concat(INTERP, S1, fmt, 0);
VTABLE_set_string_native(INTERP, SELF, S1);
RETURN(PMC *SELF);
@@ -168,17 +169,22 @@ the first line is line number zero.
ipos = last_pos;
}
- str = SELF.get_string();
+ GET_ATTR_str_val(INTERP, SELF, str);
jpos = Parrot_str_find_cclass(INTERP, enum_cclass_newline, str, ipos, pos);
while (jpos < pos) {
- line++;
+
+ if (ipos
+ && jpos == ipos
+ && string_ord(INTERP, str, jpos) == 10
+ && string_ord(INTERP, str, ipos - 1) == 13) {
+ /* do not increment line; \r\n is a single line separator */
+ }
+ else
+ line++;
ipos = jpos + 1;
- /* treat \r\n as a single line separator */
- ipos += (string_ord(INTERP, str, jpos) == 13
- && string_ord(INTERP, str, jpos + 1) == 10);
jpos = Parrot_str_find_cclass(INTERP, enum_cclass_newline, str, ipos, pos);
}
2  src/pmc/coroutine.pmc
View
@@ -149,7 +149,7 @@ Swaps the "context".
caller_ctx = CONTEXT(interp);
ctx = Parrot_set_new_context(INTERP, co->n_regs_used);
- co->ctx = ctx;
+ co->ctx = Parrot_context_ref(interp, ctx);
co->dynamic_state = interp->dynamic_env;
ctx->caller_ctx = caller_ctx;
6 src/pmc/eventhandler.pmc
View
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2007-2008, Parrot Foundation.
+Copyright (C) 2007-2009, Parrot Foundation.
$Id$
=head1 NAME
@@ -138,9 +138,9 @@ Marks this PMC and any of its contents as live.
if (! PMC_IS_NULL(e->code))
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)e->code);
- }
- SUPER();
+ SUPER();
+ }
}
/*
92 src/pmc/filehandle.pmc
View
@@ -31,24 +31,11 @@ extern "C" {
#endif
#endif
-#ifdef PIO_OS_WIN32
-# define PIO_INVALID_HANDLE INVALID_HANDLE_VALUE
-#endif
-
-#ifdef PIO_OS_UNIX
-# define PIO_INVALID_HANDLE -1
-#endif
-
-#ifdef PIO_OS_STDIO
-# define PIO_INVALID_HANDLE NULL
-#endif
-
-pmclass FileHandle need_ext {
+pmclass FileHandle extends Handle {
ATTR INTVAL flags; /* Filehandle flags */
ATTR STRING *filename; /* The opened path and filename */
ATTR STRING *mode; /* The mode string used in open */
ATTR STRING *encoding; /* The encoding for read/write */
- ATTR PIOHANDLE os_handle; /* Low level OS descriptor */
ATTR INTVAL process_id; /* Child process on pipes */
ATTR PIOOFF_T file_size; /* Current file size */
ATTR PIOOFF_T file_pos; /* Current real file pointer */
@@ -248,10 +235,9 @@ filehandle, rather than modifying the invocant).