Changeset 8322 for lang/elisp
- Timestamp:
- 03/24/08 01:18:44 (8 months ago)
- Location:
- lang/elisp/escm
- Files:
-
- 12 modified
-
. (modified) (1 prop)
-
trunk/escm-cbos.el (modified) (11 diffs)
-
trunk/escm-compile.el (modified) (4 diffs)
-
trunk/escm-env.el (modified) (13 diffs)
-
trunk/escm-errors.el (modified) (1 diff)
-
trunk/escm-icode.el (modified) (9 diffs)
-
trunk/escm-proc.el (modified) (1 diff)
-
trunk/escm-syntax.el (modified) (3 diffs)
-
trunk/escm-test.el (modified) (6 diffs)
-
trunk/escm-util.el (modified) (3 diffs)
-
trunk/escm-util.minimal.el (modified) (3 diffs)
-
trunk/escm-vm.el (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/elisp/escm
-
lang/elisp/escm/trunk/escm-cbos.el
r7953 r8322 1 ;;; escm-cbos.el --- tiny class base object sy stem for escm-vm.1 ;;; escm-cbos.el --- tiny class base object sytem for escm-vm 2 2 3 3 ;; Copyright (C) 2008 Free Software Foundation, Inc. 4 4 5 ;; Author: <lieutar@1dk.jp>6 ;; Keywords: 5 ;; Author: ;;; <onishi@THOTH> 6 ;; Keywords: oop 7 7 8 8 ;; This file is free software; you can redistribute it and/or modify … … 27 27 ;;; Code: 28 28 29 ;;;30 ;;;31 29 (require 'escm-util) 30 (require 'escm-test) 32 31 33 32 (escm-util::define-signals … … 42 41 "returns true if sym is escm::cbos class." 43 42 (and (symbolp sym) 44 (plist-member 'escm-cbos::class-fieldssym)43 (plist-member (symbol-plist 'escm-cbos::class-fields) sym) 45 44 t)) 46 45 … … 52 51 (when (escm-cbos::classp cls) 53 52 cls)))) 53 54 54 55 55 56 (defsubst escm-cbos::inheritance-list (class) … … 95 96 96 97 (defsubst escm-cbos::find-method1 (sym name) 97 ""98 98 (let ((meth nil) 99 99 (ilist (symbol-value sym))) 100 101 102 100 (while (and (not meth) ilist) 103 101 (setq meth (get (get 'escm-cbos::class-vmt (car ilist)) name)) … … 111 109 112 110 (defsubst escm-cbos::run-method (name obj args) 113 ""114 111 (let* ((class (escm-cbos::get-class obj)) 115 112 (ilist (symbol-value (get 'escm-cbos::class-vmt class))) … … 122 119 123 120 (defun escm-cbos::expand-method (args body) 124 ""125 121 `(lambda ,(cons '*ilist* (cons '*method-name* args)) 126 122 ,@(escm-util::walk-node … … 169 165 new)) 170 166 171 (defsubst ,pred (o) 172 (and (vectorp o) 173 (> (length o) 0) 174 (eq (aref new 0) ',name))) 167 (defsubst ,pred (o) (escm-cbos::isa o ',name)) 175 168 176 169 ,@(let ((p 0)) … … 197 190 fields))))) 198 191 199 (defun escm-cbos::report-class (class) 200 ) 201 202 203 192 (defface escm-cbos::report-section-face 193 '((((class color) (background light)) 194 (:foreground "white" :background "black")) 195 (((class color) (background dark)) 196 (:foreground "black" :background "white")) 197 (t ())) 198 "") 199 200 (defface escm-cbos::report-document-face 201 '((((class color) (background light)) 202 (:foreground "red" )) 203 (((class color) (background dark)) 204 (:foreground "green" )) 205 (t ())) 206 "") 207 208 (defsubst escm-cbos::isa (o class) 209 (and (vectorp o) 210 (> (length o) 0) 211 (let ((klass (aref o 0))) 212 (member class (escm-cbos::inheritance-list klass))) 213 t)) 214 215 216 (defun escm-cbos::describe-class (class) 217 (interactive 218 (list (intern (completing-read 219 "class: " 220 (mapcar (lambda (c) (list (symbol-name (car c)))) 221 (escm-util::plist-to-alist 222 (symbol-plist 'escm-cbos::class-fields))))))) 223 (if (escm-cbos::classp class) 224 (escm-util::popup "*escm-cbos::report-class*" nil 225 (insert 226 (escm-util::stext 227 `(face escm-cbos::report-section-face 228 "name:" (" " ,(format "%s" class) "\n" ) 229 "fields:" (" ",(mapconcat 'symbol-name 230 (escm-cbos::get-fields-of class) ", ") 231 "\n") 232 "methods:" 233 ("\n" 234 ,(mapcar 235 (lambda (klass) 236 (list 237 " " (symbol-name klass) "\n" 238 (mapcar 239 (lambda (meth) 240 (list " " 241 (symbol-name (car meth)) 242 " " 243 (format 244 "%S" (cddr (escm-util::get-arity (cdr meth)))) 245 (let ((doc (documentation (cdr meth)))) 246 (if doc (list "\n" 247 (list 248 'face 249 'escm-cbos::report-document-face 250 " " 251 doc)) 252 "\n\n")) 253 "\n")) 254 (escm-util::plist-to-alist 255 (symbol-plist (get 'escm-cbos::class-vmt klass)))) 256 "\n")) 257 (escm-cbos::inheritance-list class))))))) 258 (message (format "%s is not defined as class in escm-cbos")))) 259 260 261 262 (defsubst escm-cbos::Object-p (o) 263 (escm-cbos::isa o 'escm-cbos::Object)) 204 264 205 265 206 266 (escm-cbos::register-class 'escm-cbos::Object nil nil) 207 208 267 (escm-cbos::define-method 209 268 escm-cbos::Object escm-cbos::clone (self &optional copy-method) … … 213 272 (c (make-vector l nil))) 214 273 (while (> (setq l (1- l))-1) 215 (aset c l (apply cp (list (aref self l)))) 216 c))) 274 (aset c l (apply cp (list (aref self l))))) 275 c)) 276 277 (escm-cbos::define-method escm-cbos::Object escm-cbos::equal (a b) 278 (equal a b)) 279 280 217 281 218 282 (escm-cbos::define-method … … 220 284 (format "* object : %s *" (escm-cbos::get-class self))) 221 285 222 223 224 225 226 227 286 (escm-test::define-test escm-cbos escm-cbos 287 (escm-test classp-0 (escm-cbos::classp 'escm-cbos::Object)) 288 (escm-test classp-1 (not (escm-cbos::classp 'escm-cbos::OOOOO))) 289 290 (escm-cbos::define-class (escm-cbos::test0) a b c) 291 (escm-cbos::define-class (escm-cbos::test1 escm-cbos::test0) d e f) 292 293 (escm-test inheritance-list-0 294 (equal '(escm-cbos::test0 295 escm-cbos::Object) 296 (escm-test::p 'inheritance-list-0 297 (escm-cbos::inheritance-list 298 'escm-cbos::test0)))) 299 (escm-test inheritance-list-1 300 (equal '(escm-cbos::test1 301 escm-cbos::test0 302 escm-cbos::Object) 303 (escm-test::p 'inheritance-list-1 304 (escm-cbos::inheritance-list 305 'escm-cbos::test1))))) 306 ;;(escm-test::run 'escm-cbos 'escm-cbos) 228 307 229 308 (provide 'escm-cbos) -
lang/elisp/escm/trunk/escm-compile.el
r7953 r8322 1 (require 'escm-util ) 1 ;;; escm-compile.el --- Compiler of escm 2 3 ;; Copyright (C) 2008 Free Software Foundation, Inc. 4 5 ;; Author: (require 'escm-util ) <onishi@THOTH> 6 ;; Keywords: lisp 7 8 ;; This file is free software; you can redistribute it and/or modify 9 ;; it under the terms of the GNU General Public License as published by 10 ;; the Free Software Foundation; either version 2, or (at your option) 11 ;; any later version. 12 13 ;; This file is distributed in the hope that it will be useful, 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ;; GNU General Public License for more details. 17 18 ;; You should have received a copy of the GNU General Public License 19 ;; along with GNU Emacs; see the file COPYING. If not, write to 20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 ;; Boston, MA 02111-1307, USA. 22 23 ;;; Commentary: 24 25 ;; 26 27 ;;; Code: 28 29 2 30 (require 'escm-cbos ) 3 31 (require 'escm-syntax) 4 32 (require 'escm-icode ) 5 33 (require 'escm-env ) 6 7 (escm-cbos::define-class (escm-context nil t) env tail? func?) 34 (require 'escm-errors) 35 36 37 (escm-cbos::define-class (escm-context nil t) env vm tail? func? in-qq?) 38 39 (defsubst escm-context::new (env &optional vm) 40 (let ((new (create-escm-context))) 41 (escm-context::set-vm 42 (escm-context::set-env new env) 43 vm))) 44 45 (defsubst escm-context::push (self &optional syms) 46 (escm-context::new 47 (escm-dynamic-env::new 48 (escm-context::get-env self) syms) 49 (escm-context::get-vm self))) 8 50 9 51 (defun escm-compile (context sexp) … … 12 54 ((and sexp (consp sexp)) 13 55 (let* ((head (car sexp)) 14 (headv (when (symbolp head) (escm-context::gref head)))) 15 (if (escm-syntax-p headv) (escm-syntax::apply headv context sexp) 16 (escm-compile-apply context sexp)))) 17 18 ((symbolp sexp) 19 (escm-icode (,(if (escm-context::get-callp) 'fref 'ref) 20 (escm-context::get-env context)))) 21 56 (env (escm-context::get-env context)) 57 (headv (when (symbolp head) 58 (condition-case *err* 59 (escm-env::gref env head) 60 (escm-void-variable))))) 61 (cond 62 ((escm-syntax-p headv) 63 (escm-syntax::apply headv context sexp)) 64 (t (escm-compile-apply context sexp))))) 65 ((and sexp 66 (symbolp sexp)) 67 (escm-icode `(( ,(if (escm-context::get-func? context) 'fref 'ref) 68 ,sexp 69 ,(escm-context::get-env context))))) 22 70 (t (escm-icode `((store ,sexp)))))) 71 72 ;;(escm-vm::eval (escm-vm::new) '(+ 1 2)) 73 74 ;;; test code 75 (escm-test::define-test escm escm-compile-atom 76 (let* ((root (escm-root-env::new)) 77 (context (escm-context::new root))) 78 79 (escm-test numeric-constant (equal (escm-compile context 1) 80 (escm-icode '((store 1))))) 81 82 (escm-test nil-constant (equal (escm-compile context ()) 83 (escm-icode '((store ()))))) 84 85 (escm-test varref (equal (escm-test::p 'icode (escm-compile context 'a)) 86 (escm-icode `((ref a ,root))))) 87 88 (escm-test::p 'built (escm-iproc::build (escm-compile context 'a))))) 89 ;; (escm-test::run 'escm 'escm-compile-atom) 90 91 92 93 94 23 95 24 96 (defsubst escm-compile-apply (context sexp) … … 26 98 (let ((head (car sexp)) 27 99 (tail (cdr sexp)) 28 (arg-context (escm-context::set-tail pcontext nil))100 (arg-context (escm-context::set-tail? context nil)) 29 101 (ret (escm-iproc::new ()))) 30 102 (mapcar (lambda (x) … … 34 106 (escm-context::set-func? context t) head)) 35 107 (escm-iproc::merge ret 36 (escm-icode `((,(if (escm-context::get-tail pcontext)108 (escm-icode `((,(if (escm-context::get-tail? context) 37 109 'tcall 38 110 'call))))))) 39 40 (defsubst escm-compile-if (sexp) 41 "" 42 (let ((condx (escm-compile (cadr sexp))) 43 (positivex (escm-compile (caddr sexp))) 44 (negativex (escm-compile (cadddr sexp)))) 111 ;;; test code 112 (escm-test::define-test escm escm-compile-apply 113 (let* ((root (escm-root-env::new)) 114 (context (escm-context::new root)) 115 (r (escm-compile-apply context '(a b c))) 116 (ex (escm-icode `((ref b ,root) 117 (pusha) 118 (ref c ,root) 119 (pusha) 120 (fref a ,root) 121 (call))))) 122 (escm-test::p 'icode (escm-iproc::to-string r)) 123 (escm-test::p 'icode (escm-iproc::to-string ex)) 124 (escm-test compile-0 (escm-cbos::equal r ex)))) 125 ;; (escm-test::run 'escm 'escm-compile-apply) 126 127 128 129 130 (defsubst escm-compile-if::ifv0 (context condx positivex negativex) 131 (let ((posi0 (escm-iproc::get-first-block positivex)) 132 (nega0 (escm-iproc::get-first-block negativex)) 133 (nega1 (escm-iproc::get-body-without-first negativex))) 134 (when nega1 (escm-iblock::add-contents 135 posi0 (escm-inimonic::new 'jmp (list (length nega1))))) 136 (escm-iproc::merge condx (escm-icode `((ifv ,posi0 ,nega0)))) 137 (escm-iproc::merge condx (escm-iproc::new nega1)))) 138 139 (defsubst escm-compile-if::ifv1 (context condx positivex negativex) 140 (let ((posi0 (escm-iproc::get-first-block positivex)) 141 (nega0 (escm-iproc::get-first-block negativex)) 142 (posi1 (escm-iproc::get-body-without-first positivex))) 143 (when posi1 (escm-iblock::add-contents 144 nega0 (escm-inimonic::new 'jmp (list (length posi1))))) 145 (escm-iproc::merge condx (escm-icode `((ifv ,posi0 ,nega0)))) 146 (escm-iproc::merge condx (escm-iproc::new posi1)))) 147 148 (defsubst escm-compile-if::with-jump (context condx positivex negativex) 149 (escm-iproc::merge negativex 150 (escm-icode `((jmp ,(escm-iproc::length positivex))))) 151 (escm-iproc::merge condx 152 (escm-icode `((jt ,(escm-iproc::length negativex))))) 153 (escm-iproc::merge condx negativex) 154 (escm-iproc::merge condx positivex)) 155 156 (defsubst escm-compile-if (context sexp) 157 "" 158 (let ((condx (escm-compile context (cadr sexp))) 159 (positivex (escm-compile context (caddr sexp))) 160 (negativex (escm-compile context (cadddr sexp)))) 45 161 46 162 (cond ((not (escm-iproc::has-jump positivex)) 47 (escm-iproc::merge 48 condx 49 (escm-icode `(unlessv 50 ,(car (escm-iproc::get-body positivex)) 51 ,(escm-iproc::get-first negativex)))) 52 (escm-iproc::merge 53 condx 54 (escm-iproc::new 55 (escm-iproc::get-body-without-first negativex)))) 56 57 ((not (escm-iproc::has-jump positivex)) 58 (escm-iproc::merge 59 condx 60 (escm-icode `(unlessv 61 ,(car (escm-iproc::get-body negativex)) 62 ,(escm-iproc::get-first positivex)))) 63 (escm-iproc::merge 64 condx 65 (escm-iproc::new 66 (escm-iproc::get-body-without-first positivex)))) 67 68 (t 69 (escm-iproc::merge negativex 70 (escm-icode `((jmp ,(escm-iproc::length positivex))))) 71 (escm-iproc::merge condx 72 (escm-icode `((jt ,(escm-iproc::length negativex))))) 73 (escm-iproc::merge condx negativex) 74 (escm-iproc::merge condx positivex))))) 75 76 77 (defun escm-compile-define-syntax () 78 "" 163 (escm-compile-if::ifv0 context condx positivex negativex)) 164 165 ((not (escm-iproc::has-jump negativex)) 166 (escm-compile-if::ifv1 context condx positivex negativex)) 167 168 (t (escm-compile-if::with-jump context condx positivex negativex))))) 169 170 ;;; 171 (escm-test::define-test escm escm-compile-if 172 (let* ((root (escm-root-env::new)) 173 (context (escm-context::new root)) 174 175 (r0 nil) 176 (e0 (escm-icode `((fref x ,root) 177 (call) 178 (ifv ((ref y ,root)) 179 ((ref z ,root)))))) 180 (r1 nil) 181 (r2 nil) 182 (r3 nil)) 183 184 (escm-test compile-0 (setq r0 (escm-compile-if context '(if (x) y z))) t) 185 (escm-test::p 'compile-0 (escm-iproc::to-string r0)) 186 (escm-test::p 'compile-0 (escm-iproc::to-string e0)) 187 (escm-test check-0 (equal r0 e0)) 188 189 (escm-test compile-1 190 (setq r1 (escm-compile-if context '(if (x) (y (a)) z))) t) 191 (escm-test::p 'compile-1 (escm-iproc::to-string r1)) 192 193 194 (escm-test compile-2 195 (setq r2 (escm-compile-if context '(if (x) y (z (a))))) t) 196 (escm-test::p 'compile-2 (escm-iproc::to-string r2)) 197 198 (escm-test compile-3 199 (setq r3 (escm-compile-if context '(if (x) (y (a)) (z (b))))) t) 200 (escm-test::p 'compile-3 (escm-iproc::to-string r3)))) 201 ;;(escm-test::run 'escm 'escm-compile-if) 202 203 204 205 206 207 208 (defun escm-compile-define-syntax (context sexp) 209 "" 210 (let ((name (cadr sexp)) 211 (proc (caddr sexp))) 212 (escm-env::define (escm-context::get-env context) 213 name 214 (escm-syntax::new proc)))) 215 ;; 216 (defun escm-compile-let-syntax (context sexp) 217 (let* ((bind (cadr sexp)) 218 (body (cddr sexp)) 219 (ctx (escm-context::push context)) 220 (env (escm-context::get-env ctx)) 221 (ret (escm-iproc::new ()))) 222 (mapcar (lambda (b) 223 (escm-env::define 224 ctx 225 (car b) 226 (escm-syntax::new (escm-compile context (cdr b))))) 227 bind) 228 (mapcar (lambda (x) (escm-iproc::merge ret (escm-compile ctx x)) 229 body)) 230 ret)) 231 232 ;; 233 234 (defun escm-compile-define (context sexp) 235 "" 236 (let* ((spec (cadr sexp)) 237 (env (escm-context::get-env context)) 238 name 239 body 240 ret) 241 (if (listp spec) 242 (progn (setq name (car spec)) 243 (setq body (list 'lambda (cadr spec) (cddr sexp)))) 244 (setq name spec) 245 (setq body (caddr sexp))) 246 (setq ret (escm-compile body)) 247 (escm-env::define env name) 248 (escm-iproc::merge ret (escm-icode `((set! ,name ,env)))))) 249 ;; 250 251 252 (defun escm-compile-lambda (context sexp) 253 "" 254 (let* ((argspec (cadr sexp)) 255 (body (cddr sexp)) 256 (arity (escm-arity::new argspec)) 257 (proc (escm-iproc::new nil)) 258 (ctx (escm-context::push 259 context 260 (escm-arity::get-symbols arity)))) 261 (mapcar (lambda (sexp) (escm-iproc::merge proc (escm-compile ctx sexp))) body) 262 (escm-iproc::merge proc (escm-icode '((ret)))) 263 (escm-icode `((store-proc ,(escm-iproc::to-proc proc arity env)))))) 264 ;;; 265 (escm-test::define-test escm escm-compile-lambda 79 266 ) 80 81 (defun escm-compile-let-syntax () 82 "" 83 ) 84 85 (defun escm-compile-define (context sexp) 86 "" 87 ) 88 89 (defun escm-compile-lambda (context sexp) 90 "" 91 `(store-proc 92 ,(let* ((ctx (escm-context::push context)) 93 (arglist (cadr sexp)) 94 (body (cddr sexp)) 95 (mid (let ((asm ())) 96 (while body 97 (let ((head (car body)) 98 (tail (cdr body))) 99 (escm-context::set-tail ctx (not tail)) 100 (setq asm (append asm (escm-compile ctx head))) 101 (setq body tail))))) 102 (asm (escm-optimize mid))) 103 (escm-proc::new (escm-context::build-fixed-env env) 104 (escm-assemble asm))))) 105 267 ;; 268 ;;(escm-vm::eval (escm-vm::new) '((lambda () 1))) 269 270 271 ;; 106 272 (defun escm-compile-quote (context sexp) 107 ) 108 109 (defun escm-compile-quasiquote (context sexp) 110 ) 111 112 (defun escm-compile-unquote (context sexp) 113 ) 114 115 116 273 (escm-icode `((store ',(cadr sexp))))) 274 275 276 277 278 ;;(setq escm-vm::init-hook nil) 117 279 (add-hook 118 280 'escm-vm::init-hook 119 281 (lambda (vm) 120 (escm-define-builtin-syntax vm quote (function escm-compile-quote)) 121 (escm-define-builtin-syntax vm quasiquote (function escm-compile-quasiquote)) 122 (escm-define-builtin-syntax vm unquote (function escm-compile-unquote)) 123 (escm-define-builtin-syntax vm if (function escm-compile-if)) 124 (escm-define-builtin-syntax vm let-syntax (function escm-compile-let-syntax)) 125 (escm-define-builtin-syntax vm define-syntax (function escm-compile-define-syntax)) 126 (escm-define-builtin-syntax vm define (function escm-compile-define)) 127 (escm-define-builtin-syntax vm lambda (function escm-compile-lambda)) 282 283 (escm-define-builtin-syntax vm quote 284 (function escm-compile-quote)) 285 286 (escm-define-builtin-syntax vm if 287 (function escm-compile-if)) 288 289 (escm-define-builtin-syntax vm let-syntax 290 (function escm-compile-let-syntax)) 291 292 (escm-define-builtin-syntax vm define-syntax 293 (function escm-compile-define-syntax)) 294 295 (escm-define-builtin-syntax vm define 296 (function escm-compile-define)) 297 298 (escm-define-builtin-syntax vm lambda 299 (function escm-compile-lambda)) 128 300 ));; END OF INITIALIZER 129 301 302 130 303 (provide 'escm-compile) 304 ;;; escm-compile.el ends here -
lang/elisp/escm/trunk/escm-env.el
r7953 r8322 14 14 +-------------------+---------------------+ 15 15 | | | 16 +----------------+ +--------+---------+ +--------+----------+ 17 | escm-fixed-env |<-+ escm-dynamic-env | | escm-boundary-env | 18 +----------------+ -------------------+ +-------------------+ 16 +----------------+ +--------+---------+ +--------+-------+ 17 | escm-fixed-env |<-+ escm-dynamic-env | | escm-elisp-env | 18 +----------------+ -------------------+ +--------+-------+ 19 A | 20 | | 21 +------+--------+ | 22 | escm-root-env |<>----------+ 23 +---------------+ 19 24 20 25 escm-env ... abstract root class of escm environment. 21 escm-fixed-env ... fixed fields enviroment for compiled function.26 escm-fixed-env ... runtime environment for any procedures. 22 27 escm-dynamic-env ... it derives escm-fixed-env. 23 escm-boundary-env ... this is able to access to native elisp environment. 28 escm-root-env ... 29 escm-elisp-env ... this is able to access to native elisp environment. 24 30 25 31 ") … … 27 33 (escm-cbos::define-class (escm-env) parent dic) 28 34 35 (escm-cbos::define-method escm-env escm-env::to-string (self) 36 (format "<%s %S>" 37 (escm-cbos::get-class self) 38 (escm-env::get-fields self))) 39 40 (escm-cbos::define-method escm-env escm-cbos::equal (a b) 41 (and (escm-env-p b) 42 (escm-env::has-same-fields a b) 43 (if (escm-env::get-parent a) 44 (escm-cbos::equal 45 (escm-env::get-parent a) 46 (escm-env::get-parent b)) 47 (null (escm-env::get-parent b))))) 48 49 (escm-cbos::define-method escm-env escm-env::has-same-fields (a b) 50 (escm-util::equal-as-aggregate 51 (escm-env::get-fields a) 52 (escm-env::get-fields b))) 53 54 29 55 (escm-cbos::define-method escm-env escm-env::fref (self sym) 30 56 "" … … 38 64 "" 39 65 (get (escm-env::get-dic self) sym)) 66 67 (escm-cbos
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)