Moved the interpreter into ronin

This commit is contained in:
Devine Lu Linvega 2019-07-21 08:25:23 +09:00
parent 0e7af66c16
commit aaa77de890
3 changed files with 8 additions and 5 deletions

View File

@ -33,7 +33,7 @@ function Commander (ronin) {
this.run = (txt = this._input.value) => {
if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return }
const inter = new Lisp(txt, ronin.library, ronin.includes).run()
ronin.interpreter.run(txt)
ronin.always === true && requestAnimationFrame(() => this.run(txt))
}

View File

@ -1,14 +1,15 @@
'use strict'
function Lisp (input, lib, includes) {
function Lisp (lib = {}, includes = []) {
console.log(includes)
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
this.parent = parent
this.get = function (identifier) {
if (identifier in this.scope) {
return this.scope[identifier]
@ -178,7 +179,7 @@ function Lisp (input, lib, includes) {
return parenthesize(tokenize(input))
}
this.run = async function () {
this.run = async function (input) {
return interpret(this.parse(`(
${this.inc()}
${input})`))

View File

@ -11,6 +11,8 @@ function Ronin () {
b_inv: '#ffb545'
}
this.includes = ['prelude']
this.el = document.createElement('div')
this.el.id = 'ronin'
@ -19,11 +21,11 @@ function Ronin () {
this.commander = new Commander(this)
this.surface = new Surface(this)
this.library = new Library(this)
this.interpreter = new Lisp(this.library, this.includes)
// Parameters
this.always = false
this.includes = ['prelude']
this.install = function (host = document.body) {
this._wrapper = document.createElement('div')