Skip to content

Commit

Permalink
trying to auto generate a page that will report what functions need t…
Browse files Browse the repository at this point in the history
…o be implemented or not...
  • Loading branch information
gpwclark committed Jan 26, 2025
1 parent a8728bc commit 1b8a520
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 26 additions & 9 deletions doc/mdbook-slosh-eval/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions doc/mdbook-slosh-eval/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ log = "*"
pulldown-cmark = "0.10.2"
pulldown-cmark-to-cmark = "13.0.0"
slosh_lib = { path = "../../slosh_lib" }
slosh_test_lib = { path = "../../slosh_test_lib" }
toml = "*"

[workspace]
10 changes: 7 additions & 3 deletions doc/mdbook-slosh-eval/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern crate pulldown_cmark;
extern crate pulldown_cmark_to_cmark;

use crate::slosh_eval_lib::EvalSlosh;
use slosh_test_lib::docs;
use clap::{Arg, ArgMatches, Command};
use mdbook::book::{Book, BookItem};
use mdbook::errors::Error;
Expand All @@ -12,6 +13,8 @@ use semver::{Version, VersionReq};
use std::io;
use std::process;

pub const SLOSH_AS_CODE_BLOCK_TAG: &str = "slosh";

pub fn make_app() -> Command {
Command::new("mdbook-slosh-eval")
.about(
Expand Down Expand Up @@ -112,7 +115,7 @@ mod slosh_eval_lib {
match event {
Event::Start(Tag::CodeBlock(ref kind)) => match kind {
CodeBlockKind::Fenced(name) if !tracking => {
if name.starts_with("slosh") && !name.contains("no-execute") {
if name.starts_with(SLOSH_AS_CODE_BLOCK_TAG) && !name.contains("no-execute") {
slosh_code_block_num += 1;
log::debug!(
"File: {}: block #{}",
Expand Down Expand Up @@ -142,10 +145,10 @@ mod slosh_eval_lib {
buf += "\n";
}
tracking = false;
log::debug!("```slosh\n{}", buf);
log::debug!("```{}\n{}", SLOSH_AS_CODE_BLOCK_TAG, buf);
log::debug!("```");
events.push(Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(
"slosh".into(),
SLOSH_AS_CODE_BLOCK_TAG.into(),
))));
events.push(Event::Text(buf.clone().into()));
events.push(Event::End(TagEnd::CodeBlock));
Expand Down Expand Up @@ -187,6 +190,7 @@ mod slosh_eval_lib {

fn exec_code(code: String) -> String {
let mut vm = slosh_lib::new_slosh_vm_with_builtins_and_core();
docs::add_builtins(&mut vm);

let code = format!(
r#"(import test)
Expand Down
2 changes: 2 additions & 0 deletions doc/mk-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ export PATH="$PATH:./mdbook-slosh-eval/target/debug"
#
#../target/debug/slosh -c "(build-doc \"${PWD}\")"

# doing this because im tryingto use the mk-site.slosh script but don't
# see a need to re-write this shell script in slosh at this moment too.
./search-hack-patch.sh
1 change: 1 addition & 0 deletions doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Syntax and Macros](./syntax-and-macros.md)
- [Iterators](./iterators.md)
- [Shell Redirects](./shell-redirects.md)
- [Transition from Legacy](./transition-from-legacy.md)

# General

Expand Down
10 changes: 10 additions & 0 deletions doc/src/transition-from-legacy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Transition Tracking

## TODO sort these and then try to get out of the google doc (maybe need a hash map that pre-maps the one's we're skipping so the count is accurate)
```slosh
(get-globals-sorted)
```

```slosh
(legacy_forms)
```
1 change: 1 addition & 0 deletions slosh_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"

[dependencies]
slosh_lib = { path = "../slosh_lib" }
slosh_test_lib = { path = "../slosh_test_lib" }
regex = { workspace = true }
lazy_static = { workspace = true }
bridge_adapters = { path = "../bridge_adapters" }
Expand Down
6 changes: 3 additions & 3 deletions slosh_test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
pub mod docs;

use slosh_test_lib::docs;
use bridge_adapters::add_builtin;
use compile_state::state::SloshVm;
use sl_compiler::load_eval::run_reader;
use sl_compiler::Reader;
use slosh_lib::run;
use slvm::{VMError, VMResult, Value};
use std::process;
use slvm::{VMError, VMResult, Value};

pub const VERSION_STRING: &str = env!("VERSION_STRING");

Expand All @@ -17,6 +16,7 @@ fn version(vm: &mut SloshVm, registers: &[Value]) -> VMResult<Value> {
Ok(vm.alloc_string(VERSION_STRING.to_string()))
}


fn modify_vm(vm: &mut SloshVm) {
docs::add_builtins(vm);

Expand Down
3 changes: 3 additions & 0 deletions slosh_test_lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The slosh_test crate contains some special functions that use additional dependencies
used to build slosh documentation and run the slosh tests. These actions can
be performed manually but are also done by CI.
105 changes: 105 additions & 0 deletions slosh_test_lib/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use std::env::consts::{ARCH, OS};
use std::process::Command;

use chrono::prelude::Utc;

#[cfg(debug_assertions)]
const BUILD_TYPE: &str = "debug";
#[cfg(not(debug_assertions))]
const BUILD_TYPE: &str = "release";

fn main() {
let version_string = if have_git() {
format!(
"{} {} ({}:{}{}, {} build, {} [{}], {} UTC [{}])",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
get_branch_name(),
get_commit_hash(),
if is_working_tree_clean() { "" } else { "+" },
BUILD_TYPE,
OS,
ARCH,
Utc::now().format("%b %d %Y, %T"),
get_rustc_version(),
)
} else {
format!(
"{} {} ({} build, {} [{}], {} UTC [{}])",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
BUILD_TYPE,
OS,
ARCH,
Utc::now().format("%b %d %Y, %T"),
get_rustc_version(),
)
};

println!("cargo:rustc-env=VERSION_STRING={}", version_string);
}

fn have_git() -> bool {
Command::new("git")
.arg("--version")
.current_dir(env!("CARGO_MANIFEST_DIR"))
.output()
.is_ok()
}

fn get_commit_hash() -> String {
let output = Command::new("git")
.arg("log")
.arg("-1")
.arg("--pretty=format:%h") // Abbreviated commit hash
// .arg("--pretty=format:%H") // Full commit hash
.current_dir(env!("CARGO_MANIFEST_DIR"))
.output()
.unwrap();

assert!(output.status.success());

String::from_utf8_lossy(&output.stdout).to_string()
}

fn get_branch_name() -> String {
let output = Command::new("git")
.arg("rev-parse")
.arg("--abbrev-ref")
.arg("HEAD")
.current_dir(env!("CARGO_MANIFEST_DIR"))
.output()
.unwrap();

assert!(output.status.success());

String::from_utf8_lossy(&output.stdout)
.trim_end()
.to_string()
}

fn is_working_tree_clean() -> bool {
let status = Command::new("git")
.arg("diff")
.arg("--quiet")
.arg("--exit-code")
.current_dir(env!("CARGO_MANIFEST_DIR"))
.status()
.unwrap();

status.code().unwrap() == 0
}

fn get_rustc_version() -> String {
let output = Command::new("rustc")
.arg("--version")
.current_dir(env!("CARGO_MANIFEST_DIR"))
.output()
.unwrap();

assert!(output.status.success());

String::from_utf8_lossy(&output.stdout)
.trim_end()
.to_string()
}
28 changes: 28 additions & 0 deletions slosh_test_lib/run-tests.slosh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env slosh_test

(let (globals (get-globals-sorted)
globals-len (len globals)
i 0
failing-tests {})
(while (< i globals-len)
(prn "Symbol: " globals.~i)
(prn "===")
(let (doc (doc-map globals.~i))
;; for some reason printing usage for vec-slice causes rust to panic with 'Handle 2045 is not a string!'
(prn "Usage: " (str doc.:usage))
(prn "Description: " (str doc.:description))
(prn "Section: " (str doc.:section))
(if (not (err? (get failing-tests (->key globals.~i))))
(prn "~~~~~~~~~~~~~~~~~~~~~ Skipping failing test")
(let (example (str doc.:example)
read-in (read-all example))
(prn "Example: " example)
(dotimes-i j (len read-in)
(let (line (prn (str read-in.~j))
evaled (eval read-in.~j))
(if (err? evaled)
(do (prn "Err: " (str evaled))
(err (mk-err :test (str "Err: " evaled))))
(prn "Result: " (str evaled)))))))
(prn "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
(inc! i))))
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions slosh_test_lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod docs;
Loading

0 comments on commit 1b8a520

Please sign in to comment.