b66cd8627c
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply, scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro, scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin, scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if, scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2, scm_vm_return): New specials. (scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons, scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials. (eval_apply_t, g_target): Remove. (push_cc): New function. (eval_apply): Rewrite. (vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env, call_with_values_env): Remove. * posix.c (stderr_): Update. * reader.c (read_input_file_env): Update. * module/mes/base-0.mes: Update.
94 lines
2.8 KiB
Scheme
94 lines
2.8 KiB
Scheme
;;; -*-scheme-*-
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
|
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
;;;
|
|
;;; This file is part of Mes.
|
|
;;;
|
|
;;; Mes 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 3 of the License, or (at
|
|
;;; your option) any later version.
|
|
;;;
|
|
;;; Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
|
|
(mes-use-module (mes scm))
|
|
|
|
(define (f:env:define a+ a)
|
|
(set-cdr! a+ (cdr a))
|
|
(set-cdr! a a+)
|
|
;;(set-cdr! (assq '*closure* a) a+)
|
|
)
|
|
|
|
(define (env:escape-closure a n)
|
|
(if (eq? (caar a) '*closure*) (if (= 0 n) a
|
|
(env:escape-closure (cdr a) (- n 1)))
|
|
(env:escape-closure (cdr a) n)))
|
|
|
|
(define-macro (module-define! name value a)
|
|
`(f:env:define (cons (sexp:define (cons 'define (cons ',name (cons ,value '()))) ,a) '()) (env:escape-closure ,a 1)))
|
|
|
|
(define-macro (make-fluid . default)
|
|
`(begin
|
|
,(let ((fluid (symbol-append 'fluid: (gensym)))
|
|
(module (current-module)))
|
|
`(begin
|
|
(module-define! ,fluid
|
|
(let ((v ,(and (pair? default) (car default))))
|
|
(lambda ( . rest)
|
|
(if (null? rest) v
|
|
(set! v (car rest))))) ',module)
|
|
',fluid))))
|
|
|
|
(define (fluid-ref fluid)
|
|
(fluid))
|
|
|
|
(define (fluid-set! fluid value)
|
|
(fluid value))
|
|
|
|
(define-macro (fluid? fluid)
|
|
`(begin
|
|
(and (symbol? ,fluid)
|
|
(symbol-prefix? 'fluid: ,fluid))))
|
|
|
|
(define (with-fluid* fluid value thunk)
|
|
(let ((v (fluid)))
|
|
(fluid-set! fluid value)
|
|
(let ((r (thunk)))
|
|
(fluid-set! fluid v)
|
|
r)))
|
|
|
|
;; (define-macro (with-fluids*-macro fluids values thunk)
|
|
;; `(begin
|
|
;; ,@(map (lambda (f v) (list 'set! f v)) fluids values)
|
|
;; (,thunk)))
|
|
|
|
;; (define (with-fluids*-next fluids values thunk)
|
|
;; `(with-fluids*-macro ,fluids ,values ,thunk))
|
|
|
|
;; (define (with-fluids* fluids values thunk)
|
|
;; (primitive-eval (with-fluids*-next fluids values thunk)))
|
|
|
|
;; (define-macro (with-fluids bindings . bodies)
|
|
;; `(let ()
|
|
;; (define (expand bindings a)
|
|
;; (if (null? bindings)
|
|
;; (cons (car bindings) (expand (cdr bindings) a))))
|
|
;; (eval (begin ,@bodies) (expand ',bindings (current-module)))))
|
|
|
|
(define (dynamic-wind in-guard thunk out-guard)
|
|
(in-guard)
|
|
(let ((r (thunk)))
|
|
(out-guard)
|
|
r))
|