Skip to content

Commit

Permalink
Share instances of the std prelude
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Cameron <[email protected]>
  • Loading branch information
nrc committed Feb 23, 2025
1 parent d78648f commit b8b51e7
Show file tree
Hide file tree
Showing 96 changed files with 490 additions and 11,387 deletions.
15 changes: 0 additions & 15 deletions docs/kcl/const_const_std-prelude-HALF_TURN.md

This file was deleted.

15 changes: 0 additions & 15 deletions docs/kcl/const_const_std-prelude-QUARTER_TURN.md

This file was deleted.

15 changes: 0 additions & 15 deletions docs/kcl/const_const_std-prelude-THREE_QUARTER_TURN.md

This file was deleted.

15 changes: 0 additions & 15 deletions docs/kcl/const_const_std-prelude-ZERO.md

This file was deleted.

15 changes: 15 additions & 0 deletions docs/kcl/const_std-HALF_TURN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "std::HALF_TURN"
excerpt: ""
layout: manual
---





```js
std::HALF_TURN: number(deg) = 180deg
```


15 changes: 15 additions & 0 deletions docs/kcl/const_std-QUARTER_TURN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "std::QUARTER_TURN"
excerpt: ""
layout: manual
---





```js
std::QUARTER_TURN: number(deg) = 90deg
```


15 changes: 15 additions & 0 deletions docs/kcl/const_std-THREE_QUARTER_TURN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "std::THREE_QUARTER_TURN"
excerpt: ""
layout: manual
---





```js
std::THREE_QUARTER_TURN: number(deg) = 270deg
```


15 changes: 15 additions & 0 deletions docs/kcl/const_std-ZERO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "std::ZERO"
excerpt: ""
layout: manual
---





```js
std::ZERO: number = 0
```


File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions docs/kcl/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ layout: manual
* [Modules](kcl/modules)
* [Known Issues](kcl/KNOWN-ISSUES)
* **`std`**
* [`HALF_TURN`](kcl/const_std-HALF_TURN)
* [`QUARTER_TURN`](kcl/const_std-QUARTER_TURN)
* [`THREE_QUARTER_TURN`](kcl/const_std-THREE_QUARTER_TURN)
* [`ZERO`](kcl/const_std-ZERO)
* [`abs`](kcl/abs)
* [`acos`](kcl/acos)
* [`angleToMatchLengthX`](kcl/angleToMatchLengthX)
Expand Down Expand Up @@ -118,8 +122,3 @@ layout: manual
* [`cos`](kcl/std-math-cos)
* [`sin`](kcl/std-math-sin)
* [`tan`](kcl/std-math-tan)
* **`std::prelude`**
* [`HALF_TURN`](kcl/const_std-prelude-HALF_TURN)
* [`QUARTER_TURN`](kcl/const_std-prelude-QUARTER_TURN)
* [`THREE_QUARTER_TURN`](kcl/const_std-prelude-THREE_QUARTER_TURN)
* [`ZERO`](kcl/const_std-prelude-ZERO)
2 changes: 1 addition & 1 deletion src/wasm-lib/kcl/src/docs/gen_std_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ fn generate_const_from_kcl(cnst: &ConstData, file_name: String) -> Result<()> {
});

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

Ok(())
}
Expand Down
11 changes: 7 additions & 4 deletions src/wasm-lib/kcl/src/docs/kcl_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ impl CollectionVisitor {
}
}
crate::parsing::ast::types::BodyItem::VariableDeclaration(var) if !var.visibility.is_default() => {
let qual_name = if self.name == "prelude" {
"std::".to_owned()
} else {
format!("std::{}::", self.name)
};
let mut dd = match var.kind {
// TODO metadata for args
VariableKind::Fn => DocData::Fn(FnData::from_ast(var, format!("std::{}::", self.name))),
VariableKind::Const => {
DocData::Const(ConstData::from_ast(var, format!("std::{}::", self.name)))
}
VariableKind::Fn => DocData::Fn(FnData::from_ast(var, qual_name)),
VariableKind::Const => DocData::Const(ConstData::from_ast(var, qual_name)),
};

// FIXME this association of metadata with items is pretty flaky.
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/kcl/src/execution/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(super) const SIGNIFICANT_ATTRS: [&str; 2] = [SETTINGS, NO_PRELUDE];
pub(crate) const SETTINGS: &str = "settings";
pub(crate) const SETTINGS_UNIT_LENGTH: &str = "defaultLengthUnit";
pub(crate) const SETTINGS_UNIT_ANGLE: &str = "defaultAngleUnit";
pub(super) const NO_PRELUDE: &str = "no_prelude";
pub(super) const NO_PRELUDE: &str = "no_std";

pub(super) const IMPORT_FORMAT: &str = "format";
pub(super) const IMPORT_FORMAT_VALUES: [&str; 9] = ["fbx", "gltf", "glb", "obj", "ply", "sldprt", "stp", "step", "stl"];
Expand Down
19 changes: 10 additions & 9 deletions src/wasm-lib/kcl/src/execution/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use itertools::{EitherOrBoth, Itertools};
use tokio::sync::RwLock;

use crate::{
execution::{annotations, memory::ProgramMemory, ExecState, ExecutorSettings},
execution::{annotations, memory::ProgramMemory, EnvironmentRef, ExecState, ExecutorSettings},
parsing::ast::types::{Annotation, Node, Program},
walk::Node as WalkNode,
};
Expand Down Expand Up @@ -65,6 +65,7 @@ pub struct OldAstState {
pub exec_state: ExecState,
/// The last settings used for execution.
pub settings: crate::execution::ExecutorSettings,
pub result_env: EnvironmentRef,
}

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

let (program, ctx, _) = parse_execute(new).await.unwrap();
let (program, _, ctx, _) = parse_execute(new).await.unwrap();

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

let (program_old, ctx, _) = parse_execute(old).await.unwrap();
let (program_old, _, ctx, _) = parse_execute(old).await.unwrap();

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

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

let (program, ctx, _) = parse_execute(old).await.unwrap();
let (program, _, ctx, _) = parse_execute(old).await.unwrap();

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

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

let (program, ctx, _) = parse_execute(old).await.unwrap();
let (program, _, ctx, _) = parse_execute(old).await.unwrap();

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

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

let (program, mut ctx, _) = parse_execute(new).await.unwrap();
let (program, _, mut ctx, _) = parse_execute(new).await.unwrap();

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

let (program, mut ctx, _) = parse_execute(new).await.unwrap();
let (program, _, mut ctx, _) = parse_execute(new).await.unwrap();

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

let (program, mut ctx, _) = parse_execute(new).await.unwrap();
let (program, _, mut ctx, _) = parse_execute(new).await.unwrap();

// Change the settings.
ctx.settings.highlight_edges = !ctx.settings.highlight_edges;
Expand Down Expand Up @@ -582,7 +583,7 @@ startSketchOn('XY')
startSketchOn('XY')
"#;

let (program, ctx, _) = parse_execute(old_code).await.unwrap();
let (program, _, ctx, _) = parse_execute(old_code).await.unwrap();

let mut new_program = crate::Program::parse_no_errs(new_code).unwrap();
new_program.compute_digest();
Expand Down
Loading

0 comments on commit b8b51e7

Please sign in to comment.