-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathequal_predicate.c
More file actions
executable file
·90 lines (88 loc) · 2.52 KB
/
Copy pathequal_predicate.c
File metadata and controls
executable file
·90 lines (88 loc) · 2.52 KB
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
#include "common.h"
/*************************************************************
*This file provides three equivalence predicate:
* eq?, eqv? & equal?
*************************************************************/
//two args: obj1 & obj2
cellpoint eq(void)
{
if (args_ref(1) == args_ref(2)){
reg = a_true;
}else {
reg = a_false;
}
args_pop(2);
return reg;
}
//two args: obj1 & obj2
cellpoint eqv(void)
{
if (is_true(is_boolean(args_ref(1))) &&
is_true(is_boolean(args_ref(2)))){
reg = (args_ref(1) == args_ref(2)) ? a_true : a_false;
}else if (is_true(is_symbol(args_ref(1))) &&
is_true(is_symbol(args_ref(2)))){
reg = (args_ref(1) == args_ref(2)) ? a_true : a_false;
}else if (is_true(is_number(args_ref(1))) &&
is_true(is_number(args_ref(2)))){
reg = args_ref(1);
args_push(args_ref(2));
args_push(reg);
reg = number_eq();
}else if (is_true(is_char(args_ref(1))) &&
is_true(is_char(args_ref(2)))){
reg = args_ref(1);
args_push(args_ref(2));
args_push(reg);
reg = char_eq();
}else if (is_true(is_null(args_ref(1))) &&
is_true(is_null(args_ref(2)))){
reg = a_true;
}else if (is_true(is_pair(args_ref(1))) &&
is_true(is_pair(args_ref(2)))){
reg = (args_ref(1) == args_ref(2)) ? a_true : a_false;
}else if (is_true(is_string(args_ref(1))) &&
is_true(is_string(args_ref(2)))){
reg = (args_ref(1) == args_ref(2)) ? a_true : a_false;
}else if (is_true(is_vector(args_ref(1))) &&
is_true(is_vector(args_ref(2)))){
reg = (args_ref(1) == args_ref(2)) ? a_true : a_false;
}else if (is_true(is_procedure(args_ref(1))) &&
is_true(is_procedure(args_ref(2)))){
reg = (args_ref(1) == args_ref(2)) ? a_true : a_false;
}else {
reg = a_false;
}
args_pop(2);
return reg;
}
//two args: obj1 & obj2
cellpoint equal(void)
{
if (is_true(is_string(args_ref(1))) &&
is_true(is_string(args_ref(2)))){
reg = args_ref(1);
args_push(args_ref(2));
args_push(reg);
reg = string_eq();
}else if (is_true(is_vector(args_ref(1))) &&
is_true(is_vector(args_ref(2)))){
reg = args_ref(1);
args_push(args_ref(2));
args_push(reg);
reg = vector_eq();
}else if (is_true(is_list(args_ref(1))) &&
is_true(is_list(args_ref(2)))){
reg = args_ref(1);
args_push(args_ref(2));
args_push(reg);
reg = list_eq();
}else {
reg = args_ref(1);
args_push(args_ref(2));
args_push(reg);
reg = eqv();
}
args_pop(2);
return reg;
}