LispBM
exp_kind.h
Go to the documentation of this file.
1 /*
2  Copyright 2020, 2021, 2022 Joel Svensson svenssonjoel@yahoo.se
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
19 #ifndef _EXP_KIND_H_
20 #define _EXP_KIND_H_
21 
22 #include "heap.h"
23 #include "symrepr.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
33 typedef enum {
46  EXP_OR
48 
55 
56  switch (lbm_type_of(exp)) {
57  case LBM_TYPE_SYMBOL:
58  if (!lbm_is_special(exp))
59  return EXP_VARIABLE;
60  // fall through
61  case LBM_TYPE_FLOAT:
62  case LBM_TYPE_U32:
63  case LBM_TYPE_I32:
64  case LBM_TYPE_I:
65  case LBM_TYPE_U:
66  case LBM_TYPE_CHAR:
67  case LBM_TYPE_ARRAY:
68  return EXP_SELF_EVALUATING;
69  case LBM_TYPE_CONS: {
70  lbm_value head = lbm_car(exp);
71  if (lbm_type_of(head) == LBM_TYPE_SYMBOL) {
72  lbm_uint sym_id = lbm_dec_sym(head);
73  switch(sym_id){
74  case SYM_AND: return EXP_AND;
75  case SYM_OR: return EXP_OR;
76  case SYM_QUOTE: return EXP_QUOTED;
77  case SYM_DEFINE: return EXP_DEFINE;
78  case SYM_PROGN: return EXP_PROGN;
79  case SYM_LAMBDA: return EXP_LAMBDA;
80  case SYM_IF: return EXP_IF;
81  case SYM_LET: return EXP_LET;
82  default: break;
83  }
84  } // end if symbol
85 
86  if (lbm_type_of(lbm_cdr(exp)) == LBM_TYPE_SYMBOL &&
87  lbm_dec_sym(lbm_cdr(exp)) == SYM_NIL) {
88  return EXP_NO_ARGS;
89  } else {
90  return EXP_APPLICATION;
91  }
92  } // end case PTR_TYPE_CONS:
93  }
94  return EXP_KIND_ERROR;
95 }
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 #endif
static lbm_exp_kind lbm_exp_kind_of(lbm_value exp)
Definition: exp_kind.h:54
lbm_exp_kind
Definition: exp_kind.h:33
@ EXP_PROGN
Definition: exp_kind.h:41
@ EXP_LAMBDA
Definition: exp_kind.h:39
@ EXP_IF
Definition: exp_kind.h:40
@ EXP_NO_ARGS
Definition: exp_kind.h:42
@ EXP_APPLICATION
Definition: exp_kind.h:43
@ EXP_QUOTED
Definition: exp_kind.h:37
@ EXP_OR
Definition: exp_kind.h:46
@ EXP_KIND_ERROR
Definition: exp_kind.h:34
@ EXP_DEFINE
Definition: exp_kind.h:38
@ EXP_LET
Definition: exp_kind.h:44
@ EXP_VARIABLE
Definition: exp_kind.h:36
@ EXP_AND
Definition: exp_kind.h:45
@ EXP_SELF_EVALUATING
Definition: exp_kind.h:35
lbm_value lbm_cdr(lbm_value cons)
static lbm_type lbm_type_of(lbm_value x)
Definition: heap.h:657
lbm_value lbm_car(lbm_value cons)
uint32_t lbm_value
Definition: lbm_types.h:43