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
5afe9e95
Commit
5afe9e95
authored
28 years ago
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
cast_to_program rewritten
Rev: lib/master.pike:1.29
parent
7528c2d2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/master.pike
+47
-31
47 additions, 31 deletions
lib/master.pike
with
47 additions
and
31 deletions
lib/master.pike
+
47
−
31
View file @
5afe9e95
#if !efun(version)
string version() { return "Pike 0.4pl2"; }
#endif
#define UNDEFINED (([])[0])
string describe_backtrace(mixed *trace);
...
...
@@ -55,35 +51,45 @@ mapping (string:program) programs=(["/master":object_program(this_object())]);
#define capitalize(X) (upper_case((X)[..0])+(X)[1..])
static program findprog(string pname)
static program
low_
findprog(string pname
, string ext
)
{
program ret;
if(ret=programs[pname]) return ret;
if(file_stat(pname))
{
ret=compile_file(pname);
}
else if(file_stat(pname+".pike"))
{
ret=compile_file(pname+".pike");
}
#if constant(load_module)
else if(file_stat(pname+".so"))
string fname=pname+ext;
if(ret=programs[fname]) return ret;
if(file_stat(fname))
{
ret=load_module(pname+".so");
}
#endif
if(ret)
{
programs[pname]=ret;
return ret;
switch(ext)
{
case "":
case ".pike":
ret=compile_file(fname);
break;
case ".so":
ret=load_module(fname);
}
return programs[fname]=ret;
}else{
return UNDEFINED;
}
}
static program findprog(string pname, string ext)
{
switch(ext)
{
case ".pike":
case ".so":
return low_findprog(pname,ext);
default:
pname+=ext;
return
low_findprog(pname,"") ||
low_findprog(pname,".pike") ||
low_findprog(pname,".so");
}
}
/* This function is called when the driver wants to cast a string
* to a program, this might be because of an explicit cast, an inherit
* or a implict cast. In the future it might receive more arguments,
...
...
@@ -91,13 +97,18 @@ static program findprog(string pname)
*/
program cast_to_program(string pname, string current_file)
{
if(pname[sizeof(pname)-3..sizeof(pname)]==".pike")
pname=pname[0..sizeof(pname)-4];
string ext;
if(sscanf(reverse(pname),"%s.%s",ext,pname))
{
ext="."+reverse(ext);
pname=reverse(pname);
}else{
ext="";
}
if(pname[0]=='/')
{
pname=combine_path("/",pname);
return findprog(pname);
return findprog(pname
,ext
);
}else{
string cwd;
if(current_file)
...
...
@@ -108,11 +119,15 @@ program cast_to_program(string pname, string current_file)
cwd=getcwd();
}
if(program ret=findprog(combine_path(cwd,pname),ext))
return ret;
foreach(pike_include_path, string path)
if(program ret=findprog(combine_path(path,pname)))
if(program ret=findprog(combine_path(path,pname)
,ext
))
return ret;
return
findprog(combine_path(cwd,pname))
;
return
0
;
}
}
...
...
@@ -149,6 +164,7 @@ void create()
add_constant("strlen",sizeof);
add_constant("new",new);
add_constant("clone",new);
add_constant("UNDEFINED",UNDEFINED);
random_seed(time() + (getpid() * 0x11111111));
}
...
...
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