]> git.lizzy.rs Git - nothing.git/blob - src/script/scope.c
(#311) Implement plus_op
[nothing.git] / src / script / scope.c
1 #include "./scope.h"
2
3 struct Expr empty_scope(void)
4 {
5     return CONS(NIL, NIL);
6 }
7
8 struct Expr get_scope_value(struct Expr scope, struct Expr name)
9 {
10     switch (scope.type) {
11     case EXPR_CONS: {
12         struct Expr value = assoc(name, scope.cons->car);
13         return nil_p(value) ? get_scope_value(scope.cons->cdr, name) : value;
14     } break;
15
16     default:
17         return scope;
18     }
19 }
20
21 struct Expr set_scope_value(struct Expr scope, struct Expr name, struct Expr value)
22 {
23     (void) name;
24     (void) value;
25
26     /* TODO(#312): set_scope_value is not implemented */
27
28     return scope;
29 }
30
31 struct Expr push_scope_frame(struct Expr scope)
32 {
33     return CONS(empty_scope(), scope);
34 }
35
36 struct Expr pop_scope_frame(struct Expr scope)
37 {
38     if (scope.type == EXPR_CONS) {
39         return scope.cons->cdr;
40     } else {
41         return scope;
42     }
43 }