Anonymous user
Native shebang: Difference between revisions
m
{{out}} / Category:Programming environment operations
m ({{out}} / Category:Programming environment operations) |
|||
Line 1:
{{draft task|Basic language learning}} [[Category:Programming environment operations]]
'''In short:''' Use the specimen language (native) for "scripting".
;Example: If your language is "foo", then the test case of "echo.foo" runs in a terminal as "<tt>./echo.foo Hello, world!"</tt>.
'''In long''': Create a program (in the specimen language) that will automatically compile a ''test case'' (of the same specimen language) to a native binary executable and then transparently load and run this ''test case'' executable.
Make it so that all that is required is a custom [[wp:Shebang (Unix)|shebangs]]
at the start of the ''test case''. e.g. "<tt>#!/usr/local/bin/script_foo</tt>"
'''Importantly:''' This task must be coded '''strictly''' in the specimen language, '''neither''' using a shell script '''nor''' any other 3rd language.
Line 13 ⟶ 14:
Optimise this progress so that the ''test program'' '''binary executable''' is only created if the original ''test program'' '''source code''' as been touched/edited.
Note: If the lauguage (or a specific implementation) handles this automatically,
then simple provide an example of "echo.foo"
Line 25 ⟶ 27:
'''This task:'''
However in this task '''Native shebang''' task we are go ''native''.
In the shebang, instead of running a shell, we call a binary-executable
generated from the original native language,
e.g. when using [[C]] with gcc "<tt>#!/usr/local/bin/script_gcc</tt>"
to extract, compile and run the native "script" source code.
Other small innovations required of this ''Native shebang'' task:
Line 45 ⟶ 51:
{{works with|ALGOL 68G|Any - Tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.7 algol68g-2.7].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to algol68toc actually doing a real compilation.}}
Note: With Algol68G the option "-O3" will compile the script file to a ".so" file,
this ".so" file is a binary executable and dynamically loaded library.
Also note that this ".so" will only be generated if the ".a68" source file
has been touched.
'''File: echo.a68'''<lang algol68>#!/usr/bin/a68g --script #
# -*- coding: utf-8 -*- #
STRING ofs := "";
FOR i FROM 4 TO argc DO print((ofs, argv(i))); ofs:=" " OD</lang>
<pre>
$ ./echo.a68 Hello, world!
</pre>
{{out}}
<pre>
Hello, world!
Line 209 ⟶ 219:
$ ./echo.c Hello, world!
</pre>
{{out}}
▲'''Test Output:'''
<pre>
Hello, world!
Line 216 ⟶ 226:
=={{header|UNIX Shell}}==
===Using sh to script sh===
In strictly shell this is natural, native and easy
'''File: echo.sh'''
Line 226 ⟶ 236:
./echo.sh Hello, world!
</pre>
{{out}}
<pre>
Hello, world!
Line 321 ⟶ 331:
$ ./echo.c Hello, world!
</pre>
{{out}}
<pre>
Hello, world!
Line 346 ⟶ 356:
./echo.py Hello, world!
</pre>
{{out}}
<pre>
Hello, world!
|