/
myops.ops
127 lines (84 loc) · 2.05 KB
/
myops.ops
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
** myops.ops - sample
*/
#include "parrot/dynext.h"
VERSION = PARROT_VERSION;
=head1 NAME
myops.ops - Parrot Sample Ops
=cut
=head1 DESCRIPTION
A dynamic oplib loadable at demand.
=cut
=head1 Essential ops
=over 4
=item B<fortytwo>(out INT)
The famous and ever wanted opcode, proposed by Jos Visser in
"We *need* this op! :-)".
=item B<what_do_you_get_if_you_multiply_six_by_nine>(out INT)
Alternate spelling of this op, proposed by Nicholas Clark. It might bring
imcc to its limits due the lengthy name.
=cut
inline op fortytwo(out INT) {
$1 = 42;
goto NEXT();
}
inline op what_do_you_get_if_you_multiply_six_by_nine(out STR) {
$1 = string_from_cstring(interp, "fortytwo", 0);
goto NEXT();
}
=item B<hcf>
Halt and Catch Fire. Tries to crash parrot.
=cut
op hcf() {
int *a, i;
a = NULL;
i = *a;
goto OFFSET(i) ; /* in case your runtime is very forgiving. */
}
=item B<q>
Support for writing a very short quine.
=cut
op q() {
PIO_printf(interp, ".loadlib \"myops_ops\"\nq\n" );
HALT();
}
=item B<bxand>(out INT, in INT, in INT)
Binary operator, defined as A and B, but not BOTH.
=cut
op bxand(out INT, in INT, in INT) {
/* short circuit boolean logic */
$1 = 0;
goto NEXT();
}
=item B<alarm>(in NUM, in PMC)
Call alarm handler sub $2 after $1 time has elapsed.
=item B<alarm>(in NUM, in NUM, in PMC)
Call alarm handler sub $3 after $1 time has elapsed, repeat after $2.
=cut
op alarm(in NUM, in PMC) {
Parrot_new_timer_event(interp, NULL, $1, 0.0, 0, $2,
EVENT_TYPE_TIMER);
goto NEXT();
}
op alarm(in NUM, in NUM, in PMC) {
Parrot_new_timer_event(interp, NULL, $1, $2, -1, $3,
EVENT_TYPE_TIMER);
goto NEXT();
}
=item B<conv_u2>(inout INT)
Conversion of a two byte unsigned int to an INT.
Formerly in dotgnu.ops. Used only in ./languages/Zcode/z3main.pir.
=cut
inline op conv_u2(inout INT) :base_core {
$1 = (INTVAL)((Parrot_UInt2)($1));
goto NEXT();
}
=back
=cut
# vim: sw=4
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/