diff --git a/src/NITTA/LuaFrontend.hs b/src/NITTA/LuaFrontend.hs index d54f3d3b9..3950084d8 100644 --- a/src/NITTA/LuaFrontend.hs +++ b/src/NITTA/LuaFrontend.hs @@ -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 @@ -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] diff --git a/test/NITTA/LuaFrontend/Tests.hs b/test/NITTA/LuaFrontend/Tests.hs index b26feaaab..4cc98a840 100644 --- a/test/NITTA/LuaFrontend/Tests.hs +++ b/test/NITTA/LuaFrontend/Tests.hs @@ -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|