- Timestamp:
- 05/14/08 08:15:48 (6 months ago)
- Location:
- lang/c/misc/mlisp
- Files:
-
- 4 added
- 2 removed
- 6 modified
- 11 moved
-
compiler (deleted)
-
mlisp.vcproj (modified) (3 diffs)
-
readme.txt (modified) (3 diffs)
-
sexp/c_compiler.cpp (moved) (moved from lang/c/misc/mlisp/sexp/compiler.cpp) (1 diff)
-
sexp/c_compiler.h (moved) (moved from lang/c/misc/mlisp/sexp/compiler.h)
-
sexp/inner.h (modified) (2 diffs)
-
sexp/m_basic.cpp (added)
-
sexp/m_basic.h (added)
-
sexp/mlisp.cpp (added)
-
sexp/mlisp.h (added)
-
sexp/s_hash.h (moved) (moved from lang/c/misc/mlisp/sexp/shash.h)
-
sexp/s_print.cpp (moved) (moved from lang/c/misc/mlisp/sexp/sprint.cpp) (1 diff)
-
sexp/s_read.cpp (moved) (moved from lang/c/misc/mlisp/sexp/sread.cpp)
-
sexp/s_util.cpp (moved) (moved from lang/c/misc/mlisp/sexp/sutil.cpp) (1 diff)
-
sexp/s_util.h (moved) (moved from lang/c/misc/mlisp/sexp/sutil.h)
-
sexp/s_vect.cpp (moved) (moved from lang/c/misc/mlisp/sexp/svect.cpp) (1 diff)
-
sexp/s_vect.h (moved) (moved from lang/c/misc/mlisp/sexp/svect.h)
-
sexp/sexp.cpp (modified) (2 diffs)
-
sexp/sexp.h (modified) (1 diff)
-
sexp/v_vm.cpp (moved) (moved from lang/c/misc/mlisp/sexp/vm.cpp) (1 diff)
-
sexp/v_vm.h (moved) (moved from lang/c/misc/mlisp/sexp/vm.h)
-
test/main.cpp (modified) (3 diffs)
-
vm (deleted)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/misc/mlisp/mlisp.vcproj
r11547 r11549 120 120 </File> 121 121 <File 122 RelativePath=".\sexp\s_hash.h"> 123 </File> 124 <File 125 RelativePath=".\sexp\s_print.cpp"> 126 </File> 127 <File 128 RelativePath=".\sexp\s_read.cpp"> 129 </File> 130 <File 131 RelativePath=".\sexp\s_util.cpp"> 132 </File> 133 <File 134 RelativePath=".\sexp\s_util.h"> 135 </File> 136 <File 137 RelativePath=".\sexp\s_vect.cpp"> 138 </File> 139 <File 140 RelativePath=".\sexp\s_vect.h"> 141 </File> 142 <File 122 143 RelativePath=".\sexp\sexp.cpp"> 123 144 </File> … … 125 146 RelativePath=".\sexp\sexp.h"> 126 147 </File> 127 <File128 RelativePath=".\sexp\shash.h">129 </File>130 <File131 RelativePath=".\sexp\sprint.cpp">132 </File>133 <File134 RelativePath=".\sexp\sread.cpp">135 </File>136 <File137 RelativePath=".\sexp\sutil.cpp">138 </File>139 <File140 RelativePath=".\sexp\sutil.h">141 </File>142 <File143 RelativePath=".\sexp\svect.cpp">144 </File>145 <File146 RelativePath=".\sexp\svect.h">147 </File>148 148 <Filter 149 149 Name="compiler" 150 150 Filter=""> 151 151 <File 152 RelativePath=".\sexp\c ompiler.cpp">152 RelativePath=".\sexp\c_compiler.cpp"> 153 153 </File> 154 154 <File 155 RelativePath=".\sexp\c ompiler.h">155 RelativePath=".\sexp\c_compiler.h"> 156 156 </File> 157 157 </Filter> … … 163 163 </File> 164 164 <File 165 RelativePath=".\sexp\v m.cpp">165 RelativePath=".\sexp\v_vm.cpp"> 166 166 </File> 167 167 <File 168 RelativePath=".\sexp\vm.h"> 168 RelativePath=".\sexp\v_vm.h"> 169 </File> 170 </Filter> 171 <Filter 172 Name="modules" 173 Filter=""> 174 <File 175 RelativePath=".\sexp\m_basic.cpp"> 176 </File> 177 <File 178 RelativePath=".\sexp\m_basic.h"> 179 </File> 180 <File 181 RelativePath=".\sexp\mlisp.cpp"> 182 </File> 183 <File 184 RelativePath=".\sexp\mlisp.h"> 169 185 </File> 170 186 </Filter> -
lang/c/misc/mlisp/readme.txt
r11387 r11549 24 24 * �\�[�X�\�� 25 25 26 sexp 27 �r������ compiler 28 �R���p�C�� 29 vm 30 �o�[�`�����}�V�� 26 core 27 ����s_ ������ 28 �r������ ����c_ ������ 29 �R���p�C���֘A 30 ����v_ ������ 31 �o�[�`�����}�V���֘A 32 ����m_ ������ 33 ���W���[���֘A 34 31 35 test 32 36 �e�X�g�p�G���g�� … … 40 44 41 45 * ToDo 42 -[v] �X�^�b�N�x�[�X�ɒu��������-[ x] �C�ӌ̈���46 -[v] �X�^�b�N�x�[�X�ɒu��������-[v] �C�ӌ̈��� 43 47 -[x] �}�N����� 44 48 --[x] macroexpand ��- C �������[�o���̊���яo�������ɂ���- �unil�v�ut�v���V���{���Ȃ̂ŁA�R���p�C�������V���{���Q�ƂɂȂ�Ă��܂� … … 64 68 * changelog 65 69 70 ** 080513 71 - �C�ӌ̈����� 72 66 73 ** 080511 67 74 - �X�^�b�N�x�[�X�ɒu������ -
lang/c/misc/mlisp/sexp/c_compiler.cpp
r11547 r11549 6 6 //============================================================================= 7 7 8 #include "c ompiler.h"8 #include "c_compiler.h" 9 9 #include "sexp.h" 10 #include "s util.h"10 #include "s_util.h" 11 11 #include "op.h" 12 12 #include "inner.h" -
lang/c/misc/mlisp/sexp/inner.h
r11387 r11549 1 1 //============================================================================= 2 /// ���� 2 3 //============================================================================= 3 4 … … 103 104 void print_vector(SExp v); 104 105 106 107 /// ��s���F�X�^�b�N�Q�� 105 108 SExp refer_stack(int s, int i); -
lang/c/misc/mlisp/sexp/s_print.cpp
r11387 r11549 1 1 #include "inner.h" 2 #include "s util.h"2 #include "s_util.h" 3 3 4 4 static void print_cell(SExp p) { -
lang/c/misc/mlisp/sexp/s_util.cpp
r11387 r11549 6 6 //============================================================================= 7 7 8 #include "s util.h"8 #include "s_util.h" 9 9 #include <stdarg.h> 10 10 -
lang/c/misc/mlisp/sexp/s_vect.cpp
r11387 r11549 4 4 //============================================================================= 5 5 6 #include "s vect.h"6 #include "s_vect.h" 7 7 #include "inner.h" 8 8 -
lang/c/misc/mlisp/sexp/sexp.cpp
r11387 r11549 5 5 6 6 #include "sexp.h" 7 #include "s hash.h"7 #include "s_hash.h" 8 8 #include "inner.h" 9 9 #include <stdio.h> … … 283 283 //============================================================================= 284 284 285 void mlisp_new(const SVTable* vtbl) {285 void sexp_new(const SVTable* vtbl) { 286 286 init(vtbl); 287 287 } 288 288 289 void mlisp_delete(void) {289 void sexp_delete(void) { 290 290 close(); 291 291 } -
lang/c/misc/mlisp/sexp/sexp.h
r11544 r11549 72 72 // ���� 73 73 74 /// �R���e�L�X�g�̐��� 75 /** 74 /// ���̏���/** 76 75 @param f GC���������A���P�[�^�ւ̊��|�C���^ 77 76 */ 78 void mlisp_new(const SVTable* vtbl);77 void sexp_new(const SVTable* vtbl); 79 78 80 79 /// ���� 81 void mlisp_delete(void);80 void sexp_delete(void); 82 81 83 82 // Lisp�n�� -
lang/c/misc/mlisp/sexp/v_vm.cpp
r11547 r11549 6 6 //============================================================================= 7 7 8 #include "v m.h"8 #include "v_vm.h" 9 9 #include "sexp.h" 10 #include "s util.h"11 #include "s vect.h"10 #include "s_util.h" 11 #include "s_vect.h" 12 12 #include "op.h" 13 13 #include "inner.h" -
lang/c/misc/mlisp/test/main.cpp
r11544 r11549 3 3 //============================================================================= 4 4 5 #include "sexp.h" 6 #include "sutil.h" 7 #include "compiler.h" 8 #include "vm.h" 5 #include "mlisp.h" 9 6 #include <gc/gc.h> 10 7 #include <setjmp.h> 11 12 #ifndef FALSE13 #define FALSE (0)14 #define TRUE (1)15 #endif16 8 17 9 static jmp_buf s_env; … … 30 22 } 31 23 32 33 int load_file(const char* fn); 34 35 36 37 #include "op.h" 38 #include "inner.h" 39 40 /// ��s 41 SExp run(SExp c) { 42 return vm(nil, c, 0, nil, 0); 43 } 44 45 /// �g�b�v���x���ŃR���p�C�� 46 SExp compile_ontop(SExp code) { 47 SExp halt_code = cons(HALT, nil); 48 return compile(code, list(1, nil), nil, halt_code); 49 } 50 51 /// �]�� 52 SExp evaluate(SExp code) { 53 SExp c = compile_ontop(code); 54 //print(c); 55 return run(c); 56 } 57 58 59 static bool check_number(SExp a) { 60 switch (type_of(a)) { 61 default: 62 error(ERR_TYPE_REQUIRED, "integer"); 63 return false; 64 case tInt: 65 return true; 66 } 67 } 68 69 70 //============================================================================= 71 static SExp builtin_cons(int s) { 72 SExp a = refer_stack(s, 0); 73 SExp d = refer_stack(s, 1); 74 return cons(a, d); 75 } 76 77 static SExp builtin_car(int s) { 78 SExp a = refer_stack(s, 0); 79 return car(a); 80 } 81 82 static SExp builtin_cdr(int s) { 83 SExp a = refer_stack(s, 0); 84 return cdr(a); 85 } 86 87 static SExp builtin_consp(int s) { 88 SExp v = refer_stack(s, 0); 89 return consp(v) ? t : nil; 90 } 91 92 static SExp builtin_eq(int s) { 93 SExp a = refer_stack(s, 0); 94 SExp d = refer_stack(s, 1); 95 return eq(a, d) ? t : nil; 96 } 97 98 static SExp builtin_rplaca(int s) { 99 SExp a = refer_stack(s, 0); 100 SExp d = refer_stack(s, 1); 101 rplaca(a, d); 102 return nil; 103 } 104 105 static SExp builtin_rplacd(int s) { 106 SExp a = refer_stack(s, 0); 107 SExp d = refer_stack(s, 1); 108 rplacd(a, d); 109 return nil; 110 } 111 112 static SExp builtin_plus(int s) { 113 sint n = s2int(refer_stack(s, -1)); 114 sint x = 0; 115 for (int i=0; i<n; ++i) { 116 SExp a = refer_stack(s, i); 117 check_number(a); 118 x += s2int(a); 119 } 120 return int2s(x); 121 } 122 123 static SExp builtin_difference(int s) { 124 sint n = s2int(refer_stack(s, -1)); 125 SExp a = refer_stack(s, 0); 126 check_number(a); 127 sint x = s2int(a); 128 if (n == 1) { 129 x = -x; 130 } else { 131 for (int i=1; i<n; ++i) { 132 SExp a = refer_stack(s, i); 133 check_number(a); 134 x -= s2int(a); 135 } 136 } 137 return int2s(x); 138 } 139 140 static SExp builtin_times(int s) { 141 sint n = s2int(refer_stack(s, -1)); 142 sint x = 1; 143 for (int i=0; i<n; ++i) { 144 SExp a = refer_stack(s, i); 145 check_number(a); 146 x *= s2int(a); 147 } 148 return int2s(x); 149 } 150 151 static SExp builtin_quotient(int s) { 152 sint n = s2int(refer_stack(s, -1)); 153 SExp a = refer_stack(s, 0); 154 check_number(a); 155 sint x = s2int(a); 156 if (n == 1) { 157 x = 1 / x; 158 } else { 159 for (int i=1; i<n; ++i) { 160 SExp a = refer_stack(s, i); 161 check_number(a); 162 sint d = s2int(a); 163 if (d == 0) { 164 // error(ERR_ZERO_DIVIDE); 165 assert(!"zero divide"); 166 } else { 167 x /= d; 168 } 169 } 170 } 171 return int2s(x); 172 } 173 174 static SExp num_predicate(int s, int n, bool (*p)(sint, sint)) { 175 SExp a = refer_stack(s, 0); 176 check_number(a); 177 sint x = s2int(a); 178 179 for (int i=1; i<n; ++i) { 180 SExp b = refer_stack(s, i); 181 check_number(b); 182 sint y = s2int(b); 183 if (!p(x, y)) return nil; 184 x = y; 185 } 186 return t; 187 } 188 189 static bool numeq(sint a, sint b) { return a == b; } 190 static SExp builtin_numeq(int s) { 191 sint n = s2int(refer_stack(s, -1)); 192 return num_predicate(s, n, numeq); 193 } 194 195 static bool numlt(sint a, sint b) { return a < b; } 196 static SExp builtin_lt(int s) { 197 sint n = s2int(refer_stack(s, -1)); 198 return num_predicate(s, n, numlt); 199 } 200 201 static bool numgt(sint a, sint b) { return a > b; } 202 static SExp builtin_gt(int s) { 203 sint n = s2int(refer_stack(s, -1)); 204 return num_predicate(s, n, numgt); 205 } 206 207 static bool numle(sint a, sint b) { return a <= b; } 208 static SExp builtin_le(int s) { 209 sint n = s2int(refer_stack(s, -1)); 210 return num_predicate(s, n, numle); 211 } 212 213 static bool numge(sint a, sint b) { return a >= b; } 214 static SExp builtin_ge(int s) { 215 sint n = s2int(refer_stack(s, -1)); 216 return num_predicate(s, n, numge); 217 } 218 219 220 static SExp builtin_read(int s) { 221 return read_from_file(stdin); 222 } 223 224 static SExp builtin_print(int s) { 225 SExp a = refer_stack(s, 0); 226 print(a); 227 return nil; 228 } 229 230 static SExp builtin_eval(int s) { 231 SExp code = refer_stack(s, 0); 232 233 return evaluate(code); 234 } 235 236 static SExp builtin_load(int s) { 237 SExp a = refer_stack(s, 0); 238 const char* fn = s2str(a); 239 if (fn != NULL) { 240 if (load_file(fn)) { 241 return t; 242 } 243 } 244 return nil; 245 } 246 247 static SExp builtin_compile(int s) { 248 SExp code = refer_stack(s, 0); 249 SExp halt_code = cons(HALT, nil); 250 return compile_ontop(code); 251 } 252 253 254 //============================================================================= 255 256 257 258 static void add_proctbl() { 259 struct { 260 const char* name; 261 SCFunc func; 262 int b_macro; 263 int minarg; 264 int maxarg; 265 } static const tbl[] = { 266 { "cons", builtin_cons, FALSE, 2, 2, }, 267 { "car", builtin_car, FALSE, 1, 1, }, 268 { "cdr", builtin_cdr, FALSE, 1, 1, }, 269 { "pair?", builtin_consp, FALSE, 1, 1, }, 270 { "eq?", builtin_eq, FALSE, 2, 2, }, 271 { "set-car!", builtin_rplaca, FALSE, 2, 2, }, 272 { "set-cdr!", builtin_rplacd, FALSE, 2, 2, }, 273 { "+", builtin_plus, FALSE, 0, -1, }, 274 { "-", builtin_difference, FALSE, 1, -1, }, 275 { "*", builtin_times, FALSE, 0, -1, }, 276 { "/", builtin_quotient, FALSE, 1, -1, }, 277 { "=", builtin_numeq, FALSE, 1, -1, }, 278 { "<", builtin_lt, FALSE, 1, -1, }, 279 { ">", builtin_gt, FALSE, 1, -1, }, 280 { "<=", builtin_le, FALSE, 1, -1, }, 281 { ">=", builtin_ge, FALSE, 1, -1, }, 282 283 { "read", builtin_read, FALSE, 0, 0, }, 284 { "print", builtin_print, FALSE, 1, 1, }, 285 { "eval", builtin_eval, FALSE, 1, 1, }, 286 287 { "load", builtin_load, FALSE, 1, 1, }, 288 { "compile", builtin_compile, FALSE, 1, 1, }, 289 }; 290 for (int i=0; i<sizeof(tbl)/sizeof(*tbl); ++i) { 291 SExp sym = intern(tbl[i].name); 292 SExp fn = gen_cfunc(tbl[i].func, tbl[i].b_macro, tbl[i].minarg, tbl[i].maxarg); 293 define_global(sym, fn); 294 } 295 } 296 297 static void add_consttbl() { 298 struct { 299 const char* name; 300 } static const tbl[] = { 301 "t", 302 "nil", 303 }; 304 for (int i=0; i<sizeof(tbl)/sizeof(*tbl); ++i) { 305 SExp sym = intern(tbl[i].name); 306 define_global(sym, sym); 307 } 308 } 309 310 static void init_env() { 311 add_proctbl(); 312 add_consttbl(); 313 } 314 315 316 // �\�[�X�̃��[�h�i�ǂݍ��݁A�R���p�C���A��s�j 317 int load_file(const char* fn) { 318 FILE* fp = fopen(fn, "r"); 319 if (fp == NULL) { 320 return FALSE; 321 } else { 322 SExp halt_code = cons(HALT, nil); 323 for (;;) { 324 SExp sexp = read_from_file(fp); 325 if (nilp(sexp)) break; 326 run(compile(sexp, nil, nil, halt_code)); 327 } 328 fclose(fp); 329 return TRUE; 330 } 331 } 24 static const SVTable vtbl = { 25 my_gc_malloc, 26 my_error, 27 }; 332 28 333 29 334 30 void repl() { 335 SExp halt_code = cons(HALT, nil);336 337 31 for (;;) { 338 32 if (setjmp(s_env) == 0) { … … 354 48 int main(int argc, char* argv[]) 355 49 { 356 static const SVTable vtbl = {357 my_gc_malloc,358 my_error,359 };360 361 50 mlisp_new(&vtbl);
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)