浏览代码

Rename project to Numbat

David Peter 2 年之前
父节点
当前提交
ae7be9b3e4
共有 92 个文件被更改,包括 137 次插入139 次删除
  1. 25 25
      Cargo.lock
  2. 3 3
      Cargo.toml
  3. 6 6
      README.md
  4. 1 1
      book/book.toml
  5. 1 1
      book/src/introduction.md
  6. 4 4
      book/src/type-system.md
  7. 0 0
      examples/air_resistance.nbt
  8. 0 0
      examples/assert_eq_success.nbt
  9. 0 0
      examples/barometric_formula.nbt
  10. 0 0
      examples/custom_dimensions.nbt
  11. 0 0
      examples/earth_mass.nbt
  12. 0 0
      examples/generics.nbt
  13. 0 0
      examples/inter_dot_spacing.nbt
  14. 0 0
      examples/kinetic_energy.nbt
  15. 0 0
      examples/name_resolution_error/alias_clash.nbt
  16. 0 0
      examples/name_resolution_error/duplicate_unit.nbt
  17. 0 0
      examples/name_resolution_error/duplicate_variable.nbt
  18. 0 0
      examples/name_resolution_error/function_name_clash.nbt
  19. 0 0
      examples/name_resolution_error/function_name_clash2.nbt
  20. 0 0
      examples/name_resolution_error/prefix_1.nbt
  21. 0 0
      examples/name_resolution_error/prefix_2.nbt
  22. 0 0
      examples/name_resolution_error/unit_clashes_with_variables.nbt
  23. 0 0
      examples/name_resolution_error/variable_clashes_with_unit.nbt
  24. 0 0
      examples/nested_function_calls.nbt
  25. 0 0
      examples/parse_error/division_by_zero_in_dimension_expr.nbt
  26. 0 0
      examples/parse_error/duplicated_operator.nbt
  27. 0 0
      examples/parse_error/expected_comma_or_right_angle_bracket.nbt
  28. 0 0
      examples/parse_error/expected_left_paren_in_fn_definition.nbt
  29. 0 0
      examples/parse_error/expected_type_parameter_name.nbt
  30. 0 0
      examples/parse_error/trailing_characters.nbt
  31. 0 0
      examples/parse_error/unexpected_character.nbt
  32. 0 0
      examples/pendulum.nbt
  33. 0 0
      examples/print.nbt
  34. 0 0
      examples/runtime_error/assert_eq_failure1.nbt
  35. 0 0
      examples/runtime_error/assert_eq_failure2.nbt
  36. 0 0
      examples/runtime_error/assert_eq_failure3.nbt
  37. 0 0
      examples/runtime_error/division_by_zero.nbt
  38. 0 0
      examples/stopping_distance.nbt
  39. 0 0
      examples/time_units.nbt
  40. 0 0
      examples/typecheck_error/can_not_add_apples_to_oranges.nbt
  41. 0 0
      examples/typecheck_error/function_called_with_wrong_argument_types.nbt
  42. 0 0
      examples/xkcd2585.nbt
  43. 3 3
      numbat-cli/Cargo.toml
  44. 18 20
      numbat-cli/src/main.rs
  45. 12 12
      numbat-cli/tests/integration.rs
  46. 0 0
      numbat-wasm/.gitignore
  47. 0 0
      numbat-wasm/Cargo.lock
  48. 2 2
      numbat-wasm/Cargo.toml
  49. 0 0
      numbat-wasm/README.md
  50. 3 3
      numbat-wasm/src/lib.rs
  51. 0 0
      numbat-wasm/src/utils.rs
  52. 1 1
      numbat-wasm/tests/web.rs
  53. 0 0
      numbat-wasm/www/.gitignore
  54. 0 0
      numbat-wasm/www/bootstrap.js
  55. 1 1
      numbat-wasm/www/index.html
  56. 2 2
      numbat-wasm/www/index.js
  57. 0 0
      numbat-wasm/www/package-lock.json
  58. 2 2
      numbat-wasm/www/package.json
  59. 0 0
      numbat-wasm/www/webpack.config.js
  60. 1 1
      numbat/Cargo.toml
  61. 0 0
      numbat/src/arithmetic.rs
  62. 0 0
      numbat/src/ast.rs
  63. 0 0
      numbat/src/bytecode_interpreter.rs
  64. 0 0
      numbat/src/decorator.rs
  65. 0 0
      numbat/src/dimension.rs
  66. 0 0
      numbat/src/ffi.rs
  67. 0 0
      numbat/src/interpreter.rs
  68. 13 13
      numbat/src/lib.rs
  69. 0 0
      numbat/src/name_resolution.rs
  70. 0 0
      numbat/src/number.rs
  71. 1 1
      numbat/src/parser.rs
  72. 0 0
      numbat/src/prefix.rs
  73. 0 0
      numbat/src/prefix_parser.rs
  74. 0 0
      numbat/src/prefix_transformer.rs
  75. 0 0
      numbat/src/pretty_print.rs
  76. 0 0
      numbat/src/product.rs
  77. 1 1
      numbat/src/quantity.rs
  78. 0 0
      numbat/src/registry.rs
  79. 0 0
      numbat/src/span.rs
  80. 0 0
      numbat/src/tokenizer.rs
  81. 1 1
      numbat/src/typechecker.rs
  82. 0 0
      numbat/src/typed_ast.rs
  83. 0 0
      numbat/src/unit.rs
  84. 0 0
      numbat/src/unit_registry.rs
  85. 0 0
      numbat/src/vm.rs
  86. 18 18
      numbat/tests/prelude_and_examples.rs
  87. 0 0
      prelude.nbt
  88. 2 2
      vscode-extension/CHANGELOG.md
  89. 2 2
      vscode-extension/README.md
  90. 9 9
      vscode-extension/package.json
  91. 4 4
      vscode-extension/syntaxes/insect.tmLanguage.json
  92. 1 1
      vscode-extension/vsc-extension-quickstart.md

