Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
5
Task/Program-termination/00-META.yaml
Normal file
5
Task/Program-termination/00-META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- Simple
|
||||
from: http://rosettacode.org/wiki/Program_termination
|
||||
note: Basic language learning
|
||||
9
Task/Program-termination/00-TASK.txt
Normal file
9
Task/Program-termination/00-TASK.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
;Task:
|
||||
Show the syntax for a complete stoppage of a program inside a [[Conditional Structures|conditional]].
|
||||
|
||||
This includes all [[threads]]/[[processes]] which are part of your program.
|
||||
|
||||
Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks, etc.).
|
||||
|
||||
Unless otherwise described, no special cleanup outside that provided by the operating system is provided.
|
||||
<br><br>
|
||||
2
Task/Program-termination/11l/program-termination.11l
Normal file
2
Task/Program-termination/11l/program-termination.11l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
I problem
|
||||
exit(1)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
;assuming this is not a subroutine and runs inline.
|
||||
cmp TestValue ;a label for a memory address that contains some value we want to test the accumulator against
|
||||
beq continue
|
||||
rts ;unlike the Z80 there is no conditional return so we have to branch around the return instruction.
|
||||
continue:
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
sei ;disable IRQs
|
||||
halt:
|
||||
jmp halt ;trap the program counter
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program ending64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
/*******************************************/
|
||||
/* Initialized data */
|
||||
/*******************************************/
|
||||
.data
|
||||
/*******************************************/
|
||||
/* code section */
|
||||
/*******************************************/
|
||||
.text
|
||||
.global main
|
||||
main: // entry of program
|
||||
|
||||
OK:
|
||||
// end program OK
|
||||
mov x0,0 // return code
|
||||
b 100f
|
||||
NONOK:
|
||||
// if error detected end program no ok
|
||||
mov x0,1 // return code
|
||||
100: // standard end of the program
|
||||
mov x8,EXIT // request to exit program
|
||||
svc 0 // perform the system call Linux
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
IF problem = 1 THEN
|
||||
stop
|
||||
FI
|
||||
1
Task/Program-termination/ALGOL-W/program-termination.alg
Normal file
1
Task/Program-termination/ALGOL-W/program-termination.alg
Normal file
|
|
@ -0,0 +1 @@
|
|||
if anErrorOccured then assert( false );
|
||||
22
Task/Program-termination/APL/program-termination.apl
Normal file
22
Task/Program-termination/APL/program-termination.apl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/local/bin/apl --script --
|
||||
|
||||
⍝⍝ GNU APL script
|
||||
⍝⍝ Usage: errout.apl <code>
|
||||
⍝⍝
|
||||
⍝⍝ $ echo $? ## to see exit code
|
||||
⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝
|
||||
args ← 2↓⎕ARG~'--script' '--' ⍝⍝ strip off script args we don't need
|
||||
|
||||
err ← ⍎⊃args[1]
|
||||
|
||||
∇main
|
||||
→(0=err)/ok
|
||||
error:
|
||||
'Error! exiting.'
|
||||
⍎')off 1' ⍝⍝ NOTE: exit code arg was added to )OFF in SVN r1499 Nov 2021
|
||||
ok:
|
||||
'No error, continuing...'
|
||||
⍎')off'
|
||||
∇
|
||||
|
||||
main
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program ending.s */
|
||||
|
||||
/* Constantes */
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
|
||||
/* Initialized data */
|
||||
.data
|
||||
|
||||
/* code section */
|
||||
.text
|
||||
.global main
|
||||
main: @ entry of program
|
||||
push {fp,lr} @ saves registers
|
||||
|
||||
OK:
|
||||
@ end program OK
|
||||
mov r0, #0 @ return code
|
||||
b 100f
|
||||
NONOK:
|
||||
@ if error detected end program no ok
|
||||
mov r0, #1 @ return code
|
||||
100: @ standard end of the program
|
||||
pop {fp,lr} @restaur registers
|
||||
mov r7, #EXIT @ request to exit program
|
||||
swi 0 @ perform the system call Linux
|
||||
1
Task/Program-termination/AWK/program-termination-1.awk
Normal file
1
Task/Program-termination/AWK/program-termination-1.awk
Normal file
|
|
@ -0,0 +1 @@
|
|||
if(problem)exit 1
|
||||
9
Task/Program-termination/AWK/program-termination-2.awk
Normal file
9
Task/Program-termination/AWK/program-termination-2.awk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# usage: awk -f exittest.awk input.txt
|
||||
BEGIN { print "# Exit-Test" }
|
||||
|
||||
#/s.*t/ { print "!", NR, $0; next } #1: List all matches
|
||||
/s.*t/ { print "!", NR, $0; problem=1; exit} #2: Abort after first match
|
||||
{ print " ", NR, $0}
|
||||
|
||||
END { if(problem) {print "!! Problem !!"; exit 2} }
|
||||
END { print "# Lines read:", NR }
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
PROC Main()
|
||||
DO
|
||||
IF Rand(0)=10 THEN
|
||||
PrintE("Terminate program by Break() procedure")
|
||||
Break()
|
||||
FI
|
||||
OD
|
||||
PrintE("This is a dead code")
|
||||
RETURN
|
||||
10
Task/Program-termination/Ada/program-termination-1.ada
Normal file
10
Task/Program-termination/Ada/program-termination-1.ada
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
with Ada.Task_Identification; use Ada.Task_Identification;
|
||||
|
||||
procedure Main is
|
||||
-- Create as many task objects as your program needs
|
||||
begin
|
||||
-- whatever logic is required in your Main procedure
|
||||
if some_condition then
|
||||
Abort_Task (Current_Task);
|
||||
end if;
|
||||
end Main;
|
||||
11
Task/Program-termination/Ada/program-termination-2.ada
Normal file
11
Task/Program-termination/Ada/program-termination-2.ada
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
procedure Main is
|
||||
-- Create as many task objects as your program needs
|
||||
begin
|
||||
-- whatever logic is required in your Main procedure
|
||||
if some_condition then
|
||||
-- for each task created by the Main procedure
|
||||
The_task.Stop;
|
||||
-- end the Main procedure
|
||||
return; -- actually, this is not needed
|
||||
end if;
|
||||
end Main;
|
||||
14
Task/Program-termination/Ada/program-termination-3.ada
Normal file
14
Task/Program-termination/Ada/program-termination-3.ada
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
task body Some_Task is
|
||||
begin
|
||||
loop
|
||||
select
|
||||
-- Some alternatives
|
||||
...
|
||||
or accept Stop do
|
||||
-- Some cleanup while holding the caller is here
|
||||
end Stop;
|
||||
-- A cleanup asynchronous to the caller is here
|
||||
exit; -- We are through
|
||||
end select
|
||||
end loop;
|
||||
end Some_Task;
|
||||
10
Task/Program-termination/Ada/program-termination-4.ada
Normal file
10
Task/Program-termination/Ada/program-termination-4.ada
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
task body Some_Task is
|
||||
begin
|
||||
loop
|
||||
select
|
||||
-- Some alternatives
|
||||
...
|
||||
or terminate; -- We are through
|
||||
end select
|
||||
end loop;
|
||||
end Some_Task;
|
||||
15
Task/Program-termination/Aime/program-termination.aime
Normal file
15
Task/Program-termination/Aime/program-termination.aime
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
void
|
||||
f1(integer a)
|
||||
{
|
||||
if (a) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
integer
|
||||
main(void)
|
||||
{
|
||||
f1(3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
if (someCondition) then error number -128
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
on idle -- A stay-open applet's 'idle' handler is called periodically while the applet remains open.
|
||||
-- Some code, including:
|
||||
if (someCondition) then
|
||||
quit -- Quit the applet when the script stops executing.
|
||||
error number -128 -- Stop executing the script. (Not necessary on recent systems.)
|
||||
end if
|
||||
|
||||
return 10 -- Number of seconds to the next call of this handler if the applet's still open.
|
||||
end idle
|
||||
|
|
@ -0,0 +1 @@
|
|||
10 IF 1 THEN STOP
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
problem: true
|
||||
|
||||
if problem -> exit
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
If (problem)
|
||||
ExitApp
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
If problem Then
|
||||
Exit
|
||||
Endif
|
||||
1
Task/Program-termination/Axe/program-termination.axe
Normal file
1
Task/Program-termination/Axe/program-termination.axe
Normal file
|
|
@ -0,0 +1 @@
|
|||
Returnʳ
|
||||
3
Task/Program-termination/BASIC/program-termination.basic
Normal file
3
Task/Program-termination/BASIC/program-termination.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if problem = 1 then
|
||||
end
|
||||
end if
|
||||
|
|
@ -0,0 +1 @@
|
|||
IF condition% THEN QUIT
|
||||
4
Task/Program-termination/BQN/program-termination.bqn
Normal file
4
Task/Program-termination/BQN/program-termination.bqn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
0=≠•args ? •Exit 0;
|
||||
•Show "has args"
|
||||
}
|
||||
1
Task/Program-termination/BaCon/program-termination.bacon
Normal file
1
Task/Program-termination/BaCon/program-termination.bacon
Normal file
|
|
@ -0,0 +1 @@
|
|||
IF TRUE THEN END 42
|
||||
|
|
@ -0,0 +1 @@
|
|||
if condition exit
|
||||
1
Task/Program-termination/Befunge/program-termination.bf
Normal file
1
Task/Program-termination/Befunge/program-termination.bf
Normal file
|
|
@ -0,0 +1 @@
|
|||
_@
|
||||
6
Task/Program-termination/C++/program-termination-1.cpp
Normal file
6
Task/Program-termination/C++/program-termination-1.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <cstdlib>
|
||||
|
||||
void problem_occured()
|
||||
{
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
6
Task/Program-termination/C++/program-termination-2.cpp
Normal file
6
Task/Program-termination/C++/program-termination-2.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <cstdlib>
|
||||
|
||||
void problem_occured()
|
||||
{
|
||||
std::abort();
|
||||
}
|
||||
6
Task/Program-termination/C++/program-termination-3.cpp
Normal file
6
Task/Program-termination/C++/program-termination-3.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <exception>
|
||||
|
||||
void problem_occured()
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
4
Task/Program-termination/C-sharp/program-termination.cs
Normal file
4
Task/Program-termination/C-sharp/program-termination.cs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
if (problem)
|
||||
{
|
||||
Environment.Exit(1);
|
||||
}
|
||||
18
Task/Program-termination/C/program-termination-1.c
Normal file
18
Task/Program-termination/C/program-termination-1.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdlib.h>
|
||||
/* More "natural" way of ending the program: finish all work and return
|
||||
from main() */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* work work work */
|
||||
...
|
||||
return 0; /* the return value is the exit code. see below */
|
||||
}
|
||||
|
||||
if(problem){
|
||||
exit(exit_code);
|
||||
/* On unix, exit code 0 indicates success, but other OSes may follow
|
||||
different conventions. It may be more portable to use symbols
|
||||
EXIT_SUCCESS and EXIT_FAILURE; it all depends on what meaning
|
||||
of codes are agreed upon.
|
||||
*/
|
||||
}
|
||||
5
Task/Program-termination/C/program-termination-2.c
Normal file
5
Task/Program-termination/C/program-termination-2.c
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
if(problem){
|
||||
abort();
|
||||
}
|
||||
1
Task/Program-termination/C/program-termination-3.c
Normal file
1
Task/Program-termination/C/program-termination-3.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
exit_group();
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
IF problem
|
||||
STOP RUN
|
||||
END-IF
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
IF problem
|
||||
GOBACK
|
||||
END-IF
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(if problem
|
||||
(. System exit integerErrorCode))
|
||||
;conventionally, error code 0 is the code for "OK",
|
||||
; while anything else is an actual problem
|
||||
;optionally: (-> Runtime (. getRuntime) (. exit integerErrorCode))
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(if problem
|
||||
(-> Runtime (. getRuntime) (. halt integerErrorCode)))
|
||||
; conventionally, error code 0 is the code for "OK",
|
||||
; while anything else is an actual problem
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
(defun terminate (status)
|
||||
#+sbcl ( sb-ext:quit :unix-status status) ; SBCL
|
||||
#+ccl ( ccl:quit status) ; Clozure CL
|
||||
#+clisp ( ext:quit status) ; GNU CLISP
|
||||
#+cmu ( unix:unix-exit status) ; CMUCL
|
||||
#+ecl ( ext:quit status) ; ECL
|
||||
#+abcl ( ext:quit :status status) ; Armed Bear CL
|
||||
#+allegro ( excl:exit status :quiet t) ; Allegro CL
|
||||
#+gcl (common-lisp-user::bye status) ; GCL
|
||||
#+ecl ( ext:quit status) ; ECL
|
||||
(cl-user::quit)) ; Many implementations put QUIT in the sandbox CL-USER package.
|
||||
53
Task/Program-termination/D/program-termination-1.d
Normal file
53
Task/Program-termination/D/program-termination-1.d
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import core.stdc.stdio, core.stdc.stdlib;
|
||||
|
||||
extern(C) void foo() nothrow {
|
||||
"foo at exit".puts;
|
||||
}
|
||||
|
||||
extern(C) void bar() nothrow {
|
||||
"bar at exit".puts;
|
||||
}
|
||||
|
||||
extern(C) void spam() nothrow {
|
||||
"spam at exit".puts;
|
||||
}
|
||||
|
||||
int baz(in int x) pure nothrow
|
||||
in {
|
||||
assert(x != 0);
|
||||
} body {
|
||||
if (x < 0)
|
||||
return 10;
|
||||
if (x > 0)
|
||||
return 20;
|
||||
|
||||
// x can't be 0.
|
||||
|
||||
// In release mode this becomes a halt, and it's sometimes
|
||||
// necessary. If you remove this the compiler gives:
|
||||
// Error: function test.notInfinite no return exp;
|
||||
// or assert(0); at end of function
|
||||
assert(false);
|
||||
}
|
||||
|
||||
// This generates an error, that is not meant to be caught.
|
||||
// Objects are not guaranteed to be finalized.
|
||||
int empty() pure nothrow {
|
||||
throw new Error(null);
|
||||
}
|
||||
|
||||
static ~this() {
|
||||
// This module destructor is never called if
|
||||
// the program calls the exit function.
|
||||
import std.stdio;
|
||||
"Never called".writeln;
|
||||
}
|
||||
|
||||
void main() {
|
||||
atexit(&foo);
|
||||
atexit(&bar);
|
||||
atexit(&spam);
|
||||
|
||||
//abort(); // Also this is allowed. Will not call foo, bar, spam.
|
||||
exit(0);
|
||||
}
|
||||
21
Task/Program-termination/D/program-termination-2.d
Normal file
21
Task/Program-termination/D/program-termination-2.d
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import core.runtime, std.c.stdlib;
|
||||
|
||||
static ~this() {
|
||||
// This module destructor is called if
|
||||
// the program calls the dexit function.
|
||||
import std.stdio;
|
||||
"Called on dexit".writeln;
|
||||
}
|
||||
|
||||
void dexit(int rc) {
|
||||
// Calling dexit() should have the same effect with regard to cleanup as as reaching the end of the main program.
|
||||
Runtime.terminate();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
int main() {
|
||||
if(true) {
|
||||
dexit(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1
Task/Program-termination/DBL/program-termination.dbl
Normal file
1
Task/Program-termination/DBL/program-termination.dbl
Normal file
|
|
@ -0,0 +1 @@
|
|||
IF (CONDITION) STOP
|
||||
|
|
@ -0,0 +1 @@
|
|||
System.Halt;
|
||||
|
|
@ -0,0 +1 @@
|
|||
System.Halt(1); // Optional exit code
|
||||
3
Task/Program-termination/E/program-termination-1.e
Normal file
3
Task/Program-termination/E/program-termination-1.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if (true) {
|
||||
interp.exitAtTop()
|
||||
}
|
||||
3
Task/Program-termination/E/program-termination-2.e
Normal file
3
Task/Program-termination/E/program-termination-2.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if (true) {
|
||||
interp.exitAtTop("because the task said so")
|
||||
}
|
||||
6
Task/Program-termination/EMal/program-termination.emal
Normal file
6
Task/Program-termination/EMal/program-termination.emal
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
^| I try to use the exit codes described at:
|
||||
| https://github.com/openbsd/src/blob/master/include/sysexits.h
|
||||
|^
|
||||
int EX_SOFTWARE = 70 # internal software error
|
||||
logic hasProblem = true
|
||||
if hasProblem do exit EX_SOFTWARE end
|
||||
|
|
@ -0,0 +1 @@
|
|||
if rcode != :ok, do: System.halt(1)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
exit(:normal)
|
||||
# or
|
||||
exit(:shutdown)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(when something
|
||||
(kill-emacs))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
% Implemented by Arjun Sunel
|
||||
if problem ->
|
||||
exit(1).
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
% Implemented by Arjun Sunel
|
||||
if problem ->
|
||||
halt().
|
||||
4
Task/Program-termination/F-Sharp/program-termination.fs
Normal file
4
Task/Program-termination/F-Sharp/program-termination.fs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
open System
|
||||
|
||||
if condition then
|
||||
Environment.Exit 1
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
USING: kernel system ;
|
||||
|
||||
t [ 0 exit ] when
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
USING: init io ;
|
||||
|
||||
[ "Exiting Factor..." print flush ] "message" add-shutdown-hook
|
||||
4
Task/Program-termination/Forth/program-termination.fth
Normal file
4
Task/Program-termination/Forth/program-termination.fth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
debug @
|
||||
if QUIT \ quit back to the interpreter
|
||||
else BYE \ exit forth environment completely (e.g. end of a Forth shell script)
|
||||
then
|
||||
3
Task/Program-termination/Fortran/program-termination.f
Normal file
3
Task/Program-termination/Fortran/program-termination.f
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
IF (condition) STOP [message]
|
||||
! message is optional and is a character string.
|
||||
! If present, the message is output to the standard output device.
|
||||
11
Task/Program-termination/FreeBASIC/program-termination.basic
Normal file
11
Task/Program-termination/FreeBASIC/program-termination.basic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
'FB 1.05.0 Win64 'endprog.bas'
|
||||
|
||||
Dim isError As Boolean = True
|
||||
If isError Then
|
||||
End 1
|
||||
End If
|
||||
|
||||
' The following code won't be executed
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1 @@
|
|||
10 IF 1 THEN STOP
|
||||
11
Task/Program-termination/Gambas/program-termination-1.gambas
Normal file
11
Task/Program-termination/Gambas/program-termination-1.gambas
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Public Sub Form_Open()
|
||||
Dim siCount As Short
|
||||
|
||||
Do
|
||||
If siCount > 1000 Then Break
|
||||
Inc siCount
|
||||
Loop
|
||||
|
||||
Me.Close
|
||||
|
||||
End
|
||||
11
Task/Program-termination/Gambas/program-termination-2.gambas
Normal file
11
Task/Program-termination/Gambas/program-termination-2.gambas
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Public Sub Main()
|
||||
Dim siCount As Short
|
||||
|
||||
Do
|
||||
If siCount > 1000 Then Break
|
||||
Inc siCount
|
||||
Loop
|
||||
|
||||
Quit
|
||||
|
||||
End
|
||||
1
Task/Program-termination/Gema/program-termination.gema
Normal file
1
Task/Program-termination/Gema/program-termination.gema
Normal file
|
|
@ -0,0 +1 @@
|
|||
Star Trek=@err{found a Star Trek reference\n}@abort
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
problem=1
|
||||
if (problem) {
|
||||
exit gnuplot
|
||||
}
|
||||
5
Task/Program-termination/Go/program-termination-1.go
Normal file
5
Task/Program-termination/Go/program-termination-1.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func main() {
|
||||
if problem {
|
||||
return
|
||||
}
|
||||
}
|
||||
46
Task/Program-termination/Go/program-termination-2.go
Normal file
46
Task/Program-termination/Go/program-termination-2.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
const problem = true
|
||||
|
||||
func main() {
|
||||
fmt.Println("main program start")
|
||||
|
||||
// this will get run on exit
|
||||
defer paperwork()
|
||||
|
||||
// this will not run to completion
|
||||
go pcj()
|
||||
|
||||
// this will not get run on exit
|
||||
rec := &requiresExternalCleanup{"external object"}
|
||||
runtime.SetFinalizer(rec, cleanup)
|
||||
|
||||
if problem {
|
||||
fmt.Println("main program returning")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func paperwork() {
|
||||
fmt.Println("i's dotted, t's crossed")
|
||||
}
|
||||
|
||||
func pcj() {
|
||||
fmt.Println("there's uncle Joe")
|
||||
time.Sleep(1e10)
|
||||
fmt.Println("movin kinda slow")
|
||||
}
|
||||
|
||||
type requiresExternalCleanup struct {
|
||||
id string
|
||||
}
|
||||
|
||||
func cleanup(rec *requiresExternalCleanup) {
|
||||
fmt.Println(rec.id, "cleanup")
|
||||
}
|
||||
13
Task/Program-termination/Go/program-termination-3.go
Normal file
13
Task/Program-termination/Go/program-termination-3.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
func main() {
|
||||
fmt.Println("main program start")
|
||||
|
||||
// this will not get run on os.Exit
|
||||
defer func() {
|
||||
fmt.Println("deferred function")
|
||||
}()
|
||||
|
||||
if problem {
|
||||
fmt.Println("main program exiting")
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
17
Task/Program-termination/Go/program-termination-4.go
Normal file
17
Task/Program-termination/Go/program-termination-4.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
func pcj() {
|
||||
fmt.Println("at the junction")
|
||||
defer func() {
|
||||
fmt.Println("deferred from pcj")
|
||||
}()
|
||||
panic(10)
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("main program start")
|
||||
defer func() {
|
||||
fmt.Println("deferred from main")
|
||||
}()
|
||||
go pcj()
|
||||
time.Sleep(1e9)
|
||||
fmt.Println("main program done")
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
if (problem) System.exit(intExitCode)
|
||||
|
|
@ -0,0 +1 @@
|
|||
if (problem) Runtime.runtime.halt(intExitCode)
|
||||
8
Task/Program-termination/Haskell/program-termination.hs
Normal file
8
Task/Program-termination/Haskell/program-termination.hs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import Control.Monad
|
||||
import System.Exit
|
||||
|
||||
when problem do
|
||||
exitWith ExitSuccess -- success
|
||||
exitWith (ExitFailure integerErrorCode) -- some failure with code
|
||||
exitSuccess -- success; in GHC 6.10+
|
||||
exitFailure -- generic failure
|
||||
|
|
@ -0,0 +1 @@
|
|||
ALARM( 999 )
|
||||
|
|
@ -0,0 +1 @@
|
|||
100 IF CONDITION THEN STOP
|
||||
3
Task/Program-termination/Icon/program-termination.icon
Normal file
3
Task/Program-termination/Icon/program-termination.icon
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
exit(i) # terminates the program setting an exit code of i
|
||||
stop(x1,x2,..) # terminates the program writing out x1,..; if any xi is a file writing switches to that file
|
||||
runerr(i,x) # terminates the program with run time error 'i' for value 'x'
|
||||
1
Task/Program-termination/J/program-termination-1.j
Normal file
1
Task/Program-termination/J/program-termination-1.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
2!:55^:] condition
|
||||
1
Task/Program-termination/J/program-termination-2.j
Normal file
1
Task/Program-termination/J/program-termination-2.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
3 : 'if. 0~: condition do. 2!:55 condition end.'
|
||||
6
Task/Program-termination/Java/program-termination-1.java
Normal file
6
Task/Program-termination/Java/program-termination-1.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
if(problem){
|
||||
System.exit(integerErrorCode);
|
||||
//conventionally, error code 0 is the code for "OK",
|
||||
// while anything else is an actual problem
|
||||
//optionally: Runtime.getRuntime().exit(integerErrorCode);
|
||||
}
|
||||
5
Task/Program-termination/Java/program-termination-2.java
Normal file
5
Task/Program-termination/Java/program-termination-2.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
if(problem){
|
||||
Runtime.getRuntime().halt(integerErrorCode);
|
||||
//conventionally, error code 0 is the code for "OK",
|
||||
// while anything else is an actual problem
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
if (some_condition)
|
||||
quit();
|
||||
1
Task/Program-termination/Joy/program-termination.joy
Normal file
1
Task/Program-termination/Joy/program-termination.joy
Normal file
|
|
@ -0,0 +1 @@
|
|||
[true] [quit] [] ifte.
|
||||
2
Task/Program-termination/Jq/program-termination-1.jq
Normal file
2
Task/Program-termination/Jq/program-termination-1.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$ jq -n '"Hello", if 1 then error else 2 end'
|
||||
"Hello"
|
||||
2
Task/Program-termination/Jq/program-termination-2.jq
Normal file
2
Task/Program-termination/Jq/program-termination-2.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$ jq -n '"Hello" | if 1 then error else 2 end'
|
||||
jq: error: Hello
|
||||
3
Task/Program-termination/Jsish/program-termination.jsish
Normal file
3
Task/Program-termination/Jsish/program-termination.jsish
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
assert(0 == 1);
|
||||
|
||||
if (problem) exit(1);
|
||||
1
Task/Program-termination/Julia/program-termination.julia
Normal file
1
Task/Program-termination/Julia/program-termination.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
quit() # terminates program normally, with its child processes. See also exit(0).
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
// version 1.0.6
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val problem = true
|
||||
if (problem) System.exit(1) // non-zero code passed to OS to indicate a problem
|
||||
println("Program terminating normally") // this line will not be executed
|
||||
}
|
||||
12
Task/Program-termination/Lasso/program-termination-1.lasso
Normal file
12
Task/Program-termination/Lasso/program-termination-1.lasso
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/lasso9
|
||||
//[
|
||||
|
||||
handle => {
|
||||
stdoutnl('The end is here')
|
||||
}
|
||||
|
||||
stdoutnl('Starting execution')
|
||||
|
||||
abort
|
||||
|
||||
stdoutnl('Ending execution')
|
||||
12
Task/Program-termination/Lasso/program-termination-2.lasso
Normal file
12
Task/Program-termination/Lasso/program-termination-2.lasso
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/lasso9
|
||||
|
||||
handle_error => {
|
||||
stdoutnl('There was an error ' + error_msg)
|
||||
abort
|
||||
}
|
||||
|
||||
stdoutnl('Starting execution')
|
||||
|
||||
0/0
|
||||
|
||||
stdoutnl('Ending execution')
|
||||
|
|
@ -0,0 +1 @@
|
|||
if 2 =2 then end
|
||||
|
|
@ -0,0 +1 @@
|
|||
10 IF 1 THEN END
|
||||
6
Task/Program-termination/Logo/program-termination.logo
Normal file
6
Task/Program-termination/Logo/program-termination.logo
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
bye ; exits to shell
|
||||
|
||||
throw "toplevel ; exits to interactive prompt
|
||||
|
||||
pause ; escapes to interactive prompt for debugging
|
||||
continue ; resumes after a PAUSE
|
||||
3
Task/Program-termination/Lua/program-termination.lua
Normal file
3
Task/Program-termination/Lua/program-termination.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if some_condition then
|
||||
os.exit( number )
|
||||
end
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Module Checkit {
|
||||
For i=1 to 200
|
||||
Thread {
|
||||
k++
|
||||
Print "Thread:"; num, "k=";k
|
||||
} as M
|
||||
Thread M Execute {
|
||||
static num=M, k=1000*i
|
||||
}
|
||||
Thread M interval 100+900*rnd
|
||||
next i
|
||||
|
||||
Task.Main 20 {
|
||||
if random(10)=1 then Set End
|
||||
}
|
||||
}
|
||||
Checkit
|
||||
4
Task/Program-termination/M4/program-termination.m4
Normal file
4
Task/Program-termination/M4/program-termination.m4
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
beginning
|
||||
define(`problem',1)
|
||||
ifelse(problem,1,`m4exit(1)')
|
||||
ending
|
||||
3
Task/Program-termination/MATLAB/program-termination-1.m
Normal file
3
Task/Program-termination/MATLAB/program-termination-1.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if condition
|
||||
return
|
||||
end
|
||||
3
Task/Program-termination/MATLAB/program-termination-2.m
Normal file
3
Task/Program-termination/MATLAB/program-termination-2.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if condition
|
||||
quit
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
If[problem, Abort[]];
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
/* Basically, it's simply quit() */
|
||||
|
||||
block([ans], loop, if (ans: read("Really quit ? (y, n)")) = 'y
|
||||
then quit()
|
||||
elseif ans = 'n then (print("Nice choice!"), 'done)
|
||||
else (print("I dont' understand..."), go(loop)));
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue