Skip to content

Commit b8b51e7

Browse files
committed
Share instances of the std prelude
Signed-off-by: Nick Cameron <[email protected]>
1 parent d78648f commit b8b51e7

File tree

96 files changed

+490
-11387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+490
-11387
lines changed

docs/kcl/const_const_std-prelude-HALF_TURN.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/kcl/const_const_std-prelude-QUARTER_TURN.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/kcl/const_const_std-prelude-THREE_QUARTER_TURN.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/kcl/const_const_std-prelude-ZERO.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/kcl/const_std-HALF_TURN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "std::HALF_TURN"
3+
excerpt: ""
4+
layout: manual
5+
---
6+
7+
8+
9+
10+
11+
```js
12+
std::HALF_TURN: number(deg) = 180deg
13+
```
14+
15+

docs/kcl/const_std-QUARTER_TURN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "std::QUARTER_TURN"
3+
excerpt: ""
4+
layout: manual
5+
---
6+
7+
8+
9+
10+
11+
```js
12+
std::QUARTER_TURN: number(deg) = 90deg
13+
```
14+
15+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "std::THREE_QUARTER_TURN"
3+
excerpt: ""
4+
layout: manual
5+
---
6+
7+
8+
9+
10+
11+
```js
12+
std::THREE_QUARTER_TURN: number(deg) = 270deg
13+
```
14+
15+

docs/kcl/const_std-ZERO.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "std::ZERO"
3+
excerpt: ""
4+
layout: manual
5+
---
6+
7+
8+
9+
10+
11+
```js
12+
std::ZERO: number = 0
13+
```
14+
15+
File renamed without changes.
File renamed without changes.
File renamed without changes.

docs/kcl/index.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ layout: manual
1010
* [Modules](kcl/modules)
1111
* [Known Issues](kcl/KNOWN-ISSUES)
1212
* **`std`**
13+
* [`HALF_TURN`](kcl/const_std-HALF_TURN)
14+
* [`QUARTER_TURN`](kcl/const_std-QUARTER_TURN)
15+
* [`THREE_QUARTER_TURN`](kcl/const_std-THREE_QUARTER_TURN)
16+
* [`ZERO`](kcl/const_std-ZERO)
1317
* [`abs`](kcl/abs)
1418
* [`acos`](kcl/acos)
1519
* [`angleToMatchLengthX`](kcl/angleToMatchLengthX)
@@ -118,8 +122,3 @@ layout: manual
118122
* [`cos`](kcl/std-math-cos)
119123
* [`sin`](kcl/std-math-sin)
120124
* [`tan`](kcl/std-math-tan)
121-
* **`std::prelude`**
122-
* [`HALF_TURN`](kcl/const_std-prelude-HALF_TURN)
123-
* [`QUARTER_TURN`](kcl/const_std-prelude-QUARTER_TURN)
124-
* [`THREE_QUARTER_TURN`](kcl/const_std-prelude-THREE_QUARTER_TURN)
125-
* [`ZERO`](kcl/const_std-prelude-ZERO)

src/wasm-lib/kcl/src/docs/gen_std_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ fn generate_const_from_kcl(cnst: &ConstData, file_name: String) -> Result<()> {
457457
});
458458

459459
let output = hbs.render("const", &data)?;
460-
expectorate::assert_contents(format!("../../../docs/kcl/const_{}.md", file_name), &output);
460+
expectorate::assert_contents(format!("../../../docs/kcl/{}.md", file_name), &output);
461461

462462
Ok(())
463463
}