+ 25 - 25
Cargo.lock

@@ -258,31 +258,6 @@ dependencies = [
  "libc",
 ]
 
-[[package]]
-name = "insect"
-version = "0.1.0"
-dependencies = [
- "approx",
- "itertools",
- "num-rational",
- "num-traits",
- "once_cell",
- "thiserror",
-]
-
-[[package]]
-name = "insect-cli"
-version = "0.1.0"
-dependencies = [
- "anyhow",
- "assert_cmd",
- "clap",
- "dirs-next",
- "insect",
- "predicates",
- "rustyline",
-]
-
 [[package]]
 name = "io-lifetimes"
 version = "0.7.5"
@@ -393,6 +368,31 @@ dependencies = [
  "autocfg",
 ]
 
+[[package]]
+name = "numbat"
+version = "0.1.0"
+dependencies = [
+ "approx",
+ "itertools",
+ "num-rational",
+ "num-traits",
+ "once_cell",
+ "thiserror",
+]
+
+[[package]]
+name = "numbat-cli"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "assert_cmd",
+ "clap",
+ "dirs-next",
+ "numbat",
+ "predicates",
+ "rustyline",
+]
+
 [[package]]
 name = "once_cell"
 version = "1.16.0"

+ 3 - 3
Cargo.toml

@@ -1,9 +1,9 @@
 [workspace]
 members = [
-    "insect",
-    "insect-cli",
+    "numbat",
+    "numbat-cli",
 ]
 
 exclude = [
-    "insect-wasm"
+    "numbat-wasm"
 ]

+ 6 - 6
README.md

@@ -1,6 +1,6 @@
-# Insect
+# Numbat
 
-Insect is a statically typed programming language for scientific computations with
+Numbat is a statically typed programming language for scientific computations with
 first class support for physical units.
 
 ## Key features
@@ -8,12 +8,12 @@ first class support for physical units.
   * Statically typed: the 
   * Type inference
   * Strict syntax
-  * Customizable: the whole system of physical dimensions and units is written in Insect itself and can be modified or replaced
+  * Customizable: the whole system of physical dimensions and units is written in Numbat itself and can be modified or replaced
   * (Modular)
 
 ## Type system
 
-Insects treats *physical dimensions* like length or time as *types*. A value of `5 meter` is of type `Length`. A value of `2.5 inch`
+Numbat treats *physical dimensions* like length or time as *types*. A value of `5 meter` is of type `Length`. A value of `2.5 inch`
 is also of type `Length`.
 
 
@@ -41,7 +41,7 @@ In order to compute the type of `expr1 ^ expr2`, we need to fully *evaluate*
 hypothetical expression like `meter^f()` where `f()` could do *anything*. Maybe even
 get some input from the user at runtime.
 
-Insects solution to this problem looks like this: If `expr1` is *not* dimensionless, 
+Numbats solution to this problem looks like this: If `expr1` is *not* dimensionless, 
 we restrict `expr2` to a small subset of allowed operations that can be fully
 evaluated at compile time (similar to `constexpr` expressions in C++, `const`
 expressions in Rust, etc). Expressions like `meter^(2 * (2 + 1) / 3)` are completely
@@ -70,7 +70,7 @@ of the parameter `n`.
   - A redesign from scratch would allow me to focus on areas of improvement:
       - Introducing the concept of physical *dimensions* into the language
       - Experimenting with a static dimension/unit checker
-      - Allowing user-defined units => move all of the unit definitions to the Insect language
+      - Allowing user-defined units => move all of the unit definitions to the language
       - Better parser errors
       - Automated tracking of significant digits
       - Support for rational numbers? Complex numbers? Intervals?

+ 1 - 1
book/book.toml

@@ -3,7 +3,7 @@ authors = ["David Peter"]
 language = "en"
 multilingual = false
 src = "src"
-title = "Insect - scientific calculator with full support for physical units"
+title = "Numbat - scientific calculator with full support for physical units"
 
 [output.html]
 mathjax-support = true

+ 1 - 1
book/src/introduction.md

@@ -2,7 +2,7 @@
 
 > *"You see, Vergon 6 was once filled with the super-dense substance known as dark matter, each pound of which weighs over 10,000 pounds."* — Futurama, S1E4
 
