Skip to content

Commit 50b05c1

Browse files
committed
Identify Address
1 parent 8917380 commit 50b05c1

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

docs/index.js

+32-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import * as Control_Applicative from "https://compile.purescript.org/output/Control.Applicative/index.js";
44
import * as Control_Apply from "https://compile.purescript.org/output/Control.Apply/index.js";
55
import * as Control_Bind from "https://compile.purescript.org/output/Control.Bind/index.js";
6+
import * as Data_Boolean from "https://compile.purescript.org/output/Data.Boolean/index.js";
67
import * as Data_Either from "https://compile.purescript.org/output/Data.Either/index.js";
78
import * as Data_Functor from "https://compile.purescript.org/output/Data.Functor/index.js";
89
import * as Data_Int from "https://compile.purescript.org/output/Data.Int/index.js";
910
import * as Data_Maybe from "https://compile.purescript.org/output/Data.Maybe/index.js";
1011
import * as Data_Show from "https://compile.purescript.org/output/Data.Show/index.js";
12+
import * as Data_String_Regex from "https://compile.purescript.org/output/Data.String.Regex/index.js";
13+
import * as Data_String_Regex_Flags from "https://compile.purescript.org/output/Data.String.Regex.Flags/index.js";
14+
import * as Data_String_Regex_Unsafe from "https://compile.purescript.org/output/Data.String.Regex.Unsafe/index.js";
1115
import * as Effect_Console from "https://compile.purescript.org/output/Effect.Console/index.js";
1216
import * as StringParser_CodePoints from "https://compile.purescript.org/output/StringParser.CodePoints/index.js";
1317
import * as StringParser_Parser from "https://compile.purescript.org/output/StringParser.Parser/index.js";
@@ -45,6 +49,15 @@ var logShow = /* #__PURE__ */ Effect_Console.logShow(/* #__PURE__ */ showRecord(
4549
return "pos";
4650
}
4751
})(Data_Show.showInt))(Data_Show.showString)));
52+
var logShow1 = /* #__PURE__ */ Effect_Console.logShow(/* #__PURE__ */ Data_Maybe.showMaybe(/* #__PURE__ */ showRecord(/* #__PURE__ */ Data_Show.showRecordFieldsCons({
53+
reflectSymbol: function () {
54+
return "origin";
55+
}
56+
})(/* #__PURE__ */ Data_Show.showRecordFieldsConsNil({
57+
reflectSymbol: function () {
58+
return "type";
59+
}
60+
})(Data_Show.showString))(Data_Show.showString))));
4861

