Commit 256eeb34 authored by Jamie A. Jennings's avatar Jamie A. Jennings

Cleaned some things up (and fixes?). Also now printing less when infix.DEBUG...

Cleaned some things up (and fixes?).  Also now printing less when infix.DEBUG is true, to make that output more useful.  Shunting yard seems to work fine, so there must be an undocumented assumption in the compiler that is tripping up the processing of rpl_1_3 (when it is parsed, converted, validated, expanded, and compiled using the code in infix.lua).
parent bffcbc02
Pipeline #63365915 passed with stage
in 1 minute and 10 seconds
......@@ -242,12 +242,20 @@ local function pop_exp(exps)
return items
end
local function show(label, ls)
io.stdout:write(label, ": ")
for k,v in ipairs(ls) do
io.stdout:write(v.type)
end
io.stdout:write("\n")
end
local function make_prefix_tree(op, exps)
local right = pop_exp(exps)
local left = pop_exp(exps)
if infix.DEBUG then
print("right operand: "); table.print(right)
print("left operand: "); table.print(left)
show("right operand: ", right)
show("left operand: ", left)
end
assert(right[1], "missing right operand for: " .. op.data)
assert(left[1], "missing left operand for: " .. op.data)
......@@ -257,7 +265,7 @@ local function make_prefix_tree(op, exps)
assert(attr)
op.type = attr.nodetype
if infix.DEBUG then
print("result: "); table.print(op)
print("result: ", op.type); --table.print(op)
end
return op
end
......@@ -422,7 +430,11 @@ function test1(filename)
src = slurp(filename)
ok, pkgname, err = e:load(src)
if ok then
print("OK")
if pkgname then
print("OK (loaded " .. pkgname .. ")")
else
print("OK")
end
else
error("load failed. inspect 'err' for details.")
end
......@@ -469,11 +481,6 @@ function test()
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/ver.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/word.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rcfile.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rpl_1_1.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rpl_1_2.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rpl_1_3.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/Ascii.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/Block.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/Category.rpl")
......@@ -484,6 +491,12 @@ function test()
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/Script.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/SentenceBreak.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/WordBreak.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rcfile.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rpl_1_1.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rpl_1_2.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rpl_1_3.rpl")
end
function setup()
......
......@@ -12,28 +12,6 @@ local builtins = require "builtins"
local common = require "common"
local violation = require "violation"
-- Here is the bare beginnings of some compiler profiling:
local PROFILE = false
local PROFILE_PREFIX = "*prof* "
local function time(since)
return (math.floor((os.clock() - since)*100000 + 0.5))/100 -- ms, rounded to nearest 1/100
end
local profile_print =
function(...)
io.stderr:write(PROFILE_PREFIX)
for _,item in ipairs({...}) do
io.stderr:write(tostring(item))
end
io.stderr:flush()
end
local profile_println =
function(...)
profile_print(...)
io.stderr:write('\n')
io.stderr:flush()
end
local loadpkg = {}
-- 'validate_block' enforces the structure of an rpl module:
......@@ -120,20 +98,9 @@ end
local load_dependencies;
local function parse_block(compiler, source_record, messages)
local t0
if PROFILE then
t0 = os.clock()
profile_println("importing (parsing / parse_block) ", tostring(source_record.origin and source_record.origin.filename))
end
local a = compiler.parse_block(source_record, messages)
if not a then return false; end -- errors will be in messages table
if PROFILE then
profile_println("parsing / parse_block time = ", time(t0), "ms")
t0 = os.clock()
profile_println("importing (parsing / validate_block) ", tostring(source_record.origin and source_record.origin.filename))
end
if not loadpkg.validate_block(a, messages) then return false; end
if PROFILE then profile_println("parsing / validate_block time = ", time(t0), "ms"); end
-- Via side effects, a.block_pdecl and a.block_ideclists are now filled in.
return a
end
......@@ -191,19 +158,9 @@ function loadpkg.source(compiler, pkgtable, top_level_env, searchpath, source, o
end
local function import_from_source(compiler, pkgtable, searchpath, source_record, loadinglist, messages)
local t0
if PROFILE then
profile_println("importing (parsing) ", tostring(source_record.origin and source_record.origin.filename))
t0 = os.clock()
end
local src = source_record.text
local origin = source_record.origin
local a = parse_block(compiler, source_record, messages)
if PROFILE then
profile_println("time = ", time(t0), "ms")
profile_println("importing (dependencies) ", tostring(source_record.origin and source_record.origin.filename))
t0 = os.clock()
end
if not a then return false; end -- errors will be in messages table
if not a.block_pdecl then
local msg = "imported code is not a module"
......@@ -216,17 +173,9 @@ local function import_from_source(compiler, pkgtable, searchpath, source_record,
if not load_dependencies(compiler, pkgtable, searchpath, source_record, a, env, loadinglist, messages) then
return false
end
if PROFILE then
profile_println("time = ", time(t0), "ms")
profile_println("importing (compiling) ", tostring(source_record.origin and source_record.origin.filename))
t0 = os.clock()
end
if not compile(compiler, a, env, source_record, messages) then
return false
end
if PROFILE then
profile_println("time = ", time(t0), "ms")
end
common.pkgtableset(pkgtable, origin.importpath, origin.prefix, origin.packagename, env)
return true, origin.packagename, env
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment