blob: 6dc8af8c589ab8921c8fff3aabe00e82d4a41329 (
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
|
/*
* Copyright (C) 2000, Imperial College
*
* This file is part of the Imperial College Exact Real Arithmetic Library.
* See the copyright notice included in the distribution for conditions
* of use.
*/
#include <stdio.h>
#include "real.h"
#include "real-impl.h"
/*
* realDelay(f, x) allows for a user to construct a real valued
* closure which reduces to f(x) when forced.
*/
typedef struct {
Delay_Arg x;
Delay_Fun f;
} DelayData;
Real
realDelay(Delay_Fun f, Delay_Arg x)
{
Cls *cls;
DelayData *data;
void delayCont();
if ((data = (DelayData *) malloc(sizeof(DelayData))) == NULL)
Error(FATAL, E_INT, "realDelay", "malloc failed");
data->f = f;
data->x = x;
cls = allocCls(delayCont, data);
cls->tag.isSigned = TRUE;
return (Real) cls;
}
void
delayCont()
{
Cls *cls;
DelayData *data;
cls = (Cls *) POP;
data = (DelayData *) cls->userData;
cls->redirect = (data->f)(data->x);
}
|