remove module from compile, reorganize

This commit is contained in:
leaf corcoran 2012-11-28 00:42:43 -08:00
parent 33eb9510dd
commit 38463a078d
11 changed files with 65 additions and 52 deletions

View File

@ -3,7 +3,7 @@
module("moonscript", package.seeall)
require "moonscript.parse"
require "moonscript.compile"
local compile = require "moonscript.compile"
local util = require "moonscript.util"
require "alt_getopt"

View File

@ -1,8 +1,5 @@
module("moonscript.compile", package.seeall)
local util = require("moonscript.util")
local dump = require("moonscript.dump")
require("moonscript.compile.statement")
require("moonscript.compile.value")
local transform = require("moonscript.transform")
local NameProxy, LocalName
do
@ -19,11 +16,21 @@ do
local _table_0 = require("moonscript.types")
ntype, has_value = _table_0.ntype, _table_0.has_value
end
local statement_compilers
do
local _table_0 = require("moonscript.compile.statement")
statement_compilers = _table_0.statement_compilers
end
local value_compilers
do
local _table_0 = require("moonscript.compile.value")
value_compilers = _table_0.value_compilers
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 mtype = util.moon.type
local indent_char = " "
local Line, Lines
local Line, Lines, Block, RootBlock
do
local _parent_0 = nil
local _base_0 = {
@ -160,7 +167,7 @@ do
end
local _list_0 = item
for _index_0 = 1, #_list_0 do
value = _list_0[_index_0]
local value = _list_0[_index_0]
self:_append_single(value)
end
else
@ -333,7 +340,7 @@ do
self._name_whitelist = Set(names)
end,
put_name = function(self, name, ...)
value = ...
local value = ...
if select("#", ...) == 0 then
value = true
end
@ -423,11 +430,11 @@ do
end
end,
is_stm = function(self, node)
return line_compile[ntype(node)] ~= nil
return statement_compilers[ntype(node)] ~= nil
end,
is_value = function(self, node)
local t = ntype(node)
return value_compile[t] ~= nil or t == "value"
return value_compilers[t] ~= nil or t == "value"
end,
name = function(self, node)
return self:value(node)
@ -440,7 +447,7 @@ do
else
action = node[1]
end
local fn = value_compile[action]
local fn = value_compilers[action]
if not fn then
error("Failed to compile value: " .. dump.value(node))
end
@ -482,7 +489,7 @@ do
node = self.transform.statement(node)
local result
do
local fn = line_compile[ntype(node)]
local fn = statement_compilers[ntype(node)]
if fn then
result = fn(self, node, ...)
else
@ -642,6 +649,7 @@ do
end
RootBlock = _class_0
end
local format_error
format_error = function(msg, pos, file_str)
local line = pos_to_line(file_str, pos)
local line_str
@ -652,6 +660,7 @@ format_error = function(msg, pos, file_str)
(" [%d] >> %s"):format(line, trim(line_str))
}, "\n")
end
local value
value = function(value)
local out = nil
do
@ -661,6 +670,7 @@ value = function(value)
end
return out
end
local tree
tree = function(tree, options)
if options == nil then
options = { }
@ -693,3 +703,10 @@ tree = function(tree, options)
return lua_code, posmap
end
end
return {
tree = tree,
value = value,
format_error = format_error,
Block = Block,
RootBlock = RootBlock
}

View File

