diff --git a/chapter1/astToList.coffee b/chapter1/astToList.coffee index 5ed2a64..459c5a7 100644 --- a/chapter1/astToList.coffee +++ b/chapter1/astToList.coffee @@ -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. diff --git a/chapter1/interpreter.coffee b/chapter1/interpreter.coffee index 435fab5..9363084 100644 --- a/chapter1/interpreter.coffee +++ b/chapter1/interpreter.coffee @@ -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 diff --git a/chapter1/reader_types.coffee b/chapter1/reader_types.coffee index a995bde..a8fba7c 100644 --- a/chapter1/reader_types.coffee +++ b/chapter1/reader_types.coffee @@ -1,6 +1,9 @@ exports.Node = class constructor: (@type, @value, @line, @column) -> +exports.Symbol = class + constructor: (@name) -> + exports.Comment = class constructor: (@text) -> diff --git a/chapter3/interpreter.coffee b/chapter3/interpreter.coffee index 747b4d7..05fa410 100644 --- a/chapter3/interpreter.coffee +++ b/chapter3/interpreter.coffee @@ -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 diff --git a/test/test_reader.coffee b/test/test_reader.coffee index 6112466..cae888c 100644 --- a/test/test_reader.coffee +++ b/test/test_reader.coffee @@ -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