Skip to content

A tiny implementation of the Scheme programming language: the core written in Perl, and the auxiliary functions written in Scheme itself. The interpreter uses the syntactic analysis method of evaluation outlined in "Structure and Interpretation of Computer Programs" (Sussman et al)

Notifications You must be signed in to change notification settings

ashton314/mini_scheme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Mini Scheme -- A science project

DESCRIPTION

Load syntactic analyzer implementation:

perl scheme.pl [-quiet] [-no-init] [-no-stats] [-echo-file <filename>] [-load <filename>] [-init-file <filename>]

Load metacircular evaluator implementation:

perl metacircular.pl [-quiet] [-no-init] [-no-stats] [-echo-file <filename>] [-load <filename>] [-init-file <filename>]

BACKGROUND

This is for a science project that I am doing. The abstract of my project:

    Title

    Studying the Effects of a Syntactic Analyzer on Scheme Program Execution Time

    Introduction

    In the MIT introductory book to computer programming, Structure and Interpretation of Computer Programs, the outline for a simple Scheme interpreter is given. In following sections, enhancements are made to this interpreter. One of the most radical changes to the interpreter is done by separating syntactic analysis of a Scheme expression from the execution of the same. According to the authors, this greatly improves execution times.

    The purpose of this experiment is to study the effects of a syntactic analyzer on run time. We believe that if a syntactic analyzer is used before evaluation of Scheme code, a great increase in speed will be observed.

For the full, up-to-date lab report, see the doc/ directory in this project.

METACIRCULAR VS. SYNTACTIC ANALYZER

In chapter 4 of Structure and Interpretation of Computer Programs, the authors describe a simple scheme interpreter. In subsequent sections, enhancements are made to this interpreter. The two main versions of interpreters are "metacircular" interpreters and "syntactic analyzers".

METACIRCULAR

TODO: Write how a metacircular evaluator works.

SYNTACTIC ANALYZER

TODO: Write how a syntactic analyzer works.

CONTROL FLAGS

quiet

When this flag is present, load messages are silenced.

no-init

When this flag is present, the init file in init.scm is not loaded.

no-stats

When this flag present, memory statistics are suppressed.

load

Takes a filename and loads it immediately after loading the "init file" and printing the memory statistics.

echo-file

This takes a file name to output memory statistics.

init-file

Takes a alternate "init file" to load. Default is init.scm in the working directory.

KNOWN ISSUES

  • No hygienic macro system.

  • The numeric tower is not implemented. All number types are snarfed directly from Perl.

  • STRING is a special form. This is purely for ease of implementation.

  • The following features are adapted from CMU Common Lisp:

    • NIL is a symbol.

  • No tail-call optimizations.

  • Next to no type checking.

  • Next to no error checking.

FEATURES

Init file

The default init file is init.scm in the working directory. An alternate file may be specified with the "-init-file" option.

Lexical Addressing

This cut down my execution times by about 50%. Big win.

FEATURES TO ADD

When I get around to it, I'll try to add these things in:

Debugger

BIG maybe.

TODO

  • I think I could optimize memory in the following manner: because of syntactic analysis, we can know what variables are going to be needed in a given expression. We can use this to do two things: warn the user when there is a variable that is not used, and optimize which variables get saved in a closure environment.

  • I might be able to replace the Cons class with some more low-level managing of hashes. This might make it a bit more difficult to distinguish between different data types, but it might make my data structures operate a bit faster. I think I might be able to get a big speed gain out of this.

BUGS

  • DOTimes is not working in the metacircular interpreter. Big problem.

  • Macros are not inserted into the global enviroment. This allows for namespace collision. If a symbol, defined as a macro, is defined as a function, the macro will be expanded, to the confusion of the programmer. Also, a symbol may be a variable without conflict.

    I could add checking for this in variable/function lookups, definitions, and assignments.

  • The Cons package may have self-referential data structures, not allowing the garbage collector to reallocate memory so consumed.

  • Too slow. I'm looking for optimizations.

  • NIL really needs some clean-up.

  • Backquote does not handle dotted tail notation properly.

AUTHOR

Ashton Wiersdorf <ashton.wiersdorf@mailblock.net>

About

A tiny implementation of the Scheme programming language: the core written in Perl, and the auxiliary functions written in Scheme itself. The interpreter uses the syntactic analysis method of evaluation outlined in "Structure and Interpretation of Computer Programs" (Sussman et al)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published