···3030 which: Which,
3131 no_print_progress: bool,
3232) -> Result<(), Error> {
3333+ // Don't exit on ctrl+c as it is used by child erlang shell
3434+ ctrlc::set_handler(move || {}).expect("Error setting Ctrl-C handler");
3335 let command = setup(
3436 paths,
3537 arguments,
···4345 std::process::exit(status);
4446}
45474646-fn setup(
4848+pub(crate) fn setup(
4749 paths: &ProjectPaths,
4850 arguments: Vec<String>,
4951 target: Option<Target>,
···122124123125 // A module can not be run if it does not exist or does not have a public main function.
124126 let main_function = get_or_suggest_main_function(built, &module, target)?;
125125-126126- // Don't exit on ctrl+c as it is used by child erlang shell
127127- ctrlc::set_handler(move || {}).expect("Error setting Ctrl-C handler");
128127129128 telemetry.running(&format!("{module}.main"));
130129
···1717import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1818import {
1919 toList,
2020+ CustomType as $CustomType,
2121+ bitArraySlice,
2222+ bitArraySliceToInt,
2023 BitArray as $BitArray,
2124 List as $List,
2225 UtfCodepoint as $UtfCodepoint,
2323- CustomType as $CustomType,
2426} from "../gleam.mjs";
25272628export function wibble(n) {
···1515----- COMPILED JAVASCRIPT
1616import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1717import {
1818+ CustomType as $CustomType,
1919+ bitArraySlice,
2020+ bitArraySliceToInt,
1821 BitArray as $BitArray,
1922 List as $List,
2023 UtfCodepoint as $UtfCodepoint,
2121- CustomType as $CustomType,
2224} from "../gleam.mjs";
23252426export function main() {
···1414----- COMPILED JAVASCRIPT
1515import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1616import {
1717+ CustomType as $CustomType,
1818+ bitArraySlice,
1919+ bitArraySliceToInt,
1720 BitArray as $BitArray,
1821 List as $List,
1922 UtfCodepoint as $UtfCodepoint,
2020- CustomType as $CustomType,
2123} from "../gleam.mjs";
22242325export function main() {
···1414----- COMPILED JAVASCRIPT
1515import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1616import {
1717+ CustomType as $CustomType,
1818+ bitArraySlice,
1919+ bitArraySliceToInt,
1720 BitArray as $BitArray,
1821 List as $List,
1922 UtfCodepoint as $UtfCodepoint,
2020- CustomType as $CustomType,
2123} from "../gleam.mjs";
22242325function wibble(n, m) {
···1212----- COMPILED JAVASCRIPT
1313import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1414import {
1515+ CustomType as $CustomType,
1516 makeError,
1717+ bitArraySlice,
1818+ bitArraySliceToInt,
1619 BitArray as $BitArray,
1720 List as $List,
1821 UtfCodepoint as $UtfCodepoint,
1919- CustomType as $CustomType,
2022} from "../gleam.mjs";
21232224export function main() {
···1212----- COMPILED JAVASCRIPT
1313import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1414import {
1515+ CustomType as $CustomType,
1616+ bitArraySlice,
1717+ bitArraySliceToInt,
1518 BitArray as $BitArray,
1619 List as $List,
1720 UtfCodepoint as $UtfCodepoint,
1818- CustomType as $CustomType,
1921} from "../gleam.mjs";
20222123export function main() {
···1515import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1616import * as $inspect from "../../other/other/inspect.mjs";
1717import {
1818+ CustomType as $CustomType,
1919+ bitArraySlice,
2020+ bitArraySliceToInt,
1821 BitArray as $BitArray,
1922 List as $List,
2023 UtfCodepoint as $UtfCodepoint,
2121- CustomType as $CustomType,
2224} from "../gleam.mjs";
23252426export function main() {
···2020import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
2121import {
2222 toList,
2323+ CustomType as $CustomType,
2424+ bitArraySlice,
2525+ bitArraySliceToInt,
2326 BitArray as $BitArray,
2427 List as $List,
2528 UtfCodepoint as $UtfCodepoint,
2626- CustomType as $CustomType,
2729} from "../gleam.mjs";
28302931export function wibble(n) {
···1313----- COMPILED JAVASCRIPT
1414import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1515import {
1616+ CustomType as $CustomType,
1717+ bitArraySlice,
1818+ bitArraySliceToInt,
1619 BitArray as $BitArray,
1720 List as $List,
1821 UtfCodepoint as $UtfCodepoint,
1919- CustomType as $CustomType,
2022} from "../gleam.mjs";
21232224export function main() {
···4545function echo$inspectDict(map) {
4646 let body = "dict.from_list([";
4747 let first = true;
4848+4949+ let key_value_pairs = [];
4850 map.forEach((value, key) => {
5151+ key_value_pairs.push([key, value]);
5252+ });
5353+ key_value_pairs.sort();
5454+ key_value_pairs.forEach(([key, value]) => {
4955 if (!first) body = body + ", ";
5056 body = body + "#(" + echo$inspect(key) + ", " + echo$inspect(value) + ")";
5157 first = false;
···8591 if (Array.isArray(v)) return `#(${v.map(echo$inspect).join(", ")})`;
8692 if (v instanceof $List) return `[${v.toArray().map(echo$inspect).join(", ")}]`;
8793 if (v instanceof $UtfCodepoint) return `//utfcodepoint(${String.fromCodePoint(v.value)})`;
8888- if (v instanceof $BitArray) return `<<${Array.from(v.buffer).join(", ")}>>`;
9494+ if (v instanceof $BitArray) return echo$inspectBitArray(v);
8995 if (v instanceof $CustomType) return echo$inspectCustomType(v);
9096 if (echo$isDict(v)) return echo$inspectDict(v);
9197 if (v instanceof Set) return `//js(Set(${[...v].map(echo$inspect).join(", ")}))`;
···97103 return `//fn(${args.join(", ")}) { ... }`;
98104 }
99105 return echo$inspectObject(v);
106106+}
107107+108108+function echo$inspectBitArray(bitArray) {
109109+ // We take all the aligned bytes of the bit array starting from `bitOffset`
110110+ // up to the end of the section containing all the aligned bytes.
111111+ let endOfAlignedBytes = bitArray.bitOffset + 8 * Math.trunc(bitArray.bitSize / 8);
112112+ let alignedBytes = bitArraySlice(bitArray, bitArray.bitOffset, endOfAlignedBytes);
113113+114114+ // Now we need to get the remaining unaligned bits at the end of the bit array.
115115+ // They will start after `endOfAlignedBytes` and end at `bitArray.bitSize`
116116+ let remainingUnalignedBits = bitArray.bitSize % 8;
117117+ if (remainingUnalignedBits > 0) {
118118+ let remainingBits = bitArraySliceToInt(bitArray, endOfAlignedBytes, bitArray.bitSize, false, false);
119119+ let alignedBytesArray = Array.from(alignedBytes.rawBuffer);
120120+ let suffix = `${remainingBits}:size(${remainingUnalignedBits})`;
121121+ if (alignedBytesArray.length === 0) {
122122+ return `<<${suffix}>>`;
123123+ } else {
124124+ return `<<${Array.from(alignedBytes.rawBuffer).join(", ")}, ${suffix}>>`;
125125+ }
126126+ } else {
127127+ return `<<${Array.from(alignedBytes.rawBuffer).join(", ")}>>`;
128128+ }
100129}
101130102131function echo$isDict(value) {
···11pub fn main() {
22 echo #()
33 echo #(True, 1, "hello")
44- target_specific()
55-}
66-77-@target(erlang)
88-pub type Wibble {
99- Wibble
1010-}
1111-1212-@target(erlang)
1313-pub fn target_specific() {
1414- // On erlang a tuple with an enum variant as the first item is printed as a
1515- // type with fields.
1616- echo #(Wibble, 1, "hello")
1717-}
1818-1919-@target(javascript)
2020-pub fn target_specific() {
2121- Nil
224}