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) => { this.run = (txt = this._input.value) => {
if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return } 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)) ronin.always === true && requestAnimationFrame(() => this.run(txt))
} }

View File

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

View File

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