Skip to content

Commit a865e25

Browse files
committed
Wip: add ambeval2
1 parent b6e72b4 commit a865e25

File tree

7 files changed

+41
-10
lines changed

7 files changed

+41
-10
lines changed

src/ambeval.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include "ambeval.h"
22

3-
#define AREA "EVAL"
3+
#define AREA "AMBEVAL"
44

55
#include "aneval.h"
66
#include "eceval.h"
77
#include "environment.h"
8+
#include "error.h"
89
#include "list.h"
10+
#include "mceval.h"
911
#include "parser.h"
1012
#include "storage.h"
1113

@@ -153,8 +155,10 @@ static void init(obj execution_environment)
153155
ambenv);
154156
}
155157

156-
obj ambeval(obj exp, obj exenv)
158+
static obj ambeval(obj exp, obj exenv, obj succeed, obj fail)
157159
{
160+
(void)succeed, (void)fail;
161+
158162
static bool haveinit = false;
159163

160164
bool orig_gc = disable_gc;
@@ -176,3 +180,19 @@ obj ambeval(obj exp, obj exenv)
176180

177181
return eceval(analyze_execute, exenv);
178182
}
183+
184+
obj ambeval2(obj exp, obj exenv)
185+
{
186+
obj value = of_identifier("value");
187+
obj fail_s = of_identifier("fail");
188+
obj succeed =
189+
make_procedure(list2(value, fail_s), list1(value), emptylst);
190+
obj fail = make_procedure(
191+
emptylst,
192+
list2(list2(of_identifier("display"),
193+
of_string(
194+
"ERROR: (AMBEVAL) unexpected call to amb2's fail")),
195+
failed),
196+
emptylst);
197+
return ambeval(exp, exenv, succeed, fail);
198+
}

src/ambeval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
#include "obj.h"
66

7-
obj ambeval(obj exp, obj env);
7+
obj ambeval2(obj exp, obj env);
88

99
#endif

src/aneval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "aneval.h"
22

3-
#define AREA "EVAL"
3+
#define AREA "ANEVAL"
44

55
#include "eceval.h"
66
#include "environment.h"

src/error.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
#define AREA "ERROR"
99

10+
#define OBJ_4(TYPE, STYPE, VTYPE, VALUE) \
11+
{ \
12+
TYPE, STYPE, \
13+
{ \
14+
.VTYPE = VALUE \
15+
} \
16+
}
17+
1018
enum errsbtyp {
1119
ERROR_MEMORY = 1,
1220
ERROR_ARGUMENT_TYPE, // 2

src/eval.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
obj (*eval)(obj, obj) = eceval;
88

9-
void use_ambeval(void){
10-
eval = ambeval;
9+
void use_ambeval(void)
10+
{
11+
eval = ambeval2;
1112
}
1213

13-
void use_aneval(void){
14+
void use_aneval(void)
15+
{
1416
eval = aneval;
1517
}
16-

src/obj.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,15 @@ obj (*to_function(obj dat))(obj)
249249
const obj and_s = SYMBOL("and");
250250
SYMBOL_VAR(uapply)
251251
const obj __ppapply = SYMBOL("__%%apply");
252+
const obj arrow = SYMBOL("=>");
252253
SYMBOL_VAR(begin)
253254
SYMBOL_VAR(cond)
254255
const obj cons_s = SYMBOL("cons");
255256
const obj cons_stream = SYMBOL("cons-stream");
256257
SYMBOL_VAR(define)
257258
SYMBOL_VAR(delay)
258259
const obj else_s = SYMBOL("else");
259-
const obj arrow = SYMBOL("=>");
260+
SYMBOL_VAR(failed)
260261
const obj if_s = SYMBOL("if");
261262
SYMBOL_VAR(let)
262263
SYMBOL_VAR(letrec)

src/obj.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@ obj (*to_function(obj dat))(obj);
114114
extern const obj and_s;
115115
extern const obj uapply;
116116
extern const obj __ppapply;
117+
extern const obj arrow;
117118
extern const obj begin;
118119
extern const obj cond;
119120
extern const obj cons_s;
120121
extern const obj cons_stream;
121122
extern const obj define;
122123
extern const obj delay;
123124
extern const obj else_s;
124-
extern const obj arrow;
125+
extern const obj failed;
125126
extern const obj if_s;
126127
extern const obj let;
127128
extern const obj letrec;

0 commit comments

Comments
 (0)