Skip to content

Commit e7d7b95

Browse files
committed
refactor: update references from core to stdlib across multiple files
1 parent 8af68e3 commit e7d7b95

File tree

12 files changed

+73
-112
lines changed

12 files changed

+73
-112
lines changed

bin/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ server.post("withFile", (request) => {
164164
});
165165

166166
server.post("hFileSize", (request) => {
167-
fs.fstat(request.body, (err, stats) => {
167+
const fd = parseInt(request.body);
168+
fs.fstat(fd, (err, stats) => {
168169
if (err) throw err;
169170
request.respond(200, null, stats.size);
170171
});

scripts/replacements.js

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -23,77 +23,6 @@ const data = fs
2323
\t\tconsole.error(e.stack);
2424
\t}
2525
\ttypeof process !== "undefined" && process.exit(1);
26-
};`)
27-
28-
/* Prevents V8 from retaining large "concatenated string" chains, which can cause OOMs.
29-
Tested against `rtfeldman/elm-css` compilation.
30-
31-
See the related discussion for context: https://discourse.elm-lang.org/t/guida-compiler-was-there-are-3-elm-compilers-written-in-elm/10329/34
32-
and issue: https://github.com/guida-lang/compiler/issues/107
33-
*/
34-
.replace(`var _Bytes_read_string = F3(function(len, bytes, offset)
35-
{
36-
var string = '';
37-
\tvar end = offset + len;
38-
\tfor (; offset < end;)
39-
\t{
40-
\t\tvar byte = bytes.getUint8(offset++);
41-
\t\tstring +=
42-
\t\t\t(byte < 128)
43-
\t\t\t\t? String.fromCharCode(byte)
44-
\t\t\t\t:
45-
\t\t\t((byte & 0xE0 /* 0b11100000 */) === 0xC0 /* 0b11000000 */)
46-
\t\t\t\t? String.fromCharCode((byte & 0x1F /* 0b00011111 */) << 6 | bytes.getUint8(offset++) & 0x3F /* 0b00111111 */)
47-
\t\t\t\t:
48-
\t\t\t((byte & 0xF0 /* 0b11110000 */) === 0xE0 /* 0b11100000 */)
49-
\t\t\t\t? String.fromCharCode(
50-
\t\t\t\t\t(byte & 0xF /* 0b00001111 */) << 12
51-
\t\t\t\t\t| (bytes.getUint8(offset++) & 0x3F /* 0b00111111 */) << 6
52-
\t\t\t\t\t| bytes.getUint8(offset++) & 0x3F /* 0b00111111 */
53-
\t\t\t\t)
54-
\t\t\t\t:
55-
\t\t\t\t(byte =
56-
\t\t\t\t\t((byte & 0x7 /* 0b00000111 */) << 18
57-
\t\t\t\t\t\t| (bytes.getUint8(offset++) & 0x3F /* 0b00111111 */) << 12
58-
\t\t\t\t\t\t| (bytes.getUint8(offset++) & 0x3F /* 0b00111111 */) << 6
59-
\t\t\t\t\t\t| bytes.getUint8(offset++) & 0x3F /* 0b00111111 */
60-
\t\t\t\t\t) - 0x10000
61-
\t\t\t\t, String.fromCharCode(Math.floor(byte / 0x400) + 0xD800, byte % 0x400 + 0xDC00)
62-
\t\t\t\t);
63-
\t}
64-
\treturn _Utils_Tuple2(offset, string);
65-
});`, `var _Bytes_read_string = F3(function(len, bytes, offset)
66-
{
67-
\tvar string = [];
68-
\tvar end = offset + len;
69-
\tfor (; offset < end;)
70-
\t{
71-
\t\tvar byte = bytes.getUint8(offset++);
72-
\t\tstring.push(
73-
\t\t\t(byte < 128)
74-
\t\t\t\t? String.fromCharCode(byte)
75-
\t\t\t\t:
76-
\t\t\t((byte & 0xE0 /* 0b11100000 */) === 0xC0 /* 0b11000000 */)
77-
\t\t\t\t? String.fromCharCode((byte & 0x1F /* 0b00011111 */) << 6 | bytes.getUint8(offset++) & 0x3F /* 0b00111111 */)
78-
\t\t\t\t:
79-
\t\t\t((byte & 0xF0 /* 0b11110000 */) === 0xE0 /* 0b11100000 */)
80-
\t\t\t\t? String.fromCharCode(
81-
\t\t\t\t\t(byte & 0xF /* 0b00001111 */) << 12
82-
\t\t\t\t\t| (bytes.getUint8(offset++) & 0x3F /* 0b00111111 */) << 6
83-
\t\t\t\t\t| bytes.getUint8(offset++) & 0x3F /* 0b00111111 */
84-
\t\t\t\t)
85-
\t\t\t\t:
86-
\t\t\t\t(byte =
87-
\t\t\t\t\t((byte & 0x7 /* 0b00000111 */) << 18
88-
\t\t\t\t\t\t| (bytes.getUint8(offset++) & 0x3F /* 0b00111111 */) << 12
89-
\t\t\t\t\t\t| (bytes.getUint8(offset++) & 0x3F /* 0b00111111 */) << 6
90-
\t\t\t\t\t\t| bytes.getUint8(offset++) & 0x3F /* 0b00111111 */
91-
\t\t\t\t\t) - 0x10000
92-
\t\t\t\t, String.fromCharCode(Math.floor(byte / 0x400) + 0xD800, byte % 0x400 + 0xDC00)
93-
\t\t\t\t)
94-
\t\t);
95-
\t}
96-
\treturn _Utils_Tuple2(offset, string.join(''));
97-
});`);
26+
};`);
9827

9928
fs.writeFileSync(path, data, { encoding: 'utf8', flag: 'w' });

src/Builder/Guida/Outline.elm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ read root =
235235
case outline of
236236
Pkg (GuidaPkgOutline pkg _ _ _ _ deps _ _) ->
237237
Task.pure <|
238-
if not (Dict.member identity Pkg.core deps) && pkg /= Pkg.core then
238+
if not (Dict.member identity Pkg.stdlib deps) && pkg /= Pkg.stdlib then
239239
Err Exit.OutlineNoGuidaPkgCore
240240

241241
else
@@ -250,7 +250,7 @@ read root =
250250
Ok outline
251251

252252
App (GuidaAppOutline _ srcDirs direct indirect _ _) ->
253-
if not (Dict.member identity Pkg.core direct) then
253+
if not (Dict.member identity Pkg.stdlib direct) then
254254
Task.pure <| Err Exit.OutlineNoGuidaAppCore
255255

256256
else if not (Dict.member identity Pkg.json direct) && not (Dict.member identity Pkg.json indirect) then

src/Compiler/Data/Name.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ isCompappendType =
147147

148148
prefixKernel : Name
149149
prefixKernel =
150-
"Elm.Kernel."
150+
"Guida.Kernel."
151151

152152

153153
prefixNumber : Name

src/Compiler/Generate/Html.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sandwich moduleName javascript =
2929
try {
3030
""" ++ javascript ++ """
3131
32-
var app = Elm.""" ++ moduleName ++ """.init({ node: document.getElementById("guida") });
32+
var app = Guida.""" ++ moduleName ++ """.init({ node: document.getElementById("guida") });
3333
}
3434
catch (e)
3535
{

src/Compiler/Generate/JavaScript/Expression.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ generateCall : Mode.Mode -> IO.Canonical -> A.Position -> Opt.Expr -> List Opt.E
458458
generateCall mode parentModule pos func args =
459459
case func of
460460
Opt.VarGlobal _ ((Opt.Global (IO.Canonical pkg _) _) as global) ->
461-
if pkg == Pkg.core then
461+
if pkg == Pkg.core || pkg == Pkg.stdlib then
462462
generateCoreCall mode parentModule pos global args
463463

464464
else

src/Compiler/Guida/ModuleName.elm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,67 +196,67 @@ toComparableCanonical (Canonical ( author, project ) name) =
196196

197197
basics : Canonical
198198
basics =
199-
Canonical Pkg.core Name.basics
199+
Canonical Pkg.stdlib Name.basics
200200

201201

202202
char : Canonical
203203
char =
204-
Canonical Pkg.core Name.char
204+
Canonical Pkg.stdlib Name.char
205205

206206

207207
string : Canonical
208208
string =
209-
Canonical Pkg.core Name.string
209+
Canonical Pkg.stdlib Name.string
210210

211211

212212
maybe : Canonical
213213
maybe =
214-
Canonical Pkg.core Name.maybe
214+
Canonical Pkg.stdlib Name.maybe
215215

216216

217217
result : Canonical
218218
result =
219-
Canonical Pkg.core Name.result
219+
Canonical Pkg.stdlib Name.result
220220

221221

222222
list : Canonical
223223
list =
224-
Canonical Pkg.core Name.list
224+
Canonical Pkg.stdlib Name.list
225225

226226

227227
array : Canonical
228228
array =
229-
Canonical Pkg.core Name.array
229+
Canonical Pkg.stdlib Name.array
230230

231231

232232
dict : Canonical
233233
dict =
234-
Canonical Pkg.core Name.dict
234+
Canonical Pkg.stdlib Name.dict
235235

236236

237237
tuple : Canonical
238238
tuple =
239-
Canonical Pkg.core Name.tuple
239+
Canonical Pkg.stdlib Name.tuple
240240

241241

242242
platform : Canonical
243243
platform =
244-
Canonical Pkg.core Name.platform
244+
Canonical Pkg.stdlib Name.platform
245245

246246

247247
cmd : Canonical
248248
cmd =
249-
Canonical Pkg.core "Platform.Cmd"
249+
Canonical Pkg.stdlib "Platform.Cmd"
250250

251251

252252
sub : Canonical
253253
sub =
254-
Canonical Pkg.core "Platform.Sub"
254+
Canonical Pkg.stdlib "Platform.Sub"
255255

256256

257257
debug : Canonical
258258
debug =
259-
Canonical Pkg.core Name.debug
259+
Canonical Pkg.stdlib Name.debug
260260

261261

262262

src/Compiler/Guida/Package.elm

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Compiler.Guida.Package exposing
1919
, nearbyNames
2020
, parser
2121
, random
22+
, stdlib
2223
, suggestions
2324
, test
2425
, time
@@ -82,7 +83,7 @@ type alias Project =
8283

8384
isKernel : Name -> Bool
8485
isKernel ( author, _ ) =
85-
author == elm || author == elmExplorations
86+
author == elm || author == elmExplorations || author == guida
8687

8788

8889
toChars : Name -> String
@@ -116,7 +117,7 @@ dummyName =
116117

117118
kernel : Name
118119
kernel =
119-
toName elm "kernel"
120+
toName guida "kernel"
120121

121122

122123
core : Name
@@ -179,6 +180,11 @@ test =
179180
toName elmExplorations "test"
180181

181182

183+
stdlib : Name
184+
stdlib =
185+
toName guida "stdlib"
186+
187+
182188
elm : Author
183189
elm =
184190
"elm"
@@ -189,6 +195,11 @@ elmExplorations =
189195
"elm-explorations"
190196

191197

198+
guida : Author
199+
guida =
200+
"guida-lang"
201+
202+
192203

193204
-- PACKAGE SUGGESTIONS
194205

src/Compiler/Parse/Module.elm

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ isCore : ProjectType -> Bool
5353
isCore projectType =
5454
case projectType of
5555
Package pkg ->
56-
pkg == Pkg.core
56+
pkg == Pkg.core || pkg == Pkg.stdlib
5757

5858
Application ->
5959
False
@@ -82,13 +82,40 @@ type alias Module =
8282
}
8383

8484

85+
isCoreModule : Maybe Header -> Bool
86+
isCoreModule maybeHeader =
87+
case maybeHeader of
88+
Just header ->
89+
let
90+
( _, A.At _ name ) =
91+
header.name
92+
in
93+
List.member name
94+
[ Name.basics
95+
, Name.bitwise
96+
, Name.debug
97+
, Name.list
98+
, Name.maybe
99+
, Name.result
100+
, Name.string
101+
, Name.char
102+
, Name.tuple
103+
, Name.platform
104+
, "Platform.Cmd"
105+
, "Platform.Sub"
106+
]
107+
108+
Nothing ->
109+
False
110+
111+
85112
chompModule : SyntaxVersion -> ProjectType -> P.Parser E.Module Module
86113
chompModule syntaxVersion projectType =
87114
chompHeader
88115
|> P.bind
89116
(\( ( initialComments, headerComments ), header ) ->
90117
chompImports
91-
(if isCore projectType then
118+
(if isCore projectType && isCoreModule header then
92119
[]
93120

94121
else

src/Terminal/Init.elm

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,30 +237,28 @@ verify cache connection registry constraints callback =
237237
defaults : Dict ( String, String ) Pkg.Name Con.Constraint
238238
defaults =
239239
Dict.fromList identity
240-
[ ( Pkg.core, Con.anything )
241-
, ( Pkg.browser, Con.anything )
242-
, ( Pkg.html, Con.anything )
240+
[ ( Pkg.stdlib, Con.anything )
243241
]
244242

245243

246244
testDefaults : Dict ( String, String ) Pkg.Name Con.Constraint
247245
testDefaults =
248246
Dict.fromList identity
249-
[ ( Pkg.test, Con.anything )
247+
[ ( Pkg.stdlib, Con.anything )
250248
]
251249

252250

253251
packageDefaults : Dict ( String, String ) Pkg.Name Con.Constraint
254252
packageDefaults =
255253
Dict.fromList identity
256-
[ ( Pkg.core, Con.anything )
254+
[ ( Pkg.stdlib, Con.anything )
257255
]
258256

259257

260258
packageTestDefaults : Dict ( String, String ) Pkg.Name Con.Constraint
261259
packageTestDefaults =
262260
Dict.fromList identity
263-
[ ( Pkg.test, Con.anything )
261+
[ ( Pkg.stdlib, Con.anything )
264262
]
265263

266264

0 commit comments

Comments
 (0)