summaryrefslogtreecommitdiffstats
path: root/libparc/parc/algol/parc_Execution.c
blob: 8b31dcdbdbcdced3179a949e381dde1617ffc373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
//  parc_Status.c
//  Libparc
//
//
//
#include <config.h>
#include <stdio.h>

#include "parc_Execution.h"

/*
 * A PARCExecution value is a unique thing which can have a string assigned to it.
 *
 * I want the function to be:
 *
 * A thing that returns an Execution
 *
 * Execution function() { }
 *
 * A thing that an Execution value can be
 *
 * Execution value = function;
 */

struct PARCExecution {
    struct PARCExecution (*type)(char *format, ...);
    char *message;
};

PARCExecution *PARCExecution_OK = &(PARCExecution) {
    .message = "OK"
};

PARCExecution *PARCExecution_Timeout = &(PARCExecution) {
    .message = "Timeout"
};

PARCExecution *PARCExecution_Interrupted = &(PARCExecution) {
    .message = "Interrupted"
};

PARCExecution *PARCExecution_IOError = &(PARCExecution) {
    .message = "I/O Error"
};

PARCExecution *
parcExecution_OK(const char *format, ...)
{
    return PARCExecution_OK;
}

PARCExecution *
parcExecution_Interrupted(const char *format, ...)
{
    return PARCExecution_Interrupted;
}

PARCExecution *
parcExecution_IOError(const char *format, ...)
{
    return PARCExecution_IOError;
}

bool
parcExecution_Is(const PARCExecution *exec, const PARCExecution *other)
{
    return (exec == other);
}

char *
parcExecution_GetMessage(const PARCExecution *exec)
{
    return exec->message;
}

PARCExecution *
bar()
{
    return PARCExecution_OK;
}

PARCExecution *
baz()
{
    return parcExecution_OK("Nothing to say");
}

void
foo()
{
    PARCExecution *x = bar();
    PARCExecution *y = baz();

    printf("%s\n", parcExecution_GetMessage(x));
    printf("%s\n", parcExecution_GetMessage(y));
}