- Timestamp:
- 05/17/08 06:52:58 (6 months ago)
- Location:
- lang/c/misc/mlisp
- Files:
-
- 9 modified
-
Rakefile (modified) (1 diff)
-
core/inner.h (modified) (1 diff)
-
core/s_util.cpp (modified) (1 diff)
-
core/v_vm.cpp (modified) (3 diffs)
-
core/v_vm.h (modified) (1 diff)
-
inc/mlisp.h (modified) (1 diff)
-
mlisp.vcproj (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
test/main.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/misc/mlisp/Rakefile
r11617 r11715 11 11 12 12 13 OBJ_PATH = "obj s"13 OBJ_PATH = "obj" 14 14 OBJ_EXT = ".o" 15 15 -
lang/c/misc/mlisp/core/inner.h
r11617 r11715 6 6 7 7 #include "sexp.h" 8 #include "mlisp.h" 8 9 9 10 #ifndef FALSE -
lang/c/misc/mlisp/core/s_util.cpp
r11550 r11715 26 26 } 27 27 } 28 va_end(ap); 28 29 return head; 29 30 } -
lang/c/misc/mlisp/core/v_vm.cpp
r11676 r11715 178 178 179 179 static SExp continuation(int s) { 180 SExp body = list(3, REFER_LOCAL, int2s(0), list(3, NUATE, save_stack(s), list( 2, RETURN, int2s(0))));180 SExp body = list(3, REFER_LOCAL, int2s(0), list(3, NUATE, save_stack(s), list(1, RETURN))); 181 181 return closure(1, 1, body, 0, 0); 182 182 } … … 206 206 *px = index(ss, 0); *pf = s2int(index(ss, 1)); *pc = index(ss, 2); 207 207 return ss - 3; 208 } 209 210 211 static int apply(SExp fn, SExp argnum, int s, SExp* pa, SExp* px, sint* pf, SExp* pc, int* ps) { 212 int r = 0; 213 if (type_of(fn) == tProc) { 214 int ss = push(argnum, s); 215 int n = s2int(argnum); 216 Procedure* proc = (Procedure*)fn.ptr; 217 if (check_arg_num(proc, n)) { 218 switch (proc->get_func_type()) { 219 case Procedure::Builtin: 220 { 221 SCFunc cfunc = proc->u.cfunc; 222 SExp res = (*cfunc)(ss); 223 *pa = res; 224 *ps = vm_return(px, pf, pc, ss); 225 } 226 break; 227 case Procedure::Cell: 228 { 229 modify_args(proc, n, s); 230 *px = closure_body(fn); *pf = ss; *pc = fn; *ps = ss; 231 } 232 r = 1; 233 break; 234 } 235 } else { 236 runtime_error("wrong number of argument"); 237 r = -1; 238 } 239 } else { 240 runtime_error("can't call"); 241 r = -1; 242 } 243 return r; 244 } 245 246 #include <malloc.h> //<alloca.h> 247 #include <stdarg.h> 248 SExp vm_apply(SExp fn, int narg, ...) { 249 int s = 0; 250 SExp c = nil; 251 sint f = 0; 252 SExp ret = list(1, HALT); 253 254 // FRAME 255 s = push(ret, push(int2s(f), push(c, s))); 256 257 // argments 258 SExp* buf = (SExp*)alloca(sizeof(SExp) * narg); 259 va_list ap; 260 va_start(ap, narg); 261 for (int i=0; i<narg; ++i) { 262 buf[i] = va_arg(ap, SExp); 263 } 264 va_end(ap); 265 for (int i=narg; --i>=0; ) { 266 s = push(buf[i], s); 267 } 268 269 SExp a, x; 270 if (apply(fn, int2s(narg), s, &a, &x, &f, &c, &s) == 1) { 271 a = vm(a, x, f, c, s); 272 } 273 return a; 208 274 } 209 275 … … 273 339 x = xx; 274 340 } else if (op == APPLY) { 275 if (type_of(a) == tProc) { 276 SExp argnum = cadr(x); 277 int ss = push(argnum, s); 278 int n = s2int(argnum); 279 Procedure* proc = (Procedure*)a.ptr; 280 if (check_arg_num(proc, n)) { 281 modify_args(proc, n, s); 282 switch (proc->get_func_type()) { 283 case Procedure::Builtin: 284 { 285 SCFunc cfunc = proc->u.cfunc; 286 SExp res = (*cfunc)(ss); 287 a = res; 288 s = vm_return(&x, &f, &c, ss); 289 } 290 break; 291 case Procedure::Cell: 292 { 293 x = closure_body(a); f = ss; c = a; s = ss; 294 } 295 break; 296 } 297 } else { 298 runtime_error("wrong number of argument"); 299 } 300 } else { 301 runtime_error("can't call"); 302 break; 303 } 341 SExp argnum = cadr(x); 342 apply(a, argnum, s, &a, &x, &f, &c, &s); 304 343 } else if (op == RETURN) { 305 344 s = vm_return(&x, &f, &c, s); -
lang/c/misc/mlisp/core/v_vm.h
r11550 r11715 14 14 SExp vm(SExp a, SExp x, sint f, SExp c, int s); 15 15 16 void define_global(SExp sym, SExp val);17 18 16 #ifdef __cplusplus 19 17 } //extern "C" -
lang/c/misc/mlisp/inc/mlisp.h
r11551 r11715 27 27 28 28 29 30 31 void define_global(SExp sym, SExp val); 32 SExp refer_global(SExp sym); 33 34 SExp vm_apply(SExp fn, int narg, ...); 35 36 29 37 #ifdef __cplusplus 30 38 } //extern "C" -
lang/c/misc/mlisp/mlisp.vcproj
r11551 r11715 143 143 RelativePath=".\core\sexp.cpp"> 144 144 </File> 145 <File146 RelativePath=".\core\sexp.h">147 </File>148 145 <Filter 149 146 Name="compiler" … … 193 190 </File> 194 191 </Filter> 192 <Filter 193 Name="inc" 194 Filter=""> 195 <File 196 RelativePath=".\inc\mlisp.h"> 197 </File> 198 <File 199 RelativePath=".\inc\sexp.h"> 200 </File> 201 </Filter> 195 202 </Files> 196 203 <Globals> -
lang/c/misc/mlisp/readme.txt
r11676 r11715 46 46 -[v] �X�^�b�N�x�[�X�ɒu��������-[v] �C�ӌ̈��� 47 47 -[x] �}�N����� 48 --[x] macroexpand ��- C �������[�o���̊���яo�������ɂ���- �unil�v�ut�v���V���{���Ȃ̂ŁA�R���p�C�������V���{���Q�ƂɂȂ�Ă��܂�48 --[x] macroexpand ��-[v] C �������[�o���̊���яo�������ɂ���- �unil�v�ut�v���V���{���Ȃ̂ŁA�R���p�C�������V���{���Q�ƂɂȂ�Ă��܂� 49 49 - ��s���ɕϐ�������������Ƃ��̎����� 50 50 - �������� … … 56 56 --- �����ǂ����H 57 57 --- ����������Ă邩�H�i��s���� 58 59 - �n�b�V����� 58 60 59 61 - SDL �Ɨ��߂ĂȂ��i�e�g���X�j -
lang/c/misc/mlisp/test/main.cpp
r11549 r11715 46 46 47 47 48 int main(int argc, char* argv[]) 49 { 48 void test_call() { 49 SExp src = read_from_string( 50 "(define fib" 51 " (lambda (n)" 52 " (if (< n 2)" 53 " n" 54 " (+ (fib (- n 1))" 55 " (fib (- n 2))))))" 56 ); 57 58 evaluate(src); 59 60 SExp r = vm_apply(refer_global(intern("fib")), 1, int2s(6)); 61 print(r); 62 } 63 64 65 int main(int argc, char* argv[]) { 50 66 mlisp_new(&vtbl); 67 #if 1 51 68 if (argc >= 2) { 52 69 if (setjmp(s_env) == 0) { … … 56 73 repl(); 57 74 } 75 #else 76 test_call(); 77 #endif 58 78 mlisp_delete(); 59 79
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)