Changeset 11643 for lang/c

Show
Ignore:
Timestamp:
05/15/08 22:50:42 (6 months ago)
Author:
mokehehe
Message:

implement "assign"

Files:
1 modified

Legend:

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

    r11617 r11643  
    177177 
    178178//============================================================================= 
     179// �{�b�N�X 
     180 
     181static SExp box(SExp v) { 
     182        return cons(BOX, v); 
     183} 
     184 
     185static void set_box(SExp b, SExp v) { 
     186        rplacd(b, v); 
     187} 
     188 
     189static SExp unbox(SExp b) { 
     190        return cdr(b); 
     191} 
     192 
     193 
     194//============================================================================= 
    179195 
    180196static int vm_return(SExp* px, sint* pf, SExp* pc, int s) { 
     
    230246                        SExp xx = cadddr(x); 
    231247                        a = closure(body, n, s);        x = xx; s -= n; 
     248                } else if (op == BOX) { 
     249                        sint n = s2int(cadr(x)); 
     250                        SExp xx = caddr(x); 
     251                        index_set(s, n + 1, box(index(s, n + 1))); 
     252                        x = xx; 
     253                } else if (op == ASSIGN_LOCAL) { 
     254                        sint n = s2int(cadr(x)); 
     255                        SExp xx = caddr(x); 
     256                        set_box(index(f, n + 1), a); 
     257                        x = xx; 
     258                } else if (op == ASSIGN_FREE) { 
     259                        sint n = s2int(cadr(x)); 
     260                        SExp xx = caddr(x); 
     261                        set_box(index_closure(c, n), a); 
     262                        x = xx; 
    232263                } else if (op == APPLY) { 
    233264                        SExp argnum = cadr(x); 
     
    277308                        SExp xx = caddr(x); 
    278309                        a = refer_global(var);  x = xx; 
     310                } else if (op == ASSIGN_GLOBAL) { 
     311                        SExp var = cadr(x); 
     312                        SExp xx = caddr(x); 
     313                        define_global(var, a); 
     314                        a = var;        x = xx; 
    279315                } else { 
    280316                        runtime_error("illegal opecode");