Skip to content

Commit

Permalink
feat: Add __jsArrayToList__ to js internals and fix small parsing iss…
Browse files Browse the repository at this point in the history
…ue for dicts within jsx
  • Loading branch information
aboeglin committed Aug 15, 2022
1 parent 6a8bd38 commit e84b584
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .snapshots/should_build_all_internal_JS_functions/golden
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ global.__listToJSArray__ = (list) => {
return res
}

global.__jsArrayToList__ = (arr) => {
let res = null

for (let i = arr.length - 1; i >= 0; i--) {
let head = { v: arr[i], n: res }
res = head
}

return res
}

global.__listCtorSpread__ = (_spread, _next) => {
if (_spread === null) {
return _next;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ global.__listToJSArray__ = (list) => {
return res
}

global.__jsArrayToList__ = (arr) => {
let res = null

for (let i = arr.length - 1; i >= 0; i--) {
let head = { v: arr[i], n: res }
res = head
}

return res
}

global.__listCtorSpread__ = (_spread, _next) => {
if (_spread === null) {
return _next;
Expand Down
17 changes: 17 additions & 0 deletions compiler/main/Generate/JSInternals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ generateInternalsModuleContent target optimized coverage =
<> "\n"
<> listToJSArray target
<> "\n"
<> jsArrayToList target
<> "\n"
<> listConstructorSpreadFn target
<> "\n"
<> if coverage then "\n" <> hpFnWrap <> "\n" <> hpLineWrap else ""
Expand Down Expand Up @@ -269,6 +271,21 @@ listToJSArray target =
, "}"
]

jsArrayToList :: Target -> String
jsArrayToList target =
unlines
[ getGlobalForTarget target <> "." <> "__jsArrayToList__ = (arr) => {"
, " let res = null"
, ""
, " for (let i = arr.length - 1; i >= 0; i--) {"
, " let head = { v: arr[i], n: res }"
, " res = head"
, " }"
, ""
, " return res"
, "}"
]

listConstructorSpreadFn :: Target -> String
listConstructorSpreadFn target =
unlines
Expand Down
1 change: 1 addition & 0 deletions compiler/main/Parse/Madlib/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ mapToken tokenizer (posn, prevChar, pending, input) len = do

TokenLeftDoubleCurly ->
if sc /= instanceHeader then do
pushStartCode 0
pushStartCode 0
return TokenLeftDoubleCurly
else
Expand Down
4 changes: 2 additions & 2 deletions madlib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ cabal-version: 2.0
--
-- see: https://github.com/sol/hpack
--
-- hash: 3c36d8ff8b835f63fa4e6f5a0d2d964b8ddb4de47e5e6c47dac1b4f6197d532f
-- hash: 29c5cc1908364a493c67fa28b063e90f6353a77b6c85e6fa590f941d36977473

name: madlib
version: 0.13.5
version: 0.13.6
description: Please see the README on GitHub at <https://github.com/madlib-lang/madlib#readme>
homepage: https://github.com/madlib-lang/madlib#readme
bug-reports: https://github.com/madlib-lang/madlib/issues
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: madlib
version: 0.13.5
version: 0.13.6
github: "madlib-lang/madlib"
license: BSD3
author: "Arnaud Boeglin, Brekk Bockrath"
Expand Down
2 changes: 1 addition & 1 deletion pkg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@madlib-lang/madlib",
"version": "0.13.5",
"version": "0.13.6",
"main": "./src/run.js",
"bin": {
"madlib": "src/run.js"
Expand Down

0 comments on commit e84b584

Please sign in to comment.