[refactor] The great conversion continues.
This commit is contained in:
parent
501ac5fe72
commit
675577431d
|
@ -1,10 +1,12 @@
|
||||||
{car, cdr, cons, listp, nilp, nil,
|
{car, cdr, cons, listp, nilp, nil,
|
||||||
list, pairp, listToString} = require 'cons-lists/lists'
|
list, pairp, listToString} = require 'cons-lists/lists'
|
||||||
{astObject} = require './astAccessors'
|
{astObject} = require './astAccessors'
|
||||||
|
{Symbol} = require './reader_types'
|
||||||
|
|
||||||
# RICH_AST -> LISP_AST
|
# RICH_AST -> LISP_AST
|
||||||
|
|
||||||
normalizeForm = (form) ->
|
normalizeForm = (form) ->
|
||||||
|
console.log(form)
|
||||||
|
|
||||||
listToRecord1 = (l) ->
|
listToRecord1 = (l) ->
|
||||||
o = Object.create(null)
|
o = Object.create(null)
|
||||||
|
@ -25,9 +27,9 @@ normalizeForm = (form) ->
|
||||||
'record': (atom) -> listToRecord1(atom)
|
'record': (atom) -> listToRecord1(atom)
|
||||||
|
|
||||||
# Basic native types. Meh.
|
# Basic native types. Meh.
|
||||||
'symbol': id
|
'symbol': new Symbol(id)
|
||||||
'number': id
|
'number': id
|
||||||
'string': (atom) -> atom
|
'string': id
|
||||||
'nil': (atom) -> nil
|
'nil': (atom) -> nil
|
||||||
|
|
||||||
# Values inherited from the VM.
|
# Values inherited from the VM.
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{listToString, listToVector, pairp, cons, car, cdr, caar, cddr,
|
{listToString, listToVector, pairp, cons, car, cdr, caar, cddr,
|
||||||
cdar, cadr, caadr, cadar, caddr, nilp, nil, setcdr, metacadr} = require "cons-lists/lists"
|
cdar, cadr, caadr, cadar, caddr, nilp, nil, setcdr, metacadr} = require "cons-lists/lists"
|
||||||
readline = require "readline"
|
|
||||||
{Node} = require "./reader_types"
|
{Node} = require "./reader_types"
|
||||||
|
|
||||||
class LispInterpreterError extends Error
|
class LispInterpreterError extends Error
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
exports.Node = class
|
exports.Node = class
|
||||||
constructor: (@type, @value, @line, @column) ->
|
constructor: (@type, @value, @line, @column) ->
|
||||||
|
|
||||||
|
exports.Symbol = class
|
||||||
|
constructor: (@name) ->
|
||||||
|
|
||||||
exports.Comment = class
|
exports.Comment = class
|
||||||
constructor: (@text) ->
|
constructor: (@text) ->
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{listToString, listToVector, pairp, cons, car, cdr, caar, cddr, cdar,
|
{listToString, listToVector, pairp, cons, car, cdr, caar, cddr, cdar,
|
||||||
cadr, caadr, cadar, caddr, nilp, nil, setcdr,
|
cadr, caadr, cadar, caddr, nilp, nil, setcdr,
|
||||||
metacadr, setcar} = require "cons-lists/lists"
|
metacadr, setcar} = require "cons-lists/lists"
|
||||||
{normalizeForm} = require "../chapter1/astToList"
|
{normalizeForms, normalizeForm} = require "../chapter1/astToList"
|
||||||
{Node} = require '../chapter1/reader_types'
|
{Node} = require '../chapter1/reader_types'
|
||||||
|
|
||||||
class LispInterpreterError extends Error
|
class LispInterpreterError extends Error
|
||||||
|
@ -86,7 +86,7 @@ class VariableEnv extends FullEnv
|
||||||
# quoted term uninterpreted.
|
# quoted term uninterpreted.
|
||||||
|
|
||||||
evaluateQuote = (v, env, kont) ->
|
evaluateQuote = (v, env, kont) ->
|
||||||
kont.resume v
|
kont.resume normalizeForms v
|
||||||
|
|
||||||
# Evaluates the conditional expression, creating a continuation with
|
# Evaluates the conditional expression, creating a continuation with
|
||||||
# the current environment that, when resumed, evaluates either the
|
# the current environment that, when resumed, evaluates either the
|
||||||
|
|
|
@ -25,7 +25,7 @@ describe "Core reader functions", ->
|
||||||
['{}', {}]
|
['{}', {}]
|
||||||
['[1 2 3]', [1, 2, 3]]
|
['[1 2 3]', [1, 2, 3]]
|
||||||
# ['(1 2 3', 'error']
|
# ['(1 2 3', 'error']
|
||||||
['{foo "bar"}', {foo: "bar"}]
|
['{"foo" "bar"}', {foo: "bar"}]
|
||||||
]
|
]
|
||||||
|
|
||||||
for [t, v] in samples
|
for [t, v] in samples
|
||||||
|
|
Loading…
Reference in New Issue