Is there any way to compile without executing?

2025-03-26 Thread Marcos Cruz


Is there any way to compile a program but not executing it afterwards,
in order to check just the compilation? I have read the command help and
the man page but found nothing.  There's an `-E` option to run only the
preprocessor, but that's all.

Context: I have 19 little programs (between 50 and 500 LOC) I have
written using Pike 8.0;  after installing 9.0 it occurred to me I could
check possible compilation errors in a simple shell loop, instead of
executing and manually exiting each program; but that's not a big deal
anyways.

-- 
Marcos Cruz
http://programandala.net



Re: Is there any way to compile without executing?

2025-03-21 Thread william
Also, compile_string() and compile_file() are available if they're 
easier to deal with than casting.


On 2025-03-21 11:29, Marcos Cruz wrote:
[email protected] escribió/skribis/wrote/scrit 
(2025-03-20T23:15:17-0400):



How about something like:

$ pike -e '(program)"test"'


I didn't know that possibility.  Now I remember I read something about
`(program)` and files in the manual, but didn't used it yet.


$ pike -e 'return catch((program)"test")?1:0'
test.pike:1:Undefined identifier x.
$ echo $?
1


Clever.  I didn't know there's a `catch` function beside the `catch`
block.

Thank you!




Re: Is there any way to compile without executing?

2025-03-21 Thread Marcos Cruz
[email protected] escribió/skribis/wrote/scrit (2025-03-20T23:15:17-0400):

> How about something like:
> 
> $ pike -e '(program)"test"'

I didn't know that possibility.  Now I remember I read something about
`(program)` and files in the manual, but didn't used it yet.

> $ pike -e 'return catch((program)"test")?1:0'
> test.pike:1:Undefined identifier x.
> $ echo $?
> 1

Clever.  I didn't know there's a `catch` function beside the `catch`
block.

Thank you!

-- 
Marcos Cruz
http://programandala.net



Re: Is there any way to compile without executing?

2025-03-20 Thread william

Hi! Interesting idea.

How about something like:

test.pike:

int x = v;

$ pike -e '(program)"test"'

test.pike:1:Undefined identifier x.
Compilation failed.
-:1: PikeCompiler("", UNDEFINED, -1, -1, target, UNDEFINED)->compile()
-:1: DefaultCompilerEnvironment->compile(PikeCompiler("", UNDEFINED, -1, 
-1, target, UNDEFINED))
/opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:743: 
compile_string("int v = 
x;\n\n","test.pike",UNDEFINED,test.pike,0,UNDEFINED)
/opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:1517: 
master()->low_findprog("test",".pike",UNDEFINED,UNDEFINED)
/opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:1646: 
master()->findprog("test","",UNDEFINED,UNDEFINED)
/opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:1697: 
master()->low_cast_to_program("test","-",UNDEFINED,UNDEFINED)
/opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:1719: 
master()->cast_to_program("test","-",UNDEFINED)

-:2: -()->run(1,({"pike"}))

or maybe something fancier you can test for in your shell script?

$ pike -e 'return catch((program)"test")?1:0'
test.pike:1:Undefined identifier x.
$ echo $?
1

I think there's a way to silence even this output, but I don't remember 
what it is offhand, probably just as easy to redirect stderr somewhere.


If you want variable substitution to work, such as in a loop or 
something, you'll need to not use single quotes and escape the double 
quotes:


for x in *.pike; do
pike -e "return catch((program)\"$x\")?1:0"
echo "$x: $?"
done

Hope this helps!

Bill

On 2025-03-20 18:31, Marcos Cruz wrote:

Is there any way to compile a program but not executing it afterwards,
in order to check just the compilation? I have read the command help 
and

the man page but found nothing.  There's an `-E` option to run only the
preprocessor, but that's all.

Context: I have 19 little programs (between 50 and 500 LOC) I have
written using Pike 8.0;  after installing 9.0 it occurred to me I could
check possible compilation errors in a simple shell loop, instead of
executing and manually exiting each program; but that's not a big deal
anyways.