This commit is contained in:
leaf corcoran 2011-10-30 09:25:23 -07:00
parent bfef2bd06a
commit f9d47db47a
10 changed files with 310 additions and 349 deletions

View File

@ -1,9 +1,9 @@
compile:
moonc moon/ moonscript/
local:
luarocks make --local moonscript-dev-1.rockspec
global:
sudo luarocks make moonscript-dev-1.rockspec
compile:
bin/moonc moon/ moonscript/

View File

@ -19,17 +19,16 @@ 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 Line
Line = (function(_parent_0)
Line = (function()
local _parent_0 = nil
local _base_0 = {
_append_single = function(self, item)
if util.moon.type(item) == Line then
do
local _item_0 = item
for _index_0 = 1, #_item_0 do
local value = _item_0[_index_0]
local _list_0 = item
for _index_0 = 1, #_list_0 do
value = _list_0[_index_0]
self:_append_single(value)
end
end
else
insert(self, item)
end
@ -44,15 +43,13 @@ Line = (function(_parent_0)
end
end,
append = function(self, ...)
do
local _item_0 = {
local _list_0 = {
...
}
for _index_0 = 1, #_item_0 do
local item = _item_0[_index_0]
for _index_0 = 1, #_list_0 do
local item = _list_0[_index_0]
self:_append_single(item)
end
end
return nil
end,
render = function(self)
@ -83,17 +80,18 @@ Line = (function(_parent_0)
end
}, {
__index = _base_0,
__call = function(mt, ...)
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
return _class_0
end)()
local Block_
Block_ = (function(_parent_0)
Block_ = (function()
local _parent_0 = nil
local _base_0 = {
header = "do",
footer = "end",
@ -119,10 +117,9 @@ Block_ = (function(_parent_0)
local undeclared = (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = names
for _index_0 = 1, #_item_0 do
local name = _item_0[_index_0]
local _list_0 = names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
local t = util.moon.type(name)
local real_name
if t == NameProxy then
@ -139,16 +136,13 @@ Block_ = (function(_parent_0)
_accum_0[_len_0] = _value_0
end
end
end
return _accum_0
end)()
do
local _item_0 = undeclared
for _index_0 = 1, #_item_0 do
local name = _item_0[_index_0]
local _list_0 = undeclared
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
self:put_name(name)
end
end
return undeclared
end,
whitelist_names = function(self, names)
@ -230,10 +224,9 @@ Block_ = (function(_parent_0)
end
end,
add_line_tables = function(self, line)
do
local _item_0 = line
for _index_0 = 1, #_item_0 do
local chunk = _item_0[_index_0]
local _list_0 = line
for _index_0 = 1, #_list_0 do
local chunk = _list_0[_index_0]
if util.moon.type(chunk) == Block then
local current = chunk
while current do
@ -246,7 +239,6 @@ Block_ = (function(_parent_0)
end
end
end
end
end,
add = function(self, line)
local t = util.moon.type(line)
@ -347,14 +339,12 @@ Block_ = (function(_parent_0)
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = values
for _index_0 = 1, #_item_0 do
local v = _item_0[_index_0]
local _list_0 = values
for _index_0 = 1, #_list_0 do
local v = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:value(v)
end
end
return _accum_0
end)(), delim)
return _with_0
@ -425,14 +415,12 @@ Block_ = (function(_parent_0)
if ret then
self:ret_stms(stms, ret)
else
do
local _item_0 = stms
for _index_0 = 1, #_item_0 do
local stm = _item_0[_index_0]
local _list_0 = stms
for _index_0 = 1, #_list_0 do
local stm = _list_0[_index_0]
self:stm(stm)
end
end
end
return nil
end
}
@ -459,17 +447,18 @@ Block_ = (function(_parent_0)
end
}, {
__index = _base_0,
__call = function(mt, ...)
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
return _class_0
end)()
local RootBlock
RootBlock = (function(_parent_0)
RootBlock = (function()
local _parent_0 = Block_
local _base_0 = {
render = function(self)
self:_insert_breaks()
@ -488,15 +477,15 @@ RootBlock = (function(_parent_0)
end
}, {
__index = _base_0,
__call = function(mt, ...)
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
return _class_0
end)(Block_)
end)()
Block = Block_
format_error = function(msg, pos, file_str)
local line = pos_to_line(file_str, pos)
@ -520,13 +509,11 @@ end
tree = function(tree)
local scope = RootBlock()
local runner = coroutine.create(function()
do
local _item_0 = tree
for _index_0 = 1, #_item_0 do
local line = _item_0[_index_0]
local _list_0 = tree
for _index_0 = 1, #_list_0 do
local line = _list_0[_index_0]
scope:stm(line)
end
end
return scope:render()
end)
local success, result = coroutine.resume(runner)

View File

@ -30,13 +30,11 @@ default_return = function(exp)
local items = {
"explist"
}
do
local _item_0 = exp[3][2]
for _index_0 = 1, #_item_0 do
local v = _item_0[_index_0]
local _list_0 = exp[3][2]
for _index_0 = 1, #_list_0 do
local v = _list_0[_index_0]
insert(items, v)
end
end
return {
"return",
items

View File

@ -24,14 +24,12 @@ line_compile = {
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = names
for _index_0 = 1, #_item_0 do
local name = _item_0[_index_0]
local _list_0 = names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:name(name)
end
end
return _accum_0
end)(), ", ")
return _with_0
@ -78,14 +76,12 @@ line_compile = {
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = names
for _index_0 = 1, #_item_0 do
local name = _item_0[_index_0]
local _list_0 = names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:value(name)
end
end
return _accum_0
end)(), ", ")
end
@ -93,14 +89,12 @@ line_compile = {
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = values
for _index_0 = 1, #_item_0 do
local v = _item_0[_index_0]
local _list_0 = values
for _index_0 = 1, #_list_0 do
local v = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:value(v)
end
end
return _accum_0
end)(), ", ")
return _with_0
@ -141,10 +135,9 @@ line_compile = {
import = function(self, node)
local _, names, source = unpack(node)
local final_names, to_bind = { }, { }
do
local _item_0 = names
for _index_0 = 1, #_item_0 do
local name = _item_0[_index_0]
local _list_0 = names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
local final
if ntype(name) == ":" then
local tmp = self:name(name[2])
@ -156,7 +149,6 @@ line_compile = {
self:put_name(final)
insert(final_names, final)
end
end
local get_value
get_value = function(name)
if to_bind[name] then
@ -169,14 +161,12 @@ line_compile = {
local values = (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = final_names
for _index_0 = 1, #_item_0 do
local name = _item_0[_index_0]
local _list_1 = final_names
for _index_0 = 1, #_list_1 do
local name = _list_1[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = get_value(name)
end
end
return _accum_0
end)()
local line
@ -191,10 +181,9 @@ line_compile = {
do
local _with_0 = self:block("do")
source = _with_0:init_free_var("table", source)
do
local _item_0 = final_names
for _index_0 = 1, #_item_0 do
local name = _item_0[_index_0]
local _list_1 = final_names
for _index_0 = 1, #_list_1 do
local name = _list_1[_index_0]
_with_0:stm({
"assign",
{
@ -205,7 +194,6 @@ line_compile = {
}
})
end
end
return _with_0
end
end,
@ -233,13 +221,11 @@ line_compile = {
current.next = next
current = next
end
do
local _item_0 = node
for _index_0 = 4, #_item_0 do
local cond = _item_0[_index_0]
local _list_0 = node
for _index_0 = 4, #_list_0 do
cond = _list_0[_index_0]
add_clause(cond)
end
end
return root
end,
["while"] = function(self, node)
@ -289,14 +275,12 @@ line_compile = {
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = names
for _index_0 = 1, #_item_0 do
local name = _item_0[_index_0]
local _list_0 = names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:name(name)
end
end
return _accum_0
end)(), ", ")
_with_0:append(" in ", self:value(exp), " do")

View File

@ -71,14 +71,12 @@ value_compile = {
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = node
for _index_0 = 2, #_item_0 do
local v = _item_0[_index_0]
local _list_0 = node
for _index_0 = 2, #_list_0 do
local v = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:value(v)
end
end
return _accum_0
end)(), ", ")
return _with_0
@ -169,13 +167,11 @@ value_compile = {
local actions
do
local _with_0 = self:line()
do
local _item_0 = node
for _index_0 = 3, #_item_0 do
local action = _item_0[_index_0]
local _list_0 = node
for _index_0 = 3, #_list_0 do
local action = _list_0[_index_0]
_with_0:append(chain_item(action))
end
end
actions = _with_0
end
return self:line(callee_value, actions)
@ -187,10 +183,9 @@ value_compile = {
local arg_names = (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = args
for _index_0 = 1, #_item_0 do
local arg = _item_0[_index_0]
local _list_0 = args
for _index_0 = 1, #_list_0 do
local arg = _list_0[_index_0]
local name, default_value = unpack(arg)
if type(name) == "string" then
name = name
@ -209,7 +204,6 @@ value_compile = {
_accum_0[_len_0] = _value_0
end
end
end
return _accum_0
end)()
if arrow == "fat" then
@ -220,17 +214,14 @@ value_compile = {
if #whitelist > 0 then
_with_0:whitelist_names(whitelist)
end
do
local _item_0 = arg_names
for _index_0 = 1, #_item_0 do
local name = _item_0[_index_0]
local _list_0 = arg_names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
_with_0:put_name(name)
end
end
do
local _item_0 = default_args
for _index_0 = 1, #_item_0 do
local default = _item_0[_index_0]
local _list_1 = default_args
for _index_0 = 1, #_list_1 do
local default = _list_1[_index_0]
local name, value = unpack(default)
if type(name) == "table" then
name = name[2]
@ -256,18 +247,15 @@ value_compile = {
}
})
end
end
local self_arg_values = (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = self_args
for _index_0 = 1, #_item_0 do
local arg = _item_0[_index_0]
local _list_2 = self_args
for _index_0 = 1, #_list_2 do
local arg = _list_2[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = arg[2]
end
end
return _accum_0
end)()
if #self_args > 0 then
@ -282,17 +270,15 @@ value_compile = {
arg_names = (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = args
for _index_0 = 1, #_item_0 do
local arg = _item_0[_index_0]
local _list_2 = args
for _index_0 = 1, #_list_2 do
local arg = _list_2[_index_0]
local _value_0 = arg[1]
if _value_0 ~= nil then
_len_0 = _len_0 + 1
_accum_0[_len_0] = _value_0
end
end
end
return _accum_0
end)()
end
@ -331,14 +317,12 @@ value_compile = {
end
end
if items then
do
local _item_0 = items
for _index_0 = 1, #_item_0 do
local line = _item_0[_index_0]
local _list_0 = items
for _index_0 = 1, #_list_0 do
local line = _list_0[_index_0]
_with_0:add(format_line(line))
end
end
end
return _with_0
end
end,

View File

@ -2,16 +2,15 @@ module("moonscript.data", package.seeall)
local concat = table.concat
Set = function(items)
local self = { }
do
local _item_0 = items
for _index_0 = 1, #_item_0 do
local key = _item_0[_index_0]
local _list_0 = items
for _index_0 = 1, #_list_0 do
local key = _list_0[_index_0]
self[key] = true
end
end
return self
end
Stack = (function(_parent_0)
Stack = (function()
local _parent_0 = nil
local _base_0 = {
__tostring = function(self)
return "<Stack {" .. concat(self, ", ") .. "}>"
@ -33,23 +32,21 @@ Stack = (function(_parent_0)
end
local _class_0 = setmetatable({
__init = function(self, ...)
do
local _item_0 = {
local _list_0 = {
...
}
for _index_0 = 1, #_item_0 do
local v = _item_0[_index_0]
for _index_0 = 1, #_list_0 do
local v = _list_0[_index_0]
self:push(v)
end
end
return nil
end
}, {
__index = _base_0,
__call = function(mt, ...)
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0

View File

@ -13,14 +13,12 @@ flat_value = function(op, depth)
local items = (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = op
for _index_0 = 1, #_item_0 do
local item = _item_0[_index_0]
local _list_0 = op
for _index_0 = 1, #_list_0 do
local item = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = flat_value(item, depth + 1)
end
end
return _accum_0
end)()
local pos = op[-1]
@ -33,14 +31,12 @@ tree = function(block)
return (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = block
for _index_0 = 1, #_item_0 do
local value = _item_0[_index_0]
local _list_0 = block
for _index_0 = 1, #_list_0 do
value = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = print(flat_value(value))
end
end
return _accum_0
end)()
end

View File

@ -8,7 +8,10 @@ require "moonscript.util"
import concat, insert from table
import split, dump from util
export moon_chunk, moon_loader, dirsep, line_tables
lua = :loadstring, :load
export to_lua, moon_chunk, moon_loader, dirsep, line_tables
export dofile, loadfile, loadstring
dirsep = "/"
line_tables = {}
@ -21,22 +24,24 @@ create_moonpath = (package_path) ->
if p then paths[i] = p..".moon"
concat paths, ";"
-- load the chunk function from a file objec:
moon_chunk = (file, file_path) ->
text = file\read "*a"
if not text then error "Could not read file"
to_lua = (text) ->
tree, err = parse.string text
if not tree
error "Parse error: " .. err
error "Parse error: " .. err, 2
code, ltable, pos = compile.tree tree
if not code
error compile.format_error ltable, pos, text
error compile.format_error(ltable, pos, text), 2
line_tables[file_path] = ltable
code, ltable
-- load the chunk function from a file objec:
moon_chunk = (text, source_path) ->
code, ltable = to_lua text
line_tables[source_path] = ltable if source_path
runner = -> with code do code = nil
load runner, file_path
lua.load runner, source_path
moon_loader = (name) ->
name_path = name\gsub "%.", dirsep
@ -48,6 +53,8 @@ moon_loader = (name) ->
break if file
if file
text = file\read "*a"
if not text then error "Could not read file", 2
moon_chunk file, file_path
else
nil, "Could not find moon file"
@ -61,3 +68,17 @@ init_loader = ->
init_loader! if not _G.moon_no_loader
loadstring = (str) ->
code = to_lua str
lua.loadstring code
loadfile = (fname) ->
file, err = io.open fname
return nil, err if not file
loadstring file\read "*a"
-- throws errros
dofile = (fname) ->
f = assert loadfile fname
f!

View File

@ -4,7 +4,8 @@ local util = require("moonscript.util")
local data = require("moonscript.data")
local ntype, build, smart_node, is_slice = types.ntype, types.build, types.smart_node, types.is_slice
local insert = table.insert
NameProxy = (function(_parent_0)
NameProxy = (function()
local _parent_0 = nil
local _base_0 = {
get_name = function(self, scope)
if not self.name then
@ -19,10 +20,9 @@ NameProxy = (function(_parent_0)
items = (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = items
for _index_0 = 1, #_item_0 do
local i = _item_0[_index_0]
local _list_0 = items
for _index_0 = 1, #_list_0 do
local i = _list_0[_index_0]
local _value_0
if type(i) == "string" then
_value_0 = {
@ -37,7 +37,6 @@ NameProxy = (function(_parent_0)
_accum_0[_len_0] = _value_0
end
end
end
return _accum_0
end)()
return build.chain({
@ -73,16 +72,17 @@ NameProxy = (function(_parent_0)
end
}, {
__index = _base_0,
__call = function(mt, ...)
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
return _class_0
end)()
Run = (function(_parent_0)
Run = (function()
local _parent_0 = nil
local _base_0 = {
call = function(self, state)
return self.fn(state)
@ -99,10 +99,10 @@ Run = (function(_parent_0)
end
}, {
__index = _base_0,
__call = function(mt, ...)
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
@ -233,10 +233,9 @@ stm = Transformer({
local properties = (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = tbl[2]
for _index_0 = 1, #_item_0 do
local entry = _item_0[_index_0]
local _list_0 = tbl[2]
for _index_0 = 1, #_list_0 do
local entry = _list_0[_index_0]
local _value_0
if entry[1] == constructor_name then
constructor = entry[2]
@ -249,7 +248,6 @@ stm = Transformer({
_accum_0[_len_0] = _value_0
end
end
end
return _accum_0
end)()
tbl[2] = properties
@ -354,14 +352,12 @@ stm = Transformer({
local slice = (function()
local _accum_0 = { }
local _len_0 = 0
do
local _item_0 = chain
for _index_0 = 3, #_item_0 do
local item = _item_0[_index_0]
local _list_0 = chain
for _index_0 = 3, #_list_0 do
local item = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = item
end
end
return _accum_0
end)()
slice[1] = {

View File

@ -164,13 +164,11 @@ build = setmetatable({
"chain",
base
}
do
local _item_0 = parts
for _index_0 = 1, #_item_0 do
local part = _item_0[_index_0]
local _list_0 = parts
for _index_0 = 1, #_list_0 do
local part = _list_0[_index_0]
insert(node, part)
end
end
return node
end
}, {