1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #ifndef LI_LISP_HH
|
---|
10 | #define LI_LISP_HH
|
---|
11 |
|
---|
12 | #include "lisp/li_types.hh"
|
---|
13 | #include "lisp/li_optr.hh"
|
---|
14 |
|
---|
15 | class i4_status_class;
|
---|
16 |
|
---|
17 | // this is used for debugging... it doesn't evaluate o
|
---|
18 | void lip(li_object *o);
|
---|
19 |
|
---|
20 | // this is the function added into the system, arguments are evaluated
|
---|
21 | li_object *li_print(li_object *o, li_environment *env=0);
|
---|
22 |
|
---|
23 | li_object *li_get_expression(char *&s, li_environment *env);
|
---|
24 |
|
---|
25 | li_object *li_eval(li_object *expression, li_environment *env=0);
|
---|
26 | li_object *li_call(char *fun_name, li_object *params=0, li_environment *env=0);
|
---|
27 | li_object *li_call(li_symbol *fun_name, li_object *params=0, li_environment *env=0);
|
---|
28 |
|
---|
29 | // if env is 0, global function is set
|
---|
30 | void li_add_function(li_symbol *sym, li_function_type fun, li_environment *env=0);
|
---|
31 | void li_add_function(char *sym_name, li_function_type fun, li_environment *env=0);
|
---|
32 |
|
---|
33 | li_symbol *li_find_symbol(const char *name); // if symbol doesn't exsist, 0 is returned
|
---|
34 | li_symbol *li_get_symbol(const char *name); // if symbol doesn't exsist, it is created
|
---|
35 |
|
---|
36 | // if cache_to is 0, then the symbol is found and stored there, otherwise cache_to is returned
|
---|
37 | li_symbol *li_get_symbol(char *name, li_symbol *&cache_to);
|
---|
38 |
|
---|
39 |
|
---|
40 | inline li_object *li_get_value(li_symbol *sym, li_environment *env=0)
|
---|
41 | {
|
---|
42 | if (env)
|
---|
43 | return env->value(sym);
|
---|
44 | else return sym->value();
|
---|
45 | }
|
---|
46 |
|
---|
47 | inline li_object *li_get_value(char *sym, li_environment *env=0)
|
---|
48 | { return li_get_value(li_get_symbol(sym),env); }
|
---|
49 |
|
---|
50 | inline void li_set_value(li_symbol *sym, li_object *value, li_environment *env=0)
|
---|
51 | {
|
---|
52 | if (env)
|
---|
53 | env->set_value(sym, value);
|
---|
54 | else sym->set_value(value);
|
---|
55 | }
|
---|
56 |
|
---|
57 | inline void li_set_value(char *sym, li_object *value, li_environment *env=0)
|
---|
58 | { li_set_value(li_get_symbol(sym),value,env); }
|
---|
59 |
|
---|
60 |
|
---|
61 | // gets a function for a symbol. Checks to see if it has a local value in the environment
|
---|
62 | // first
|
---|
63 | li_object *li_get_fun(li_symbol *sym, li_environment *env);
|
---|
64 |
|
---|
65 | li_object *li_get_fun(char *sym, li_environment *env);
|
---|
66 |
|
---|
67 | // return 0 if type doesn't exsist
|
---|
68 | li_object *li_new(char *type_name, li_object *params=0, li_environment *env=0);
|
---|
69 | li_object *li_new(int type, li_object *params=0, li_environment *env=0);
|
---|
70 |
|
---|
71 |
|
---|
72 | // CAR comes from old LISP machines which stands for Contents of the Address Register
|
---|
73 | // though lisp machines aren't used anymore, the term has stuck around.
|
---|
74 | inline li_object *li_car(li_object *o, li_environment *env) { return li_list::get(o,env)->data(); }
|
---|
75 |
|
---|
76 | // CDR = Contents of the Destination Register. or better know by "C" people as ->next
|
---|
77 | inline li_object *li_cdr(li_object *o, li_environment *env) { return li_list::get(o,env)->next(); }
|
---|
78 |
|
---|
79 | i4_bool li_get_bool(li_object *o, li_environment *env); // return i4_T if o is 'T, i4_F if it is 'F or nil
|
---|
80 | float li_get_float(li_object *o, li_environment *env); // will convert int to float
|
---|
81 | int li_get_int(li_object *o, li_environment *env); // will convert float to int
|
---|
82 | char *li_get_string(li_object *o, li_environment *env);
|
---|
83 | i4_bool li_is_number(li_object *o, li_environment *env); // returns true if item is LI_INT or LI_FLOAT
|
---|
84 |
|
---|
85 | // these function return the 1st, 2nd... item in a list first=li_cdr(o), second=li_cdr(li_cdr(o))
|
---|
86 | li_object *li_first(li_object *o, li_environment *env);
|
---|
87 | li_object *li_second(li_object *o, li_environment *env);
|
---|
88 | li_object *li_third(li_object *o, li_environment *env);
|
---|
89 | li_object *li_fourth(li_object *o, li_environment *env);
|
---|
90 | li_object *li_fifth(li_object *o, li_environment *env);
|
---|
91 | li_object *li_nth(li_object *o, int x, li_environment *env);
|
---|
92 |
|
---|
93 | // li_make_list takes a variable @ of arguments (null terminated) and return a list of
|
---|
94 | // add the members : example li_make_list(new li_int(4), new li_string("hello"), 0);
|
---|
95 | li_list *li_make_list(li_object *first, ...);
|
---|
96 | int li_length(li_object *o, li_environment *env); // returns the length of the list
|
---|
97 |
|
---|
98 | // this version of load take a list of li_strings which are loaded sequentially
|
---|
99 | // return result of last evaluated expression
|
---|
100 | li_object *li_load(li_object *name, li_environment *env, i4_status_class *status);
|
---|
101 | li_object *li_load(li_object *name, li_environment *env=0);
|
---|
102 |
|
---|
103 | // this loads a single file and returns result of last evaluated expression
|
---|
104 | li_object *li_load(char *filename, li_environment *env=0, i4_status_class *status=0);
|
---|
105 |
|
---|
106 | // loads from a file pointer, reads entire buffer
|
---|
107 | li_object *li_load(i4_file_class *fp, li_environment *env=0, i4_status_class *status=0);
|
---|
108 |
|
---|
109 | // reads an expression from i4_debug and prints the result of evaluation to i4_debug
|
---|
110 | li_object *li_read_eval(li_object *o, li_environment *env=0);
|
---|
111 |
|
---|
112 | // simply add an item to the begining of a list
|
---|
113 | inline void li_push(li_list *&l, li_object *o) { l=new li_list(o, l); }
|
---|
114 |
|
---|
115 | // global symbols
|
---|
116 | extern li_symbol *li_nil,
|
---|
117 | *li_true_sym,
|
---|
118 | *li_quote,
|
---|
119 | *li_backquote,
|
---|
120 | *li_comma,
|
---|
121 | *li_function_symbol;
|
---|
122 |
|
---|
123 |
|
---|
124 | class li_symbol_ref
|
---|
125 | {
|
---|
126 | char *name;
|
---|
127 | li_symbol *sym;
|
---|
128 | public:
|
---|
129 | li_symbol *get() { if (!sym) sym=li_get_symbol(name); return sym; }
|
---|
130 | i4_bool operator==(const li_symbol *&b) { return (get() == b); }
|
---|
131 |
|
---|
132 | li_symbol_ref(char *sym_name) : name(sym_name) { sym=0; }
|
---|
133 | };
|
---|
134 |
|
---|
135 | #endif
|
---|