-Insect is a high precision scientific calculator with full support for physical units. You can use
+Numbat is a high precision scientific calculator with full support for physical units. You can use
 it for simple mathematical computations like
 ```
 1920/16*9

+ 4 - 4
book/src/type-system.md

@@ -1,19 +1,19 @@
 # Type system
 
-Insect is a language with a special type system that treats *physical dimensions* as types.
+Numbat is a language with a special type system that treats *physical dimensions* as types.
 A type checker infers types for every expression in the program and ensures that everything is correct in terms of physical dimensions, which implies correctness in terms of physical *units*.
 For example, the expression `2 meter` has a *type* of `Length`.
 The expression `3 inch` *also* has a type of `Length`.
 The combined expression `2 meter + 3 inch` is therefore well-typed.
 On the other hand, `2 meter + 3 second` is ill-typed, as `3 second` is of type `Time`.
 
-The type system is *static* which means that the correctness of an Insect program is verified before the program starts executing.
+The type system is *static* which means that the correctness of an Numbat program is verified before the program starts executing.
 Note that certain *runtime* errors (like division-by-zero) can still occur.
 
 ## Algebra of types
 
 
-Types in Insect can be combined in various ways to produce new types.
+Types in Numbat can be combined in various ways to produce new types.
 In its most general form, a type can be thought of as a product of physical (base) dimensions \\( D_k \\) with exponents \\( \alpha_k \in \mathbb{Q} \\):
 \\[ \prod_k D_k^{\alpha_k} \\]
 For example, the type *Energy* can be represented as *Mass¹ × Length² × Time⁻²*.
@@ -79,7 +79,7 @@ fn air_pressure(height: Length) -> Pressure = p0 · (1 - gradient · height / t0
 
 ## Generic types
 
-Insects type system also supports generic types (type polymorphism).
+Numbats type system also supports generic types (type polymorphism).
 These can be used for functions that work regardless of the physical dimension of the argument(s).
 For example, the type signature of the absolute value function is given by
 ```rs

+ 0 - 0
examples/air_resistance.ins → examples/air_resistance.nbt


+ 0 - 0
examples/assert_eq_success.ins → examples/assert_eq_success.nbt


+ 0 - 0
examples/barometric_formula.ins → examples/barometric_formula.nbt


+ 0 - 0
examples/custom_dimensions.ins → examples/custom_dimensions.nbt


+ 0 - 0
examples/earth_mass.ins → examples/earth_mass.nbt


+ 0 - 0
examples/generics.ins → examples/generics.nbt


+ 0 - 0
examples/inter_dot_spacing.ins → examples/inter_dot_spacing.nbt


+ 0 - 0
examples/kinetic_energy.ins → examples/kinetic_energy.nbt


+ 0 - 0
examples/name_resolution_error/alias_clash.ins → examples/name_resolution_error/alias_clash.nbt


+ 0 - 0
examples/name_resolution_error/duplicate_unit.ins → examples/name_resolution_error/duplicate_unit.nbt


+ 0 - 0
examples/name_resolution_error/duplicate_variable.ins → examples/name_resolution_error/duplicate_variable.nbt


+ 0 - 0
examples/name_resolution_error/function_name_clash.ins → examples/name_resolution_error/function_name_clash.nbt


+ 0 - 0
examples/name_resolution_error/function_name_clash2.ins → examples/name_resolution_error/function_name_clash2.nbt


+ 0 - 0
examples/name_resolution_error/prefix_1.ins → examples/name_resolution_error/prefix_1.nbt


+ 0 - 0
examples/name_resolution_error/prefix_2.ins → examples/name_resolution_error/prefix_2.nbt


+ 0 - 0
examples/name_resolution_error/unit_clashes_with_variables.ins → examples/name_resolution_error/unit_clashes_with_variables.nbt


+ 0 - 0
examples/name_resolution_error/variable_clashes_with_unit.ins → examples/name_resolution_error/variable_clashes_with_unit.nbt


+ 0 - 0
examples/nested_function_calls.ins → examples/nested_function_calls.nbt


+ 0 - 0
examples/parse_error/division_by_zero_in_dimension_expr.ins → examples/parse_error/division_by_zero_in_dimension_expr.nbt


+ 0 - 0
examples/parse_error/duplicated_operator.ins → examples/parse_error/duplicated_operator.nbt


+ 0 - 0
examples/parse_error/expected_comma_or_right_angle_bracket.ins → examples/parse_error/expected_comma_or_right_angle_bracket.nbt


+ 0 - 0
examples/parse_error/expected_left_paren_in_fn_definition.ins → examples/parse_error/expected_left_paren_in_fn_definition.nbt


+ 0 - 0
examples/parse_error/expected_type_parameter_name.ins → examples/parse_error/expected_type_parameter_name.nbt


+ 0 - 0
examples/parse_error/trailing_characters.ins → examples/parse_error/trailing_characters.nbt


+ 0 - 0
examples/parse_error/unexpected_character.ins → examples/parse_error/unexpected_character.nbt


+ 0 - 0
examples/pendulum.ins → examples/pendulum.nbt


+ 0 - 0
examples/print.ins → examples/print.nbt


+ 0 - 0
examples/runtime_error/assert_eq_failure1.ins → examples/runtime_error/assert_eq_failure1.nbt


+ 0 - 0
examples/runtime_error/assert_eq_failure2.ins → examples/runtime_error/assert_eq_failure2.nbt


+ 0 - 0
examples/runtime_error/assert_eq_failure3.ins → examples/runtime_error/assert_eq_failure3.nbt


+ 0 - 0
examples/runtime_error/division_by_zero.ins → examples/runtime_error/division_by_zero.nbt