@ -1,17 +1,15 @@
module "moonscript.compile", package.seeall
util = require "moonscript.util"
dump = require "moonscript.dump"
require "moonscript.compile.statement"
require "moonscript.compile.value"
transform = require "moonscript.transform"
import NameProxy, LocalName from require "moonscript.transform.names"
import Set from require "moonscript.data"
import ntype, has_value from require "moonscript.types"
import statement_compilers from require "moonscript.compile.statement"
import value_compilers from require "moonscript.compile.value"
import concat, insert from table
import pos_to_line, get_closest_line, trim from util
@ -19,10 +17,7 @@ mtype = util.moon.type
indent_char = " "
export tree, value, format_error
export Block, RootBlock
local Line, Lines
local Line, Lines, Block, RootBlock
-- a buffer for building up lines
class Lines
@ -277,11 +272,11 @@ class Block
\append ...
is_stm: (node) =>
line_compile[ntype node] != nil
statement_compilers[ntype node] != nil
is_value: (node) =>
t = ntype node
value_compile[t] != nil or t == "value"
value_compilers[t] != nil or t == "value"
-- line wise compile functions
name: (node) => @value node
@ -292,7 +287,7 @@ class Block
else
node[1]
fn = value_compile[action]
fn = value_compilers[action]
error "Failed to compile value: "..dump.value node if not fn
out = fn self, node, ...
@ -314,7 +309,7 @@ class Block
return if not node -- skip blank statements
node = @transform.statement node
result = if fn = line_compile[ntype(node)]
result = if fn = statement_compilers[ntype(node)]
fn self, node, ...
else
-- coerce value into statement
@ -399,3 +394,4 @@ tree = (tree, options={}) ->
posmap = scope._lines\flatten_posmap!
lua_code, posmap
{ :tree, :value, :format_error, :Block, :RootBlock }

View File

@ -1,15 +1,15 @@
module("moonscript.compile", package.seeall)
local util = require("moonscript.util")
local dump = require("moonscript.dump")
local transform = require("moonscript.transform")
local reversed = util.reversed
local reversed
do
local _table_0 = require("moonscript.util")
reversed = _table_0.reversed
end
local ntype
do
local _table_0 = require("moonscript.types")
ntype = _table_0.ntype
end
local concat, insert = table.concat, table.insert
line_compile = {
local statement_compilers = {
raw = function(self, node)
return self:add(node[2])
end,
@ -246,3 +246,6 @@ line_compile = {
end
end
}
return {
statement_compilers = statement_compilers
}

View File

@ -1,17 +1,9 @@
module "moonscript.compile", package.seeall
util = require "moonscript.util"
dump = require "moonscript.dump"
transform = require "moonscript.transform"
import reversed from util
import reversed from require "moonscript.util"
import ntype from require "moonscript.types"
import concat, insert from table
export line_compile
line_compile =
statement_compilers =
raw: (node) => @add node[2]
lines: (node) =>
@ -139,3 +131,5 @@ line_compile =
with @block!
\stms node[2]
{ :statement_compilers }

View File

@ -1,4 +1,3 @@
module("moonscript.compile", package.seeall)
local util = require("moonscript.util")
local data = require("moonscript.data")
local ntype
@ -13,7 +12,7 @@ do
end
local concat, insert = table.concat, table.insert
local table_delim = ","
value_compile = {
local value_compilers = {
exp = function(self, node)
local _comp
_comp = function(i, value)
@ -302,3 +301,6 @@ value_compile = {
return tostring(value)
end
}
return {
value_compilers = value_compilers
}

View File

@ -1,19 +1,14 @@
module "moonscript.compile", package.seeall
util = require "moonscript.util"
data = require "moonscript.data"
import ntype from require "moonscript.types"
import user_error from require "moonscript.errors"
import concat, insert from table
export value_compile
table_delim = ","
value_compile =
value_compilers =
-- list of values separated by binary operators
exp: (node) =>
_comp = (i, value) ->
@ -189,3 +184,6 @@ value_compile =
@send "varargs"
tostring value
{ :value_compilers }

View File

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

View File

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

View File

@ -37,7 +37,8 @@ has_value = function(node)
end
local is_value
is_value = function(stm)
local compile, transform = moonscript.compile, moonscript.transform
local compile = require("moonscript.compile")
local transform = require("moonscript.transform")
return compile.Block:is_value(stm) or transform.Value:can_transform(stm)
end
local comprehension_has_value

View File

@ -31,7 +31,9 @@ has_value = (node) ->
true
is_value = (stm) ->
import compile, transform from moonscript
compile = require "moonscript.compile"
transform = require "moonscript.transform"
compile.Block\is_value(stm) or transform.Value\can_transform stm
comprehension_has_value = (comp) ->