;;; escm-context.el --- ;; Copyright (C) 2008 Free Software Foundation, Inc. ;; Author: Zaurus User ;; Keywords: ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; ;;; Code: (require 'escm-base) (require 'escm-env) (escm-cbos::define-class (escm-context escm-object t) (objdic :copy) ;; created objects. (env :copy) ;; environment of current context. (vm :copy) ;; virtual machine. (tail? :copy) ;; non nil if current context is terminal. (func? :copy)) (defconst escm-context::gensym::counter 0) (defsubst escm-context::gensym () (intern (format "escm-context::gensym::symbol::%s" (setq escm-context::gensym::counter (1+ escm-context::gensym::counter))))) (defsubst escm-context::new (env &optional vm objdic) (escm-context::set-objdic (escm-context::set-vm (escm-context::set-env (create-escm-context) env) vm) (or objdic (list nil)))) (defsubst escm-context::push (self &optional syms) (escm-context::new (escm-dynamic-env::new (escm-context::get-env self) syms) (escm-context::get-vm self) (escm-context::get-objdic self))) (defsubst escm-context::define (self obj) (let ((sym (escm-context::gensym)) (dic (escm-context::get-objdic self))) (set-car dic (cons (cons sym val) (car dic))) sym)) (defsubst escm-context::elize (self) `(let* ,(mapcar (lambda (step) (list (car step) (escm-object::to-source (cdr spec)))) (reverse (car (escm-context::get-objdic self)))))) ;;; (escm-cbos::define-class (escm-reference escm-object) (sym)) (defsubst escm-reference::new (sym) (let ((new (create-escm-reference))) (escm-reference::set-sym new sym) new)) (escm-cbos::define-method nil escm-object::elize (context self) (cond ((consp self) (list 'quote self)) (t self))) (escm-cbos::define-method nil escm-object::value (context self) self) (escm-cbos::define-method escm-reference escm-object::elize (context self) (escm-reference::get-sym self)) (escm-cbos::define-method escm-reference escm-object::value (context self) self (escm-context::ref context (escm-reference::get-sym self))) (escm-cbos::define-method escm-env escm-object::elize (context self) (let* ((syms (escm-env::get-fields self)) (symval (mapcar (lambda (s) (cons s (escm-env::gref self s))) syms))) `(let ((e (escm-fixed-env::new ,syms))) ,@(mapcar (lambda (sv) `(escm-env::gset! e ',(car sv) ,(escm-object::elize (cdr sv)))) symval) e))) (escm-cbos::define-method escm-proc escm-object::elize (self) ) (provide 'escm-context) ;;; escm-context.el ends here