+ 0 - 0
examples/stopping_distance.ins → examples/stopping_distance.nbt


+ 0 - 0
examples/time_units.ins → examples/time_units.nbt


+ 0 - 0
examples/typecheck_error/can_not_add_apples_to_oranges.ins → examples/typecheck_error/can_not_add_apples_to_oranges.nbt


+ 0 - 0
examples/typecheck_error/function_called_with_wrong_argument_types.ins → examples/typecheck_error/function_called_with_wrong_argument_types.nbt


+ 0 - 0
examples/xkcd2585.ins → examples/xkcd2585.nbt


+ 3 - 3
insect-cli/Cargo.toml → numbat-cli/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "insect-cli"
+name = "numbat-cli"
 description = "A high precision scientific calculator with full support for physical units."
 authors = ["David Peter <[email protected]>"]
 version = "0.1.0"
@@ -9,7 +9,7 @@ edition = "2021"
 anyhow = "1"
 rustyline = "10"
 dirs-next = "2"
-insect = { path = "../insect" }
+numbat = { path = "../numbat" }
 
 [dependencies.clap]
 version = "4"
@@ -20,5 +20,5 @@ assert_cmd = "2"
 predicates = "2"
 
 [[bin]]
-name = "insect"
+name = "numbat"
 path = "src/main.rs"

+ 18 - 20
insect-cli/src/main.rs → numbat-cli/src/main.rs

@@ -1,22 +1,22 @@
 use std::fs;
 use std::path::PathBuf;
 
-use insect::pretty_print::PrettyPrint;
-use insect::{ExitStatus, Insect, InsectError, InterpreterResult, ParseError};
+use numbat::pretty_print::PrettyPrint;
+use numbat::{ExitStatus, InterpreterResult, Numbat, NumbatError, ParseError};
 
 use anyhow::{bail, Context, Result};
 use clap::Parser;
 use rustyline::error::ReadlineError;
 use rustyline::Editor;
 
-type ControlFlow = std::ops::ControlFlow<insect::ExitStatus>;
+type ControlFlow = std::ops::ControlFlow<numbat::ExitStatus>;
 
 const PROMPT: &str = ">>> ";
 
 #[derive(Parser, Debug)]