src/wasm-lib/kcl/src/docs/kcl_doc.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ impl CollectionVisitor {
4949
}
5050
}
5151
crate::parsing::ast::types::BodyItem::VariableDeclaration(var) if !var.visibility.is_default() => {
52+
let qual_name = if self.name == "prelude" {
53+
"std::".to_owned()
54+
} else {
55+
format!("std::{}::", self.name)
56+
};
5257
let mut dd = match var.kind {
5358
// TODO metadata for args
54-
VariableKind::Fn => DocData::Fn(FnData::from_ast(var, format!("std::{}::", self.name))),
55-
VariableKind::Const => {
56-
DocData::Const(ConstData::from_ast(var, format!("std::{}::", self.name)))
57-
}
59+
VariableKind::Fn => DocData::Fn(FnData::from_ast(var, qual_name)),
60+
VariableKind::Const => DocData::Const(ConstData::from_ast(var, qual_name)),
5861
};
5962

6063
// FIXME this association of metadata with items is pretty flaky.

src/wasm-lib/kcl/src/execution/annotations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(super) const SIGNIFICANT_ATTRS: [&str; 2] = [SETTINGS, NO_PRELUDE];
1515
pub(crate) const SETTINGS: &str = "settings";
1616
pub(crate) const SETTINGS_UNIT_LENGTH: &str = "defaultLengthUnit";
1717
pub(crate) const SETTINGS_UNIT_ANGLE: &str = "defaultAngleUnit";
18-
pub(super) const NO_PRELUDE: &str = "no_prelude";
18+
pub(super) const NO_PRELUDE: &str = "no_std";
1919

2020
pub(super) const IMPORT_FORMAT: &str = "format";
2121
pub(super) const IMPORT_FORMAT_VALUES: [&str; 9] = ["fbx", "gltf", "glb", "obj", "ply", "sldprt", "stp", "step", "stl"];

src/wasm-lib/kcl/src/execution/cache.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use itertools::{EitherOrBoth, Itertools};
66
use tokio::sync::RwLock;
77

88
use crate::{
9-
execution::{annotations, memory::ProgramMemory, ExecState, ExecutorSettings},
9+
execution::{annotations, memory::ProgramMemory, EnvironmentRef, ExecState, ExecutorSettings},
1010
parsing::ast::types::{Annotation, Node, Program},
1111
walk::Node as WalkNode,
1212
};
@@ -65,6 +65,7 @@ pub struct OldAstState {
6565
pub exec_state: ExecState,
6666
/// The last settings used for execution.
6767
pub settings: crate::execution::ExecutorSettings,
68+
pub result_env: EnvironmentRef,
6869
}
6970

7071
/// The result of a cache check.
@@ -267,7 +268,7 @@ firstSketch = startSketchOn('XY')
267268
// Remove the end face for the extrusion.
268269
shell(firstSketch, faces = ['end'], thickness = 0.25)"#;
269270

270-
let (program, ctx, _) = parse_execute(new).await.unwrap();
271+
let (program, _, ctx, _) = parse_execute(new).await.unwrap();
271272

272273
let result = get_changed_program(
273274
CacheInformation {
@@ -310,7 +311,7 @@ firstSketch = startSketchOn('XY')
310311
// Remove the end face for the extrusion.
311312
shell(firstSketch, faces = ['end'], thickness = 0.25)"#;
312313

313-
let (program_old, ctx, _) = parse_execute(old).await.unwrap();
314+
let (program_old, _, ctx, _) = parse_execute(old).await.unwrap();
314315

315316
let program_new = crate::Program::parse_no_errs(new).unwrap();
316317

@@ -355,7 +356,7 @@ firstSketch = startSketchOn('XY')
355356
// Remove the end face for the extrusion.
356357
shell(firstSketch, faces = ['end'], thickness = 0.25)"#;
357358

358-
let (program, ctx, _) = parse_execute(old).await.unwrap();
359+
let (program, _, ctx, _) = parse_execute(old).await.unwrap();
359360

360361
let program_new = crate::Program::parse_no_errs(new).unwrap();
361362

@@ -404,7 +405,7 @@ firstSketch = startSketchOn('XY')
404405
// Remove the end face for the extrusion.
405406
shell(firstSketch, faces = ['end'], thickness = 0.25)"#;
406407

407-
let (program, ctx, _) = parse_execute(old).await.unwrap();
408+
let (program, _, ctx, _) = parse_execute(old).await.unwrap();
408409

409410
let program_new = crate::Program::parse_no_errs(new).unwrap();
410411

@@ -438,7 +439,7 @@ firstSketch = startSketchOn('XY')
438439
// Remove the end face for the extrusion.
439440
shell(firstSketch, faces = ['end'], thickness = 0.25)"#;
440441

441-
let (program, mut ctx, _) = parse_execute(new).await.unwrap();
442+
let (program, _, mut ctx, _) = parse_execute(new).await.unwrap();
442443

443444
// Change the settings to cm.
444445
ctx.settings.units = crate::UnitLength::Cm;
@@ -480,7 +481,7 @@ firstSketch = startSketchOn('XY')
480481
// Remove the end face for the extrusion.
481482
shell(firstSketch, faces = ['end'], thickness = 0.25)"#;
482483

483-
let (program, mut ctx, _) = parse_execute(new).await.unwrap();
484+
let (program, _, mut ctx, _) = parse_execute(new).await.unwrap();
484485

485486
// Change the settings.
486487
ctx.settings.show_grid = !ctx.settings.show_grid;
@@ -515,7 +516,7 @@ firstSketch = startSketchOn('XY')
515516
// Remove the end face for the extrusion.
516517
shell(firstSketch, faces = ['end'], thickness = 0.25)"#;
517518

518-
let (program, mut ctx, _) = parse_execute(new).await.unwrap();
519+
let (program, _, mut ctx, _) = parse_execute(new).await.unwrap();
519520

520521
// Change the settings.
521522
ctx.settings.highlight_edges = !ctx.settings.highlight_edges;
@@ -582,7 +583,7 @@ startSketchOn('XY')
582583
startSketchOn('XY')
583584
"#;
584585

585-
let (program, ctx, _) = parse_execute(old_code).await.unwrap();
586+
let (program, _, ctx, _) = parse_execute(old_code).await.unwrap();
586587

587588
let mut new_program = crate::Program::parse_no_errs(new_code).unwrap();
588589
new_program.compute_digest();

0 commit comments

Comments
 (0)