add run command

This commit is contained in:
Quentin Leonetti 2019-07-13 14:49:53 +02:00
parent d309a9f032
commit 55d6a409a3

View File

@ -1,6 +1,9 @@
'use strict'
function Lisp (input, lib) {
const path = require('path')
const fs = require('fs')
const TYPES = { identifier: 0, number: 1, string: 2, bool: 3 }
const Context = function (scope, parent) {
this.scope = scope
@ -16,6 +19,13 @@ function Lisp (input, lib) {
}
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) {
const letContext = input[1].reduce(function (acc, x) {
acc.scope[x[0].value] = interpret(x[1], context)
@ -47,6 +57,7 @@ function Lisp (input, lib) {
}
const interpret = function (input, context) {
console.log(input, context)
if (context === undefined) {
return interpret(input, new Context(lib))
} else if (input instanceof Array) {