From 9990b5ad29cf3a225becbbf8d63e9592ce9173bd Mon Sep 17 00:00:00 2001 From: Denis Buzdalov Date: Wed, 25 Nov 2020 21:10:26 +0300 Subject: [PATCH] Namespaces were shadowed in all standard codegens. This allows, for exmaple, to have apostrophes in module names. Test was added only for chez, however this should be viable for all targets with `:exec` implemented. --- src/Compiler/ES/ES.idr | 2 +- src/Compiler/RefC/RefC.idr | 2 +- src/Compiler/Scheme/Common.idr | 2 +- tests/Main.idr | 2 +- tests/idris2/basic048/Module'.idr | 7 +++++++ tests/idris2/basic048/expected | 4 ++++ tests/idris2/basic048/input | 2 ++ tests/idris2/basic048/run | 4 ++++ 8 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 tests/idris2/basic048/Module'.idr create mode 100644 tests/idris2/basic048/expected create mode 100644 tests/idris2/basic048/input create mode 100644 tests/idris2/basic048/run diff --git a/src/Compiler/ES/ES.idr b/src/Compiler/ES/ES.idr index 88bb6c4a2..aa5186742 100644 --- a/src/Compiler/ES/ES.idr +++ b/src/Compiler/ES/ES.idr @@ -109,7 +109,7 @@ keywordSafe "var" = "var_" keywordSafe s = s jsName : Name -> String -jsName (NS ns n) = showNSWithSep "_" ns ++ "_" ++ jsName n +jsName (NS ns n) = jsIdent (showNSWithSep "_" ns) ++ "_" ++ jsName n jsName (UN n) = keywordSafe $ jsIdent n jsName (MN n i) = jsIdent n ++ "_" ++ show i jsName (PV n d) = "pat__" ++ jsName n diff --git a/src/Compiler/RefC/RefC.idr b/src/Compiler/RefC/RefC.idr index f621acadb..112162241 100644 --- a/src/Compiler/RefC/RefC.idr +++ b/src/Compiler/RefC/RefC.idr @@ -87,7 +87,7 @@ cCleanString : String -> String cCleanString cs = showcCleanString (unpack cs) "" cName : Name -> String -cName (NS ns n) = showNSWithSep "_" ns ++ "_" ++ cName n +cName (NS ns n) = cCleanString (showNSWithSep "_" ns) ++ "_" ++ cName n cName (UN n) = cCleanString n cName (MN n i) = cCleanString n ++ "_" ++ cCleanString (show i) cName (PV n d) = "pat__" ++ cName n diff --git a/src/Compiler/Scheme/Common.idr b/src/Compiler/Scheme/Common.idr index 85f94058f..6c78ece10 100644 --- a/src/Compiler/Scheme/Common.idr +++ b/src/Compiler/Scheme/Common.idr @@ -31,7 +31,7 @@ schString s = concatMap okchar (unpack s) export schName : Name -> String -schName (NS ns n) = showNSWithSep "-" ns ++ "-" ++ schName n +schName (NS ns n) = schString (showNSWithSep "-" ns) ++ "-" ++ schName n schName (UN n) = schString n schName (MN n i) = schString n ++ "-" ++ show i schName (PV n d) = "pat--" ++ schName n diff --git a/tests/Main.idr b/tests/Main.idr index ba4737d25..909800efc 100644 --- a/tests/Main.idr +++ b/tests/Main.idr @@ -44,7 +44,7 @@ idrisTests = MkTestPool [] "basic031", "basic032", "basic033", "basic034", "basic035", "basic036", "basic037", "basic038", "basic039", "basic040", "basic041", "basic042", "basic043", "basic044", "basic045", - "basic046", "basic047", + "basic046", "basic047", "basic048", -- Coverage checking "coverage001", "coverage002", "coverage003", "coverage004", "coverage005", "coverage006", "coverage007", "coverage008", diff --git a/tests/idris2/basic048/Module'.idr b/tests/idris2/basic048/Module'.idr new file mode 100644 index 000000000..33d33d30c --- /dev/null +++ b/tests/idris2/basic048/Module'.idr @@ -0,0 +1,7 @@ +module Module' + +function' : Int -> Int +function' x = x + 1 + +main : IO () +main = printLn . show $ function' 4 diff --git a/tests/idris2/basic048/expected b/tests/idris2/basic048/expected new file mode 100644 index 000000000..5cb4d4c79 --- /dev/null +++ b/tests/idris2/basic048/expected @@ -0,0 +1,4 @@ +1/1: Building Module' (Module'.idr) +Module'> 2 +Module'> Bye for now! +"5" diff --git a/tests/idris2/basic048/input b/tests/idris2/basic048/input new file mode 100644 index 000000000..441ce8daa --- /dev/null +++ b/tests/idris2/basic048/input @@ -0,0 +1,2 @@ +function' 1 +:q diff --git a/tests/idris2/basic048/run b/tests/idris2/basic048/run new file mode 100644 index 000000000..2731baecf --- /dev/null +++ b/tests/idris2/basic048/run @@ -0,0 +1,4 @@ +$1 --no-banner --no-color --console-width 0 "Module'.idr" < input +$1 --exec main --cg ${IDRIS2_TESTS_CG} "Module'.idr" + +rm -rf build