Started lisp implementation

This commit is contained in:
Devine Lu Linvega
2019-07-13 11:37:54 +09:00
parent 7f01d369ed
commit cfc30f518e
8 changed files with 45 additions and 40 deletions

View File

@@ -1,4 +1,4 @@
function Commander () {
function Commander (ronin) {
this.el = document.createElement('yu')
this.el.id = 'commander'
this._input = document.createElement('textarea')
@@ -34,6 +34,10 @@ function Commander () {
this._input.focus()
}
this.run = function (txt = this.el.value) {
console.log(new Lisp(txt, ronin.library))
}
this.update = function () {
}

View File

@@ -0,0 +1,5 @@
function Library (ronin) {
this.hello = function () {
}
}

View File

@@ -1,10 +1,7 @@
'use strict'
// Originally created by maryrosecook
// https://github.com/maryrosecook/littlelisp
function Lisp (input, lib, tables, host) {
const TYPES = { identifier: 0, keyword: 1, number: 2, string: 3, bool: 4 }
function Lisp (input, lib) {
const TYPES = { identifier: 0, number: 1, string: 2, bool: 3 }
const Context = function (scope, parent) {
this.scope = scope
this.parent = parent
@@ -56,8 +53,6 @@ function Lisp (input, lib, tables, host) {
return interpretList(input, context)
} else if (input.type === TYPES.identifier) {
return context.get(input.value)
} else if (input.type === TYPES.keyword) {
return host[input.value] ? host[input.value] : null
} else if (input.type === TYPES.number || input.type === TYPES.string || input.type === TYPES.bool) {
return input.value
}
@@ -68,8 +63,6 @@ function Lisp (input, lib, tables, host) {
return { type: TYPES.number, value: parseFloat(input) }
} else if (input[0] === '"' && input.slice(-1) === '"') {
return { type: TYPES.string, value: input.slice(1, -1) }
} else if (input[0] === ':') {
return { type: TYPES.keyword, value: input.substr(1, input.length - 1) }
} else if (input === 'true' || input === 'false') {
return { type: TYPES.bool, value: input === 'true' }
} else {
@@ -79,9 +72,7 @@ function Lisp (input, lib, tables, host) {
const parenthesize = function (input, list) {
if (list === undefined) { return parenthesize(input, []) }
const token = input.shift()
if (token === undefined) {
return list.pop()
} else if (token === '(') {
@@ -102,7 +93,7 @@ function Lisp (input, lib, tables, host) {
return parenthesize(tokenize(input))
}
this.toString = function () {
return `${interpret(this.parse(input))}`
this.toPixels = function () {
return interpret(this.parse(input))
}
}

View File

@@ -15,16 +15,15 @@ function Ronin () {
this.el.id = 'ronin'
this.theme = new Theme(defaultTheme)
this.commander = new Commander()
this.surface = new Surface()
this.commander = new Commander(this)
this.surface = new Surface(this)
this.library = new Library(this)
this.install = function (host = document.body) {
host.appendChild(this.el)
this.commander.install(this.el)
this.surface.install(this.el)
this.theme.install(host, () => { this.update() })
host.appendChild(this.el)
this.theme.install()
}
this.start = function () {
@@ -32,15 +31,6 @@ function Ronin () {
this.commander.start()
this.surface.start()
// window.addEventListener('dragover', ronin.io.drag_over)
// window.addEventListener('drop', ronin.io.drop)
// ronin.frame.el.addEventListener('mousedown', ronin.cursor.mouse_down)
// ronin.frame.el.addEventListener('mousemove', ronin.cursor.mouse_move)
// ronin.frame.el.addEventListener('mouseup', ronin.cursor.mouse_up)
// ronin.frame.el.addEventListener('contextmenu', ronin.cursor.mouse_alt)
// window.addEventListener('keydown', ronin.keyboard.key_down)
// window.addEventListener('keyup', ronin.keyboard.key_up)
console.log('Ronin', 'Started')
}
@@ -48,10 +38,6 @@ function Ronin () {
this.theme.reset()
}
this.update = function () {
}
this.load = function (content = this.default()) {
}

View File

@@ -1,16 +1,35 @@
function Surface () {
function Surface (ronin) {
this.el = document.createElement('canvas')
this.el.id = 'surface'
this.ratio = window.devicePixelRatio
this.install = function (host) {
host.appendChild(this.el)
window.addEventListener('resize', (e) => { this.onResize() }, false)
}
this.start = function () {
this.maximize()
console.log('Surface', `Ratio:${this.ratio}`)
}
this.update = function () {
}
this.resize = function (size) {
this.el.width = size.w
this.el.height = size.h
this.el.style.width = size.w + 'px'
this.el.style.height = size.h + 'px'
}
this.maximize = function () {
const size = { w: Math.floor(window.innerWidth / 2) - 15, h: Math.floor(window.innerHeight) - 30 }
this.resize(size)
}
this.onResize = function () {
this.maximize()
}
}