[refactor] The great conversion continues.

This commit is contained in:
Elf M. Sternberg 2015-07-30 07:29:39 -07:00
parent 501ac5fe72
commit 675577431d
5 changed files with 11 additions and 7 deletions

View File

@ -1,11 +1,13 @@
{car, cdr, cons, listp, nilp, nil,
list, pairp, listToString} = require 'cons-lists/lists'
{astObject} = require './astAccessors'
{Symbol} = require './reader_types'
# RICH_AST -> LISP_AST
normalizeForm = (form) ->
console.log(form)
listToRecord1 = (l) ->
o = Object.create(null)
while(l != nil)
@ -25,9 +27,9 @@ normalizeForm = (form) ->
'record': (atom) -> listToRecord1(atom)
# Basic native types. Meh.
'symbol': id
'symbol': new Symbol(id)
'number': id
'string': (atom) -> atom
'string': id
'nil': (atom) -> nil
# Values inherited from the VM.

View File

@ -1,6 +1,5 @@
{listToString, listToVector, pairp, cons, car, cdr, caar, cddr,
cdar, cadr, caadr, cadar, caddr, nilp, nil, setcdr, metacadr} = require "cons-lists/lists"
readline = require "readline"
{Node} = require "./reader_types"
class LispInterpreterError extends Error

View File

@ -1,6 +1,9 @@
exports.Node = class
constructor: (@type, @value, @line, @column) ->
exports.Symbol = class
constructor: (@name) ->
exports.Comment = class
constructor: (@text) ->

View File

@ -1,7 +1,7 @@
{listToString, listToVector, pairp, cons, car, cdr, caar, cddr, cdar,
cadr, caadr, cadar, caddr, nilp, nil, setcdr,
metacadr, setcar} = require "cons-lists/lists"
{normalizeForm} = require "../chapter1/astToList"
{normalizeForms, normalizeForm} = require "../chapter1/astToList"
{Node} = require '../chapter1/reader_types'
class LispInterpreterError extends Error
@ -86,7 +86,7 @@ class VariableEnv extends FullEnv
# quoted term uninterpreted.
evaluateQuote = (v, env, kont) ->
kont.resume v
kont.resume normalizeForms v
# Evaluates the conditional expression, creating a continuation with
# the current environment that, when resumed, evaluates either the

View File

@ -25,7 +25,7 @@ describe "Core reader functions", ->
['{}', {}]
['[1 2 3]', [1, 2, 3]]
# ['(1 2 3', 'error']
['{foo "bar"}', {foo: "bar"}]
['{"foo" "bar"}', {foo: "bar"}]
]
for [t, v] in samples