- Timestamp:
- 05/15/08 08:34:39 (6 months ago)
- Location:
- lang/c/misc/mlisp
- Files:
-
- 7 modified
-
Rakefile (modified) (1 diff)
-
core/inner.h (modified) (1 diff)
-
core/m_basic.cpp (modified) (19 diffs)
-
core/mlisp.cpp (modified) (1 diff)
-
core/s_print.cpp (modified) (1 diff)
-
core/s_vect.cpp (modified) (1 diff)
-
core/v_vm.cpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/misc/mlisp/Rakefile
r11185 r11617 14 14 OBJ_EXT = ".o" 15 15 16 INC_PATHS = %w( sexp compiler vm)16 INC_PATHS = %w(inc) 17 17 18 18 INCLUDES = INC_PATHS.map {|x| "-I#{x}"}.join(" ") -
lang/c/misc/mlisp/core/inner.h
r11550 r11617 106 106 107 107 /// ��s���F�X�^�b�N�Q�� 108 SExp refer_stack(int s, int i); 108 sint get_arg_num(int s); 109 SExp get_arg(int s, int idx); -
lang/c/misc/mlisp/core/m_basic.cpp
r11550 r11617 6 6 #include "v_vm.h" 7 7 #include "mlisp.h" 8 #include "s_util.h" 8 9 #include "inner.h" 9 10 … … 11 12 //============================================================================= 12 13 static SExp builtin_cons(int s) { 13 SExp a = refer_stack(s, 0);14 SExp d = refer_stack(s, 1);14 SExp a = get_arg(s, 0); 15 SExp d = get_arg(s, 1); 15 16 return cons(a, d); 16 17 } 17 18 18 19 static SExp builtin_car(int s) { 19 SExp a = refer_stack(s, 0);20 SExp a = get_arg(s, 0); 20 21 return car(a); 21 22 } 22 23 23 24 static SExp builtin_cdr(int s) { 24 SExp a = refer_stack(s, 0);25 SExp a = get_arg(s, 0); 25 26 return cdr(a); 26 27 } 27 28 28 29 static SExp builtin_consp(int s) { 29 SExp v = refer_stack(s, 0);30 SExp v = get_arg(s, 0); 30 31 return consp(v) ? t : nil; 31 32 } 32 33 33 34 static SExp builtin_eq(int s) { 34 SExp a = refer_stack(s, 0);35 SExp d = refer_stack(s, 1);35 SExp a = get_arg(s, 0); 36 SExp d = get_arg(s, 1); 36 37 return eq(a, d) ? t : nil; 37 38 } 38 39 39 40 static SExp builtin_rplaca(int s) { 40 SExp a = refer_stack(s, 0);41 SExp d = refer_stack(s, 1);41 SExp a = get_arg(s, 0); 42 SExp d = get_arg(s, 1); 42 43 rplaca(a, d); 43 44 return nil; … … 45 46 46 47 static SExp builtin_rplacd(int s) { 47 SExp a = refer_stack(s, 0);48 SExp d = refer_stack(s, 1);48 SExp a = get_arg(s, 0); 49 SExp d = get_arg(s, 1); 49 50 rplacd(a, d); 50 51 return nil; … … 52 53 53 54 static SExp builtin_plus(int s) { 54 sint n = s2int(refer_stack(s, -1));55 sint n = get_arg_num(s); 55 56 sint x = 0; 56 57 for (int i=0; i<n; ++i) { 57 SExp a = refer_stack(s, i);58 SExp a = get_arg(s, i); 58 59 type_check(a, tInt); 59 60 x += s2int(a); … … 63 64 64 65 static SExp builtin_difference(int s) { 65 sint n = s2int(refer_stack(s, -1));66 SExp a = refer_stack(s, 0);66 sint n = get_arg_num(s); 67 SExp a = get_arg(s, 0); 67 68 type_check(a, tInt); 68 69 sint x = s2int(a); … … 71 72 } else { 72 73 for (int i=1; i<n; ++i) { 73 SExp a = refer_stack(s, i);74 SExp a = get_arg(s, i); 74 75 type_check(a, tInt); 75 76 x -= s2int(a); … … 80 81 81 82 static SExp builtin_times(int s) { 82 sint n = s2int(refer_stack(s, -1));83 sint n = get_arg_num(s); 83 84 sint x = 1; 84 for (int i= 0; i<n; ++i) {85 SExp a = refer_stack(s, i);85 for (int i=1; i<n; ++i) { 86 SExp a = get_arg(s, i); 86 87 type_check(a, tInt); 87 88 x *= s2int(a); … … 91 92 92 93 static SExp builtin_quotient(int s) { 93 sint n = s2int(refer_stack(s, -1));94 SExp a = refer_stack(s, 0);94 sint n = get_arg_num(s); 95 SExp a = get_arg(s, 0); 95 96 type_check(a, tInt); 96 97 sint x = s2int(a); … … 99 100 } else { 100 101 for (int i=1; i<n; ++i) { 101 SExp a = refer_stack(s, i);102 SExp a = get_arg(s, i); 102 103 type_check(a, tInt); 103 104 sint d = s2int(a); … … 114 115 115 116 static SExp num_predicate(int s, int n, bool (*p)(sint, sint)) { 116 SExp a = refer_stack(s, 0);117 SExp a = get_arg(s, 0); 117 118 type_check(a, tInt); 118 119 sint x = s2int(a); 119 120 120 121 for (int i=1; i<n; ++i) { 121 SExp b = refer_stack(s, i);122 SExp b = get_arg(s, i); 122 123 type_check(b, tInt); 123 124 sint y = s2int(b); … … 130 131 static bool numeq(sint a, sint b) { return a == b; } 131 132 static SExp builtin_numeq(int s) { 132 sint n = s2int(refer_stack(s, -1));133 sint n = get_arg_num(s); 133 134 return num_predicate(s, n, numeq); 134 135 } … … 136 137 static bool numlt(sint a, sint b) { return a < b; } 137 138 static SExp builtin_lt(int s) { 138 sint n = s2int(refer_stack(s, -1));139 sint n = get_arg_num(s); 139 140 return num_predicate(s, n, numlt); 140 141 } … … 142 143 static bool numgt(sint a, sint b) { return a > b; } 143 144 static SExp builtin_gt(int s) { 144 sint n = s2int(refer_stack(s, -1));145 sint n = get_arg_num(s); 145 146 return num_predicate(s, n, numgt); 146 147 } … … 148 149 static bool numle(sint a, sint b) { return a <= b; } 149 150 static SExp builtin_le(int s) { 150 sint n = s2int(refer_stack(s, -1));151 sint n = get_arg_num(s); 151 152 return num_predicate(s, n, numle); 152 153 } … … 154 155 static bool numge(sint a, sint b) { return a >= b; } 155 156 static SExp builtin_ge(int s) { 156 sint n = s2int(refer_stack(s, -1));157 sint n = get_arg_num(s); 157 158 return num_predicate(s, n, numge); 158 159 } … … 164 165 165 166 static SExp builtin_print(int s) { 166 SExp a = refer_stack(s, 0);167 SExp a = get_arg(s, 0); 167 168 print(a); 168 169 return nil; … … 170 171 171 172 static SExp builtin_eval(int s) { 172 SExp code = refer_stack(s, 0);173 SExp code = get_arg(s, 0); 173 174 174 175 return evaluate(code); … … 176 177 177 178 static SExp builtin_load(int s) { 178 SExp a = refer_stack(s, 0);179 SExp a = get_arg(s, 0); 179 180 const char* fn = s2str(a); 180 181 if (fn != NULL) { … … 186 187 187 188 static SExp builtin_compile(int s) { 188 SExp code = refer_stack(s, 0);189 SExp code = get_arg(s, 0); 189 190 return compile_ontop(code); 190 191 } -
lang/c/misc/mlisp/core/mlisp.cpp
r11550 r11617 25 25 SExp evaluate(SExp code) { 26 26 SExp c = compile_ontop(code); 27 //print(c);27 print(c); 28 28 return run(c); 29 29 } -
lang/c/misc/mlisp/core/s_print.cpp
r11550 r11617 1 //============================================================================= 2 /// S���̏o�� 3 //============================================================================= 4 1 5 #include "inner.h" 2 6 #include "s_util.h" -
lang/c/misc/mlisp/core/s_vect.cpp
r11550 r11617 1 1 //============================================================================= 2 /// S ������/** 3 mallloc �Ŋm�ۂ����A�h���X�͂S�̔{���Ɖ���*/ 2 /// �x�N�^ 4 3 //============================================================================= 5 4 -
lang/c/misc/mlisp/core/v_vm.cpp
r11550 r11617 23 23 static SExp g_stack[STACK_SIZE]; 24 24 25 26 25 inline static SExp stack_ref(int idx) { 27 26 assert(0 <= idx && idx < STACK_SIZE); … … 31 30 32 31 inline static SExp index(int s, int i) { 33 return g_stack[s - i - 2];32 return g_stack[s - i - 1]; 34 33 } 35 34 36 35 inline static void index_set(int s, int i, SExp v) { 37 g_stack[s - i - 2] = v;36 g_stack[s - i - 1] = v; 38 37 } 39 38 … … 51 50 static int shift_args(int n, int m, int s) { 52 51 for (int i=n-1; --i > -2; ) { 53 index_set(s, i + m + 1, index(s, i));52 index_set(s, i + m + 2, index(s, i + 1)); 54 53 } 55 54 return s - m - 1; … … 59 58 60 59 61 SExp refer_stack(int s, int i) { 62 return index(s, i); 60 sint get_arg_num(int s) { 61 return s2int(index(s, 0)); 62 } 63 64 SExp get_arg(int s, int i) { 65 return index(s, i + 1); 63 66 } 64 67 … … 67 70 printf("#%d[", s); 68 71 for (int i=0; i<s; ++i) { 69 print_rec(refer_stack(s, i-1));70 print f(" ");72 if (i != 0) printf(","); 73 print_rec(g_stack[i]); 71 74 } 72 75 printf("]\n"); … … 176 179 177 180 static int vm_return(SExp* px, sint* pf, SExp* pc, int s) { 178 int n = s2int(index(s, -1));179 int ss = s - n ;181 int n = s2int(index(s, 0)); 182 int ss = s - n - 1; 180 183 *px = index(ss, 0); *pf = s2int(index(ss, 1)); *pc = index(ss, 2); 181 return ss - (3 + 1);184 return ss - 3; 182 185 } 183 186 … … 194 197 SExp op = car(x); 195 198 196 //dump_stack(s);197 //print(op);199 dump_stack(s); 200 print(op); 198 201 199 202 if (op == HALT) { … … 213 216 sint n = s2int(cadr(x)); 214 217 SExp xx = caddr(x); 215 a = index(f, n ); x = xx;218 a = index(f, n + 1); x = xx; 216 219 } else if (op == REFER_FREE) { 217 220 sint n = s2int(cadr(x)); … … 255 258 } else if (op == SHIFT) { 256 259 sint n = s2int(cadr(x)); 257 sint m = s2int(index(s, n - 1));260 sint m = s2int(index(s, n)); 258 261 SExp xx = caddr(x); 259 262 x = xx; s = shift_args(n, m, s); … … 264 267 SExp stack = cadr(x); 265 268 SExp xx = caddr(x); 266 x = xx; s = restore_stack(stack);269 x = xx; s = push(int2s(0), restore_stack(stack)); 267 270 } else if (op == DEFINE) { 268 271 SExp var = cadr(x);
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)