Skip to content

Commit

Permalink
Merge pull request #203 from ryukzak/192_console_output
Browse files Browse the repository at this point in the history
loop arguments added to trace
  • Loading branch information
ArturGogiyan authored Mar 27, 2022
2 parents 41b87cf + 3bec4b2 commit 9dd317e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/NITTA/LuaFrontend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ data LuaAlgBuilder x = LuaAlgBuilder
algVarCounters :: HM.HashMap T.Text Int
, -- | A table lists all uses of a particular LuaValueInstance.
algVars :: HM.HashMap LuaValueInstance [T.Text]
, -- | A table correlating the ordinal number of an argument with a variable storing its value and startup value of this variable.
, -- | Map argument index to the variable name and initial value (in text).
algStartupArgs :: HM.HashMap Int (T.Text, T.Text)
, -- | A table correlating constant with LuaValueInstance which store this constant.
algConstants :: HM.HashMap T.Text LuaValueInstance
Expand Down Expand Up @@ -392,8 +392,16 @@ alg2graph LuaAlgBuilder{algGraph, algLatestLuaValueInstance, algVars} = flip exe
lua2functions src =
let syntaxTree = getLuaBlockFromSources src
luaAlgBuilder = buildAlg syntaxTree
frTrace = getFrTrace $ algTraceFuncs luaAlgBuilder
in FrontendResult{frDataFlow = alg2graph luaAlgBuilder, frTrace = frTrace, frPrettyLog = prettyLog frTrace}
frTrace = getFrTrace $ getAllTraceFuncs luaAlgBuilder
in FrontendResult{frDataFlow = alg2graph luaAlgBuilder, frTrace, frPrettyLog = prettyLog frTrace}
where
getAllTraceFuncs algBuilder =
let traceFuncs = algTraceFuncs algBuilder
startupArgNames =
map
(\(_idx, (varName, _initValue)) -> varName)
$ HM.toList $ algStartupArgs algBuilder
in map (\name -> ([name <> "^0"], defaultFmt)) startupArgNames <> traceFuncs

getFrTrace traceFuncs = [TraceVar fmt var | (vars, fmt) <- traceFuncs, var <- vars]

Expand Down
18 changes: 18 additions & 0 deletions test/NITTA/LuaFrontend/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,24 @@ test_complex_examples =

test_trace_features =
[ traceLuaSimulationTestCase
pInt
"loop argument tracing"
[__i|
function counter(i)
counter(i + 1)
end
counter(0)
|]
[__i|
| Cycle | i |
|:-------|:-------|
| 1 | 0.000 |
| 2 | 1.000 |
| 3 | 2.000 |
| 4 | 3.000 |
| 5 | 4.000 |\n
|]
, traceLuaSimulationTestCase
pInt
"simple trace"
[__i|
Expand Down

0 comments on commit 9dd317e

Please sign in to comment.