- Timestamp:
- 05/21/08 08:27:12 (6 months ago)
- Location:
- lang/c/misc/mlisp
- Files:
-
- 8 modified
-
core/c_compiler.cpp (modified) (1 diff)
-
core/m_basic.cpp (modified) (3 diffs)
-
core/v_vm.cpp (modified) (2 diffs)
-
inc/mlisp.h (modified) (1 diff)
-
inc/sexp.h (modified) (1 diff)
-
proto/stackbased.scm (modified) (7 diffs)
-
readme.txt (modified) (2 diffs)
-
test/main.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/misc/mlisp/core/c_compiler.cpp
r11789 r12093 422 422 SExp apply = list(2, APPLY, int2s(1)); 423 423 SExp nx = is_tail ? list(3, SHIFT, int2s(1), apply) : apply; 424 SExp c = list( 2, CONTI, list(2, ARGUMENT, compile(xx, e, s, nx)));424 SExp c = list(3, CONTI, is_tail ? t : nil, list(2, ARGUMENT, compile(xx, e, s, nx))); 425 425 if (is_tail) 426 426 return c; -
lang/c/misc/mlisp/core/m_basic.cpp
r11789 r12093 8 8 #include "s_util.h" 9 9 #include "inner.h" 10 #include <stdlib.h> // for exit() 10 11 11 12 … … 214 215 } 215 216 217 static SExp builtin_exit() { 218 sint n = get_arg_num(); 219 int ret = 0; 220 if (n >= 1) { 221 SExp s = get_arg(0); 222 if (type_of(s) == tInt) { 223 ret = s2int(s); 224 } else { 225 ret = -1; 226 } 227 } 228 exit(ret); 229 return nil; 230 } 231 216 232 217 233 … … 294 310 { "load", builtin_load, 1, 1, }, 295 311 { "compile", builtin_compile, 1, 1, }, 312 { "exit", builtin_exit, 0, 1, }, 296 313 }; 297 314 for (int i=0; i<sizeof(tbl)/sizeof(*tbl); ++i) { -
lang/c/misc/mlisp/core/v_vm.cpp
r11789 r12093 205 205 } 206 206 207 static SExp continuation(int s ) {208 SExp body = list(3, REFER_LOCAL, int2s(0), list( 3, NUATE, save_stack(s), list(1, RETURN)));207 static SExp continuation(int s, SExp tt) { 208 SExp body = list(3, REFER_LOCAL, int2s(0), list(4, NUATE, save_stack(s), tt, list(1, RETURN))); 209 209 return closure(1, 1, body, 0, 0); 210 210 } … … 389 389 x = xx; 390 390 } else if (op == CONTI) { 391 SExp xx = cadr(x); 392 a = continuation(g_sp); x = xx; 391 SExp tt = cadr(x); 392 SExp xx = caddr(x); 393 a = continuation(g_sp, tt); x = xx; 393 394 } else if (op == NUATE) { 394 395 SExp stack = cadr(x); 395 SExp xx = caddr(x); 396 SExp tt = caddr(x); 397 SExp xx = cadddr(x); 396 398 397 399 restore_stack(stack); 400 if (nilp(tt)) push(int2s(0)); 398 401 x = xx; 399 402 } else if (op == DEFINE) { -
lang/c/misc/mlisp/inc/mlisp.h
r11756 r12093 23 23 SExp evaluate(SExp code); 24 24 25 // �\�[�X�̓ǂݍ��݁A�]��25 /// �\�[�X�̓ǂݍ��݁A�]�� 26 26 SExp load_eval(const char* fn); 27 27 28 28 29 /// �O���[�o���Ȓl�̒� 30 void define_global(SExp sym, SExp val); 29 31 32 /// �O���[�o���̎Q�� 33 SExp refer_global(SExp sym); 30 34 31 void define_global(SExp sym, SExp val); 32 SExp refer_global(SExp sym); 35 /// �O���[�o���ɒl�����݂��邩�H 33 36 int exist_global(SExp sym); 34 37 38 /// �Ăяo�� 35 39 SExp vm_apply(SExp fn, int narg, ...); 36 40 -
lang/c/misc/mlisp/inc/sexp.h
r11756 r12093 103 103 void reset_error(void); 104 104 105 SExp list(int n, ...);106 107 105 SExp gen_cfunc(SCFunc cfunc, int minnarg, int maxnarg); 108 106 SExp gen_cmacro(SCFuncM mfunc, int minnarg, int maxnarg); -
lang/c/misc/mlisp/proto/stackbased.scm
r11789 r12093 184 184 (compile xx e s (list 'ASSIGN-GLOBAL var next))))) 185 185 (call/cc (x) 186 (let ((c `(CONTI 187 (ARGUMENT 188 ,(compile x e s 189 (if (tail? next) 190 (list 'SHIFT 191 1 192 '(APPLY 1)) 193 '(APPLY 1))))))) 194 (if (tail? next) 186 (let* ((t? (tail? next)) 187 (c `(CONTI 188 ,t? 189 (ARGUMENT 190 ,(compile x e s 191 (if t? 192 `(SHIFT 193 1 194 (APPLY 1)) 195 '(APPLY 1))))))) 196 (if t? 195 197 c 196 (list 'FRAME cnext))))198 `(FRAME ,c ,next)))) 197 199 (define (var) 198 200 (let ((body (cddr x))) … … 353 355 (define VM 354 356 (lambda (a x f c) 355 ; (write/ss (list (car x) a(dump-stack *sp*)))356 ;(newline)357 (write/ss (list (car x) (dump-stack *sp*))) 358 (newline) 357 359 (record-case x 358 360 (HALT () a) … … 380 382 (set-box! (index-closure c n) a) 381 383 (VM a x f c)) 382 (CONTI ( x)383 (VM (continuation *sp* ) x f c))384 (NUATE (stack x)384 (CONTI (t? x) 385 (VM (continuation *sp* t?) x f c)) 386 (NUATE (stack t? x) 385 387 (begin 386 388 (restore-stack stack) 389 (if (not t?) (push 0)) 387 390 (VM a x f c))) 388 391 (FRAME (x ret) … … 452 455 453 456 (define continuation 454 (lambda (s )457 (lambda (s t?) 455 458 (closure 456 459 '(1 . 1) 457 (list 'REFER-LOCAL 0 (list 'NUATE (save-stack s) '(RETURN)))460 (list 'REFER-LOCAL 0 (list 'NUATE (save-stack s) t? '(RETURN))) 458 461 0 459 462 0))) … … 463 466 (let ((v (make-vector s))) 464 467 (recur copy ((i 0)) 465 (unless ( = i s)468 (unless (>= i s) 466 469 (vector-set! v i (vector-ref *stack* i)) 467 470 (copy (+ i 1)))) … … 811 814 (load "./stackbased.scm") 812 815 (repl) 813 816 quit 814 817 815 818 … … 841 844 842 845 843 846 (call/cc (lambda (cc) (cc 1234))) 847 848 849 1234 850 851 (load "test_nondet.scm") 844 852 845 853 -
lang/c/misc/mlisp/readme.txt
r11756 r12093 41 41 Cygwin �p Rakefile 42 42 43 proto 44 Gauche �ɂ��v���g�^�C�v�� 45 43 46 44 47 … … 46 49 -[v] �X�^�b�N�x�[�X�ɒu��������-[v] �C�ӌ̈��� 47 50 -[v] �}�N����� 48 --[ x] macroexpand ��-[v] C �������[�o���̊���яo�������ɂ���- �unil�v�ut�v���V���{���Ȃ̂ŁA�R���p�C�������V���{���Q�ƂɂȂ�Ă��܂�51 --[v] macroexpand ��-[v] C �������[�o���̊���яo�������ɂ���- �unil�v�ut�v���V���{���Ȃ̂ŁA�R���p�C�������V���{���Q�ƂɂȂ�Ă��܂� 49 52 - ��s���ɕϐ�������������Ƃ��̎����� 50 53 - �������� -
lang/c/misc/mlisp/test/main.cpp
r11715 r12093 6 6 #include <gc/gc.h> 7 7 #include <setjmp.h> 8 9 #define MESSAGE "To quit, type '(exit)'\n" 10 8 11 9 12 static jmp_buf s_env; … … 29 32 30 33 void repl() { 34 printf("%s", MESSAGE); 31 35 for (;;) { 32 36 if (setjmp(s_env) == 0) { … … 34 38 printf("> "); 35 39 SExp s = read_from_file(stdin); 36 if (eq(s, intern("quit"))) {37 return;38 }39 40 40 41 SExp r = evaluate(s);
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)