Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
0e7022a2
Commit
0e7022a2
authored
27 years ago
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
bugs in o_cast() fixed
Rev: src/opcodes.c:1.17
parent
62d3e4a8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/opcodes.c
+30
-168
30 additions, 168 deletions
src/opcodes.c
with
30 additions
and
168 deletions
src/opcodes.c
+
30
−
168
View file @
0e7022a2
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
#include
"cyclic.h"
#include
"cyclic.h"
#include
"builtin_functions.h"
#include
"builtin_functions.h"
RCSID
(
"$Id: opcodes.c,v 1.1
6
1998/0
3/28 15:08:54 gr
ubb
a
Exp $"
);
RCSID
(
"$Id: opcodes.c,v 1.1
7
1998/0
4/06 04:18:33 h
ubb
e
Exp $"
);
void
index_no_free
(
struct
svalue
*
to
,
struct
svalue
*
what
,
struct
svalue
*
ind
)
void
index_no_free
(
struct
svalue
*
to
,
struct
svalue
*
what
,
struct
svalue
*
ind
)
{
{
...
@@ -79,167 +79,6 @@ void o_index(void)
...
@@ -79,167 +79,6 @@ void o_index(void)
sp
++
;
sp
++
;
}
}
void
cast
(
struct
pike_string
*
s
)
{
INT32
i
;
i
=
compile_type_to_runtime_type
(
s
);
if
(
i
!=
sp
[
-
1
].
type
)
{
if
(
i
==
T_MIXED
)
return
;
if
(
sp
[
-
2
].
type
==
T_OBJECT
)
{
push_string
(
describe_type
(
s
));
if
(
!
sp
[
-
2
].
u
.
object
->
prog
)
error
(
"Cast called on destructed object.
\n
"
);
if
(
FIND_LFUN
(
sp
[
-
2
].
u
.
object
->
prog
,
LFUN_CAST
)
==
-
1
)
error
(
"No cast method in object.
\n
"
);
apply_lfun
(
sp
[
-
2
].
u
.
object
,
LFUN_CAST
,
1
);
free_svalue
(
sp
-
2
);
sp
[
-
2
]
=
sp
[
-
1
];
sp
--
;
return
;
}
switch
(
i
)
{
case
T_MIXED
:
break
;
case
T_INT
:
switch
(
sp
[
-
1
].
type
)
{
case
T_FLOAT
:
i
=
(
int
)(
sp
[
-
1
].
u
.
float_number
);
break
;
case
T_STRING
:
i
=
STRTOL
(
sp
[
-
1
].
u
.
string
->
str
,
0
,
0
);
free_string
(
sp
[
-
1
].
u
.
string
);
break
;
default:
error
(
"Cannot cast to int.
\n
"
);
}
sp
[
-
1
].
type
=
T_INT
;
sp
[
-
1
].
u
.
integer
=
i
;
break
;
case
T_FLOAT
:
{
FLOAT_TYPE
f
;
switch
(
sp
[
-
1
].
type
)
{
case
T_INT
:
f
=
(
FLOAT_TYPE
)(
sp
[
-
1
].
u
.
integer
);
break
;
case
T_STRING
:
f
=
STRTOD
(
sp
[
-
1
].
u
.
string
->
str
,
0
);
free_string
(
sp
[
-
1
].
u
.
string
);
break
;
default:
error
(
"Cannot cast to float.
\n
"
);
f
=
0
.
0
;
}
sp
[
-
1
].
type
=
T_FLOAT
;
sp
[
-
1
].
u
.
float_number
=
f
;
break
;
}
case
T_STRING
:
{
char
buf
[
200
];
switch
(
sp
[
-
1
].
type
)
{
case
T_INT
:
sprintf
(
buf
,
"%ld"
,(
long
)
sp
[
-
1
].
u
.
integer
);
break
;
case
T_FLOAT
:
sprintf
(
buf
,
"%f"
,(
double
)
sp
[
-
1
].
u
.
float_number
);
break
;
default:
error
(
"Cannot cast to string.
\n
"
);
}
sp
[
-
1
].
type
=
T_STRING
;
sp
[
-
1
].
u
.
string
=
make_shared_string
(
buf
);
break
;
}
case
T_OBJECT
:
{
switch
(
sp
[
-
1
].
type
)
{
case
T_STRING
:
APPLY_MASTER
(
"cast_to_object"
,
1
);
break
;
case
T_FUNCTION
:
sp
[
-
1
].
type
=
T_OBJECT
;
break
;
}
break
;
}
case
T_PROGRAM
:
{
switch
(
sp
[
-
1
].
type
)
{
case
T_STRING
:
APPLY_MASTER
(
"cast_to_program"
,
1
);
break
;
case
T_FUNCTION
:
{
struct
program
*
p
=
program_from_function
(
sp
-
1
);
if
(
p
)
{
p
->
refs
++
;
pop_stack
();
push_program
(
p
);
}
else
{
pop_stack
();
push_int
(
0
);
}
}
}
return
;
}
case
T_FUNCTION
:
{
INT32
i
;
if
(
fp
->
current_object
->
prog
)
error
(
"Cast to function in destructed object.
\n
"
);
i
=
find_shared_string_identifier
(
sp
[
-
1
].
u
.
string
,
fp
->
current_object
->
prog
);
free_string
(
sp
[
-
1
].
u
.
string
);
/* FIXME, check that it is a indeed a function */
if
(
i
==-
1
)
{
sp
[
-
1
].
type
=
T_FUNCTION
;
sp
[
-
1
].
subtype
=
i
;
sp
[
-
1
].
u
.
object
=
fp
->
current_object
;
fp
->
current_object
->
refs
++
;
}
else
{
sp
[
-
1
].
type
=
T_INT
;
sp
[
-
1
].
subtype
=
NUMBER_UNDEFINED
;
sp
[
-
1
].
u
.
integer
=
0
;
}
break
;
}
}
}
}
void
o_cast
(
struct
pike_string
*
type
,
INT32
run_time_type
)
void
o_cast
(
struct
pike_string
*
type
,
INT32
run_time_type
)
{
{
INT32
i
;
INT32
i
;
...
@@ -385,15 +224,38 @@ void o_cast(struct pike_string *type, INT32 run_time_type)
...
@@ -385,15 +224,38 @@ void o_cast(struct pike_string *type, INT32 run_time_type)
break
;
break
;
case
T_PROGRAM
:
case
T_PROGRAM
:
if
(
fp
->
pc
)
switch
(
sp
[
-
1
].
type
)
{
case
T_STRING
:
if
(
fp
->
pc
)
{
INT32
lineno
;
push_text
(
get_line
(
fp
->
pc
,
fp
->
context
.
prog
,
&
lineno
));
}
else
{
push_int
(
0
);
}
APPLY_MASTER
(
"cast_to_program"
,
2
);
return
;
case
T_FUNCTION
:
{
{
INT32
lineno
;
struct
program
*
p
=
program_from_function
(
sp
-
1
);
push_text
(
get_line
(
fp
->
pc
,
fp
->
context
.
prog
,
&
lineno
));
if
(
p
)
}
else
{
{
push_int
(
0
);
p
->
refs
++
;
pop_stack
();
push_program
(
p
);
}
else
{
pop_stack
();
push_int
(
0
);
}
}
}
APPLY_MASTER
(
"cast_to_program"
,
2
);
return
;
return
;
default:
error
(
"Cannot cast that to a program.
\n
"
);
}
case
T_FUNCTION
:
case
T_FUNCTION
:
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment