Changeset 12268 for lang/c

Show
Ignore:
Timestamp:
05/24/08 14:18:59 (6 months ago)
Author:
mokehehe
Message:

fix a bug of sending empty argument for rest parameter.

Location:
lang/c/misc/mlisp
Files:
1 added
6 modified

Legend:

Unmodified
Added
Removed
  • lang/c/misc/mlisp/core/c_compiler.cpp

    r12263 r12268  
    435435// �K�p����p�C�� 
    436436static SExp compile_apply(SExp x, SExp e, SExp s, SExp next) { 
    437         SExp expanded = macroexpand_1(x); 
    438         if (!eq(expanded, x)) { 
    439                 return compile(expanded, e, s, next); 
    440         } else { 
     437//      SExp expanded = macroexpand_1(x); 
     438//      if (!eq(expanded, x)) { 
     439//              return compile(expanded, e, s, next); 
     440//      } else { 
    441441                SExp args = cdr(x); 
    442442                int argnum = length(args); 
     
    445445                SExp c = compile(car(x), e, s, nx); 
    446446                return compile_pair_loop(args, c, e, s, next); 
    447         } 
     447//      } 
    448448} 
    449449 
  • lang/c/misc/mlisp/core/inner.h

    r12263 r12268  
    66 
    77#include "sexp.h" 
    8 #include "mlisp.h" 
     8#include "sexp_dev.h" 
    99 
    1010#ifndef FALSE 
     
    2828        ERR_UNDEFINED_SYMBOL, 
    2929        ERR_UNEXPECTED, 
    30 }; 
    31  
    32  
    33 /// S���̒lj���x�[�X�N���X�i�Z���Ȃǁj 
    34 struct SExpExt { 
    35         SType type;                             ///< �^ 
    3630}; 
    3731 
     
    9286 
    9387 
    94 __inline SExp gen_sexpext(struct SExpExt* p) { 
    95         SExp s; 
    96         s.ptr = (SExpExtU*)p; 
    97         return s; 
    98 } 
    99  
    100  
    10188 
    10289 
  • lang/c/misc/mlisp/core/v_vm.cpp

    r12263 r12268  
    173173} 
    174174 
    175 static void modify_args(Procedure* proc, int n, int s) { 
     175static void modify_args(Procedure* proc, int n) { 
     176        int s = g_sp - 1; 
    176177        if (proc->minnarg != proc->maxnarg) { 
    177                 SExp rest = nil; 
    178                 for (int i=n; --i >= proc->minnarg; ) { 
    179                         rest = cons(index(s, i), rest); 
     178                if (proc->maxnarg == -1) {              // REST �p�����[�^ 
     179                        SExp rest = nil; 
     180                        for (int i=n; --i >= proc->minnarg; ) { 
     181                                rest = cons(index(s, i), rest); 
     182                        } 
     183                        if (n == proc->minnarg) {               // REST �p�����[�^�ɉ��������Ȃ�����ꍇ�A�X�^�b�N�t���[�����������̂Ŋg������                         const int m = n - proc->minnarg + 1; 
     184                                for (int i=0; i<n; ++i) { 
     185                                        index_set(s, i, index(s, i + m)); 
     186                                } 
     187                                push(int2s(n + m)); 
     188                                s += m; 
     189                        } 
     190                        index_set(s, proc->minnarg, rest); 
     191                } else { 
     192                        assert(!"not implemented"); 
    180193                } 
    181                 index_set(s, proc->minnarg, rest); 
    182194        } 
    183195} 
     
    245257                if (check_arg_num(proc, n)) { 
    246258                        push(argnum); 
    247                         int ss = g_sp; 
    248259                        switch (proc->get_func_type()) { 
    249260                        case Procedure::Builtin: 
     
    257268                        case Procedure::Cell: 
    258269                                { 
    259                                         modify_args(proc, n, ss - 1); 
    260                                         *px = closure_body(fn); *pf = ss;       *pc = fn; 
     270                                        modify_args(proc, n); 
     271                                        *px = closure_body(fn); *pf = g_sp;     *pc = fn; 
    261272                                } 
    262273                                r = 1; 
  • lang/c/misc/mlisp/mlisp.vcproj

    r12263 r12268  
    197197                        </File> 
    198198                        <File 
     199                                RelativePath=".\inc\mlisp_dev.h"> 
     200                        </File> 
     201                        <File 
    199202                                RelativePath=".\inc\sexp.h"> 
     203                        </File> 
     204                        <File 
     205                                RelativePath=".\inc\sexp_dev.h"> 
    200206                        </File> 
    201207                </Filter> 
  • lang/c/misc/mlisp/proto/stackbased.scm

    r12180 r12268  
    452452                        (if (is-a? a <functional>) 
    453453                            (if (check-arg-num a n) 
    454                                 (let ((ss (push n)) 
    455                                       (body (closure-body a))) 
     454                                (let ((body (closure-body a))) 
     455                                  (push n) 
    456456                                  (if (procedure? body) 
    457457                                      (let* ((res (body)) 
     
    459459                                        (VM res ret f c)) 
    460460                                    (begin 
    461                                       (modify-args a n (- ss 1)) 
    462                                       (VM a body ss a)))) 
     461                                      (modify-args a n) 
     462                                      (VM a body *sp* a)))) 
    463463                              (error "wrong number of argument")) 
    464464                          (error "can't apply"))) 
     
    567567 
    568568;; 可変引数の受け取り 
    569 (define (modify-args c n s) 
    570   (let* ((min (closure-min-arg-num c)) 
    571          (max (closure-max-arg-num c))) 
    572     (if (!= min max) 
    573         (let ((rest (do ((i (-1+ n) (-1+ i)) 
    574                          (ls '() (cons (index s i) ls))) 
    575                         ((< i min) ls)))) 
    576           (index-set! s min rest))))) 
     569(define (modify-args c n) 
     570  (let ((s (-1+ *sp*))) 
     571    (define (expand-frame n m) 
     572      (dotimes (i n '()) 
     573        (index-set! s i (index s (+ i m)))) 
     574      (push (+ n m))) 
     575    (let* ((min (closure-min-arg-num c)) 
     576           (max (closure-max-arg-num c))) 
     577      (if (!= min max) 
     578          (if (= max -1)  ; REST パラメータ 
     579              (let ((rest (do ((i (-1+ n) (-1+ i)) 
     580                               (ls '() (cons (index s i) ls))) 
     581                              ((< i min) ls)))) 
     582                (if (= n min)  ; REST パラメータに何も与えられなかった場合、スタックフレームが足りないので拡張する 
     583                    (let ((m (1+ (- n min)))) 
     584                      (expand-frame n m) 
     585                      (inc! s (+ n m)))) 
     586                (index-set! s min rest)) 
     587            (error "not implemented")))))) 
    577588 
    578589 
  • lang/c/misc/mlisp/readme.txt

    r12263 r12268  
    4747 
    4848* ToDo 
    49 -if ��else ���̕����ɑΉ�����-[v] �x�N�^��W���[���Ƃ��Ď������-[v] �X�^�b�N�x�[�X�ɒu��������-[v] �C�ӌ‚̈��󂯎� 
     49-[v] �C�ӌ‚̈��O�‚���Ɨ�����-�G���[���b�Z�[�W���Ƃ킩������ 
     50-begin 
     51-[v] �x�N�^��W���[���Ƃ��Ď������-[v] �X�^�b�N�x�[�X�ɒu��������-[v] �C�ӌ‚̈��󂯎� 
    5052-[v] �}�N����� 
    5153--[v] macroexpand ��-[v] C �������[�o���̊֐���яo�������ɂ���- �unil�v�ut�v���V���{���Ȃ̂ŁA�R���p�C�������V���{���Q�ƂɂȂ�Ă��܂