Author: jonathan
Date: Wed Jan 7 06:12:23 2009
New Revision: 35123
Modified:
trunk/PBC_COMPAT
trunk/src/ops/core.ops
trunk/src/ops/ops.num
trunk/t/op/annotate.t
Log:
[core] Implement and test annotations opcode, for getting the current set of
annotations in force or a particular annotation.
Modified: trunk/PBC_COMPAT
==============================================================================
--- trunk/PBC_COMPAT (original)
+++ trunk/PBC_COMPAT Wed Jan 7 06:12:23 2009
@@ -27,6 +27,7 @@
# please insert tab separated entries at the top of the list
+3.28 2009.01.07 jonathan changes for bytecode annoations
(packfile and ops)
3.27 2008.01.07 coke removed find_global_p_p_s, find_global_p_s,
store_global_p_s
3.26 2008.12.30 chromatic removed deprecated infix, n_infix,
get_mro opcodes
3.25 2008.11.15 tewk changed size of Parrot_sub structure which
effects frozen sub pmc size
Modified: trunk/src/ops/core.ops
==============================================================================
--- trunk/src/ops/core.ops (original)
+++ trunk/src/ops/core.ops Wed Jan 7 06:12:23 2009
@@ -1394,6 +1394,60 @@
###############################################################################
+=head2 Annotations operations
+
+These operations relate to bytecode annotations.
+
+=over 4
+
+=cut
+
+########################################
+
+=item B<annotations>(out PMC)
+
+Gets all bytecode annotations in effect at the current point, in a Hash.
+If there are none, returns an empty Hash.
+
+=cut
+
+inline op annotations(out PMC) {
+ if (interp->code->annotations) {
+ opcode_t const cur_pos = (expr NEXT()) - interp->code->base.data;
+ $1 = PackFile_Annotations_lookup(interp, interp->code->annotations,
+ cur_pos, NULL);
+ }
+ else {
+ $1 = pmc_new(interp, enum_class_Hash);
+ }
+ goto NEXT();
+}
+
+=item B<annotations>(out PMC, in STR)
+
+Gets the bytecode annotation with the given name that is in effect at the
+current point. Returns PMCNULL if there is none.
+
+=cut
+
+inline op annotations(out PMC, in STR) {
+ if (interp->code->annotations) {
+ opcode_t const cur_pos = (expr NEXT()) - interp->code->base.data;
+ $1 = PackFile_Annotations_lookup(interp, interp->code->annotations,
+ cur_pos, $2);
+ }
+ else {
+ $1 = PMCNULL;
+ }
+ goto NEXT();
+}
+
+=back
+
+=cut
+
+###############################################################################
+
=head1 COPYRIGHT
Copyright (C) 2001-2008, The Perl Foundation.
Modified: trunk/src/ops/ops.num
==============================================================================
--- trunk/src/ops/ops.num (original)
+++ trunk/src/ops/ops.num Wed Jan 7 06:12:23 2009
@@ -1279,3 +1279,6 @@
find_global_p_sc_sc 1249
find_name_p_s 1250
find_name_p_sc 1251
+annotations_p 1252
+annotations_p_s 1253
+annotations_p_sc 1254
Modified: trunk/t/op/annotate.t
==============================================================================
--- trunk/t/op/annotate.t (original)
+++ trunk/t/op/annotate.t Wed Jan 7 06:12:23 2009
@@ -19,10 +19,11 @@
.sub main :main
.include 'include/test_more.pir'
- plan(9)
+ plan(15)
'no_annotations'()
- 'annotations_exception'()
+ 'annotations_exception'()
+ 'annotations_ops'()
.end
@@ -70,7 +71,31 @@
$P1 = $P0["line"]
is ($P1, 2, "line annotation got OK from hash")
.end
-
+
+
+.sub 'annotations_ops'
+ .annotate 'file', 'loo.py'
+ .annotate 'line', 1
+
+ $P1 = annotations 'file'
+ is ($P1, 'loo.py', 'annotations_p_sc op returned correct thing')
+ $S0 = 'line'
+ $P1 = annotations $S0
+ is ($P1, 1, 'annotations_p_s op returned correct thing')
+
+ .annotate 'line', 2
+ $P0 = annotations
+ .annotate 'line', 3
+
+ isa_ok ($P0, 'Hash', 'annotations_p op gives back hash')
+ $I0 = elements $P0
+ is ($I0, 2, 'annoations op gave hash with right number of elements')
+ $S0 = $P0['file']
+ is ($S0, 'loo.py', 'annotations_p op gave back correct hash')
+ $I1 = $P0['line']
+ is ($I1, 2, 'annotations_p op gave back correct hash')
+.end
+
# Local Variables:
# mode: pir