Merge pull request #30 from lctrt/master

adds (run "/path/file.lisp")
This commit is contained in:
Лu Лinveгa 2019-07-14 09:10:48 +12:00 committed by GitHub
commit 13d498c09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,9 @@
'use strict' 'use strict'
function Lisp (input, lib) { function Lisp (input, lib) {
const path = require('path')
const fs = require('fs')
const TYPES = { identifier: 0, number: 1, string: 2, bool: 3 } const TYPES = { identifier: 0, number: 1, string: 2, bool: 3 }
const Context = function (scope, parent) { const Context = function (scope, parent) {
this.scope = scope this.scope = scope
@ -16,6 +19,13 @@ function Lisp (input, lib) {
} }
const special = { const special = {
run: (input, context) => {
const file = fs.readFileSync(
path.resolve(input[1].value),
{encoding: "utf-8"})
return interpret(this.parse(file), context)
},
let: function (input, context) { let: function (input, context) {
const letContext = input[1].reduce(function (acc, x) { const letContext = input[1].reduce(function (acc, x) {
acc.scope[x[0].value] = interpret(x[1], context) acc.scope[x[0].value] = interpret(x[1], context)