refactor types out of compile

This commit is contained in:
leaf corcoran 2011-09-27 08:40:18 -07:00
parent 445ef4314a
commit 64fd33c089
17 changed files with 71 additions and 44 deletions

View File

@ -1,11 +1,19 @@
module("moonscript.compile", package.seeall)
local util = require("moonscript.util")
local data = require("moonscript.data")
local dump = require("moonscript.dump")
require("moonscript.compile.format")
require("moonscript.compile.line")
require("moonscript.compile.value")
local ntype, Set = data.ntype, data.Set
local Set
do
local _table_0 = require("moonscript.data")
Set = _table_0.Set
end
local ntype
do
local _table_0 = require("moonscript.types")
ntype = _table_0.ntype
end
local concat, insert = table.concat, table.insert
local pos_to_line, get_closest_line, trim = util.pos_to_line, util.get_closest_line, util.trim
local bubble_names = {

View File

@ -1,14 +1,15 @@
module "moonscript.compile", package.seeall
util = require "moonscript.util"
data = require "moonscript.data"
dump = require "moonscript.dump"
require "moonscript.compile.format"
require "moonscript.compile.line"
require "moonscript.compile.value"
import ntype, Set from data
import Set from require "moonscript.data"
import ntype from require "moonscript.types"
import concat, insert from table
import pos_to_line, get_closest_line, trim from util

View File

@ -1,7 +1,16 @@
module("moonscript.compile", package.seeall)
local util = require("moonscript.util")
local data = require("moonscript.data")
local Set, ntype = data.Set, data.ntype
local Set
do
local _table_0 = require("moonscript.data")
Set = _table_0.Set
end
local ntype
do
local _table_0 = require("moonscript.types")
ntype = _table_0.ntype
end
local concat, insert = table.concat, table.insert
indent_char = " "
user_error = function(...)

View File

@ -3,7 +3,8 @@ module "moonscript.compile", package.seeall
util = require "moonscript.util"
data = require "moonscript.data"
import Set, ntype from data
import Set from require "moonscript.data"
import ntype from require "moonscript.types"
import concat, insert from table
export indent_char, default_return, moonlib, cascading, non_atomic, has_value, is_non_atomic

View File

@ -1,10 +1,13 @@
module("moonscript.compile", package.seeall)
local util = require("moonscript.util")
local data = require("moonscript.data")
require("moonscript.compile.format")
require("moonscript.compile.types")
local reversed = util.reversed
local ntype = data.ntype
local ntype, smart_node
do
local _table_0 = require("moonscript.types")
ntype = _table_0.ntype
smart_node = _table_0.smart_node
end
local concat, insert = table.concat, table.insert
local constructor_name = "new"
line_compile = {

View File

@ -1,13 +1,11 @@
module "moonscript.compile", package.seeall
util = require "moonscript.util"
data = require "moonscript.data"
require "moonscript.compile.format"
require "moonscript.compile.types"
import reversed from util
import ntype from data
import ntype, smart_node from require "moonscript.types"
import concat, insert from table
export line_compile

View File

@ -2,7 +2,11 @@ module("moonscript.compile", package.seeall)
local util = require("moonscript.util")
local data = require("moonscript.data")
require("moonscript.compile.format")
local ntype = data.ntype
local ntype
do
local _table_0 = require("moonscript.types")
ntype = _table_0.ntype
end
local concat, insert = table.concat, table.insert
local table_append
table_append = function(name, len, value)

View File

@ -6,7 +6,7 @@ data = require "moonscript.data"
require "moonscript.compile.format"
import ntype from data
import ntype from require "moonscript.types"
import concat, insert from table
export value_compile

View File

@ -1,12 +1,5 @@
module("moonscript.data", package.seeall)
local concat = table.concat
ntype = function(node)
if type(node) ~= "table" then
return "value"
else
return node[1]
end
end
Set = function(items)
local self = { }
do

View File

@ -1,19 +1,11 @@
-- data structure utils
-- data structures & static data
module "moonscript.data", package.seeall
export Set, Stack
export ntype, lua_keywords
export lua_keywords
import concat from table
-- type of node as string
ntype = (node) ->
if type(node) != "table"
"value"
else
node[1]
Set = (items) ->
self = {}
self[key] = true for key in *items

View File

@ -1,6 +1,6 @@
module("moonscript", package.seeall)
require("moonscript.parse")
require("moonscript.compile")
require("moonscript.parse")
require("moonscript.util")
local concat, insert = table.concat, table.insert
local split, dump = util.split, util.dump

View File

@ -1,8 +1,8 @@
module "moonscript", package.seeall
require "moonscript.parse"
require "moonscript.compile"
require "moonscript.parse"
require "moonscript.util"
import concat, insert from table

View File

@ -4,10 +4,12 @@ local util = require"moonscript.util"
require"lpeg"
local dump = require"moonscript.dump"
local data = require"moonscript.data"
local types = require"moonscript.types"
local ntype = data.ntype
local ntype = types.ntype
local dump = util.dump
local trim = util.trim
local Stack = data.Stack

View File

@ -1,7 +1,13 @@
module("moonscript.compile", package.seeall)
module("moonscript.types", package.seeall)
local util = require("moonscript.util")
local data = require("moonscript.data")
local ntype = data.ntype
ntype = function(node)
if type(node) ~= "table" then
return "value"
else
return node[1]
end
end
local t = { }
local node_types = {
fndef = {

View File

@ -1,13 +1,15 @@
module "moonscript.compile", package.seeall
module "moonscript.types", package.seeall
util = require "moonscript.util"
data = require "moonscript.data"
import ntype from data
export smart_node, build
export ntype, smart_node, build
-- todo: this should be merged into data
-- lets us index a node by item name based on it's type
-- type of node as string
ntype = (node) ->
if type(node) != "table"
"value"
else
node[1]
t = {}
@ -51,6 +53,7 @@ build = setmetatable {}, {
rawget self, name
}
-- makes it so node properties can be accessed by name instead of index
smart_node = (node) ->
index = key_table[ntype node]
if not index then return node

View File

@ -1,3 +1,5 @@
#!/usr/bin/env lua
require "lfs"
require "alt_getopt"

7
todo
View File

@ -1,6 +1,11 @@
# TODO
..= append string
if hello else world
-> if hello then hello else world
- enhance with documentation
- fix variable names starting with and, not, or, etc..
- varargs that get put in a nested generated function aren't valid anymore: