line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Language::Prolog::Types::Internal; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION=0.09; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
313
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# factory class methods: |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new_factory { |
13
|
1
|
|
|
1
|
0
|
2
|
my $class=shift; |
14
|
1
|
|
|
|
|
4
|
my $self= \ "I'm a $class prolog factory"; |
15
|
1
|
|
|
|
|
3
|
bless $self, $class; |
16
|
1
|
|
|
|
|
7
|
$self |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new_nil { |
20
|
0
|
|
|
0
|
0
|
|
shift; |
21
|
0
|
|
|
|
|
|
Language::Prolog::Types::Internal::nil->new(@_) |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new_list { |
25
|
0
|
|
|
0
|
0
|
|
shift; |
26
|
0
|
|
|
|
|
|
Language::Prolog::Types::Internal::list->new(@_) |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new_ulist { |
30
|
0
|
|
|
0
|
0
|
|
shift; |
31
|
0
|
|
|
|
|
|
Language::Prolog::Types::Internal::ulist->new(@_) |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new_functor { |
35
|
0
|
|
|
0
|
0
|
|
shift; |
36
|
0
|
|
|
|
|
|
Language::Prolog::Types::Internal::functor->new(@_) |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new_variable { |
40
|
0
|
|
|
0
|
0
|
|
shift; |
41
|
0
|
|
|
|
|
|
Language::Prolog::Types::Internal::variable->new(@_) |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new_opaque { |
45
|
0
|
|
|
0
|
0
|
|
shift; |
46
|
0
|
|
|
|
|
|
Language::Prolog::Types::Internal::opaque->new(@_) |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# internal types implementation: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
package Language::Prolog::Types::Internal::nil; |
52
|
|
|
|
|
|
|
our @ISA=qw(Language::Prolog::Types::Nil); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
54
|
|
55
|
1
|
|
|
1
|
|
577
|
use Language::Prolog::Types::Factory; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
254
|
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
|
|
sub largs { () } |
58
|
0
|
|
|
0
|
|
|
sub larg { croak "larg index $_[1] is out of range" } |
59
|
0
|
|
|
0
|
|
|
sub length { 0 } |
60
|
0
|
|
|
0
|
|
|
sub tail { prolog_nil } |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new { |
63
|
0
|
|
|
0
|
|
|
my $class=shift; |
64
|
0
|
|
|
|
|
|
my $self=[]; |
65
|
0
|
|
|
|
|
|
bless $self, $class; |
66
|
0
|
|
|
|
|
|
return $self; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
package Language::Prolog::Types::Internal::functor; |
71
|
|
|
|
|
|
|
our @ISA=qw(Language::Prolog::Types::Functor); |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
74
|
1
|
|
|
1
|
|
14
|
use Language::Prolog::Types::Factory; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
375
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub fargs { |
77
|
0
|
|
|
0
|
|
|
my $self=shift; |
78
|
0
|
|
|
|
|
|
return @{$self}[1..(@$self-1)] |
|
0
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub farg { |
82
|
0
|
|
|
0
|
|
|
my ($self, $index)=@_; |
83
|
0
|
0
|
|
|
|
|
$index=@$self-1+$index |
84
|
|
|
|
|
|
|
if $index<0; |
85
|
0
|
0
|
|
|
|
|
croak sprintf( "farg index %d out of range for %s/%d", |
86
|
|
|
|
|
|
|
$index, $self->[0], @$self-1 ) |
87
|
|
|
|
|
|
|
if $index > @$self-2; |
88
|
0
|
|
|
|
|
|
$self->[$index+1]; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
0
|
|
|
sub functor { $_[0]->[0] } |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
0
|
|
|
sub arity { @{$_[0]} - 1 } |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub new { |
96
|
0
|
|
|
0
|
|
|
my $class=shift; |
97
|
0
|
|
|
|
|
|
my $self=[@_]; |
98
|
0
|
|
|
|
|
|
bless $self, $class; |
99
|
0
|
|
|
|
|
|
return $self; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
package Language::Prolog::Types::Internal::list; |
104
|
|
|
|
|
|
|
our @ISA=qw( Language::Prolog::Types::List); |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
99
|
|
107
|
1
|
|
|
1
|
|
5
|
use Language::Prolog::Types::Factory; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
539
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub car { |
110
|
0
|
|
|
0
|
|
|
my $self=shift; |
111
|
0
|
0
|
|
|
|
|
return undef if $self->is_nil; |
112
|
0
|
|
|
|
|
|
$_[0]->[0]; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub cdr { |
116
|
0
|
|
|
0
|
|
|
my $self=shift; |
117
|
0
|
0
|
|
|
|
|
return prolog_nil if @$self<2; |
118
|
0
|
|
|
|
|
|
my $cdr=[ @{$self} ]; |
|
0
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
shift @{$cdr}; |
|
0
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
bless $cdr, ref $self; |
121
|
0
|
|
|
|
|
|
return $cdr; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub car_cdr { |
125
|
0
|
|
|
0
|
|
|
my $self=shift; |
126
|
0
|
0
|
|
|
|
|
return prolog_nil if @$self<2; |
127
|
0
|
|
|
|
|
|
my $cdr=[ @{$self} ]; |
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $car=shift @{$cdr}; |
|
0
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
bless $cdr, ref $self; |
130
|
0
|
|
|
|
|
|
return $car, $cdr; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub new { |
134
|
0
|
|
|
0
|
|
|
my $class=shift; |
135
|
0
|
|
|
|
|
|
my $self=[@_]; |
136
|
0
|
|
|
|
|
|
bless $self, $class; |
137
|
0
|
|
|
|
|
|
return $self; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub larg { |
141
|
0
|
|
|
0
|
|
|
my ($self, $index)=@_; |
142
|
0
|
0
|
|
|
|
|
$index=@{$self}+$index |
|
0
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
if $index<0; |
144
|
0
|
|
|
|
|
|
croak "larg index $index is out of range" |
145
|
0
|
0
|
|
|
|
|
if $index >= @{$self}; |
146
|
0
|
|
|
|
|
|
$self->[$index]; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
0
|
|
|
sub largs { @{$_[0]} } |
|
0
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
0
|
|
|
sub length { scalar @{$_[0]} } |
|
0
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
0
|
|
|
sub tail { prolog_nil } |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
package Language::Prolog::Types::Internal::ulist; |
156
|
|
|
|
|
|
|
our @ISA=qw(Language::Prolog::Types::UList); |
157
|
|
|
|
|
|
|
|
158
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
159
|
1
|
|
|
1
|
|
5
|
use Language::Prolog::Types::Factory; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
698
|
|
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
0
|
|
|
sub car { $_[0]->[0] } |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub cdr { |
164
|
0
|
|
|
0
|
|
|
my $self=shift; |
165
|
0
|
|
|
|
|
|
return prolog_ulist(@{$self}[1..@$self-1]) |
|
0
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub car_cdr { |
169
|
0
|
|
|
0
|
|
|
my $self=shift; |
170
|
0
|
|
|
|
|
|
return ($self->[0], prolog_ulist(@{$self}[1..@$self-1])) |
|
0
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub new { |
174
|
0
|
|
|
0
|
|
|
my $class=shift; |
175
|
0
|
|
|
|
|
|
my $self=[@_]; |
176
|
0
|
|
|
|
|
|
bless $self, $class; |
177
|
0
|
|
|
|
|
|
return $self; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
0
|
|
|
sub largs { @{$_[0]}[0..@{$_[0]}-2] } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub larg { |
183
|
0
|
|
|
0
|
|
|
my ($self, $index)=@_; |
184
|
0
|
0
|
|
|
|
|
$index=@{$self}-1+$index |
|
0
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
if $index<0; |
186
|
0
|
|
|
|
|
|
croak "larg index $index is out of range" |
187
|
0
|
0
|
|
|
|
|
if $index >= @{$self}-1; |
188
|
0
|
|
|
|
|
|
$self->[$index]; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
0
|
|
|
sub tail { $_[0]->[-1] }; |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
0
|
|
|
sub length { @{$_[0]} - 1 } |
|
0
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
package Language::Prolog::Types::Internal::variable; |
196
|
|
|
|
|
|
|
our @ISA=qw(Language::Prolog::Types::Variable); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub new { |
199
|
0
|
|
|
0
|
|
|
my ($class, $name)=@_; |
200
|
0
|
|
|
|
|
|
my $self=\$name; |
201
|
0
|
|
|
|
|
|
bless $self, $class; |
202
|
0
|
|
|
|
|
|
return $self; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
0
|
|
|
sub name { $ {$_[0]} } |
|
0
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
0
|
|
|
sub rename { ${$_[0]}=$_[1] } |
|
0
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
package Language::Prolog::Types::Internal::opaque; |
211
|
|
|
|
|
|
|
our @ISA=qw(Language::Prolog::Types::Opaque); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub new { |
214
|
0
|
|
|
0
|
|
|
my ($class, $ref)=@_; |
215
|
0
|
|
|
|
|
|
my $self=\$ref; |
216
|
0
|
|
|
|
|
|
bless $self, $class; |
217
|
0
|
|
|
|
|
|
return $self |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub opaque_reference { |
221
|
0
|
|
|
0
|
|
|
my $self=shift; |
222
|
0
|
|
|
|
|
|
return $$self; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
0
|
|
|
0
|
|
|
sub opaque_class { ref shift->opaque_reference } |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
1; |
229
|
|
|
|
|
|
|
__END__ |