2017年1月22日日曜日

開発環境

Cを高級アセンブラーとした、Scheme の コンパイラー(ksc)、インタプリター(ksi)の作成で、標準ライブラリの cxr ライブラリの手続きのを合成手続きとして実装。(python を使用。)

コード

kscm

cxr.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

cxrs = ['caaaar',
        'caaar',
        'caaddr',
        'cadaar',
        'cadar',
        'cadddr',
        'cdaaar',
        'cdaar',
        'cdaddr',
        'cddaar',
        'cddar',
        'cddddr',
        'caaadr',
        'caadar',
        'caadr',
        'cadadr',
        'caddar',
        'caddr',
        'cdaadr',
        'cdadar',
        'cdadr',
        'cddadr',
        'cdddar',
        'cdddr']

result = '(begin\n'
for cxr in sorted(cxrs):
    t = '  (define ({0} pair) '.format(cxr)
    s = 'pair'
    for x in reversed(cxr[1:-1]):
        s = '(c{0}r {1})'.format(x, s)
    t += '{0})\n'.format(t)
    result += t

result += ')'
with open('compound_procedures.scm', 'w') as f:
    print(result, file=f)

lib/stdlib/cxr/compound_procedures.scm

(begin
  (define (caaaar pair) (car (car (car (car pair)))))
  (define (caaadr pair) (car (car (car (cdr pair)))))
  (define (caaar pair) (car (car (car pair))))
  (define (caadar pair) (car (car (cdr (car pair)))))
  (define (caaddr pair) (car (car (cdr (cdr pair)))))
  (define (caadr pair) (car (car (cdr pair))))
  (define (cadaar pair) (car (cdr (car (car pair)))))
  (define (cadadr pair) (car (cdr (car (cdr pair)))))
  (define (cadar pair) (car (cdr (car pair))))
  (define (caddar pair) (car (cdr (cdr (car pair)))))
  (define (cadddr pair) (car (cdr (cdr (cdr pair)))))
  (define (caddr pair) (car (cdr (cdr pair))))
  (define (cdaaar pair) (cdr (car (car (car pair)))))
  (define (cdaadr pair) (cdr (car (car (cdr pair)))))
  (define (cdaar pair) (cdr (car (car pair))))
  (define (cdadar pair) (cdr (car (cdr (car pair)))))
  (define (cdaddr pair) (cdr (car (cdr (cdr pair)))))
  (define (cdadr pair) (cdr (car (cdr pair))))
  (define (cddaar pair) (cdr (cdr (car (car pair)))))
  (define (cddadr pair) (cdr (cdr (car (cdr pair)))))
  (define (cddar pair) (cdr (cdr (car pair))))
  (define (cdddar pair) (cdr (cdr (cdr (car pair)))))
  (define (cddddr pair) (cdr (cdr (cdr (cdr pair)))))
  (define (cdddr pair) (cdr (cdr (cdr pair))))
  )

ksi.scm

(begin
  ;; 
  (eval '(begin
           (load "./lib/stdlib/base/compound_procedures.scm")
           (load "./lib/stdlib/char/compound_procedures.scm")
           (load "./lib/stdlib/cxr/compound_procedures.scm")
           )
        the-global-environment)
           
  (driver-loop)
  )

0 コメント:

コメントを投稿