4962
// Parse a line of NuttX Stack Dump.
5063
// Given this line of NuttX Stack Dump: `stack_dump: 0xc02027e0: c0202010 00000000 00000001 00000000 00000000 00000000 8000ad8a 00000000`
@@ -113,11 +126,17 @@ var parseException = /* #__PURE__ */ discard1(/* #__PURE__ */ $$void(/* #__PURE_
113126
});
114127
});
115128
});
116-
var identifyAddress = function (v) {
117-
return new Data_Maybe.Just({
118-
mod: "aaaa",
119-
type: "bbbb"
120-
});
129+
var identifyAddress = function (s) {
130+
if (Data_Maybe.isJust(Data_String_Regex.match(Data_String_Regex_Unsafe.unsafeRegex("a")(Data_String_Regex_Flags.noFlags))(s))) {
131+
return new Data_Maybe.Just({
132+
origin: "a",
133+
type: "b"
134+
});
135+
};
136+
if (Data_Boolean.otherwise) {
137+
return Data_Maybe.Nothing.value;
138+
};
139+
throw new Error("Failed pattern match at Main (line 42, column 1 - line 42, column 69): " + [ s.constructor.name ]);
121140
};
122141

123142
// Given this NuttX Exception: `riscv_exception: EXCEPTION: Instruction page fault. MCAUSE: 000000000000000c, EPC: 000000008000ad8a, MTVAL: 000000008000ad8a`
@@ -155,7 +174,7 @@ var doRunParser = function (dictShow) {
155174
if (v instanceof Data_Either.Right) {
156175
return Effect_Console.log("Result: " + show1(v.value0))();
157176
};
158-
throw new Error("Failed pattern match at Main (line 188, column 3 - line 190, column 52): " + [ v.constructor.name ]);
177+
throw new Error("Failed pattern match at Main (line 198, column 3 - line 200, column 52): " + [ v.constructor.name ]);
159178
})();
160179
return Effect_Console.log("-----")();
161180
};
@@ -218,11 +237,18 @@ var doRunParser2 = /* #__PURE__ */ doRunParser(/* #__PURE__ */ showRecord(/* #__
218237
}
219238
})(Data_Show.showString))(Data_Show.showString))(Data_Show.showString))(Data_Show.showString))(Data_Show.showString))(Data_Show.showString))(Data_Show.showString))(Data_Show.showString))(Data_Show.showString)));
220239

240+
// identifyAddress _ = Just
241+
// {
242+
// origin: "aaaa"
243+
// , type: "bbbb"
244+
// }
221245
// Parse the NuttX Exception and NuttX Stack Dump. Explain the NuttX Exception.
222246
// `Effect` says that it will do Side Effects (printing to console)
223247
// `Unit` means that no value will be returned
224248
// The next line declares the Function Type. We can actually erase it, VSCode PureScript Extension will helpfully suggest it for us.
225249
var printResults = function __do() {
250+
logShow1(identifyAddress("abc"))();
251+
logShow1(identifyAddress("bc"))();
226252
Effect_Console.log(explainException(12)("epc")("mtval"))();
227253
Effect_Console.log(explainException(13)("epc")("mtval"))();
228254
Effect_Console.log(explainException(0)("epc")("mtval"))();

spago.dhall

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ to generate this file without the comments in this block.
1919
, "maybe"
2020
, "prelude"
2121
, "string-parsers"
22+
, "strings"
2223
]
2324
, packages = ./packages.dhall
2425
, sources = [ "src/**/*.purs", "test/**/*.purs" ]

src/Main.purs

+17-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import Prelude hiding (between)
77

88
import Data.Either (Either(..))
99
import Data.Int (fromStringAs, hexadecimal)
10-
import Data.Maybe (Maybe(..), fromMaybe)
10+
import Data.Maybe (Maybe(..), fromMaybe, isJust)
11+
import Data.String.Regex (match)
12+
import Data.String.Regex.Flags (noFlags)
13+
import Data.String.Regex.Unsafe (unsafeRegex)
1114
import Effect (Effect)
1215
import Effect.Console (log, logShow)
1316
import StringParser (Parser, regex, runParser, skipSpaces, string)
@@ -36,12 +39,16 @@ explainException 13 epc mtval =
3639
explainException mcause epc mtval =
3740
"Unknown Exception: mcause=" <> show mcause <> ", epc=" <> epc <> ", mtval=" <> mtval
3841

39-
identifyAddress String Maybe { mod String , type String }
40-
identifyAddress _ = Just
41-
{
42-
mod: "aaaa"
43-
, type: "bbbb"
44-
}
42+
identifyAddress String Maybe { origin String , type String }
43+
44+
identifyAddress s | isJust (match (unsafeRegex "a" noFlags) s) = Just { origin: "a", type: "b" }
45+
| otherwise = Nothing
46+
47+
-- identifyAddress _ = Just
48+
-- {
49+
-- origin: "aaaa"
50+
-- , type: "bbbb"
51+
-- }
4552

4653
-- Parse the NuttX Exception and NuttX Stack Dump. Explain the NuttX Exception.
4754
-- `Effect` says that it will do Side Effects (printing to console)
@@ -50,6 +57,9 @@ identifyAddress _ = Just
5057
printResults :: Effect Unit
5158
printResults = do
5259

60+
logShow $ identifyAddress "abc"
61+
logShow $ identifyAddress "bc"
62+
5363
-- Explain the NuttX Exception.
5464
-- `$ something something` is shortcut for `( something something )`
5565
log $ explainException 12 "epc" "mtval"

0 commit comments

Comments
 (0)