-#[command(version, about, name("insect"))]
+#[command(version, about, name("numbat"))]
 struct Args {
-    /// Path to source file with Insect code. If none is given, an interactive
+    /// Path to source file with Numbat code. If none is given, an interactive
     /// session is started.
     file: Option<PathBuf>,
 
@@ -24,7 +24,7 @@ struct Args {
     #[arg(short, long, value_name = "CODE", conflicts_with = "file")]
     expression: Option<String>,
 
-    /// Do not load Insects prelude with predefined physical dimensions and units.
+    /// Do not load the prelude with predefined physical dimensions and units.
     #[arg(long)]
     no_prelude: bool,
 
@@ -54,7 +54,7 @@ impl ExecutionMode {
 
 struct Cli {
     args: Args,
-    insect: Insect,
+    numbat: Numbat,
     current_filename: Option<PathBuf>,
 }
 
@@ -62,7 +62,7 @@ impl Cli {
     fn new() -> Self {
         let args = Args::parse();
         Self {
-            insect: Insect::new_without_prelude(args.debug),
+            numbat: Numbat::new_without_prelude(args.debug),
             args,
             current_filename: None,
         }
@@ -110,11 +110,9 @@ impl Cli {
     }
 
     fn repl(&mut self) -> Result<()> {
-        println!(r" _                     _   ");
-        println!(r"(_)_ __  ___  ___  ___| |_ ");
-        println!(r"| | '_ \/ __|/ _ \/ __| __|   version 0.1");
-        println!(r"| | | | \__ \  __/ (__| |_    enter '?' for help");
-        println!(r"|_|_| |_|___/\___|\___|\__|");
+        println!();
+        println!(" █▄░█ █░█ █▀▄▀█ █▄▄ ▄▀█ ▀█▀");
+        println!(" █░▀█ █▄█ █░▀░█ █▄█ █▀█ ░█░");
         println!();
 
         let history_path = self.get_history_path()?;
@@ -165,7 +163,7 @@ impl Cli {
 
     #[must_use]
     fn parse_and_evaluate(&mut self, input: &str, execution_mode: ExecutionMode) -> ControlFlow {
-        let result = self.insect.interpret(input);
+        let result = self.numbat.interpret(input);
 
         match result {
             Ok((statements, interpreter_result)) => {
@@ -191,7 +189,7 @@ impl Cli {
                     InterpreterResult::Exit(exit_status) => ControlFlow::Break(exit_status),
                 }
             }
-            Err(InsectError::ParseError(ref e @ ParseError { ref span, .. })) => {
+            Err(NumbatError::ParseError(ref e @ ParseError { ref span, .. })) => {
                 let line = input.lines().nth(span.line - 1).unwrap();
 
                 let filename = self
@@ -211,15 +209,15 @@ impl Cli {
 
                 execution_mode.exit_status_in_case_of_error()
             }
-            Err(InsectError::NameResolutionError(e)) => {
+            Err(NumbatError::NameResolutionError(e)) => {
                 eprintln!("Name resolution error: {:#}", e);
                 execution_mode.exit_status_in_case_of_error()
             }
-            Err(InsectError::TypeCheckError(e)) => {
+            Err(NumbatError::TypeCheckError(e)) => {
                 eprintln!("Type check error: {:#}", e);
                 execution_mode.exit_status_in_case_of_error()
             }
-            Err(InsectError::RuntimeError(e)) => {
+            Err(NumbatError::RuntimeError(e)) => {
                 eprintln!("Runtime error: {:#}", e);
                 execution_mode.exit_status_in_case_of_error()
             }
@@ -228,13 +226,13 @@ impl Cli {
 
     fn get_prelude_path(&self) -> PathBuf {
         let config_dir = dirs_next::config_dir().unwrap_or_else(|| PathBuf::from("."));
-        config_dir.join("insect").join("prelude.ins") // TODO: allow for preludes in system paths, user paths, …
+        config_dir.join("numbat").join("prelude.nbt") // TODO: allow for preludes in system paths, user paths, …
     }
 
     fn get_history_path(&self) -> Result<PathBuf> {
         let data_dir = dirs_next::data_dir()
             .unwrap_or_else(|| PathBuf::from("."))
-            .join("insect");
+            .join("numbat");
         fs::create_dir(&data_dir).ok();
         Ok(data_dir.join("history"))
     }

+ 12 - 12
insect-cli/tests/integration.rs → numbat-cli/tests/integration.rs

@@ -1,33 +1,33 @@
 use assert_cmd::Command;
 
-fn insect() -> Command {
-    Command::cargo_bin("insect").unwrap()
+fn numbat() -> Command {
+    Command::cargo_bin("numbat").unwrap()
 }
 
 #[test]
 fn pass_expression_on_command_line() {
-    insect()
+    numbat()
         .arg("--expression")
         .arg("2 meter + 3 meter")
         .assert()
         .success()
         .stdout(predicates::str::contains("5.000000 meter"));
 
-    insect()
+    numbat()
         .arg("--expression")
         .arg("2 ++ 3")
         .assert()
         .failure()
         .stderr(predicates::str::contains("Parse error"));
 
-    insect()
+    numbat()
         .arg("--expression")
         .arg("2 meter + 3 second")
         .assert()
         .failure()
         .stderr(predicates::str::contains("Type check error"));
 
-    insect()
+    numbat()
         .arg("--expression")
         .arg("1/0")
         .assert()
@@ -37,10 +37,10 @@ fn pass_expression_on_command_line() {
 
 #[test]
 fn read_code_from_file() {
-    insect().arg("../examples/pendulum.ins").assert().success();
+    numbat().arg("../examples/pendulum.nbt").assert().success();
 
-    insect()
-        .arg("../examples/parse_error/trailing_characters.ins")
+    numbat()
+        .arg("../examples/parse_error/trailing_characters.nbt")
         .assert()
         .failure()
         .stderr(predicates::str::contains("Parse error"));
@@ -48,8 +48,8 @@ fn read_code_from_file() {
 
 #[test]
 fn print_calls() {
-    insect()
-        .arg("../examples/print.ins")
+    numbat()
+        .arg("../examples/print.nbt")
         .assert()
         .success()
         .stdout(predicates::str::contains("1.000000 \n2.000000 meter"));
@@ -57,7 +57,7 @@ fn print_calls() {
 
 #[test]
 fn without_prelude() {
-    insect()
+    numbat()
         .arg("--no-prelude")
         .arg("--expression")
         .arg("2 + 3")

+ 0 - 0
insect-wasm/.gitignore → numbat-wasm/.gitignore


+ 0 - 0
insect-wasm/Cargo.lock → numbat-wasm/Cargo.lock


+ 2 - 2
insect-wasm/Cargo.toml → numbat-wasm/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "insect-wasm"
+name = "numbat-wasm"
 authors = ["David Peter <[email protected]>"]
 version = "0.1.0"
 edition = "2021"
@@ -24,7 +24,7 @@ console_error_panic_hook = { version = "0.1.6", optional = true }
 # allocator, however.
 wee_alloc = { version = "0.4.5", optional = true }
 
-insect = { path = "../insect" }
+numbat = { path = "../numbat" }
 
 [dev-dependencies]
 wasm-bindgen-test = "0.3.13"

+ 0 - 0
insect-wasm/README.md → numbat-wasm/README.md


+ 3 - 3
insect-wasm/src/lib.rs → numbat-wasm/src/lib.rs

@@ -1,6 +1,6 @@
 mod utils;
 
-use insect::{Insect, InterpreterResult};
+use numbat::{Numbat, InterpreterResult};
 
 use wasm_bindgen::prelude::*;
 
@@ -14,8 +14,8 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
 pub fn interpret(code: &str) -> String {
     utils::set_panic_hook();
 
-    let mut insect = Insect::new(true);
-    match insect.interpret(&code) {
+    let mut numbat = Numbat::new(true);
+    match numbat.interpret(&code) {
         Ok((_, result)) => match result {
             InterpreterResult::Quantity(q) => format!("{}", q),
             InterpreterResult::Continue => "Nothing to show".into(),

+ 0 - 0
insect-wasm/src/utils.rs → numbat-wasm/src/utils.rs


+ 1 - 1
insect-wasm/tests/web.rs → numbat-wasm/tests/web.rs

@@ -1,7 +1,7 @@
 #![cfg(target_arch = "wasm32")]
 
 use wasm_bindgen_test::*;
-use insect_wasm::interpret;
+use numbat_wasm::interpret;
 
 wasm_bindgen_test_configure!(run_in_browser);
 

+ 0 - 0
insect-wasm/www/.gitignore → numbat-wasm/www/.gitignore


+ 0 - 0
insect-wasm/www/bootstrap.js → numbat-wasm/www/bootstrap.js


+ 1 - 1
insect-wasm/www/index.html → numbat-wasm/www/index.html

@@ -2,7 +2,7 @@
 <html>
   <head>
     <meta charset="utf-8">
-    <title>insect</title>
+    <title>Numbat</title>
     <style>
     #code {
       font-size: 16px;

+ 2 - 2
insect-wasm/www/index.js → numbat-wasm/www/index.js

@@ -1,9 +1,9 @@
-import * as insect from "insect-wasm";
+import * as numbat from "numbat-wasm";
 
 const runButton = document.getElementById("run");
 const codeTextarea = document.getElementById("code");
 
 runButton.addEventListener("click", event => {
-  const output = insect.interpret(codeTextarea.value);
+  const output = numbat.interpret(codeTextarea.value);
   document.getElementById("output").innerHTML = output;
 });

+ 0 - 0
insect-wasm/www/package-lock.json → numbat-wasm/www/package-lock.json


+ 2 - 2
insect-wasm/www/package.json → numbat-wasm/www/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "insect",
+  "name": "numbat",
   "version": "0.1.0",
   "main": "index.js",
   "scripts": {
@@ -7,7 +7,7 @@
     "start": "webpack-dev-server"
   },
   "devDependencies": {
-    "insect-wasm": "file:../pkg",
+    "numbat-wasm": "file:../pkg",
     "webpack": "^4.29.3",
     "webpack-cli": "^3.1.0",
     "webpack-dev-server": "^3.1.5",

+ 0 - 0
insect-wasm/www/webpack.config.js → numbat-wasm/www/webpack.config.js


+ 1 - 1
insect/Cargo.toml → numbat/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "insect"
+name = "numbat"
 description = "A high precision scientific calculator with full support for physical units."
 authors = ["David Peter <[email protected]>"]
 version = "0.1.0"

+ 0 - 0
insect/src/arithmetic.rs → numbat/src/arithmetic.rs


+ 0 - 0
insect/src/ast.rs → numbat/src/ast.rs


+ 0 - 0
insect/src/bytecode_interpreter.rs → numbat/src/bytecode_interpreter.rs


+ 0 - 0
insect/src/decorator.rs → numbat/src/decorator.rs


+ 0 - 0
insect/src/dimension.rs → numbat/src/dimension.rs


+ 0 - 0
insect/src/ffi.rs → numbat/src/ffi.rs


+ 0 - 0
insect/src/interpreter.rs → numbat/src/interpreter.rs


+ 13 - 13
insect/src/lib.rs → numbat/src/lib.rs

@@ -37,7 +37,7 @@ pub use interpreter::InterpreterResult;
 pub use parser::ParseError;
 
 #[derive(Debug, Error)]
-pub enum InsectError {
+pub enum NumbatError {
     #[error("{0}")]
     ParseError(ParseError),
     #[error("{0}")]
@@ -48,17 +48,17 @@ pub enum InsectError {
     RuntimeError(RuntimeError),
 }
 
-pub type Result<T> = std::result::Result<T, InsectError>;
+pub type Result<T> = std::result::Result<T, NumbatError>;
 
-pub struct Insect {
+pub struct Numbat {
     prefix_transformer: Transformer,
     typechecker: TypeChecker,
     interpreter: BytecodeInterpreter,
 }
 
-impl Insect {
+impl Numbat {
     pub fn new_without_prelude(debug: bool) -> Self {
-        Insect {
+        Numbat {
             prefix_transformer: Transformer::new(),
             typechecker: TypeChecker::default(),
             interpreter: BytecodeInterpreter::new(debug),
@@ -66,29 +66,29 @@ impl Insect {
     }
 
     pub fn new(debug: bool) -> Self {
-        let mut insect = Self::new_without_prelude(debug);
-        assert!(insect
-            .interpret(include_str!("../../prelude.ins"))
+        let mut numbat = Self::new_without_prelude(debug);
+        assert!(numbat
+            .interpret(include_str!("../../prelude.nbt"))
             .expect("Error while running prelude")
             .1
             .is_success()); // TODO: read prelude dynamically, error handling
-        insect
+        numbat
     }
 
     pub fn interpret(&mut self, code: &str) -> Result<(Vec<Statement>, InterpreterResult)> {
-        let statements = parse(code).map_err(InsectError::ParseError)?;
+        let statements = parse(code).map_err(NumbatError::ParseError)?;
         let transformed_statements = self
             .prefix_transformer
             .transform(statements)
-            .map_err(InsectError::NameResolutionError)?;
+            .map_err(NumbatError::NameResolutionError)?;
         let typed_statements = self
             .typechecker
             .check_statements(transformed_statements.clone()) // TODO: get rid of clone?
-            .map_err(InsectError::TypeCheckError)?;
+            .map_err(NumbatError::TypeCheckError)?;
         let result = self
             .interpreter
             .interpret_statements(&typed_statements)
-            .map_err(InsectError::RuntimeError)?;
+            .map_err(NumbatError::RuntimeError)?;
 
         Ok((transformed_statements, result))
     }

+ 0 - 0
insect/src/name_resolution.rs → numbat/src/name_resolution.rs


+ 0 - 0
insect/src/number.rs → numbat/src/number.rs


+ 1 - 1
insect/src/parser.rs → numbat/src/parser.rs

@@ -1,4 +1,4 @@
-//! Insect Parser
+//! Numbat Parser
 //!
 //! Operator precedence, low to high
 //! * postfix apply ("//")

+ 0 - 0
insect/src/prefix.rs → numbat/src/prefix.rs


+ 0 - 0
insect/src/prefix_parser.rs → numbat/src/prefix_parser.rs


+ 0 - 0
insect/src/prefix_transformer.rs → numbat/src/prefix_transformer.rs


+ 0 - 0
insect/src/pretty_print.rs → numbat/src/pretty_print.rs


+ 0 - 0
insect/src/product.rs → numbat/src/product.rs


+ 1 - 1
insect/src/quantity.rs → numbat/src/quantity.rs

@@ -56,7 +56,7 @@ impl Quantity {
             // to also perform the hour->second conversion, which would be needed, as
             // we go back to base units for now. Removing common factors is just one
             // heuristic, but it would be better to solve this in a more general way.
-            // For more details on this problem, see `examples/xkcd2585.ins`.
+            // For more details on this problem, see `examples/xkcd2585.nbt`.
             let mut common_unit_factors = Unit::scalar();
             let target_unit_canonicalized = target_unit.canonicalized();
             for factor in self.unit.canonicalized().iter() {

+ 0 - 0
insect/src/registry.rs → numbat/src/registry.rs


+ 0 - 0
insect/src/span.rs → numbat/src/span.rs


+ 0 - 0
insect/src/tokenizer.rs → numbat/src/tokenizer.rs


+ 1 - 1
insect/src/typechecker.rs → numbat/src/typechecker.rs

@@ -412,7 +412,7 @@ impl TypeChecker {
                         .get_base_representation(
                             &optional_dexpr.expect("Parameter types can not be deduced."),
                         )
-                        // TODO: add type inference, see https://github.com/sharkdp/insect-rs/issues/29
+                        // TODO: add type inference, see https://github.com/sharkdp/numbat/issues/29
                         // TODO: once we add type inference, make sure that annotations are required for foreign functions
                         .map_err(TypeCheckError::RegistryError)?;
                     typechecker_fn

+ 0 - 0
insect/src/typed_ast.rs → numbat/src/typed_ast.rs


+ 0 - 0
insect/src/unit.rs → numbat/src/unit.rs


+ 0 - 0
insect/src/unit_registry.rs → numbat/src/unit_registry.rs


+ 0 - 0
insect/src/vm.rs → numbat/src/vm.rs


+ 18 - 18
insect/tests/prelude_and_examples.rs → numbat/tests/prelude_and_examples.rs

@@ -1,10 +1,10 @@
-use insect::{Insect, InsectError, InterpreterResult};
+use numbat::{Numbat, NumbatError, InterpreterResult};
 
 use std::ffi::OsStr;
 use std::fs;
 
 fn assert_typechecks_and_runs(code: &str) {
-    let result = Insect::new_without_prelude(false).interpret(code);
+    let result = Numbat::new_without_prelude(false).interpret(code);
     assert!(result.is_ok());
     assert!(matches!(
         result.unwrap().1,
@@ -14,40 +14,40 @@ fn assert_typechecks_and_runs(code: &str) {
 
 fn assert_parse_error(code: &str) {
     assert!(matches!(
-        Insect::new_without_prelude(false).interpret(code),
-        Err(InsectError::ParseError(_))
+        Numbat::new_without_prelude(false).interpret(code),
+        Err(NumbatError::ParseError(_))
     ));
 }
 
 fn assert_name_resolution_error(code: &str) {
     assert!(matches!(
-        Insect::new_without_prelude(false).interpret(code),
-        Err(InsectError::NameResolutionError(_))
+        Numbat::new_without_prelude(false).interpret(code),
+        Err(NumbatError::NameResolutionError(_))
     ));
 }
 
 fn assert_typecheck_error(code: &str) {
     assert!(matches!(
-        Insect::new_without_prelude(false).interpret(code),
-        Err(InsectError::TypeCheckError(_))
+        Numbat::new_without_prelude(false).interpret(code),
+        Err(NumbatError::TypeCheckError(_))
     ));
 }
 
 fn assert_runtime_error(code: &str) {
     assert!(matches!(
-        Insect::new_without_prelude(false).interpret(code),
-        Err(InsectError::RuntimeError(_))
+        Numbat::new_without_prelude(false).interpret(code),
+        Err(NumbatError::RuntimeError(_))
     ));
 }
 
 #[test]
 fn prelude_can_be_parsed_and_interpreted() {
-    let prelude_code = fs::read_to_string("../prelude.ins").unwrap();
+    let prelude_code = fs::read_to_string("../prelude.nbt").unwrap();
     assert_typechecks_and_runs(&prelude_code);
 }
 
-fn run_for_each_insect_file_in(folder: &str, f: impl Fn(&str)) {
-    let prelude_code = fs::read_to_string("../prelude.ins").unwrap();
+fn run_for_each_numbat_file_in(folder: &str, f: impl Fn(&str)) {
+    let prelude_code = fs::read_to_string("../prelude.nbt").unwrap();
     for entry in fs::read_dir(folder).unwrap() {
         let path = entry.unwrap().path();
         if path.extension() != Some(OsStr::new("ins")) {
@@ -67,17 +67,17 @@ fn run_for_each_insect_file_in(folder: &str, f: impl Fn(&str)) {
 
 #[test]
 fn examples_can_be_parsed_and_interpreted() {
-    run_for_each_insect_file_in("../examples/", assert_typechecks_and_runs);
+    run_for_each_numbat_file_in("../examples/", assert_typechecks_and_runs);
 }
 
 #[test]
 fn parse_error_examples_fail_as_expected() {
-    run_for_each_insect_file_in("../examples/parse_error", assert_parse_error);
+    run_for_each_numbat_file_in("../examples/parse_error", assert_parse_error);
 }
 
 #[test]
 fn name_resolution_error_examples_fail_as_expected() {
-    run_for_each_insect_file_in(
+    run_for_each_numbat_file_in(
         "../examples/name_resolution_error",
         assert_name_resolution_error,
     );
@@ -85,10 +85,10 @@ fn name_resolution_error_examples_fail_as_expected() {
 
 #[test]
 fn typecheck_error_examples_fail_as_expected() {
-    run_for_each_insect_file_in("../examples/typecheck_error", assert_typecheck_error);
+    run_for_each_numbat_file_in("../examples/typecheck_error", assert_typecheck_error);
 }
 
 #[test]
 fn runtime_error_examples_fail_as_expected() {
-    run_for_each_insect_file_in("../examples/runtime_error", assert_runtime_error);
+    run_for_each_numbat_file_in("../examples/runtime_error", assert_runtime_error);
 }

+ 0 - 0
prelude.ins → prelude.nbt


+ 2 - 2
vscode-extension/CHANGELOG.md

@@ -1,9 +1,9 @@
 # Change Log
 
-All notable changes to the "insect" extension will be documented in this file.
+All notable changes to the "numbat" extension will be documented in this file.
 
 Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
 
 ## [Unreleased]
 
-- Initial release
+- Initial release

+ 2 - 2
vscode-extension/README.md

@@ -1,6 +1,6 @@
-# insect README
+# numbat README
 
-This is the README for your extension "insect". After writing up a brief description, we recommend including the following sections.
+This is the README for your extension "numbat". After writing up a brief description, we recommend including the following sections.
 
 ## Features
 

+ 9 - 9
vscode-extension/package.json

@@ -1,7 +1,7 @@
 {
-    "name": "insect",
-    "displayName": "Insect",
-    "description": "Syntax highlighting for the Insect programming language",
+    "name": "numbat",
+    "displayName": "Numbat",
+    "description": "Syntax highlighting for the Numbat programming language",
     "version": "0.0.1",
     "engines": {
         "vscode": "^1.71.0"
@@ -11,15 +11,15 @@
     ],
     "contributes": {
         "languages": [{
-            "id": "insect",
-            "aliases": ["Insect", "insect"],
-            "extensions": [".ins"],
+            "id": "numbat",
+            "aliases": ["Numbat", "numbat"],
+            "extensions": [".nbt"],
             "configuration": "./language-configuration.json"
         }],
         "grammars": [{
-            "language": "insect",
-            "scopeName": "source.insect",
-            "path": "./syntaxes/insect.tmLanguage.json"
+            "language": "numbat",
+            "scopeName": "source.numbat",
+            "path": "./syntaxes/numbat.tmLanguage.json"
         }]
     }
 }

+ 4 - 4
vscode-extension/syntaxes/insect.tmLanguage.json

@@ -1,6 +1,6 @@
 {
     "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
-    "name": "Insect",
+    "name": "Numbat",
     "patterns": [
         {
             "include": "#keywords"
@@ -28,7 +28,7 @@
         "keywords": {
             "patterns": [
                 {
-                    "name": "keyword.control.insect",
+                    "name": "keyword.control.numbat",
                     "match": "\\b(per|to|let|fn|dimension|unit|print|assert_eq)\\b"
                 }
             ]
@@ -36,7 +36,7 @@
         "decorators": {
             "patterns": [
                 {
-                    "name": "support.function.insect",
+                    "name": "support.function.numbat",
                     "match": "@(metric_prefixes|binary_prefixes|aliases|aliases_short)\\b"
                 }
             ]
@@ -82,5 +82,5 @@
             ]
         }
     },
-    "scopeName": "source.insect"
+    "scopeName": "source.numbat"
 }

+ 1 - 1
vscode-extension/vsc-extension-quickstart.md

@@ -4,7 +4,7 @@
 
 * This folder contains all of the files necessary for your extension.
 * `package.json` - this is the manifest file in which you declare your language support and define the location of the grammar file that has been copied into your extension.
-* `syntaxes/insect.tmLanguage.json` - this is the Text mate grammar file that is used for tokenization.
+* `syntaxes/numbat.tmLanguage.json` - this is the Text mate grammar file that is used for tokenization.
 * `language-configuration.json` - this is the language configuration, defining the tokens that are used for comments and brackets.
 
 ## Get up and running straight away