From: Thomas Walker Lynch Date: Sun, 10 May 2026 12:47:24 +0000 (+0000) Subject: intermediate, names updated for v3.0, but references still outdated X-Git-Url: https://git.reasoningtechnology.com/%27%20%20%20window.RT_REPO_ROOT%20%20%20%27shared/setup.js?a=commitdiff_plain;h=2803bed21fc123632ca4ed81e49baba2b321c8c6;p=Harmony intermediate, names updated for v3.0, but references still outdated --- diff --git a/administrator/document/Release_howto.html b/administrator/document/Release_howto.html deleted file mode 100644 index 888d414..0000000 --- a/administrator/document/Release_howto.html +++ /dev/null @@ -1,101 +0,0 @@ - - - - - Release howto - - - - - - - - - - -

Prerequisites

-

- A release requires a tested promotion candidate. The developer compiles the code and promotes it to the consumer/made directory. The tester validates the candidate. The product manager gives the order to release. -

- -

Create the release branch

-

- The administrator executes the release. Open a terminal. Enter the project workspace. -

- - > . setup administrator - - -

- Switch to the core development branch. Ensure the local repository is current. -

- - > git checkout core_developer_branch - > git pull - - -

- Create a new branch for the release. Use the major version number. -

- - > git checkout -b release_v<major> - - -

Issue management and patching

-

- Only critical issues receive patches on a release branch. The product manager defines what is critical. If approved, the release team applies the fix directly to the existing release_v<major> branch. -

-

- The branch name release_v<major> remains static. The code on the branch is updated. The administrator advances the minor release number in the shared/tool/version file. -

-

- The administrator tags the new commit with the full version number, such as v<major>.<minor>. Minor versions are edits on the major release branch. They are visible to a person by running the version command. -

-

- The developer must ensure the fix is also ported to the core_developer_branch. This prevents the defect from reappearing in future major releases. -

- -

Tag and push

-

- Tag the release with the exact version number. -

- - > git tag -a v<major>.<minor> -m "Release v<major>.<minor>" - - -

- Push the branch to the remote repository. Push the tags. -

- - > git push origin release_v<major> - > git push origin --tags - - -

Repository default branch

-

- Set the repository default branch to the new release_v<major> branch on the hosting platform. This ensures a person cloning or pulling the repository receives the most recent major release code by default. -

- -

Verification

-

- Check the remote repository. Confirm the branch exists. Confirm the tag is visible. Confirm the default branch is updated. -

- -

Role responsibilities

- - -
- - diff --git a/administrator/document/how-to_release.html b/administrator/document/how-to_release.html new file mode 100644 index 0000000..888d414 --- /dev/null +++ b/administrator/document/how-to_release.html @@ -0,0 +1,101 @@ + + + + + Release howto + + + + + + + + + + +

Prerequisites

+

+ A release requires a tested promotion candidate. The developer compiles the code and promotes it to the consumer/made directory. The tester validates the candidate. The product manager gives the order to release. +

+ +

Create the release branch

+

+ The administrator executes the release. Open a terminal. Enter the project workspace. +

+ + > . setup administrator + + +

+ Switch to the core development branch. Ensure the local repository is current. +

+ + > git checkout core_developer_branch + > git pull + + +

+ Create a new branch for the release. Use the major version number. +

+ + > git checkout -b release_v<major> + + +

Issue management and patching

+

+ Only critical issues receive patches on a release branch. The product manager defines what is critical. If approved, the release team applies the fix directly to the existing release_v<major> branch. +

+

+ The branch name release_v<major> remains static. The code on the branch is updated. The administrator advances the minor release number in the shared/tool/version file. +

+

+ The administrator tags the new commit with the full version number, such as v<major>.<minor>. Minor versions are edits on the major release branch. They are visible to a person by running the version command. +

+

+ The developer must ensure the fix is also ported to the core_developer_branch. This prevents the defect from reappearing in future major releases. +

+ +

Tag and push

+

+ Tag the release with the exact version number. +

+ + > git tag -a v<major>.<minor> -m "Release v<major>.<minor>" + + +

+ Push the branch to the remote repository. Push the tags. +

+ + > git push origin release_v<major> + > git push origin --tags + + +

Repository default branch

+

+ Set the repository default branch to the new release_v<major> branch on the hosting platform. This ensures a person cloning or pulling the repository receives the most recent major release code by default. +

+ +

Verification

+

+ Check the remote repository. Confirm the branch exists. Confirm the tag is visible. Confirm the default branch is updated. +

+ +

Role responsibilities

+ + +
+ + diff --git a/developer/document/File_directory_naming.html b/developer/document/File_directory_naming.html deleted file mode 100644 index 2d7a350..0000000 --- a/developer/document/File_directory_naming.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - File and directory naming conventions - - - - - - - - - - -

Program file system objects

- -

- Harmony files and directories are considered to be program file systems objects. -

- -

Files

-

- Files that hold a single class, have he same base name as that class. If a file holds multiple classes, but there is a class of primary importance and auxiliary classes, the file carries the name of the primary class. -

- -

- If a file represents a module or name space, follow the same naming conventions specified for classes and name spaces in the RT_code_format.html document. -

- -

- Other program files follow the same naming conventions specified in the RT_code_format.html document for an identifier of the - contained or related language. -

- -

Hyphens and spaces

- -

In a C language culture, file names use underscores between words. In a Lisp language culture use snake-kebab_case. Spaces are generally not used in program file names. Though the Harmony skeleton is language agnostic, it was first used with C, hence file names use primarily underscores. -

- - -

Program Directories

-

- A directory that is a package, follows the convention for name spaces. -

- -

- A directory that is used to give the contained files a property is an identifier. -

- -

- What is a reasonable primary property for a set of files? Perhaps: -

- - -

Property indicators on files

-

- We add a second property to a file using dot extensions to the file's name. We can extend the dot suffix model by using multiple dot suffixes. File name extensions are used to signal to the build tools how the file is to be processed: -

- - -

Exercises

-

Exercise 1: Program file names

-

- Rename the following poorly named files to strictly adhere to the RT naming conventions. Pay close attention to the language culture, the capitalization of acronyms, and the rule for spelling out abbreviations in outer scope identifiers. -

- - -
- - diff --git a/developer/document/RT-code-format-Lisp.html b/developer/document/RT-code-format-Lisp.html new file mode 100644 index 0000000..edbed6b --- /dev/null +++ b/developer/document/RT-code-format-Lisp.html @@ -0,0 +1,392 @@ + + + + + RT Code Format: Lisp Addendum + + + + + + + + + + +

+ This document serves as the authoritative addendum for applying the RT code format conventions to Lisp dialects, specifically Emacs Lisp. It integrates micro-syntax rules with macro-structural organization to ensure consistency across the software ecosystem. +

+ +

File Architecture and Section Banners

+

+ To maintain a predictable progression from static data to external hooks, a Lisp file is divided into standard architectural sections. Each section is introduced by an Architectural Banner. +

+ + + +

Comment Ontology

+

+ The commenting style in Lisp is highly structured, using semicolon counts and indentation to create a clear visual hierarchy. A programmer should assume the reader can understand Lisp syntax; avoid comments that merely translate the code below them into English prose. +

+ + + +

Header case, for all RT documents and code, is an initial capital letter, and no trailing period. Acronyms and tagged code or terms keep their original capitalization or lack thereof.

+ +

Identifier Naming and Namespaces

+ +

Primary and Secondary Separators

+

+ Because Emacs Lisp and Common Lisp support the hyphen character in identifiers, Lisp code utilizes snake-kebab_case. The hyphen acts as the primary word separator. The underscore is reserved strictly as a secondary separator to group logically related portions of an identifier or to denote semantic boundaries, acting as a structural namespace within the symbol (e.g., city-scape_building-height). +

+ +

Ad Hoc Namespaces

+

+ Emacs Lisp shares a global environment. To prevent global environment pollution, functions and global variables use the center dot (·) to separate namespace hierarchies. Spaces are omitted around the dot to ensure the symbol evaluates contiguously. +

+ + (defconst RT·first-order-list·control·continue 0) + + +

Code Structure Attributes

+

+ The code structure heavily applies the RT Code Format conventions to a Lisp environment, resulting in a distinct visual footprint. +

+ +

Global Two Space Offset

+

+ Unlike standard Emacs Lisp where top level forms like defun or setq are flush left, the entire programmatic contents of the file are indented by two spaces. +

+ +

Function Call Enclosures

+

+ Lisp function calls are exempt from the multi-level enclosure padding rule. The outer parentheses forming a function call receive no padding, even when they contain nested data lists. +

+ + (cat 'a 'b '( 2 (4 5))) + + +

Vertical Branching

+

+ The if and while statements are expanded vertically. The operator, the condition, the true branch, and the false branch each occupy their own isolated lines. +

+ +

Isolated Binding Blocks

+

+ In let and let* forms, the variable declaration list is pushed to its own level. The opening parenthesis sits alone on a new line. Each binding sits on its own line. The closing parenthesis sits alone, vertically aligned with the opening parenthesis. The body of the form follows on the subsequent line. +

+ +

Using let to destructure a list

+

+ Don't destructure a list and then use the parts in a single `let*`, instead destructure the list in a first list, then use the parts in a second nested `let`. +

+ +

Cascading Closures

+

+ When the items of a list appear one per line, i.e. for a vertical list, the closing parenthesis, and all cascading closures, appear on a line of their own at the same indention level as though an element of the list. In a sense, the innermost vertical list wins, as it will close all the vertical lists it is nested in. +

+ + (let + ( + (example_list + (list + '(4 [0]) + '(5 [1]) + '(6 []) + ))) + ... + + + +

A comment subsection

+

+ When a comment under a triple semicolon section forms a subsection, the + comment starts at the indention level of the code, has two semicolons. After the comment there is a line at the indent level with only two semicolons. Then there is a blank line. The subsection contents follow. +

+ + ;; Color logic + ;; + + (defun RT-literal·highlight-none () + nil + ) + + (defun RT-literal·highlight-default () + 'region + ) + + +

one line specific comment

+

+ A single semicolon occurs after the code on the line, followed by a comment. +

+ + + + + +

Contiguous Form Cluster

+

+ When the comment adds insight into the code, the comment typically appears with two semicolons at the same indentation level above said code. There is no following blank line. All code the comment applies to then follows without intervening blank lines. +

+ + ;; By contract: only called when overlay is in quoted form, and null string case already handled + ;; Everything from content_leftmost to content_rightmost is data, inclusive. + (setq RT-literal·describe-new-form_status (list 'new-good)) + (defun RT-literal·describe-new-form_message (status) + nil + ) + (defun RT-literal·describe-new-form (overlay_leftmost content_rightmost_right-neighbor) + (let* + ( ... ) + ... + ))) + + +

API Design Conventions

+ +

Parameter Ordering

+

+ When defining function signatures, static configuration parameters (such as sizes, limits, or modes) must precede data payloads or instances that are actively manipulated. This facilitates partial application and logical readability. +

+ +

TTCA Theory Terminology

+

+ The following definitions bridge the gap between abstract TTCA theory and practical implementation conventions. +

+ + + +

+ The TTCA ontology is a topological description. It speaks of left, and right, of leftmost and rightmost. Time dependent terms such as first or last imply scanning/traversal. The first cell scanned could be anywhere on the tape, depending on the algorithm used for the scan or traversal. Careful, the term rightmost refers to a cell that is included on the tape. It is an inclusive bound. Today exclusive bounds are more common. Inclusive found loops often exit from the middle. +

+ + +

The First/Rest Loop Technique

+ +

The first/rest loop is an iterative control flow pattern designed for sequence traversal and state machine evaluation. The pattern explicitly separates the evaluation of the initial state (the "first") from the continuous cycle of advancing and re-evaluating (the "rest").

+ +

This technique eliminates the need for mid-loop escape clauses, such as break or throw/catch, and avoids evaluating out-of-bounds memory by ensuring the tape head is always validated before stepping.

+ +

The Structural Form

+ +

The structure requires performing the initial work on the first valid cell and evaluating the boundary condition simultaneously. Because a freshly cued tape machine always rests on valid data, the first cell is processed immediately within the initial variable bindings. The loop condition then evaluates both the result of that work and whether the machine has a right neighbor. Inside the loop, the machine steps, and both the work and boundary conditions are explicitly re-evaluated and updated at the absolute bottom.

+ +

If the work performed on the cell is extensive, a programmer should extract that logic into a helper function. This helper function is called once in the initial bindings for the "first" phase, and once inside the loop for the "rest" phase.

+ +

Here is the canonical RT code format for the first/rest loop:

+ + + (let + ( + ;; 1. The "First" Work & Boundary Evaluation + (work-successful (evaluate-current-cell machine)) + (has_right-neighbor (RT·TM·has-right-neighbor machine)) + ) + ;; 2. The rest loop + (while (and work-successful has_right-neighbor) + (progn + ;; 3. The "Step" phase + (RT·TM·step machine) + + ;; 4. The "Rest" Work & Boundary Evaluation + (setq work-successful (evaluate-current-cell machine)) + (setq has_right-neighbor (RT·TM·has-right-neighbor machine)) + )) + ;; Return the final state of the work + work-successful + ) + + +

+ Elisp does not have a middle-of-loop exit, but if it did, the logic would look like this: +

+ + + (let + ( + (work-successful nil) + (has_right-neighbor nil) + ) + (loop + (setq work-successful (evaluate-current-cell machine)) + (setq has_right-neighbor (RT·TM·has-right-neighbor machine)) + + (if + (not (and work-successful has_right-neighbor)) + (break) + (RT·TM·step machine) + )) + work-successful + ) + + +

Which eliminates the need for two calls to evaluate-current-cell and has-right-neighbor. This can be done in other languages that have a loop break. (Donald Knuth argued in his 1974 paper, Structured Programming with go to Statements, that forcing programmers to duplicate code simply to satisfy a rigid while or repeat/until pre/post-test constraint was a failure of the language's expressiveness. Also discussed in the Art of Computer Programming.) +

+ +

If we are willing to us catch and throw in normal control flow, this can be done in elisp as: +

+ + + (catch 'loop-exit + (while t + (let + ( + (work-successful (evaluate-current-cell machine)) + (has_right-neighbor (RT·TM·has-right-neighbor machine)) + ) + (if + (not (and work-successful has_right-neighbor)) + (throw 'loop-exit work-successful) + (RT·TM·step machine) + )))) + + +

So defining:

+ + (defmacro RT·loop (&rest body) + "An infinite loop construct designed to be exited via RT·break." + `(catch 'loop-exit + (while t + ,@body + ))) + + (defmacro RT·break (&optional return_val) + "Break out of an RT·loop, optionally returning RETURN_VAL." + `(throw 'loop-exit ,return_val) + ) + + +

Our example becomes:

+ + + (let + ( + (work-successful nil) + (has_right-neighbor nil) + ) + (RT·loop + ;; 1. The Work & Boundary Evaluation + (setq work-successful (evaluate-current-cell machine)) + (setq has_right-neighbor (RT·TM·has-right-neighbor machine)) + + ;; 2. The Mid-Loop Condition Check + (if + (not (and work-successful has_right-neighbor)) + (RT·break work-successful) + ;; 3. The "Step" phase + (RT·TM·step machine) + )) + ) + + +

+ Production code first/rest loop example without a middle loop break. +

+ + + (defun RT·TM·sequence·eq (TM_substrate TM_target) + (let + ( + (TM-substrate-copy (RT·TM·entangled-copy TM_substrate)) + (TM-target-copy (RT·TM·entangled-copy TM_target)) + ) + (let + ( + (are-eq (= (RT·TM·read TM-substrate-copy) (RT·TM·read TM-target-copy))) + (target-has-right-neighbor (RT·TM·has-right-neighbor TM-target-copy)) + (substrate-has-right-neighbor (RT·TM·has-right-neighbor TM-substrate-copy)) + ) + (while + (and are-eq target-has-right-neighbor substrate-has-right-neighbor) + (progn + (RT·TM·step TM-substrate-copy) + (RT·TM·step TM-target-copy) + (setq are-eq (= (RT·TM·read TM-substrate-copy) (RT·TM·read TM-target-copy))) + (setq target-has-right-neighbor (RT·TM·has-right-neighbor TM-target-copy)) + (setq substrate-has-right-neighbor (RT·TM·has-right-neighbor TM-substrate-copy)) + )) + (and are-eq (not target-has-right-neighbor)) + ))) + + +

If the double call code is substantial, and we do not want to use a middle break, it can be put in a helper function, and then this reduces to two calls to the helper. the helper function is called in the first part and the rest loop. If the programmer tries to trick the loop by giving the variables fake values in the first part, the first/rest pattern will be broken. +

+ +

Relationship between first/rest and Tail Recursion

+ +

The first/rest loop is the exact iterative equivalent of a tail-recursive function.

+ +

In a functional paradigm, a sequence is algebraically defined as a head (first) and a tail (rest). A tail-recursive function evaluates the head, performs the necessary work, and then returns the result of calling itself on the tail.

+ +

Environments lacking Tail Call Optimization (TCO), such as Emacs Lisp, will throw a stack overflow error if a recursive function traverses a long sequence. The first/rest loop flattens this recursive mathematical model into memory-safe iteration by mapping the recursive phases directly to iterative steps:

+ +

The Initial Function Call: The initial work and the let block bindings in the first/rest loop mirror the initial execution and argument evaluation of the recursive function.

+ +

The Base Case Check: The while loop condition mirrors the recursive base case. If the condition fails, the loop terminates, mimicking the recursive function returning its final value.

+ +

The Tail Call: The step and setq updates at the bottom of the loop body mirror the argument passing of the tail-recursive call. Updating the variables and allowing the while loop to jump back to the top is functionally identical to the function invoking itself with a new set of parameters for the "rest" of the sequence.

+ +

By adhering to this pattern, a programmer retains the strict, predictable state management of functional recursion while satisfying the physical memory constraints of an iterative runtime environment.

+ +

To illustrate the mathematical equivalence, here is the exact same logic written as a tail-recursive function. Note that while this form is theoretically pure, the first/rest iterative loop is strictly preferred in Emacs Lisp. Because Elisp lacks Tail Call Optimization (TCO), this recursive form would eventually exhaust the call stack and crash when traversing massive sequences.

+ + + (defun process-sequence-recursively (machine) + (let + ( + ;; 1. The "First" Work & Boundary Evaluation + (work-successful (evaluate-current-cell machine)) + (active (RT·TM·has-right-neighbor machine)) + ) + ;; 2. The Condition check + (if (and work-successful active) + (progn + ;; 3. The "Step" phase + (RT·TM·step machine) + + ;; 4. The Tail Call (The "Rest") + ;; This directly replaces the setq updates and loop jump + (process-sequence-recursively machine) + ) + ;; Base case: loop terminates, return final state + work-successful + ))) + + +

Exercise

+

Show the 'production code' with a first/rest pattern using the RT macros and a middle break loop.

+ +
+ + diff --git a/developer/document/RT-code-format.html b/developer/document/RT-code-format.html new file mode 100644 index 0000000..43069bc --- /dev/null +++ b/developer/document/RT-code-format.html @@ -0,0 +1,281 @@ + + + + + RT code format conventions + + + + + + + + + + +

+ This document has been evolving. Consequently there is a body of non-conforming code. Whenever we run up against it, it is nice to update it. +

+ +

Object vs. instance nomenclature

+

+ It is too much of an ask to remove the word 'object' from the English language, and then set it aside and give it a esoteric technical meaning. This is why the term is often misused. So we instead talk about an interface as being a set of functions that share one or more state variables. The term instance is then a collection of such state variables and their values sitting in memory. Interface functions are usually grouped within a named container, and state variables are often grouped into a single named data structure. +

+

+ In some languages the instance occurs to the left of a lower dot (period) operator and is referred to as this from inside the interface functions. In other languages there is a convention where the instance is passed in as the first parameter to interface functions. There can also be interface functions that accept multiple instances of the same type. Bridge interfaces can be created that accept two instances potentially of different types. +

+

+ Since we have released object from captivity, a programmer can talk about math objects, as things found in mathematics, and C objects, as things found in the C language, even though they are not instantiated from classes, or might not even be data. For example, the for loop is a C object. +

+ +

Identifier names

+ +

Case

+ + +

Proper nouns and acronyms

+

+ Even in PascalCase and snake-kebab_case, proper nouns and acronyms remain capitalized, as per standard English language conventions (e.g., IEEE_publication-count). +

+ +

Abbreviations

+

+ For outer scope identifiers we spell things out for clarity. This follows Lisp programming culture. This makes it clear for people who are 'not in the club' to be able to get started and read the code, and tends to be self documenting. Our file system names mirror our program identifier rules, so you find things such as 'library', 'source', spelled out. +

+

+ For long words, inner scope identifiers, temporary variables, and conventional suffixes, abbreviations become more common. By the time we get to inner loops variable names, such as loop counters are typically 1 letter long. +

+ +

Primary and secondary separator use

+

+ When a language supports the dash, -, dash connected components are given precedence and of choice, and bind semantically higher than under score separated components. E.g. rounded_x-coordinate. +

+

+ Otherwise, if the language does not support hyphens in identifiers (such as C, Python, and Java), we conventionally drop the nicety of multiple semantic bindings, e.g. rounded_x_coordinate. However if the distinction has high value, a double underscore and be used, rounded__x_coordinate. +

+ +

Ad hoc namespacing

+

+ Most parsers now a allow a center dot (·) in identifiers. In languages were namespaces are not explicitly available, we use the cdot to represent a namespace. Namespaces are closely related to module names, class names, interface names, and to type names,so all are written in PascalCase. So for example, Math·rounded__x_coordinate, might be variable in the Math namespace, a function on the Math interface, etc. + +

Component order

+

+ As long as it is sensible, and doesn't break parallel constructions, place the least changing component, or the broadest category, to the left of the identifer. For example, a conditional write functions would be called, `write-conditional`, not `conditional-write` because it is a refinement on the general category or write functions. +

+ +

Copy,read, write

+

+ 'read' and 'write', are the two ends of a copy. When 'this instance' is understood as being one end of the copy, then using 'read' or 'write' makes sense. However, it is generally better to provide an external copy command. The order of arguments in a copy command are `read from source value --> write to destination value` i.e. data flows from left to write. (This is contrary to an assignment operator, which has data flowing from right to left during a copy.) +

+ +

The term make

+

+ When allowed by the langauge, factory functions are called 'make'. They are not called 'create', nor 'new'. +

+ +

Function terminology

+

+ Parameters are what give a function its characteristics. They are typically static. They are one step away from values that are curried into a function. Parameter variables are given with the function definition, and parameter values are given to the function at run time when it is called. +

+

+ Given argument values can be said to be bound to arguments variables upon call. +

+

+ Arguments drive the function computation. Conceptually they might change on every separate call, so they are highly dynamic. Argument variables are specified when the function is defined. Argument values are given to the function at call time. +

+

+ Values are said to be given to a function. We don't say a function takes arguments, as though a call stack could reach into memory and grab values. We use terms accept and reject of values for guard code. For a function to accept an argument value is to mean that argument value was tested and passed. As an example, we can say that a square root function only accepts values greater than or equal to zero, or that it rejects negative values. +

+

+ Operators are logically functions by another name. Syntactically infix notation is often used. Operands are arguments given to an operator. +

+ +

Plural identifiers

+ +

+ Do not make the names of containers plural, instead prefix the container abstract type, or actual type before the identifier. Recall that types are PascalCase. +

+ + + +

Add a type prefix when it adds clarity.

+ + +

Identifiers for directory/file names

+ + +

Comma separated lists

+ +

Horizontal comma list

+

The comma is preceded by a space and abuts the item it follows.

+ + int x ,y ,z; + + +

Vertical comma list

+

The comma is placed before the item on the new line, aligned with the item's indentation. This applies to all languages, including Python and C.

+ + result = some_function( + first_argument + ,second_argument + ,third_argument + ); + + +

Enclosure spacing

+ +

Single-level enclosures

+

No space padding inside the enclosure punctuation.

+ + if(condition){ + do_something(); + } + + +

Multi-level enclosures

+

One space of padding is applied only to the outermost enclosure punctuation.

+ + + if( f(g(x)) ){ + do_something(); + } + + +

This rule is not applied to function calls in Lisp. For example, the outer parentheses forming a function call receive no padding, even when they contain nested data lists:

+ + + (cat 'a 'b '( 2 (4 5))) + + +

Indentation

+ +

Python enforces indentation syntactically. Use two-space indentation for all Python code, even though four is common in the wider ecosystem.

+ +

The CLI vs. work function pattern

+

+ To avoid the "String Trap" (where logic is tightly coupled to the terminal and requires string serialization to reuse) executable modules must separate the Command Line Interface from the core logic. +

+ + +

Python application

+

Put argument parsing and if __name__ == "__main__": in the CLI section. Keep side effects out of import time.

+ +

Bash application

+

Bash scripts should start with #!/usr/bin/env bash and set -euo pipefail. RT-style Bash separates a small top-level CLI harness from a set of functions that implement the work. Parse arguments into variables, call a main function with explicit parameters, and avoid relying on global mutable state where possible.

+ +

C addendum: error handling and ownership

+ + +

Automated formatting tools

+

+ To ensure consistency without manual drudgery, the Harmony skeleton provides a dedicated code formatter called RTfmt. A person can find this tool in the shared/tool/ directory. +

+ +

The RTfmt CLI

+

+ RTfmt is a shallow-tokenizing formatter written in Python. It parses source code into structural blocks (strings, comments, commas, and enclosures) without needing a full Abstract Syntax Tree. This architecture allows it to safely enforce RT formatting rules across multiple languages while preserving indentation and protecting native operators. +

+ + +

Emacs integration

+

+ For Emacs users, the RTfmt.el file provides the RTfmt-buffer interactive command. +

+

+ This wrapper passes the current buffer through the RTfmt pipe command. It automatically detects Lisp-derived modes to append the --lisp flag. Furthermore, it utilizes a non-destructive buffer replacement strategy. This ensures that a programmer's cursor position, selection marks, and window scroll state remain anchored exactly where they were before the formatting occurred. +

+ +

Exercises

+

Exercise 1: Comma and function call formatting

+

Reformat the following C code snippet to strictly adhere to the RT code format rules.

+ + void my_function(int a, int b, int c) { + int result = calculate_value(a, b, c); + printf("Result: %d, a: %d, b: %d, c: %d\n", result, a, b, c); + } + + +

Exercise 2: Multi-level enclosure and short stuff rule

+

Reformat the following C code snippet to use the multi-level enclosure rule and the short stuff rule.

+ + if (check_permissions(user_id, file_path) && is_valid(file_path)) { + for (int i = 0; i < 10; i++) { + if (i % 2 == 0) { + printf("Even: %d\n", i); + } + } + } + + +

Exercise 3: Identifier Naming Conventions

+

+ Rename the following poorly named variables to strictly adhere to the RT code format rules. Assume these are variables in a C or Python program (using standard snake_case). Pay close attention to proper nouns, acronyms, and the expanded suffix semantics. +

+ + +

Exercise 4: Identifier naming with hyphens

+

+ Rename the same poorly named variables from Exercise 3, but this time assume they are written in a language that supports the hyphen (-) in identifiers. Apply the rules for primary and secondary separators, keeping in mind the structural boundary of suffixes. +

+ + +
+ + diff --git a/developer/document/RT_code_format.html b/developer/document/RT_code_format.html deleted file mode 100644 index 7f2de0c..0000000 --- a/developer/document/RT_code_format.html +++ /dev/null @@ -1,225 +0,0 @@ - - - - - RT code format conventions - - - - - - - - - - -

- We are not big on revising inherited or legacy code for naming conventions, though no one will hold you back. However, new code should follow these conventions. -

- -

Object vs. instance nomenclature

-

- We reserve the word 'object' for its general English meaning. When discussing data that is manipulated solely through a defined interface, use the term instance. It is too much of an ask to remove the word object from the language, and this is reflected in the fact that few people use the term precisely. -

-

- Hence, a programmer can talk about math objects, as things found in mathematics, and C objects, as things found in the C language, even though they are not instantiated from classes, or might not even be data. For example, the for loop is a C object. -

- -

Identifier Names

- -

Case

- - -

Proper nouns and acronyms

-

- Even in PascalCase and snake_case, proper nouns and acronyms remain capitalized, as per standard English language conventions (e.g., IEEE_publication_count). -

- -

Abbreviations

-

- For outer scope identifiers we spell things out for clarity. This follows Lisp programming culture. This makes it clear for people who are 'not in the club' to be able to get started and read the code, and tends to be self documenting. Our file system names mirror our program identifier rules, so you find things such as 'library', 'source', spelled out. -

-

- For long words, inner scope identifiers, temporary variables, and conventional suffixes, abbreviations become more common. By the time we get to inner loops variable names, such as loop counters are typically 1 letter long. -

- -

Primary and secondary separators (snake-kebab_case)

-

- If a language supports the hyphen (-) in identifiers (such as Common Lisp and Emacs Lisp), the identifier is written in snake-kebab_case. The hyphen is used as the primary word separator. The underscore (_) is then reserved strictly as a secondary separator to group logically related portions of an identifier or to denote semantic boundaries, acting as a structural namespace within the symbol (e.g., city-scape_building-height). -

-

- Otherwise, if the language does not support hyphens in identifiers (such as C, Python, and Java), the identifier falls back to standard snake_case and only the underscore (_) is used for all separation. In C specifically, a center dot (·) is used for ad hoc namespaces. -

- -

Suffixes

- -

Add a container type suffix instead of making variable names plural.

- - -

Add a type suffix when it adds clarity.

- - - - - - -

Comma separated lists

- -

Horizontal comma list

-

The comma is preceded by a space and abuts the item it follows.

- - int x ,y ,z; - - -

Vertical comma list

-

The comma is placed before the item on the new line, aligned with the item's indentation. This applies to all languages, including Python and C.

- - result = some_function( - first_argument - ,second_argument - ,third_argument - ); - - -

Enclosure spacing

- -

Single-level enclosures

-

No space padding inside the enclosure punctuation.

- - if(condition){ - do_something(); - } - - -

Multi-level enclosures

-

One space of padding is applied only to the outermost enclosure punctuation.

- - - if( f(g(x)) ){ - do_something(); - } - - -

This rule is not applied to function calls in Lisp. For example, the outer parentheses forming a function call receive no padding, even when they contain nested data lists:

- - - (cat 'a 'b '( 2 (4 5))) - - -

Indentation

- -

Python enforces indentation syntactically. Use two-space indentation for all Python code, even though four is common in the wider ecosystem.

- -

The CLI vs. work function pattern

-

- To avoid the "String Trap" (where logic is tightly coupled to the terminal and requires string serialization to reuse) executable modules must separate the Command Line Interface from the core logic. -

- - -

Python application

-

Put argument parsing and if __name__ == "__main__": in the CLI section. Keep side effects out of import time.

- -

Bash application

-

Bash scripts should start with #!/usr/bin/env bash and set -euo pipefail. RT-style Bash separates a small top-level CLI harness from a set of functions that implement the work. Parse arguments into variables, call a main function with explicit parameters, and avoid relying on global mutable state where possible.

- -

C addendum: error handling and ownership

- - -

Automated formatting tools

-

- To ensure consistency without manual drudgery, the Harmony skeleton provides a dedicated code formatter called RTfmt. A person can find this tool in the shared/tool/ directory. -

- -

The RTfmt CLI

-

- RTfmt is a shallow-tokenizing formatter written in Python. It parses source code into structural blocks (strings, comments, commas, and enclosures) without needing a full Abstract Syntax Tree. This architecture allows it to safely enforce RT formatting rules across multiple languages while preserving indentation and protecting native operators. -

- - -

Emacs integration

-

- For Emacs users, the RTfmt.el file provides the RTfmt-buffer interactive command. -

-

- This wrapper passes the current buffer through the RTfmt pipe command. It automatically detects Lisp-derived modes to append the --lisp flag. Furthermore, it utilizes a non-destructive buffer replacement strategy. This ensures that a programmer's cursor position, selection marks, and window scroll state remain anchored exactly where they were before the formatting occurred. -

- -

Exercises

-

Exercise 1: Comma and function call formatting

-

Reformat the following C code snippet to strictly adhere to the RT code format rules.

- - void my_function(int a, int b, int c) { - int result = calculate_value(a, b, c); - printf("Result: %d, a: %d, b: %d, c: %d\n", result, a, b, c); - } - - -

Exercise 2: Multi-level enclosure and short stuff rule

-

Reformat the following C code snippet to use the multi-level enclosure rule and the short stuff rule.

- - if (check_permissions(user_id, file_path) && is_valid(file_path)) { - for (int i = 0; i < 10; i++) { - if (i % 2 == 0) { - printf("Even: %d\n", i); - } - } - } - - -

Exercise 3: Identifier Naming Conventions

-

- Rename the following poorly named variables to strictly adhere to the RT code format rules. Assume these are variables in a C or Python program (using standard snake_case). Pay close attention to proper nouns, acronyms, and the expanded suffix semantics. -

- - -
- - diff --git a/developer/document/Single-file_C_modules_and_namespaces.html b/developer/document/Single-file_C_modules_and_namespaces.html deleted file mode 100644 index 23af5f8..0000000 --- a/developer/document/Single-file_C_modules_and_namespaces.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - C modules, namespaces, and the build lifecycle - - - - - - - - - - -

Single-file C source

-

- The RT C language culture abandons the traditional separation of declarations into .h header files and definitions into .c source files. A developer integrates the interface and the implementation into a single file. -

-

- When a person includes the file using an #include directive, the file exposes only its interface. When the build system compiles the file into an object, a preprocessor macro acts as an implementation gate to compile the definitions. This keeps the source tree clean and ensures the interface and implementation never fall out of synchronization. -

- -

Ad hoc namespaces

-

- The C language lacks native namespaces. To prevent symbol collisions in large projects, RT code format uses a center dot (·) to denote ad hoc namespaces within identifiers. -

-

- A programmer maps the directory structure directly to these namespaces. For example, a file located at authored/ExampleGreet/Math.lib.c belongs to the ExampleGreet namespace and defines the Math module. -

- -

- An exported function from this module carries the full namespace and module prefix, such as ExampleGreet·Math·add. -

- -

The implementation gate

-

- To achieve the single-file source pattern, the code relies on two preprocessor constructs: -

- - -

Build system mechanics

-

- When a consumer file, such as hello.CLI.c, contains #include "Math.lib.c", the compiler processes the file without the ExampleGreet·Math macro defined. It skips the implementation and reads only the function prototype. -

-

- When the orchestrator compiles the library object, it evaluates the target name and explicitly passes -DExampleGreet·Math to the compiler. This unlocks the gate, compiling the machine code for the definitions into Math.lib.o. -

- -

Example: Math.lib.c

-

- The following example demonstrates the complete structure. -

- - - #ifndef ExampleGreet·Math·ONCE - #define ExampleGreet·Math·ONCE - - int ExampleGreet·Math·add(int a ,int b); - - #ifdef ExampleGreet·Math - - int ExampleGreet·Math·add(int a ,int b){ - return a + b; - } - - #endif // ExampleGreet·Math - #endif // ExampleGreet·Math·ONCE - - -

Cross-module dependencies

-

- When one module depends on another, the developer directly includes the library source file. For example, if the Greeter module requires the Math module, the file Greeter.lib.c will contain: -

- - #include "Math.lib.c" - -

- Because every file is protected by a ·ONCE include guard, it is safe for multiple modules to include the same dependency. The preprocessor will expand the interface once per translation unit. -

- -

Information hiding

-

- To define internal helper functions or private data that should not be exposed in the module's public interface, a programmer places them strictly inside the #ifdef implementation block. -

-

- To prevent these internal symbols from leaking into the global namespace during linking, they must be given internal linkage. The RT skeleton provides the Local macro (defined as static in RT_global.h) for this exact purpose. -

- - #ifdef ExampleGreet·Math - - Local int internal_helper(int val){ - return val * 2; - } - - int ExampleGreet·Math·add(int a ,int b){ - return internal_helper(a) + b; - } - - #endif // ExampleGreet·Math - - -

Executable entry points

-

- Programs intended to be compiled into standalone executables use the .CLI.c suffix. These files consume the library modules but do not define their own namespaces or include guards, as they are never included by other files. -

-

- A .CLI.c file includes the necessary .lib.c files, parses command-line arguments in the main function, and passes native data types to a dedicated CLI() function to orchestrate the core logic. -

- -

Directory structure and namespaces

-

- The physical layout of the authored directory dictates how the build orchestrator finds the source code. -

- - -

Making the code

-

- The developer compiles the code using the make wrapper script located in developer/tool/make. This script accepts two primary arguments: the build command and the target namespace. -

- - - > make <command> [namespace] - - -

- To build the ExampleGreet code, a person issues the following command from the developer workspace: -

- - - > make all ExampleGreet - - -

- Behind the scenes, the make wrapper assigns the namespace to an environment variable and calls the master orchestrator makefile. The orchestrator detects the namespace, updates the source directory search path to authored/ExampleGreet, and injects the appropriate namespace macros during compilation. -

-

- The orchestrator compiles the .lib.c files into object files under scratchpad/build/object/, archives them into a library file, and links the .CLI.c objects into standalone executables. The final artifacts are placed in the scratchpad/made/ directory. -

- -

Promoting the artifacts

-

- Artifacts resting in the scratchpad are volatile and private to the developer. To share the executables and libraries with the rest of the project (such as the tester or consumer roles), the developer must promote them. -

- - - > promote write - - -

- The promote tool compares the contents of developer/scratchpad/made/ against consumer/made/. It atomically copies any new or updated files to the consumer workspace, stripping write permissions to enforce the immutability of the deployment target. Once promoted, the hello executable is ready for testing. -

- -
- - diff --git a/developer/document/naming_file-and-directory.html b/developer/document/naming_file-and-directory.html new file mode 100644 index 0000000..2d7a350 --- /dev/null +++ b/developer/document/naming_file-and-directory.html @@ -0,0 +1,90 @@ + + + + + File and directory naming conventions + + + + + + + + + + +

Program file system objects

+ +

+ Harmony files and directories are considered to be program file systems objects. +

+ +

Files

+

+ Files that hold a single class, have he same base name as that class. If a file holds multiple classes, but there is a class of primary importance and auxiliary classes, the file carries the name of the primary class. +

+ +

+ If a file represents a module or name space, follow the same naming conventions specified for classes and name spaces in the RT_code_format.html document. +

+ +

+ Other program files follow the same naming conventions specified in the RT_code_format.html document for an identifier of the + contained or related language. +

+ +

Hyphens and spaces

+ +

In a C language culture, file names use underscores between words. In a Lisp language culture use snake-kebab_case. Spaces are generally not used in program file names. Though the Harmony skeleton is language agnostic, it was first used with C, hence file names use primarily underscores. +

+ + +

Program Directories

+

+ A directory that is a package, follows the convention for name spaces. +

+ +

+ A directory that is used to give the contained files a property is an identifier. +

+ +

+ What is a reasonable primary property for a set of files? Perhaps: +

+ + +

Property indicators on files

+

+ We add a second property to a file using dot extensions to the file's name. We can extend the dot suffix model by using multiple dot suffixes. File name extensions are used to signal to the build tools how the file is to be processed: +

+ + +

Exercises

+

Exercise 1: Program file names

+

+ Rename the following poorly named files to strictly adhere to the RT naming conventions. Pay close attention to the language culture, the capitalization of acronyms, and the rule for spelling out abbreviations in outer scope identifiers. +

+ + +
+ + diff --git a/developer/document/single-file_C-module-and-namespace.html b/developer/document/single-file_C-module-and-namespace.html new file mode 100644 index 0000000..23af5f8 --- /dev/null +++ b/developer/document/single-file_C-module-and-namespace.html @@ -0,0 +1,171 @@ + + + + + C modules, namespaces, and the build lifecycle + + + + + + + + + + +

Single-file C source

+

+ The RT C language culture abandons the traditional separation of declarations into .h header files and definitions into .c source files. A developer integrates the interface and the implementation into a single file. +

+

+ When a person includes the file using an #include directive, the file exposes only its interface. When the build system compiles the file into an object, a preprocessor macro acts as an implementation gate to compile the definitions. This keeps the source tree clean and ensures the interface and implementation never fall out of synchronization. +

+ +

Ad hoc namespaces

+

+ The C language lacks native namespaces. To prevent symbol collisions in large projects, RT code format uses a center dot (·) to denote ad hoc namespaces within identifiers. +

+

+ A programmer maps the directory structure directly to these namespaces. For example, a file located at authored/ExampleGreet/Math.lib.c belongs to the ExampleGreet namespace and defines the Math module. +

+ +

+ An exported function from this module carries the full namespace and module prefix, such as ExampleGreet·Math·add. +

+ +

The implementation gate

+

+ To achieve the single-file source pattern, the code relies on two preprocessor constructs: +

+ + +

Build system mechanics

+

+ When a consumer file, such as hello.CLI.c, contains #include "Math.lib.c", the compiler processes the file without the ExampleGreet·Math macro defined. It skips the implementation and reads only the function prototype. +

+

+ When the orchestrator compiles the library object, it evaluates the target name and explicitly passes -DExampleGreet·Math to the compiler. This unlocks the gate, compiling the machine code for the definitions into Math.lib.o. +

+ +

Example: Math.lib.c

+

+ The following example demonstrates the complete structure. +

+ + + #ifndef ExampleGreet·Math·ONCE + #define ExampleGreet·Math·ONCE + + int ExampleGreet·Math·add(int a ,int b); + + #ifdef ExampleGreet·Math + + int ExampleGreet·Math·add(int a ,int b){ + return a + b; + } + + #endif // ExampleGreet·Math + #endif // ExampleGreet·Math·ONCE + + +

Cross-module dependencies

+

+ When one module depends on another, the developer directly includes the library source file. For example, if the Greeter module requires the Math module, the file Greeter.lib.c will contain: +

+ + #include "Math.lib.c" + +

+ Because every file is protected by a ·ONCE include guard, it is safe for multiple modules to include the same dependency. The preprocessor will expand the interface once per translation unit. +

+ +

Information hiding

+

+ To define internal helper functions or private data that should not be exposed in the module's public interface, a programmer places them strictly inside the #ifdef implementation block. +

+

+ To prevent these internal symbols from leaking into the global namespace during linking, they must be given internal linkage. The RT skeleton provides the Local macro (defined as static in RT_global.h) for this exact purpose. +

+ + #ifdef ExampleGreet·Math + + Local int internal_helper(int val){ + return val * 2; + } + + int ExampleGreet·Math·add(int a ,int b){ + return internal_helper(a) + b; + } + + #endif // ExampleGreet·Math + + +

Executable entry points

+

+ Programs intended to be compiled into standalone executables use the .CLI.c suffix. These files consume the library modules but do not define their own namespaces or include guards, as they are never included by other files. +

+

+ A .CLI.c file includes the necessary .lib.c files, parses command-line arguments in the main function, and passes native data types to a dedicated CLI() function to orchestrate the core logic. +

+ +

Directory structure and namespaces

+

+ The physical layout of the authored directory dictates how the build orchestrator finds the source code. +

+ + +

Making the code

+

+ The developer compiles the code using the make wrapper script located in developer/tool/make. This script accepts two primary arguments: the build command and the target namespace. +

+ + + > make <command> [namespace] + + +

+ To build the ExampleGreet code, a person issues the following command from the developer workspace: +

+ + + > make all ExampleGreet + + +

+ Behind the scenes, the make wrapper assigns the namespace to an environment variable and calls the master orchestrator makefile. The orchestrator detects the namespace, updates the source directory search path to authored/ExampleGreet, and injects the appropriate namespace macros during compilation. +

+

+ The orchestrator compiles the .lib.c files into object files under scratchpad/build/object/, archives them into a library file, and links the .CLI.c objects into standalone executables. The final artifacts are placed in the scratchpad/made/ directory. +

+ +

Promoting the artifacts

+

+ Artifacts resting in the scratchpad are volatile and private to the developer. To share the executables and libraries with the rest of the project (such as the tester or consumer roles), the developer must promote them. +

+ + + > promote write + + +

+ The promote tool compares the contents of developer/scratchpad/made/ against consumer/made/. It atomically copies any new or updated files to the consumer workspace, stripping write permissions to enforce the immutability of the deployment target. Once promoted, the hello executable is ready for testing. +

+ +
+ + diff --git a/developer/tool/do-all b/developer/tool/do-all new file mode 100755 index 0000000..2350fd8 --- /dev/null +++ b/developer/tool/do-all @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") + +# input guards + + setup_must_be="developer/tool/setup" + if [ "$SETUP" != "$setup_must_be" ]; then + echo "$(script_fp):: error: must be run in the $setup_must_be environment" + exit 1 + fi + +set -e +set -x + + cd "$REPO_HOME"/developer || exit 1 + # /bin/make -f tool/makefile $@ + + scratchpad clear + make + release clean + release write + +set +x +echo "$(script_fn) done." diff --git a/developer/tool/do_all b/developer/tool/do_all deleted file mode 100755 index 2350fd8..0000000 --- a/developer/tool/do_all +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -script_afp=$(realpath "${BASH_SOURCE[0]}") - -# input guards - - setup_must_be="developer/tool/setup" - if [ "$SETUP" != "$setup_must_be" ]; then - echo "$(script_fp):: error: must be run in the $setup_must_be environment" - exit 1 - fi - -set -e -set -x - - cd "$REPO_HOME"/developer || exit 1 - # /bin/make -f tool/makefile $@ - - scratchpad clear - make - release clean - release write - -set +x -echo "$(script_fn) done." diff --git a/document/Introduction_to_Harmony.html b/document/Introduction_to_Harmony.html deleted file mode 100644 index 10560fa..0000000 --- a/document/Introduction_to_Harmony.html +++ /dev/null @@ -1,380 +0,0 @@ - - - - - Introduction to Harmony - - - - - - - - - - -

Purpose

-

- Harmony provides a language-agnostic project directory structure and maintenance tools for long-lived, multi-person team software development. The structure exists to enforce: -

-
    -
  1. Clarity about where things live. -
      -
    • Role-based work areas.
    • -
    • Separation of skeleton, team member authored, machine-made, and third-party installed software.
    • -
    -
  2. -
  3. A safe, predictable build and promotion workflow.
  4. -
- -

- Harmony is a project skeleton, a set of tools and directories that have been checked into a git repository. To create a Harmony-based project, the project administrator performs these steps: -

-
    -
  1. Clone the Harmony project to a local directory.
  2. -
  3. Remove the .git tree.
  4. -
  5. Rename the Harmony directory to the name of the new project.
  6. -
  7. Rename the 0pus_Harmony file to reflect the name of the new project.
  8. -
  9. Add a line to the shared/tool/version file for the new project.
  10. -
  11. git init -b core_developer_branch
  12. -
- -

- The order is important so as to protect the Harmony skeleton project from accidental check-ins from users. -

-

- Leave the Harmony skeleton version in the version file, so that project administrators can understand what has changed in the skeleton over time. -

-

- The core_developer_branch is the branch that the core development team works on. Project releases are moved to release branches. -

- -

Environment setup

-

- Python programmers who use virtual environments will be familiar with an analogous process. The term 'virtual environment' does not invoke any hardware virtualization features; rather, it is a local environment setup. To avoid confusion, a Harmony user refers instead to the 'project setup'. The command to establish the environment is called 'setup' instead of 'activate'. Also note that in Harmony, unlike in Python, there are multiple setups available, each tailored to the specific role a person takes on. -

-

- As of the time of this writing, the defined roles are: administrator, consumer, developer, and tester. A person takes on a role by sourcing the top-level setup script and giving the target role as an argument. For example, in a bash shell with > as the prompt, the command is: -

- - - > . setup <role> - - -

- Specifically for the developer role: -

- - - > . setup developer - - -

- For the administrator role: -

- - - > . setup administrator - - -

- Instead of starting with a period, the source command can be spelled out explicitly, for example: -

- - - > source setup tester - - -

- Behind the scenes, the setup script performs the following actions: -

- - - -

After git clone

-

- Because git does not track certain directories (such as shared/third_party/ and consumer/made/), a freshly cloned repository lacks external dependencies and consumable products. Team members must perform a few steps to populate these areas. -

- -

Third-party tools

-

- Harmony is language agnostic. When a project makes use of project-specific C, Python, NodeJS, Java, or other tools, the project administrator configures the project to expect these tools in the shared/third_party directory. -

-

- Because multiple team members will have to repeat the third-party install process after cloning a project, the administrator should carefully document the third party tools installation steps and place the resulting documents in the shared/document directory. (The most common installation method is to clone the third party tool next to the project, then to symbolic link it under shared/third_party/.) -

-

- If a person clones the project and does not set up third-party tools, commands will fall through the search path and perhaps find system-installed tools. Using system default tools is generally undesirable because each person who clones the project might be running different versions. This variation makes it harder for team members to coordinate and for consumers of the project work product to build functioning tools. -

- -

Consumer build

-

- In this section we use the term 'consumer' to mean any team member that wants to make use of the project work product. The tester will want to test it, and the consumer role will want to deploy it, etc. -

-

- An earlier version of Harmony used platform-specific made directories, but this left binaries in the repository and added excessive complexity. - So as to avoid that mess, the current version of Harmony requires a work product consumer to run a local build after cloning the project. The results of the build will appear in the consumer/made directory. -

-

- To facilitate this, the developer must explicitly document the project's build and promote procedure, saving this guide as developer/document/build.html. -

-

- The consumer must then read this document and execute the described steps to compile the source and locally populate their consumer/made directory. -

- -

- Because the build and promotion tools are strictly isolated within the developer workspace, the consumer must temporarily put on the developer hat to perform the build. Typically the consumer build procedure will be a variation of the following: -

- -
    -
  1. > bash
  2. -
  3. > cd <project>
  4. -
  5. > . setup developer
  6. -
  7. > make CLI
  8. -
  9. > promote write
  10. -
  11. > exit
  12. -
  13. > bash
  14. -
  15. > cd <project>
  16. -
  17. > . setup <role>
  18. -
- -

- This sequence opens a bash shell, assumes the developer role to orchestrate the build, makes the work product, then promotes it to the consumer's workspace. The exit command drops the developer role. The last two lines put the person into the <role> workspace, typically for testing or deploying. Commonly, deployment is a matter of adding the consumer/made directory into the executable search path. -

- - -

Directory semantic properties

-

- This section discusses our thinking in naming the files and directories found in the Harmony skeleton. -

-

- A directory name is considered to be a property given to each file contained in the directory. A full path then forms a semantic sentence describing each file. -

-

- Because a directory name represents a property, it is rarely plural. For example, when each and every file in a directory is a test, the directory is named test. -

-

- We run into limitations when using a conventional file system as though it were a property based file system. One limitation is that we are forced to choose a single directory name for each file. When a set of files in a directory all share the same multiple properties, we can use a compound directory name with the properties separated by an underscore, but it is impractical to specify overlapping directory groupings, i.e. we can't arbitrarily define any number of properties for a file in this manner. -

-

- The following list presents each property type in order of preference when naming directories: -

- - -

Authored, made, scratchpad, inherited

-

- Files found in a directory named authored were written by project team members. They did not come with the Harmony skeleton, nor with the installation of other software. Project build tools treat authored directories as strictly read-only. Typically these files constitute the intellectual property of a project. -

-

- All source code that gets built into a promotion or project release must be placed in the developers' authored directory. The story is not as clean for build tools and other files. New documents go into document directories, and new tools go into the tool directories, etc. As a specific example, the developer will almost certainly edit the developer/tool/make file. -

-

- When the Harmony version line in the shared/tool/version file is left in place, it is straightforward for a project administrator to determine which Harmony skeleton files have been edited in a project, and which new files have been added. -

-

- Files found in a directory named scratchpad are not tracked. Hence, a git clone will always return empty scratchpad directories. It is common for tools to place intermediate files on a scratchpad. It is also common for files to be staged on a scratchpad. Tools play nice and use subdirectories on the pad, so a person who is aware of those subdirectory names can use a scratchpad as a temporary directory. There is a scratchpad maintenance tool that comes with the Harmony, called unimaginatively, scratchpad. Pay attention as one of its commands is clear, and that deletes everything on the current directory's scratchpad. -

-

- Third party software is installed under shared/third_party. Other files are said to be inherited, or to be customizations. -

- -

Top-level repository layout

-

- A team member will source the project setup file to take on a role. As of this writing, the supported roles are: administrator, developer, tester, and consumer. -

- - - -

The administrator work area

-

- This directory holds the tools and documentation used to manage the project as a whole. It includes the HTML documentation for the project ontology and workflow, as well as project-local tools utilized by the administrator to maintain the Harmony skeleton. -

- -

The developer work area

-

- This directory is entered by first going to the top-level directory of the project, then sourcing . setup developer. -

- - -

The tester work area

-

- This directory is dedicated to formal testing, including regression suites. While a developer can run and keep informal spot tests in their experiment/ directory, any experiment promoted to a formal test is moved here. This enforces the boundary between writing code and validating it. -

- -

The shared tree

-

- This directory contains ecosystem tools and global environments available to all roles. This includes the shared tool directory, as well as third-party installations (like Python virtual environments or compilers) required by the project. To assist in project specific modifications to the Harmony skeleton, Harmony comes with an empty shared/authored directory that is listed earlier in the executable search path than shared/tool. -

- -

The consumer tree

-

- The consumer/made/ tree is where developers put work product that is ready to be consumed. The entire consumer/made directory is git-ignored and treated as a transient deployment target. -

-

- Artifacts arrive in the consumer/made/ tree only when the promote script is invoked, which performs a flat-copy from the developer's scratchpad/made directory. -

- -

Document directories

-

- There is a directory for documents that talks about the project as a whole, one for each role, one for tools that are shared among the roles, and the released work product probably comes with a document directory of its own. -

- - -

- Note that the consumer/made directory is untracked by git and maintained by a tool. (Said tool is developer/tool/promote. It is owned and used by the developer as part of the build process.) Documents that are being promoted for eventual release, and appear in the made directory originate from somewhere from the developer/authored directory depending on how the developer has organized his workspace, but probably in developer/authored/document. Perhaps a future version of Harmony will have a tech-writer role, but that is not the case now. -

- -

- Currently, our developers write documents directly in HTML using the RT semantic tags. See the RT-style-JS_public project and the documentation there. A common approach is to copy another document and the setup.js file, then to type over the top of that other document. Only one setup.js file is used per directory. Be sure to edit the relative root path found at the top of setup.js. Plain text, emacs org, and mark down have all been used in prior versions of Harmony. -

- -

Untracked directories

-
    -
  1. consumer/made/
  2. -
  3. shared/third_party/
  4. -
  5. **/scratchpad/
  6. -
- -

Workflow

-

See the document "Product Development Roles and Workflow" for more details.

- -

Developer promotion and project releases

-

- As a first step, a developer creates a promotion candidate inside of the consumer/made/ directory. This is typically done by running make to stage the artifacts into scratchpad/made, where they can be experimented on, followed by running promote write. The developer will often modify the versions of one or both of those tools that come with the Harmony skeleton. The promotion candidate remains stable until the next promotion. -

-

- Then the tester runs tests on the promotion candidate. Tests must only read from the consumer/made/ directory, though local copies can be made and edited as experiments. Currently bugs are filed using an external issues tool. -

-

- It is common for a developer to open a second window on his desktop, and then enter the project as a tester in that second window. The developer can then make a promotion candidate, run the tests, edit source code, and perhaps tests, and then quickly spin through the test-debug-fix-promote cycle repeatedly. -

-

- When the product manager determines the work product to be sufficiently reliable and feature rich, the administrator will make a project release. He will do this by creating a branch called release_v<major> and tagging it. The major release numbers go up incrementally. -

- -

The version 2.2 Harmony directory tree

- - - 2026-03-09 01:42:16 Z [Harmony:administrator] Thomas_developer@StanleyPark - §/home/Thomas/subu_data/developer/project§ - > tree Harmony - Harmony - ├── 0pus_Harmony - ├── administrator - │ ├── authored - │ ├── document - │ │ └── setup.js - │ └── tool - │ ├── archive - │ └── setup - ├── consumer - │ ├── scratchpad - │ └── tool - │ └── env - ├── developer - │ ├── authored - │ │ └── hello.CLI.c - - - │ ├── document - │ │ ├── 02_RT_Code_Format.html - │ │ ├── 03_Naming_and_Directory_Conventions.html - │ │ ├── 04_Language_Addenda.html - │ │ └── setup.js - │ ├── experiment - │ ├── made - │ ├── scratchpad - │ └── tool - │ ├── do_all - │ ├── make - │ ├── makefile - │ ├── promote - │ └── setup - ├── document - │ ├── Introduction_to_Harmony.html - │ ├── Product_Development_Roles_and_Workflow.html - │ └── setup.js - ├── LICENSE - - - ├── README.md - ├── scratchpad - │ ├── Harmony__79f9d52__2026-03-07_085628Z.tar - │ └── Harmony__e665bb7__2026-03-09_013712Z.tar - ├── setup - ├── shared - │ ├── authored - │ ├── document - │ │ ├── install_generic.org - │ │ ├── install_Python.org - │ │ └── setup.js - │ ├── made - │ ├── style_directory_dict.js - │ ├── third_party - │ │ ├── RT-style-JS_public -> ../../../RT-style-JS_public/ - │ │ └── upstream - │ └── tool - │ ├── scratchpad - │ ├── setup - - - │ ├── style - │ └── version - └── tester - ├── authored - │ └── test_routine.sh - ├── RT_Format - │ ├── RT_Format - │ ├── RT_Format.el - │ ├── test_0_data.c - │ └── test_1_data.py - └── tool - └── setup - - 30 directories, 36 files - - 2026-03-09 01:42:19 Z [Harmony:administrator] Thomas_developer@StanleyPark - §/home/Thomas/subu_data/developer/project§ - > - - -
- - diff --git a/document/Product-development_roles-and-workflow.html b/document/Product-development_roles-and-workflow.html deleted file mode 100644 index 149624b..0000000 --- a/document/Product-development_roles-and-workflow.html +++ /dev/null @@ -1,123 +0,0 @@ - - - - - Product development roles and workflow - - - - - - - - - - -

Roles as hats

-

- In Harmony, a role is a hat a person wears. There can be multiple people sharing a single role, and a single person can wear many hats. Some roles interact directly with the project directory structure, while others guide the process from outside the codebase. -

- -

Workspace roles

-

- These roles interact directly with the repository. To enter a workspace, change directory to the top-level of the project and source the setup file for the desired role: -

- - > . setup administrator - > . setup developer - > . setup tester - > . setup consumer - -

- It is common for a person to have multiple terminal sessions or IDEs open, each running under a different role environment. -

- -

Administrator role

-

Responsibilities:

-
    -
  1. Set up the project directory and keep it in sync with the Harmony skeleton.
  2. -
  3. Maintain role environments (apart from role-specific tool/setup files).
  4. -
  5. Install and maintain shared and third_party tools, addressing issues with the project workflow. Note that the term "third_party" encompasses any software not authored within this specific project.
  6. -
- -

Developer role

-

Responsibilities and Boundaries:

-
    -
  1. Write and modify authored/ source.
  2. -
  3. Run builds and place artifacts in scratchpad/made, then execute the promote write script to copy artifacts to consumer/made for testing.
  4. -
  5. Run experiments in experiment/. These experiments can sometimes be promoted to formal tests, but there is no requirement to do so. The developer role should not blur into the tester role; experiments are informal, whereas tests are formal and retained.
  6. -
  7. Strict Boundary: A developer never writes into the tester/ directory. Instead, a developer adds tests to developer/experiment/ and offers to share them.
  8. -
- -

Tester role

-

Responsibilities and Boundaries:

-
    -
  1. Evaluate candidates under consumer/made/ and run regression suites to confirm: -
      -
    • That the code does not crash.
    • -
    • That consumers do not have a bad experience.
    • -
    • That the goals specified by the product manager are met.
    • -
    -
  2. -
  3. File issues and communicate feedback to the developers.
  4. -
  5. Strict Boundary: A tester never patches code in the developer/ directory. Instead, the tester files issues or proposes code fixes on a separate branch.
  6. -
- -

Consumer role

-

Responsibilities:

-
    -
  1. Act as the end-user simulation environment.
  2. -
  3. Consume and deploy artifacts exclusively from the consumer/made/ target.
  4. -
  5. Never author or modify code; strictly run local builds or deployments for architecture-specific testing.
  6. -
  7. Report issues. (Anyone can report an issue, and consumers regularly do).
  8. -
- -

External roles

-

- These roles drive the project forward but do not have a dedicated setup <role> workspace, as they do not directly build or test the code in that capacity. If these individuals need to interface with the code, they simply put on a workspace role hat, such as administer, developer, tester, or consumer. -

- -

Product manager

-

- The product manager receives specifications from the architect and sets the specific goals for a release. When the project manager provides updates indicating readiness, the product manager makes the final decision to cut a project release. -

- -

Project manager

-

- The project manager owns the schedule (such as the Gantt chart) and monitors progress. They coordinate code reviews, read issues and announcements, reformulate the schedule, and instruct the product manager. When parts of the codebase are outsourced, the project manager serves as the primary point of contact with the external teams. -

- -

Architect

-

- The architect writes the original specification, sets the technical direction, and performs code reviews. The architect might be a contractor or an in-house team member. -

- -

The four interacting loops

-

- The project moves forward through the continuous interaction of four distinct operational cycles. -

- -
    -
  1. Developer Loop: Write code, compile to the scratchpad made directory, promote to the consumer made directory, announce the promotion to the tester, read issues, and repeat.
  2. -
  3. Tester Loop: Read developer announcements, read the consumer made directory, run tests, and file issues.
  4. -
  5. Product Manager Loop: Provide specifications to the developer, receive progress updates from the project manager, and instruct the project administrator to make new git branch project releases and deploy.
  6. -
  7. Project Manager Loop: Own the Gantt chart, coordinate code reviews, read issues and announcements, reformulate the Gantt chart, and instruct the product manager.
  8. -
- -

Promotion mechanics

-

- Building and promotion are separate activities. The developer compiles and places files in developer/scratchpad/made. The developer then runs promote write to transfer those files to consumer/made. -

-

- The consumer/made directory is strictly an untracked deployment target. No tools are permitted to rebuild during promotion, and no builds are run directly inside the consumer made directory. -

- -
- - diff --git a/document/Product-maintenance_roles-and-workflow.html b/document/Product-maintenance_roles-and-workflow.html deleted file mode 100644 index 6063077..0000000 --- a/document/Product-maintenance_roles-and-workflow.html +++ /dev/null @@ -1,100 +0,0 @@ - - - - - Product maintenance roles and workflow - - - - - - - - - - -

Maintenance philosophy

-

- Deployed software must be a usable quality product for the customer, beyond that we favor addressing issues in new releases, and encourage customers who are having issues to upgrade. This approach is purely one of keeping the maintenance problem tractable. -

- -

Maintenance structure

-

- Teams mentioned in this document: -

-
    -
  1. tester team
  2. -
  3. core developer team
  4. -
  5. branch maintenance team
  6. -
  7. triage team
  8. -
- -

- Team membership is a role a person takes on. Multiple people can share a single role, and one person might take on multiple roles. -

- -

- The tester team develops and maintains the regression suite, the reliability suite, and additional tests. -

- -

- The core developer team writes the source code and compiles promotion candidates. -

- -

- The branch maintenance team is typically a subset of the core developer team. This group is dedicated to applying approved fixes to specific release branches. -

- -

- The triage team evaluates defects reported against active releases. The team usually includes a developer contact, the project manager, and the product manager. -

- -

Issue queues

-

- The project maintains two primary issue queues: -

-
    -
  1. released product
  2. -
  3. core developer
  4. -
- -

- There can be additional queues for multiple branches of development, and for experiments. -

- -

Core developer queue

-

- This queue serves the core_developer_branch. A tester writes a test for every issue reported in this queue. Doing so isolates the defect, proves the fix, and guards against future regressions. -

- -

Released product queue

-

- All issues found in release branches go onto this queue initially. It tracks defects reported against deployed software across any major version. -

- -

Triage and patching

-

- Guided by the project philosophy, the triage team reviews each release queue issue to determine its impact. The team assesses whether the defect affects the core_developer_branch, assuming by default that it probably does. The team also determines if the defect is critical enough to warrant a patch on one or more active release branches. -

-

- Based on this assessment, the triage team files actionable tickets in the core developer queue. A ticket explicitly specifies its target branches. A ticket will be filed against either the core developer branch, specific release branches, or a combination of both. -

-

- Members of the tester team also file tickets directly into the core developer queue when they discover defects in the core branch. -

-

- Responsibility for resolving a ticket depends on its target. The core developer team addresses fixes required on the core_developer_branch. The branch maintenance team addresses fixes required on the release_v<major> branches. -

-

- When a release is patched, the branch name remains static. The administrator advances the minor release number in the shared/tool/version file and tags the commit. -

- -
- - diff --git a/document/introduction_Harmony.html b/document/introduction_Harmony.html new file mode 100644 index 0000000..10560fa --- /dev/null +++ b/document/introduction_Harmony.html @@ -0,0 +1,380 @@ + + + + + Introduction to Harmony + + + + + + + + + + +

Purpose

+

+ Harmony provides a language-agnostic project directory structure and maintenance tools for long-lived, multi-person team software development. The structure exists to enforce: +

+
    +
  1. Clarity about where things live. +
      +
    • Role-based work areas.
    • +
    • Separation of skeleton, team member authored, machine-made, and third-party installed software.
    • +
    +
  2. +
  3. A safe, predictable build and promotion workflow.
  4. +
+ +

+ Harmony is a project skeleton, a set of tools and directories that have been checked into a git repository. To create a Harmony-based project, the project administrator performs these steps: +

+
    +
  1. Clone the Harmony project to a local directory.
  2. +
  3. Remove the .git tree.
  4. +
  5. Rename the Harmony directory to the name of the new project.
  6. +
  7. Rename the 0pus_Harmony file to reflect the name of the new project.
  8. +
  9. Add a line to the shared/tool/version file for the new project.
  10. +
  11. git init -b core_developer_branch
  12. +
+ +

+ The order is important so as to protect the Harmony skeleton project from accidental check-ins from users. +

+

+ Leave the Harmony skeleton version in the version file, so that project administrators can understand what has changed in the skeleton over time. +

+

+ The core_developer_branch is the branch that the core development team works on. Project releases are moved to release branches. +

+ +

Environment setup

+

+ Python programmers who use virtual environments will be familiar with an analogous process. The term 'virtual environment' does not invoke any hardware virtualization features; rather, it is a local environment setup. To avoid confusion, a Harmony user refers instead to the 'project setup'. The command to establish the environment is called 'setup' instead of 'activate'. Also note that in Harmony, unlike in Python, there are multiple setups available, each tailored to the specific role a person takes on. +

+

+ As of the time of this writing, the defined roles are: administrator, consumer, developer, and tester. A person takes on a role by sourcing the top-level setup script and giving the target role as an argument. For example, in a bash shell with > as the prompt, the command is: +

+ + + > . setup <role> + + +

+ Specifically for the developer role: +

+ + + > . setup developer + + +

+ For the administrator role: +

+ + + > . setup administrator + + +

+ Instead of starting with a period, the source command can be spelled out explicitly, for example: +

+ + + > source setup tester + + +

+ Behind the scenes, the setup script performs the following actions: +

+ + + +

After git clone

+

+ Because git does not track certain directories (such as shared/third_party/ and consumer/made/), a freshly cloned repository lacks external dependencies and consumable products. Team members must perform a few steps to populate these areas. +

+ +

Third-party tools

+

+ Harmony is language agnostic. When a project makes use of project-specific C, Python, NodeJS, Java, or other tools, the project administrator configures the project to expect these tools in the shared/third_party directory. +

+

+ Because multiple team members will have to repeat the third-party install process after cloning a project, the administrator should carefully document the third party tools installation steps and place the resulting documents in the shared/document directory. (The most common installation method is to clone the third party tool next to the project, then to symbolic link it under shared/third_party/.) +

+

+ If a person clones the project and does not set up third-party tools, commands will fall through the search path and perhaps find system-installed tools. Using system default tools is generally undesirable because each person who clones the project might be running different versions. This variation makes it harder for team members to coordinate and for consumers of the project work product to build functioning tools. +

+ +

Consumer build

+

+ In this section we use the term 'consumer' to mean any team member that wants to make use of the project work product. The tester will want to test it, and the consumer role will want to deploy it, etc. +

+

+ An earlier version of Harmony used platform-specific made directories, but this left binaries in the repository and added excessive complexity. + So as to avoid that mess, the current version of Harmony requires a work product consumer to run a local build after cloning the project. The results of the build will appear in the consumer/made directory. +

+

+ To facilitate this, the developer must explicitly document the project's build and promote procedure, saving this guide as developer/document/build.html. +

+

+ The consumer must then read this document and execute the described steps to compile the source and locally populate their consumer/made directory. +

+ +

+ Because the build and promotion tools are strictly isolated within the developer workspace, the consumer must temporarily put on the developer hat to perform the build. Typically the consumer build procedure will be a variation of the following: +

+ +
    +
  1. > bash
  2. +
  3. > cd <project>
  4. +
  5. > . setup developer
  6. +
  7. > make CLI
  8. +
  9. > promote write
  10. +
  11. > exit
  12. +
  13. > bash
  14. +
  15. > cd <project>
  16. +
  17. > . setup <role>
  18. +
+ +

+ This sequence opens a bash shell, assumes the developer role to orchestrate the build, makes the work product, then promotes it to the consumer's workspace. The exit command drops the developer role. The last two lines put the person into the <role> workspace, typically for testing or deploying. Commonly, deployment is a matter of adding the consumer/made directory into the executable search path. +

+ + +

Directory semantic properties

+

+ This section discusses our thinking in naming the files and directories found in the Harmony skeleton. +

+

+ A directory name is considered to be a property given to each file contained in the directory. A full path then forms a semantic sentence describing each file. +

+

+ Because a directory name represents a property, it is rarely plural. For example, when each and every file in a directory is a test, the directory is named test. +

+

+ We run into limitations when using a conventional file system as though it were a property based file system. One limitation is that we are forced to choose a single directory name for each file. When a set of files in a directory all share the same multiple properties, we can use a compound directory name with the properties separated by an underscore, but it is impractical to specify overlapping directory groupings, i.e. we can't arbitrarily define any number of properties for a file in this manner. +

+

+ The following list presents each property type in order of preference when naming directories: +

+ + +

Authored, made, scratchpad, inherited

+

+ Files found in a directory named authored were written by project team members. They did not come with the Harmony skeleton, nor with the installation of other software. Project build tools treat authored directories as strictly read-only. Typically these files constitute the intellectual property of a project. +

+

+ All source code that gets built into a promotion or project release must be placed in the developers' authored directory. The story is not as clean for build tools and other files. New documents go into document directories, and new tools go into the tool directories, etc. As a specific example, the developer will almost certainly edit the developer/tool/make file. +

+

+ When the Harmony version line in the shared/tool/version file is left in place, it is straightforward for a project administrator to determine which Harmony skeleton files have been edited in a project, and which new files have been added. +

+

+ Files found in a directory named scratchpad are not tracked. Hence, a git clone will always return empty scratchpad directories. It is common for tools to place intermediate files on a scratchpad. It is also common for files to be staged on a scratchpad. Tools play nice and use subdirectories on the pad, so a person who is aware of those subdirectory names can use a scratchpad as a temporary directory. There is a scratchpad maintenance tool that comes with the Harmony, called unimaginatively, scratchpad. Pay attention as one of its commands is clear, and that deletes everything on the current directory's scratchpad. +

+

+ Third party software is installed under shared/third_party. Other files are said to be inherited, or to be customizations. +

+ +

Top-level repository layout

+

+ A team member will source the project setup file to take on a role. As of this writing, the supported roles are: administrator, developer, tester, and consumer. +

+ + + +

The administrator work area

+

+ This directory holds the tools and documentation used to manage the project as a whole. It includes the HTML documentation for the project ontology and workflow, as well as project-local tools utilized by the administrator to maintain the Harmony skeleton. +

+ +

The developer work area

+

+ This directory is entered by first going to the top-level directory of the project, then sourcing . setup developer. +

+ + +

The tester work area

+

+ This directory is dedicated to formal testing, including regression suites. While a developer can run and keep informal spot tests in their experiment/ directory, any experiment promoted to a formal test is moved here. This enforces the boundary between writing code and validating it. +

+ +

The shared tree

+

+ This directory contains ecosystem tools and global environments available to all roles. This includes the shared tool directory, as well as third-party installations (like Python virtual environments or compilers) required by the project. To assist in project specific modifications to the Harmony skeleton, Harmony comes with an empty shared/authored directory that is listed earlier in the executable search path than shared/tool. +

+ +

The consumer tree

+

+ The consumer/made/ tree is where developers put work product that is ready to be consumed. The entire consumer/made directory is git-ignored and treated as a transient deployment target. +

+

+ Artifacts arrive in the consumer/made/ tree only when the promote script is invoked, which performs a flat-copy from the developer's scratchpad/made directory. +

+ +

Document directories

+

+ There is a directory for documents that talks about the project as a whole, one for each role, one for tools that are shared among the roles, and the released work product probably comes with a document directory of its own. +

+ + +

+ Note that the consumer/made directory is untracked by git and maintained by a tool. (Said tool is developer/tool/promote. It is owned and used by the developer as part of the build process.) Documents that are being promoted for eventual release, and appear in the made directory originate from somewhere from the developer/authored directory depending on how the developer has organized his workspace, but probably in developer/authored/document. Perhaps a future version of Harmony will have a tech-writer role, but that is not the case now. +

+ +

+ Currently, our developers write documents directly in HTML using the RT semantic tags. See the RT-style-JS_public project and the documentation there. A common approach is to copy another document and the setup.js file, then to type over the top of that other document. Only one setup.js file is used per directory. Be sure to edit the relative root path found at the top of setup.js. Plain text, emacs org, and mark down have all been used in prior versions of Harmony. +

+ +

Untracked directories

+
    +
  1. consumer/made/
  2. +
  3. shared/third_party/
  4. +
  5. **/scratchpad/
  6. +
+ +

Workflow

+

See the document "Product Development Roles and Workflow" for more details.

+ +

Developer promotion and project releases

+

+ As a first step, a developer creates a promotion candidate inside of the consumer/made/ directory. This is typically done by running make to stage the artifacts into scratchpad/made, where they can be experimented on, followed by running promote write. The developer will often modify the versions of one or both of those tools that come with the Harmony skeleton. The promotion candidate remains stable until the next promotion. +

+

+ Then the tester runs tests on the promotion candidate. Tests must only read from the consumer/made/ directory, though local copies can be made and edited as experiments. Currently bugs are filed using an external issues tool. +

+

+ It is common for a developer to open a second window on his desktop, and then enter the project as a tester in that second window. The developer can then make a promotion candidate, run the tests, edit source code, and perhaps tests, and then quickly spin through the test-debug-fix-promote cycle repeatedly. +

+

+ When the product manager determines the work product to be sufficiently reliable and feature rich, the administrator will make a project release. He will do this by creating a branch called release_v<major> and tagging it. The major release numbers go up incrementally. +

+ +

The version 2.2 Harmony directory tree

+ + + 2026-03-09 01:42:16 Z [Harmony:administrator] Thomas_developer@StanleyPark + §/home/Thomas/subu_data/developer/project§ + > tree Harmony + Harmony + ├── 0pus_Harmony + ├── administrator + │ ├── authored + │ ├── document + │ │ └── setup.js + │ └── tool + │ ├── archive + │ └── setup + ├── consumer + │ ├── scratchpad + │ └── tool + │ └── env + ├── developer + │ ├── authored + │ │ └── hello.CLI.c + + + │ ├── document + │ │ ├── 02_RT_Code_Format.html + │ │ ├── 03_Naming_and_Directory_Conventions.html + │ │ ├── 04_Language_Addenda.html + │ │ └── setup.js + │ ├── experiment + │ ├── made + │ ├── scratchpad + │ └── tool + │ ├── do_all + │ ├── make + │ ├── makefile + │ ├── promote + │ └── setup + ├── document + │ ├── Introduction_to_Harmony.html + │ ├── Product_Development_Roles_and_Workflow.html + │ └── setup.js + ├── LICENSE + + + ├── README.md + ├── scratchpad + │ ├── Harmony__79f9d52__2026-03-07_085628Z.tar + │ └── Harmony__e665bb7__2026-03-09_013712Z.tar + ├── setup + ├── shared + │ ├── authored + │ ├── document + │ │ ├── install_generic.org + │ │ ├── install_Python.org + │ │ └── setup.js + │ ├── made + │ ├── style_directory_dict.js + │ ├── third_party + │ │ ├── RT-style-JS_public -> ../../../RT-style-JS_public/ + │ │ └── upstream + │ └── tool + │ ├── scratchpad + │ ├── setup + + + │ ├── style + │ └── version + └── tester + ├── authored + │ └── test_routine.sh + ├── RT_Format + │ ├── RT_Format + │ ├── RT_Format.el + │ ├── test_0_data.c + │ └── test_1_data.py + └── tool + └── setup + + 30 directories, 36 files + + 2026-03-09 01:42:19 Z [Harmony:administrator] Thomas_developer@StanleyPark + §/home/Thomas/subu_data/developer/project§ + > + + +
+ + diff --git a/document/role-and-workflow_product-development.html b/document/role-and-workflow_product-development.html new file mode 100644 index 0000000..149624b --- /dev/null +++ b/document/role-and-workflow_product-development.html @@ -0,0 +1,123 @@ + + + + + Product development roles and workflow + + + + + + + + + + +

Roles as hats

+

+ In Harmony, a role is a hat a person wears. There can be multiple people sharing a single role, and a single person can wear many hats. Some roles interact directly with the project directory structure, while others guide the process from outside the codebase. +

+ +

Workspace roles

+

+ These roles interact directly with the repository. To enter a workspace, change directory to the top-level of the project and source the setup file for the desired role: +

+ + > . setup administrator + > . setup developer + > . setup tester + > . setup consumer + +

+ It is common for a person to have multiple terminal sessions or IDEs open, each running under a different role environment. +

+ +

Administrator role

+

Responsibilities:

+
    +
  1. Set up the project directory and keep it in sync with the Harmony skeleton.
  2. +
  3. Maintain role environments (apart from role-specific tool/setup files).
  4. +
  5. Install and maintain shared and third_party tools, addressing issues with the project workflow. Note that the term "third_party" encompasses any software not authored within this specific project.
  6. +
+ +

Developer role

+

Responsibilities and Boundaries:

+
    +
  1. Write and modify authored/ source.
  2. +
  3. Run builds and place artifacts in scratchpad/made, then execute the promote write script to copy artifacts to consumer/made for testing.
  4. +
  5. Run experiments in experiment/. These experiments can sometimes be promoted to formal tests, but there is no requirement to do so. The developer role should not blur into the tester role; experiments are informal, whereas tests are formal and retained.
  6. +
  7. Strict Boundary: A developer never writes into the tester/ directory. Instead, a developer adds tests to developer/experiment/ and offers to share them.
  8. +
+ +

Tester role

+

Responsibilities and Boundaries:

+
    +
  1. Evaluate candidates under consumer/made/ and run regression suites to confirm: +
      +
    • That the code does not crash.
    • +
    • That consumers do not have a bad experience.
    • +
    • That the goals specified by the product manager are met.
    • +
    +
  2. +
  3. File issues and communicate feedback to the developers.
  4. +
  5. Strict Boundary: A tester never patches code in the developer/ directory. Instead, the tester files issues or proposes code fixes on a separate branch.
  6. +
+ +

Consumer role

+

Responsibilities:

+
    +
  1. Act as the end-user simulation environment.
  2. +
  3. Consume and deploy artifacts exclusively from the consumer/made/ target.
  4. +
  5. Never author or modify code; strictly run local builds or deployments for architecture-specific testing.
  6. +
  7. Report issues. (Anyone can report an issue, and consumers regularly do).
  8. +
+ +

External roles

+

+ These roles drive the project forward but do not have a dedicated setup <role> workspace, as they do not directly build or test the code in that capacity. If these individuals need to interface with the code, they simply put on a workspace role hat, such as administer, developer, tester, or consumer. +

+ +

Product manager

+

+ The product manager receives specifications from the architect and sets the specific goals for a release. When the project manager provides updates indicating readiness, the product manager makes the final decision to cut a project release. +

+ +

Project manager

+

+ The project manager owns the schedule (such as the Gantt chart) and monitors progress. They coordinate code reviews, read issues and announcements, reformulate the schedule, and instruct the product manager. When parts of the codebase are outsourced, the project manager serves as the primary point of contact with the external teams. +

+ +

Architect

+

+ The architect writes the original specification, sets the technical direction, and performs code reviews. The architect might be a contractor or an in-house team member. +

+ +

The four interacting loops

+

+ The project moves forward through the continuous interaction of four distinct operational cycles. +

+ +
    +
  1. Developer Loop: Write code, compile to the scratchpad made directory, promote to the consumer made directory, announce the promotion to the tester, read issues, and repeat.
  2. +
  3. Tester Loop: Read developer announcements, read the consumer made directory, run tests, and file issues.
  4. +
  5. Product Manager Loop: Provide specifications to the developer, receive progress updates from the project manager, and instruct the project administrator to make new git branch project releases and deploy.
  6. +
  7. Project Manager Loop: Own the Gantt chart, coordinate code reviews, read issues and announcements, reformulate the Gantt chart, and instruct the product manager.
  8. +
+ +

Promotion mechanics

+

+ Building and promotion are separate activities. The developer compiles and places files in developer/scratchpad/made. The developer then runs promote write to transfer those files to consumer/made. +

+

+ The consumer/made directory is strictly an untracked deployment target. No tools are permitted to rebuild during promotion, and no builds are run directly inside the consumer made directory. +

+ +
+ + diff --git a/document/role-and-workflow_product-maintenance.html b/document/role-and-workflow_product-maintenance.html new file mode 100644 index 0000000..6063077 --- /dev/null +++ b/document/role-and-workflow_product-maintenance.html @@ -0,0 +1,100 @@ + + + + + Product maintenance roles and workflow + + + + + + + + + + +

Maintenance philosophy

+

+ Deployed software must be a usable quality product for the customer, beyond that we favor addressing issues in new releases, and encourage customers who are having issues to upgrade. This approach is purely one of keeping the maintenance problem tractable. +

+ +

Maintenance structure

+

+ Teams mentioned in this document: +

+
    +
  1. tester team
  2. +
  3. core developer team
  4. +
  5. branch maintenance team
  6. +
  7. triage team
  8. +
+ +

+ Team membership is a role a person takes on. Multiple people can share a single role, and one person might take on multiple roles. +

+ +

+ The tester team develops and maintains the regression suite, the reliability suite, and additional tests. +

+ +

+ The core developer team writes the source code and compiles promotion candidates. +

+ +

+ The branch maintenance team is typically a subset of the core developer team. This group is dedicated to applying approved fixes to specific release branches. +

+ +

+ The triage team evaluates defects reported against active releases. The team usually includes a developer contact, the project manager, and the product manager. +

+ +

Issue queues

+

+ The project maintains two primary issue queues: +

+
    +
  1. released product
  2. +
  3. core developer
  4. +
+ +

+ There can be additional queues for multiple branches of development, and for experiments. +

+ +

Core developer queue

+

+ This queue serves the core_developer_branch. A tester writes a test for every issue reported in this queue. Doing so isolates the defect, proves the fix, and guards against future regressions. +

+ +

Released product queue

+

+ All issues found in release branches go onto this queue initially. It tracks defects reported against deployed software across any major version. +

+ +

Triage and patching

+

+ Guided by the project philosophy, the triage team reviews each release queue issue to determine its impact. The team assesses whether the defect affects the core_developer_branch, assuming by default that it probably does. The team also determines if the defect is critical enough to warrant a patch on one or more active release branches. +

+

+ Based on this assessment, the triage team files actionable tickets in the core developer queue. A ticket explicitly specifies its target branches. A ticket will be filed against either the core developer branch, specific release branches, or a combination of both. +

+

+ Members of the tester team also file tickets directly into the core developer queue when they discover defects in the core branch. +

+

+ Responsibility for resolving a ticket depends on its target. The core developer team addresses fixes required on the core_developer_branch. The branch maintenance team addresses fixes required on the release_v<major> branches. +

+

+ When a release is patched, the branch name remains static. The administrator advances the minor release number in the shared/tool/version file and tags the commit. +

+ +
+ + diff --git a/document/todo.txt b/document/todo.txt new file mode 100644 index 0000000..5e09e0e --- /dev/null +++ b/document/todo.txt @@ -0,0 +1,4 @@ +2026-03-26 03:41:44 + +when making a skeleton from Harmony, set skeleton docs and other files not to be edited to read only + diff --git a/next-generation-name.py b/next-generation-name.py new file mode 100755 index 0000000..7aa8c84 --- /dev/null +++ b/next-generation-name.py @@ -0,0 +1,65 @@ +#!/usr/bin/env -S python3 -B +# -*- mode: python; coding: utf-8; python-indent-offset: 2; indent-tabs-mode: nil -*- + +import os ,sys + +def CLI(argv=None) -> int: + # Ordered list of renames: files first, then directories to preserve paths + substitutions = [ + # Administrator + ("administrator/document/Release_howto.html" ,"administrator/document/how-to_release.html") + + # Developer + ,("developer/document/File_directory_naming.html" ,"developer/document/naming_file-and-directory.html") + ,("developer/document/RT_code_format.html" ,"developer/document/format_RT-code.html") + ,("developer/document/Single-file_C_modules_and_namespaces.html" ,"developer/document/single-file_C-module-and-namespace.html") + ,("developer/tool/do_all" ,"developer/tool/do-all") + + # Top-level documents + ,("document/Introduction_to_Harmony.html" ,"document/introduction_Harmony.html") + ,("document/Product-development_roles-and-workflow.html" ,"document/role-and-workflow_product-development.html") + ,("document/Product-maintenance_roles-and-workflow.html" ,"document/role-and-workflow_product-maintenance.html") + + # Shared tools and documents + ,("shared/document/install_Python.org" ,"shared/document/installation_Python.org") + ,("shared/document/install_generic.org" ,"shared/document/installation_generic.org") + ,("shared/style_directory_dict.js" ,"shared/dictionary_style-directory.js") + ,("shared/tool/RTfmt" ,"shared/tool/RT-formatter") + ,("shared/tool/RTfmt.el" ,"shared/tool/RT-formatter.el") + ,("shared/tool/makefile/target_kmod.mk" ,"shared/tool/makefile/target_kernel-module.mk") + + # Tester files (referenced by the old directory name before it is renamed) + ,("tester/RT_format/RT_Format.el" ,"tester/RT_format/RT-formatter.el") + ,("tester/RT_format/RT_format.el" ,"tester/RT_format/RT-formatter_alt.el") + ,("tester/RT_format/RTfmt" ,"tester/RT_format/RT-formatter") + ,("tester/RT_format/RTfmt.el" ,"tester/RT_format/RT-formatter_script.el") + ,("tester/RT_format/RTfmt_with_compare" ,"tester/RT_format/RT-formatter_with-compare") + ,("tester/RT_format/RTfmt_with_compare.el" ,"tester/RT_format/RT-formatter_with-compare.el") + ,("tester/RT_format/test_0_data.c" ,"tester/RT_format/data_test-0.c") + ,("tester/RT_format/test_1_data.py" ,"tester/RT_format/data_test-1.py") + + # Directories + ,("shared/third_party" ,"shared/linked-project") + ,("tester/RT_format" ,"tester/RT-formatter") + ] + + for src ,dst in substitutions: + if not os.path.exists(src): + print(f"Skipping (not found): {src}") + continue + + if os.path.exists(dst): + print(f"Warning: Destination {dst} already exists. Skipping rename for {src}.") + continue + + try: + os.rename(src ,dst) + print(f"Renamed: {src} -> {dst}") + except Exception as e: + print(f"Error renaming {src} to {dst}: {e}") + + return 0 + +if __name__ == "__main__": + sys.exit(CLI()) + diff --git a/shared/dictionary_style-directory.js b/shared/dictionary_style-directory.js new file mode 100644 index 0000000..cdd9138 --- /dev/null +++ b/shared/dictionary_style-directory.js @@ -0,0 +1,4 @@ +window.StyleRT_namespaces = { + "RT": window.RT_REPO_ROOT + "shared/third_party/RT-style-JS_public/consumer/release/RT" + ,"Project": window.RT_REPO_ROOT + "shared/authored/style" +}; diff --git a/shared/document/install_Python.org b/shared/document/install_Python.org deleted file mode 100644 index 0aa11d1..0000000 --- a/shared/document/install_Python.org +++ /dev/null @@ -1,73 +0,0 @@ -#+TITLE: Installing Python in Harmony -#+AUTHOR: Thomas Walker Lynch -#+OPTIONS: toc:2 num:nil - -* Overview - -This document describes how to install a project-local Python environment under: - -#+begin_src bash -shared/third_party/Python -#+end_src - -* Precondition - -Ensure the following: - -- You are in a POSIX shell with =python3= installed. -- The =python3-venv= package is available (on Debian: =sudo apt install python3-venv=). -- You have sourced the Harmony environment via =env_toolsmith= to initialize =REPO_HOME= and related variables. - -* Step-by-Step Installation - -1. Source the Harmony environment: - #+begin_src bash - source env_toolsmith - #+end_src - -2. Create the virtual environment: - #+begin_src bash - python3 -m venv "$REPO_HOME/shared/third_party/Python" - #+end_src - -3. Activate it temporarily to install required packages: - #+begin_src bash - source "$REPO_HOME/shared/third_party/Python/bin/activate" - pip install --upgrade pip - pip install pytest # Add any shared packages here - deactivate - #+end_src - -4. Rename Python's default activate and deactivate: - Harmony provides its own role-aware environment management. Using Python’s default activation scripts may interfere with prompt logic, PATH order, and role-specific behavior. - - Disable the default scripts by renaming them: - #+begin_src bash - mv "$REPO_HOME/shared/third_party/Python/bin/activate" \ - "$REPO_HOME/shared/third_party/Python/bin/activate_deprecated" - #+end_src - - This ensures that accidental sourcing of Python’s =activate= script won't override Harmony's environment setup. - -5. Verify installation: - #+begin_src bash - ls "$REPO_HOME/shared/third_party/Python/bin/python3" - #+end_src - - The binary should exist and report a working Python interpreter when run. - -* Notes - -- The virtual environment is deliberately named =Python=, not =venv=, to reflect its role as a shared system component. -- Harmony environment scripts define and control =VIRTUAL_ENV=, =PYTHON_HOME=, and =PATH=, making Python activation seamless and uniform. -- There is no need to use Python’s =bin/activate= directly — it is fully replaced by Harmony’s environment logic. - -* Related Files - -- =shared/authored/env= -- =shared/authored/env_source= -- =env_developer=, =env_tester=, =env_toolsmith= - -* Last Verified - -2025-05-19 :: Activate/deactivate renamed post-install. Requires Harmony environment sourcing prior to execution. diff --git a/shared/document/install_generic.org b/shared/document/install_generic.org deleted file mode 100644 index 90af13e..0000000 --- a/shared/document/install_generic.org +++ /dev/null @@ -1,81 +0,0 @@ - -This is the generic install.org doc that comes with the skeleton. - -1. $REPO_HOME/shared/third_party/.gitignore: - - * - !/.gitignore - !/patch - - The only things from the third party directory that will be pushed to the repo origin is the .gitignore file and the patches. - - -2. downloaded tar files etc. go into the directory `upstream` - - $REPO_HOME/shared/upstream - - Typically the contents of upstream are deleted after the install. - -3. for the base install - - cd $REPO_HOME/shared/third_party - do whatever it takes to install tool, as examples: - git clone - tar -xzf ../upstream/tar - ... - - Be sure to add the path to the tool executable(s) in the $REPO_HOME/env_$ROLE files for the $ROLE who uses the tool. - - Assuming you are not also developing the tool, for safety - change each installed git project to a local branch: - - b=__local_$USER - git switch -c "$b" - - -4. Define some variables to simplify our discussion. Lowercase variable names - are not exported from the shell. - - # already set in the environment - # REPO_HOME - # PROJECT - # USER - - # example tool names: 'RT_gcc' 'RT-project share` etc. - tool= - tool_dpath="$REPO_HOME/shared/third_party/$tool" - patch_dpath="$REPO_HOME/shared/patch/" - - -5. create a patch series (from current vendor state → your local edits) - - # this can be repeated and will create an encompassing diff file - - # optionally crate a new branch after cloning the third party tool repo and work from there. You won't make any commits, but in case you plan to ever check the changes in, or have a the bad habit of doing ommits burned into your brain-stem, making a brnch will help. - - # make changes - - cd "$tool_dpath" - - # do your edits - - # Stage edits. Do not commit them!! Be sure you are in the third party - # tool directory when doing `git add -A` and `git diff` commands. - git add -A - - # diff the stage from the current repo to create the patch file - git diff --staged > "$patch_dpath/$tool" - - # the diff file can be added to the project and checked in at the project level. - - -6. how to apply an existing patch - - Get a fresh clone of the tool into $tool_dpath. - - cd "$tool_dpath" - git apply "$patch_dpath/$tool" - - You can see what `git apply` would do by running - - git apply --check /path/to/your/patch_dpath/$tool diff --git a/shared/document/installation_Python.org b/shared/document/installation_Python.org new file mode 100644 index 0000000..0aa11d1 --- /dev/null +++ b/shared/document/installation_Python.org @@ -0,0 +1,73 @@ +#+TITLE: Installing Python in Harmony +#+AUTHOR: Thomas Walker Lynch +#+OPTIONS: toc:2 num:nil + +* Overview + +This document describes how to install a project-local Python environment under: + +#+begin_src bash +shared/third_party/Python +#+end_src + +* Precondition + +Ensure the following: + +- You are in a POSIX shell with =python3= installed. +- The =python3-venv= package is available (on Debian: =sudo apt install python3-venv=). +- You have sourced the Harmony environment via =env_toolsmith= to initialize =REPO_HOME= and related variables. + +* Step-by-Step Installation + +1. Source the Harmony environment: + #+begin_src bash + source env_toolsmith + #+end_src + +2. Create the virtual environment: + #+begin_src bash + python3 -m venv "$REPO_HOME/shared/third_party/Python" + #+end_src + +3. Activate it temporarily to install required packages: + #+begin_src bash + source "$REPO_HOME/shared/third_party/Python/bin/activate" + pip install --upgrade pip + pip install pytest # Add any shared packages here + deactivate + #+end_src + +4. Rename Python's default activate and deactivate: + Harmony provides its own role-aware environment management. Using Python’s default activation scripts may interfere with prompt logic, PATH order, and role-specific behavior. + + Disable the default scripts by renaming them: + #+begin_src bash + mv "$REPO_HOME/shared/third_party/Python/bin/activate" \ + "$REPO_HOME/shared/third_party/Python/bin/activate_deprecated" + #+end_src + + This ensures that accidental sourcing of Python’s =activate= script won't override Harmony's environment setup. + +5. Verify installation: + #+begin_src bash + ls "$REPO_HOME/shared/third_party/Python/bin/python3" + #+end_src + + The binary should exist and report a working Python interpreter when run. + +* Notes + +- The virtual environment is deliberately named =Python=, not =venv=, to reflect its role as a shared system component. +- Harmony environment scripts define and control =VIRTUAL_ENV=, =PYTHON_HOME=, and =PATH=, making Python activation seamless and uniform. +- There is no need to use Python’s =bin/activate= directly — it is fully replaced by Harmony’s environment logic. + +* Related Files + +- =shared/authored/env= +- =shared/authored/env_source= +- =env_developer=, =env_tester=, =env_toolsmith= + +* Last Verified + +2025-05-19 :: Activate/deactivate renamed post-install. Requires Harmony environment sourcing prior to execution. diff --git a/shared/document/installation_generic.org b/shared/document/installation_generic.org new file mode 100644 index 0000000..90af13e --- /dev/null +++ b/shared/document/installation_generic.org @@ -0,0 +1,81 @@ + +This is the generic install.org doc that comes with the skeleton. + +1. $REPO_HOME/shared/third_party/.gitignore: + + * + !/.gitignore + !/patch + + The only things from the third party directory that will be pushed to the repo origin is the .gitignore file and the patches. + + +2. downloaded tar files etc. go into the directory `upstream` + + $REPO_HOME/shared/upstream + + Typically the contents of upstream are deleted after the install. + +3. for the base install + + cd $REPO_HOME/shared/third_party + do whatever it takes to install tool, as examples: + git clone + tar -xzf ../upstream/tar + ... + + Be sure to add the path to the tool executable(s) in the $REPO_HOME/env_$ROLE files for the $ROLE who uses the tool. + + Assuming you are not also developing the tool, for safety + change each installed git project to a local branch: + + b=__local_$USER + git switch -c "$b" + + +4. Define some variables to simplify our discussion. Lowercase variable names + are not exported from the shell. + + # already set in the environment + # REPO_HOME + # PROJECT + # USER + + # example tool names: 'RT_gcc' 'RT-project share` etc. + tool= + tool_dpath="$REPO_HOME/shared/third_party/$tool" + patch_dpath="$REPO_HOME/shared/patch/" + + +5. create a patch series (from current vendor state → your local edits) + + # this can be repeated and will create an encompassing diff file + + # optionally crate a new branch after cloning the third party tool repo and work from there. You won't make any commits, but in case you plan to ever check the changes in, or have a the bad habit of doing ommits burned into your brain-stem, making a brnch will help. + + # make changes + + cd "$tool_dpath" + + # do your edits + + # Stage edits. Do not commit them!! Be sure you are in the third party + # tool directory when doing `git add -A` and `git diff` commands. + git add -A + + # diff the stage from the current repo to create the patch file + git diff --staged > "$patch_dpath/$tool" + + # the diff file can be added to the project and checked in at the project level. + + +6. how to apply an existing patch + + Get a fresh clone of the tool into $tool_dpath. + + cd "$tool_dpath" + git apply "$patch_dpath/$tool" + + You can see what `git apply` would do by running + + git apply --check /path/to/your/patch_dpath/$tool diff --git a/shared/linked-project/.git-holder b/shared/linked-project/.git-holder new file mode 100644 index 0000000..e69de29 diff --git a/shared/linked-project/RT-style-JS_public b/shared/linked-project/RT-style-JS_public new file mode 120000 index 0000000..9600bc6 --- /dev/null +++ b/shared/linked-project/RT-style-JS_public @@ -0,0 +1 @@ +../../../RT-style-JS_public/ \ No newline at end of file diff --git a/shared/style_directory_dict.js b/shared/style_directory_dict.js deleted file mode 100644 index cdd9138..0000000 --- a/shared/style_directory_dict.js +++ /dev/null @@ -1,4 +0,0 @@ -window.StyleRT_namespaces = { - "RT": window.RT_REPO_ROOT + "shared/third_party/RT-style-JS_public/consumer/release/RT" - ,"Project": window.RT_REPO_ROOT + "shared/authored/style" -}; diff --git a/shared/third_party/.gitignore b/shared/third_party/.gitignore deleted file mode 100644 index 0de97f0..0000000 --- a/shared/third_party/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Ignore all files -* - -# But don't ignore the .gitignore file itself -!/.gitignore - -# keep the upstream directory -!/upstream diff --git a/shared/third_party/upstream/.gitignore b/shared/third_party/upstream/.gitignore deleted file mode 100644 index aa0e8eb..0000000 --- a/shared/third_party/upstream/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!/.gitignore \ No newline at end of file diff --git a/shared/tool/RT-formatter b/shared/tool/RT-formatter new file mode 100644 index 0000000..f65c4e5 --- /dev/null +++ b/shared/tool/RT-formatter @@ -0,0 +1,326 @@ +#!/usr/bin/env -S python3 -B +# -*- mode: python; coding: utf-8; python-indent-offset: 2; indent-tabs-mode: nil -*- +""" +RTfmt — Reasoning Technology code formatter (Predicate Tokenizer) + +Commands: + RTfmt write [--lisp] Format files in place (rewrite originals) + RTfmt copy [--lisp] Save backups as ~ then format originals + RTfmt pipe [--lisp] Read from stdin, write to stdout + RTfmt self_test Run built-in tests + RTfmt version Show tool version + RTfmt help | --help Show usage +""" + +import sys ,re ,shutil ,os +from typing import List ,Tuple ,Optional ,TextIO + +RTF_VERSION = "0.5.0-predicate" + +def get_usage() -> str: + prog_name = os.path.basename(sys.argv[0]) + return f"""\ +Usage: + {prog_name} write [--lisp] + {prog_name} copy [--lisp] + {prog_name} pipe [--lisp] + {prog_name} self_test + {prog_name} version + {prog_name} help | --help +""" + +# Removed < and > so they are treated as standard CODE operators +BR_OPEN = "([{" +BR_CLOSE = ")]}" +PAIR = dict( zip(BR_OPEN ,BR_CLOSE) ) +REV = dict( zip(BR_CLOSE ,BR_OPEN) ) + +# --------------- Lexer ---------------- + +class RT_Token: + def __init__(self ,kind: str ,text: str): + self.kind = kind + self.text = text + + def __repr__(self): + return f"<{self.kind}:{repr(self.text)}>" + +TOKEN_REGEX = re.compile( + r'(?P//[^\n]*|#[^\n]*|(?s:/\*.*?\*/))' + r'|(?P"""[\s\S]*?"""|\'\'\'[\s\S]*?\'\'\'|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\')' + r'|(?P[ \t]+)' + r'|(?P\n)' + r'|(?P,)' + r'|(?P[\[\(\{])' + r'|(?P[\]\)\}])' + r'|(?P[^ \t\n,\[\(\{\]\)\}"\'#/]+|/)' +) + +def tokenize(text: str) -> List[RT_Token]: + tokens = [] + for TM_match in TOKEN_REGEX.finditer(text): + kind = TM_match.lastgroup + text_val = TM_match.group(kind) + tokens.append( RT_Token(kind ,text_val) ) + return tokens + +# --------------- Intelligence API ---------------- + +class TokenStream: + def __init__(self ,tokens: List[RT_Token]): + self.tokens = tokens + + def get_token(self ,index: int) -> Optional[RT_Token]: + if 0 <= index < len(self.tokens): + return self.tokens[index] + return None + + def next_sig_index(self ,index: int) -> Optional[int]: + for TM_i in range(index + 1 ,len(self.tokens)): + if self.tokens[TM_i].kind not in ("SPACE" ,"NEWLINE" ,"COMMENT"): + return TM_i + return None + + def is_first_on_line(self ,index: int) -> bool: + for TM_i in range(index - 1 ,-1 ,-1): + k = self.tokens[TM_i].kind + if k == "NEWLINE": + return True + if k != "SPACE": + return False + return True # Start of file + + def indent_of_line(self ,index: int) -> str: + for TM_i in range(index ,-1 ,-1): + if self.tokens[TM_i].kind == "NEWLINE": + if TM_i + 1 < len(self.tokens) and self.tokens[TM_i + 1].kind == "SPACE": + return self.tokens[TM_i + 1].text + return "" + if self.tokens and self.tokens[0].kind == "SPACE": + return self.tokens[0].text + return "" + + def indent_of_left_match(self ,index: int) -> Optional[str]: + tok = self.get_token(index) + if not tok or tok.kind != "BR_CLOSE": + return None + target_opener = REV[tok.text] + depth = 0 + for TM_i in range(index - 1 ,-1 ,-1): + t = self.tokens[TM_i] + if t.kind == "BR_CLOSE": + depth += 1 + elif t.kind == "BR_OPEN": + if depth > 0: + depth -= 1 + elif t.text == target_opener: + return self.indent_of_line(TM_i) + return None + +# --------------- Rule Engine ---------------- + +def rule_migrate_vertical_commas(stream: TokenStream): + TM_i = 0 + while TM_i < len(stream.tokens): + if stream.tokens[TM_i].kind == "COMMA": + is_trailing = False + next_sig = stream.next_sig_index(TM_i) + if next_sig is not None: + for TM_j in range(TM_i + 1 ,next_sig): + if stream.tokens[TM_j].kind == "NEWLINE": + is_trailing = True + break + + if is_trailing: + comma_tok = stream.tokens.pop(TM_i) + next_sig -= 1 # Shifted because of pop + stream.tokens.insert(next_sig ,comma_tok) + continue + TM_i += 1 + +def rule_format_horizontal_commas(stream: TokenStream): + for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): + if stream.tokens[TM_i].kind == "COMMA": + if stream.is_first_on_line(TM_i): + continue + + next_tok = stream.get_token(TM_i + 1) + if next_tok and next_tok.kind == "SPACE": + stream.tokens.pop(TM_i + 1) + + prev_tok = stream.get_token(TM_i - 1) + if prev_tok and prev_tok.kind == "SPACE": + if prev_tok.text != " ": + prev_tok.text = " " + else: + stream.tokens.insert(TM_i ,RT_Token("SPACE" ," ")) + +def rule_fix_closing_indent(stream: TokenStream): + for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): + if stream.tokens[TM_i].kind == "BR_CLOSE" and stream.is_first_on_line(TM_i): + target_indent = stream.indent_of_left_match(TM_i) + if target_indent is not None: + prev = stream.get_token(TM_i - 1) + if prev and prev.kind == "SPACE": + prev.text = target_indent + else: + stream.tokens.insert(TM_i ,RT_Token("SPACE" ,target_indent)) + +def rule_tighten_brackets(stream: TokenStream): + for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): + if stream.tokens[TM_i].kind == "SPACE" and not stream.is_first_on_line(TM_i): + prev_t = stream.get_token(TM_i - 1) + next_t = stream.get_token(TM_i + 1) + if (prev_t and prev_t.kind == "BR_OPEN") or (next_t and next_t.kind == "BR_CLOSE"): + stream.tokens.pop(TM_i) + +def get_bracket_spans(stream: TokenStream) -> List[Tuple[int ,int]]: + stack = [] + spans = [] + for TM_i ,tok in enumerate(stream.tokens): + if tok.kind == "BR_OPEN": + stack.append( (tok.text ,TM_i) ) + elif tok.kind == "BR_CLOSE": + if stack and REV[tok.text] == stack[-1][0]: + _ ,pos = stack.pop() + if not stack: + spans.append( (pos ,TM_i) ) + return spans + +def rule_pad_outermost(stream: TokenStream ,is_lisp: bool): + if is_lisp: + return + while True: + spans = get_bracket_spans(stream) + changed = False + for TM_start ,TM_end in reversed(spans): + has_inner = False + for TM_k in range(TM_start + 1 ,TM_end): + if stream.tokens[TM_k].kind in ("BR_OPEN" ,"BR_CLOSE"): + has_inner = True + break + + if has_inner: + left_has = (TM_start + 1 < len(stream.tokens)) and stream.tokens[TM_start + 1].kind == "SPACE" + right_has = (TM_end - 1 >= 0) and stream.tokens[TM_end - 1].kind == "SPACE" + if not left_has or not right_has: + if not right_has: + stream.tokens.insert(TM_end ,RT_Token("SPACE" ," ")) + if not left_has: + stream.tokens.insert(TM_start + 1 ,RT_Token("SPACE" ," ")) + changed = True + break + if not changed: + break + +# --------------- Public API ---------------- + +def format_tokens(tokens: List[RT_Token] ,is_lisp: bool) -> str: + stream = TokenStream(tokens) + + rule_migrate_vertical_commas(stream) + rule_format_horizontal_commas(stream) + rule_tighten_brackets(stream) + rule_fix_closing_indent(stream) + rule_pad_outermost(stream ,is_lisp) + + return "".join(t.text for t in stream.tokens) + +def rt_format_text(text: str ,is_lisp: bool) -> str: + tokens = tokenize(text) + return format_tokens(tokens ,is_lisp) + +def rt_format_stream(inp: TextIO ,out: TextIO ,is_lisp: bool) -> None: + text = inp.read() + out.write( rt_format_text(text ,is_lisp) ) + +# --------------- Self-test ---------------- + +def run_self_test() -> bool: + ok = True + def chk(src ,exp): + nonlocal ok + got = rt_format_text(src ,False) + if got != exp: + print("FAIL:\n" + src + "\n=>\n" + got + "\nexpected:\n" + exp) + ok = False + + chk("a,b,c" ,"a ,b ,c") + chk("a , b , c" ,"a ,b ,c") + chk(" ,vertical_arg" ," ,vertical_arg") + + chk("int a=0,\n b=1,\n c=2;" ,"int a=0\n ,b=1\n ,c=2;") + + chk("f ( x )" ,"f(x)") + chk("f(x) + g(y)" ,"f(x) + g(y)") + chk(" {" ," {") + + src = "int g(){int a=0,b=1,c=2; return h(a,b,c);}" + exp = "int g(){ int a=0 ,b=1 ,c=2; return h(a ,b ,c); }" + chk(src ,exp) + + chk("outer( inner(a,b) )" ,"outer( inner(a ,b) )") + + # Operator protection check + chk("for(int TM = 0; TM < count; ++TM)" ,"for(int TM = 0; TM < count; ++TM)") + + print("SELFTEST OK" if ok else "SELFTEST FAILED") + return ok + +# --------------- CLI ---------------- +def write_files(paths: List[str] ,is_lisp: bool) -> int: + for TM_path in paths: + with open(TM_path ,"r" ,encoding="utf-8") as f: + data = f.read() + formatted = rt_format_text(data ,is_lisp) + with open(TM_path ,"w" ,encoding="utf-8") as f: + f.write(formatted) + return 0 + +def copy_files(paths: List[str] ,is_lisp: bool) -> int: + for TM_path in paths: + shutil.copy2(TM_path ,TM_path + "~") + return write_files(paths ,is_lisp) + +def CLI(argv=None) -> int: + args = list(sys.argv[1:] if argv is None else argv) + usage_text = get_usage() + + if not args or args[0] in {"help" ,"--help" ,"-h"}: + print(usage_text) + return 0 + + is_lisp = "--lisp" in args + args = [TM_a for TM_a in args if TM_a != "--lisp"] + + if not args: + return 0 + + cmd = args[0] + rest = args[1:] + + if cmd == "version": + print(RTF_VERSION) + return 0 + if cmd == "self_test": + ok = run_self_test() + return 0 if ok else 1 + if cmd == "pipe": + rt_format_stream(sys.stdin ,sys.stdout ,is_lisp) + return 0 + if cmd == "write": + if not rest: + print("write: missing \n" + usage_text) + return 2 + return write_files(rest ,is_lisp) + if cmd == "copy": + if not rest: + print("copy: missing \n" + usage_text) + return 2 + return copy_files(rest ,is_lisp) + + print(f"Unknown command: {cmd}\n" + usage_text) + return 2 + +if __name__ == "__main__": + sys.exit( CLI() ) diff --git a/shared/tool/RT-formatter.el b/shared/tool/RT-formatter.el new file mode 100644 index 0000000..272504a --- /dev/null +++ b/shared/tool/RT-formatter.el @@ -0,0 +1,22 @@ +(defun RTfmt0-buffer () + "Format the current buffer using RTfmt0." + (interactive) + (if (not (executable-find "RTfmt0")) + (message "Error: RTfmt0 executable not found in PATH.") + (let ((temp-buffer (generate-new-buffer " *RTfmt0*")) + (args (list "pipe"))) + (when (derived-mode-p 'emacs-lisp-mode 'lisp-mode) + (setq args (append args (list "--lisp")))) + (unwind-protect + (let ((exit-code (apply #'call-process-region + (point-min) (point-max) + "RTfmt0" + nil temp-buffer nil + args))) + (if (zerop exit-code) + (progn + ;; Applies a non-destructive diff, preserving point and markers natively + (replace-buffer-contents temp-buffer) + (message "RTfmt0 formatting successful.")) + (message "RTfmt0 failed with exit code %s. Buffer unchanged." exit-code))) + (kill-buffer temp-buffer))))) diff --git a/shared/tool/RTfmt b/shared/tool/RTfmt deleted file mode 100644 index f65c4e5..0000000 --- a/shared/tool/RTfmt +++ /dev/null @@ -1,326 +0,0 @@ -#!/usr/bin/env -S python3 -B -# -*- mode: python; coding: utf-8; python-indent-offset: 2; indent-tabs-mode: nil -*- -""" -RTfmt — Reasoning Technology code formatter (Predicate Tokenizer) - -Commands: - RTfmt write [--lisp] Format files in place (rewrite originals) - RTfmt copy [--lisp] Save backups as ~ then format originals - RTfmt pipe [--lisp] Read from stdin, write to stdout - RTfmt self_test Run built-in tests - RTfmt version Show tool version - RTfmt help | --help Show usage -""" - -import sys ,re ,shutil ,os -from typing import List ,Tuple ,Optional ,TextIO - -RTF_VERSION = "0.5.0-predicate" - -def get_usage() -> str: - prog_name = os.path.basename(sys.argv[0]) - return f"""\ -Usage: - {prog_name} write [--lisp] - {prog_name} copy [--lisp] - {prog_name} pipe [--lisp] - {prog_name} self_test - {prog_name} version - {prog_name} help | --help -""" - -# Removed < and > so they are treated as standard CODE operators -BR_OPEN = "([{" -BR_CLOSE = ")]}" -PAIR = dict( zip(BR_OPEN ,BR_CLOSE) ) -REV = dict( zip(BR_CLOSE ,BR_OPEN) ) - -# --------------- Lexer ---------------- - -class RT_Token: - def __init__(self ,kind: str ,text: str): - self.kind = kind - self.text = text - - def __repr__(self): - return f"<{self.kind}:{repr(self.text)}>" - -TOKEN_REGEX = re.compile( - r'(?P//[^\n]*|#[^\n]*|(?s:/\*.*?\*/))' - r'|(?P"""[\s\S]*?"""|\'\'\'[\s\S]*?\'\'\'|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\')' - r'|(?P[ \t]+)' - r'|(?P\n)' - r'|(?P,)' - r'|(?P[\[\(\{])' - r'|(?P[\]\)\}])' - r'|(?P[^ \t\n,\[\(\{\]\)\}"\'#/]+|/)' -) - -def tokenize(text: str) -> List[RT_Token]: - tokens = [] - for TM_match in TOKEN_REGEX.finditer(text): - kind = TM_match.lastgroup - text_val = TM_match.group(kind) - tokens.append( RT_Token(kind ,text_val) ) - return tokens - -# --------------- Intelligence API ---------------- - -class TokenStream: - def __init__(self ,tokens: List[RT_Token]): - self.tokens = tokens - - def get_token(self ,index: int) -> Optional[RT_Token]: - if 0 <= index < len(self.tokens): - return self.tokens[index] - return None - - def next_sig_index(self ,index: int) -> Optional[int]: - for TM_i in range(index + 1 ,len(self.tokens)): - if self.tokens[TM_i].kind not in ("SPACE" ,"NEWLINE" ,"COMMENT"): - return TM_i - return None - - def is_first_on_line(self ,index: int) -> bool: - for TM_i in range(index - 1 ,-1 ,-1): - k = self.tokens[TM_i].kind - if k == "NEWLINE": - return True - if k != "SPACE": - return False - return True # Start of file - - def indent_of_line(self ,index: int) -> str: - for TM_i in range(index ,-1 ,-1): - if self.tokens[TM_i].kind == "NEWLINE": - if TM_i + 1 < len(self.tokens) and self.tokens[TM_i + 1].kind == "SPACE": - return self.tokens[TM_i + 1].text - return "" - if self.tokens and self.tokens[0].kind == "SPACE": - return self.tokens[0].text - return "" - - def indent_of_left_match(self ,index: int) -> Optional[str]: - tok = self.get_token(index) - if not tok or tok.kind != "BR_CLOSE": - return None - target_opener = REV[tok.text] - depth = 0 - for TM_i in range(index - 1 ,-1 ,-1): - t = self.tokens[TM_i] - if t.kind == "BR_CLOSE": - depth += 1 - elif t.kind == "BR_OPEN": - if depth > 0: - depth -= 1 - elif t.text == target_opener: - return self.indent_of_line(TM_i) - return None - -# --------------- Rule Engine ---------------- - -def rule_migrate_vertical_commas(stream: TokenStream): - TM_i = 0 - while TM_i < len(stream.tokens): - if stream.tokens[TM_i].kind == "COMMA": - is_trailing = False - next_sig = stream.next_sig_index(TM_i) - if next_sig is not None: - for TM_j in range(TM_i + 1 ,next_sig): - if stream.tokens[TM_j].kind == "NEWLINE": - is_trailing = True - break - - if is_trailing: - comma_tok = stream.tokens.pop(TM_i) - next_sig -= 1 # Shifted because of pop - stream.tokens.insert(next_sig ,comma_tok) - continue - TM_i += 1 - -def rule_format_horizontal_commas(stream: TokenStream): - for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): - if stream.tokens[TM_i].kind == "COMMA": - if stream.is_first_on_line(TM_i): - continue - - next_tok = stream.get_token(TM_i + 1) - if next_tok and next_tok.kind == "SPACE": - stream.tokens.pop(TM_i + 1) - - prev_tok = stream.get_token(TM_i - 1) - if prev_tok and prev_tok.kind == "SPACE": - if prev_tok.text != " ": - prev_tok.text = " " - else: - stream.tokens.insert(TM_i ,RT_Token("SPACE" ," ")) - -def rule_fix_closing_indent(stream: TokenStream): - for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): - if stream.tokens[TM_i].kind == "BR_CLOSE" and stream.is_first_on_line(TM_i): - target_indent = stream.indent_of_left_match(TM_i) - if target_indent is not None: - prev = stream.get_token(TM_i - 1) - if prev and prev.kind == "SPACE": - prev.text = target_indent - else: - stream.tokens.insert(TM_i ,RT_Token("SPACE" ,target_indent)) - -def rule_tighten_brackets(stream: TokenStream): - for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): - if stream.tokens[TM_i].kind == "SPACE" and not stream.is_first_on_line(TM_i): - prev_t = stream.get_token(TM_i - 1) - next_t = stream.get_token(TM_i + 1) - if (prev_t and prev_t.kind == "BR_OPEN") or (next_t and next_t.kind == "BR_CLOSE"): - stream.tokens.pop(TM_i) - -def get_bracket_spans(stream: TokenStream) -> List[Tuple[int ,int]]: - stack = [] - spans = [] - for TM_i ,tok in enumerate(stream.tokens): - if tok.kind == "BR_OPEN": - stack.append( (tok.text ,TM_i) ) - elif tok.kind == "BR_CLOSE": - if stack and REV[tok.text] == stack[-1][0]: - _ ,pos = stack.pop() - if not stack: - spans.append( (pos ,TM_i) ) - return spans - -def rule_pad_outermost(stream: TokenStream ,is_lisp: bool): - if is_lisp: - return - while True: - spans = get_bracket_spans(stream) - changed = False - for TM_start ,TM_end in reversed(spans): - has_inner = False - for TM_k in range(TM_start + 1 ,TM_end): - if stream.tokens[TM_k].kind in ("BR_OPEN" ,"BR_CLOSE"): - has_inner = True - break - - if has_inner: - left_has = (TM_start + 1 < len(stream.tokens)) and stream.tokens[TM_start + 1].kind == "SPACE" - right_has = (TM_end - 1 >= 0) and stream.tokens[TM_end - 1].kind == "SPACE" - if not left_has or not right_has: - if not right_has: - stream.tokens.insert(TM_end ,RT_Token("SPACE" ," ")) - if not left_has: - stream.tokens.insert(TM_start + 1 ,RT_Token("SPACE" ," ")) - changed = True - break - if not changed: - break - -# --------------- Public API ---------------- - -def format_tokens(tokens: List[RT_Token] ,is_lisp: bool) -> str: - stream = TokenStream(tokens) - - rule_migrate_vertical_commas(stream) - rule_format_horizontal_commas(stream) - rule_tighten_brackets(stream) - rule_fix_closing_indent(stream) - rule_pad_outermost(stream ,is_lisp) - - return "".join(t.text for t in stream.tokens) - -def rt_format_text(text: str ,is_lisp: bool) -> str: - tokens = tokenize(text) - return format_tokens(tokens ,is_lisp) - -def rt_format_stream(inp: TextIO ,out: TextIO ,is_lisp: bool) -> None: - text = inp.read() - out.write( rt_format_text(text ,is_lisp) ) - -# --------------- Self-test ---------------- - -def run_self_test() -> bool: - ok = True - def chk(src ,exp): - nonlocal ok - got = rt_format_text(src ,False) - if got != exp: - print("FAIL:\n" + src + "\n=>\n" + got + "\nexpected:\n" + exp) - ok = False - - chk("a,b,c" ,"a ,b ,c") - chk("a , b , c" ,"a ,b ,c") - chk(" ,vertical_arg" ," ,vertical_arg") - - chk("int a=0,\n b=1,\n c=2;" ,"int a=0\n ,b=1\n ,c=2;") - - chk("f ( x )" ,"f(x)") - chk("f(x) + g(y)" ,"f(x) + g(y)") - chk(" {" ," {") - - src = "int g(){int a=0,b=1,c=2; return h(a,b,c);}" - exp = "int g(){ int a=0 ,b=1 ,c=2; return h(a ,b ,c); }" - chk(src ,exp) - - chk("outer( inner(a,b) )" ,"outer( inner(a ,b) )") - - # Operator protection check - chk("for(int TM = 0; TM < count; ++TM)" ,"for(int TM = 0; TM < count; ++TM)") - - print("SELFTEST OK" if ok else "SELFTEST FAILED") - return ok - -# --------------- CLI ---------------- -def write_files(paths: List[str] ,is_lisp: bool) -> int: - for TM_path in paths: - with open(TM_path ,"r" ,encoding="utf-8") as f: - data = f.read() - formatted = rt_format_text(data ,is_lisp) - with open(TM_path ,"w" ,encoding="utf-8") as f: - f.write(formatted) - return 0 - -def copy_files(paths: List[str] ,is_lisp: bool) -> int: - for TM_path in paths: - shutil.copy2(TM_path ,TM_path + "~") - return write_files(paths ,is_lisp) - -def CLI(argv=None) -> int: - args = list(sys.argv[1:] if argv is None else argv) - usage_text = get_usage() - - if not args or args[0] in {"help" ,"--help" ,"-h"}: - print(usage_text) - return 0 - - is_lisp = "--lisp" in args - args = [TM_a for TM_a in args if TM_a != "--lisp"] - - if not args: - return 0 - - cmd = args[0] - rest = args[1:] - - if cmd == "version": - print(RTF_VERSION) - return 0 - if cmd == "self_test": - ok = run_self_test() - return 0 if ok else 1 - if cmd == "pipe": - rt_format_stream(sys.stdin ,sys.stdout ,is_lisp) - return 0 - if cmd == "write": - if not rest: - print("write: missing \n" + usage_text) - return 2 - return write_files(rest ,is_lisp) - if cmd == "copy": - if not rest: - print("copy: missing \n" + usage_text) - return 2 - return copy_files(rest ,is_lisp) - - print(f"Unknown command: {cmd}\n" + usage_text) - return 2 - -if __name__ == "__main__": - sys.exit( CLI() ) diff --git a/shared/tool/RTfmt.el b/shared/tool/RTfmt.el deleted file mode 100644 index 272504a..0000000 --- a/shared/tool/RTfmt.el +++ /dev/null @@ -1,22 +0,0 @@ -(defun RTfmt0-buffer () - "Format the current buffer using RTfmt0." - (interactive) - (if (not (executable-find "RTfmt0")) - (message "Error: RTfmt0 executable not found in PATH.") - (let ((temp-buffer (generate-new-buffer " *RTfmt0*")) - (args (list "pipe"))) - (when (derived-mode-p 'emacs-lisp-mode 'lisp-mode) - (setq args (append args (list "--lisp")))) - (unwind-protect - (let ((exit-code (apply #'call-process-region - (point-min) (point-max) - "RTfmt0" - nil temp-buffer nil - args))) - (if (zerop exit-code) - (progn - ;; Applies a non-destructive diff, preserving point and markers natively - (replace-buffer-contents temp-buffer) - (message "RTfmt0 formatting successful.")) - (message "RTfmt0 failed with exit code %s. Buffer unchanged." exit-code))) - (kill-buffer temp-buffer))))) diff --git a/shared/tool/makefile/target_kernel-module.mk b/shared/tool/makefile/target_kernel-module.mk new file mode 100644 index 0000000..9aa8eba --- /dev/null +++ b/shared/tool/makefile/target_kernel-module.mk @@ -0,0 +1,130 @@ +# make/target_kmod.mk — build *.kmod.c as kernel modules (single-pass, kmod-only) +# invoked from $REPO_HOME/ +# version 1.4 + +.SUFFIXES: +.DELETE_ON_ERROR: + +#-------------------------------------------------------------------------------- +# defaults for environment variables (override from outer make/env as needed) + +# Kernel build tree, which is part of the Linux system, use running kernel if unset +KMOD_BUILD_DIR ?= /lib/modules/$(shell uname -r)/build + +# Authored source directory (single dir) +KMOD_SOURCE_DIR ?= cc + +# Extra compiler flags passed to Kbuild (e.g., -I $(KMOD_SOURCE_DIR)) +KMOD_CCFLAGS ?= + +# Include *.lib.c into modules (1=yes, 0=no) +KMOD_INCLUDE_LIB ?= 1 + +# KMOD_OUTPUT_DIR is constrained, relative path, on the scratchpad, and ends in kmod +# Require: non-empty, relative, no '..', ends with 'kmod' dir +define assert_kmod_output_dir_ok + $(if $(strip $(1)),,$(error KMOD_OUTPUT_DIR is empty)) + $(if $(filter /%,$(1)),$(error KMOD_OUTPUT_DIR must be relative: '$(1)'),) + $(if $(filter %/../% ../% %/.. ..,$(1)),$(error KMOD_OUTPUT_DIR must not contain '..': '$(1)'),) + $(if $(filter %/kmod %/kmod/ kmod,$(1)),,$(error KMOD_OUTPUT_DIR must end with 'kmod': '$(1)')) +endef +KMOD_OUTPUT_DIR ?= scratchpad/kmod +$(eval $(call assert_kmod_output_dir_ok,$(KMOD_OUTPUT_DIR))) + +# The kernel make needs and absolute path to find the output directory +ABS_KMOD_OUTPUT_DIR := $(CURDIR)/$(KMOD_OUTPUT_DIR) + +#-------------------------------------------------------------------------------- +# derived variables (computed from the above) + +# Authored basenames (without suffix) +base_list := $(patsubst %.kmod.c,%,$(notdir $(wildcard $(KMOD_SOURCE_DIR)/*.kmod.c))) + +# Optional library sources (without suffix) to include inside modules +ifeq ($(KMOD_INCLUDE_LIB),1) +lib_base := $(patsubst %.lib.c,%,$(notdir $(wildcard $(KMOD_SOURCE_DIR)/*.lib.c))) +else +lib_base := +endif + +# Staged sources (kept namespaced to prevent .o collisions) +all_kmod_c := $(addsuffix .kmod.c,$(addprefix $(KMOD_OUTPUT_DIR)/,$(base_list))) +all_lib_c := $(addsuffix .lib.c,$(addprefix $(KMOD_OUTPUT_DIR)/,$(lib_base))) + + + +#-------------------------------------------------------------------------------- +# targets + +.PHONY: usage +usage: + @printf "Usage: make [kmod|clean|information|version]\n" + +.PHONY: version +version: + @echo target_kmod version 1.4 + +.PHONY: information +information: + @echo "KMOD_SOURCE_DIR: " $(KMOD_SOURCE_DIR) + @echo "KMOD_BUILD_DIR: " $(KMOD_BUILD_DIR) + @echo "KMOD_OUTPUT_DIR: " $(KMOD_OUTPUT_DIR) + @echo "base_list: " $(base_list) + @echo "lib_base: " $(lib_base) + @echo "all_kmod_c: " $(all_kmod_c) + @echo "all_lib_c: " $(all_lib_c) + @echo "KMOD_INCLUDE_LIB=" $(KMOD_INCLUDE_LIB) + + +ifeq ($(strip $(base_list)),) + $(warning No *.kmod.c found under $(KMOD_SOURCE_DIR); nothing to build) +endif + +# --- Parallel-safe preparation as real targets --- + +# ensure the staging dir exists (order-only prereq) +$(KMOD_OUTPUT_DIR): + @mkdir -p "$(KMOD_OUTPUT_DIR)" + +# generate the Kbuild control Makefile +$(KMOD_OUTPUT_DIR)/Makefile: | $(KMOD_OUTPUT_DIR) + @{ \ + printf "ccflags-y += %s\n" "$(KMOD_CCFLAGS)"; \ + printf "obj-m := %s\n" "$(foreach m,$(base_list),$(m).o)"; \ + for m in $(base_list); do \ + printf "%s-objs := %s.kmod.o" "$$m" "$$m"; \ + for lb in $(lib_base); do printf " %s.lib.o" "$$lb"; done; \ + printf "\n"; \ + done; \ + } > "$@" + +# stage kmod sources (one rule per file; parallelizable) +$(KMOD_OUTPUT_DIR)/%.kmod.c: $(KMOD_SOURCE_DIR)/%.kmod.c | $(KMOD_OUTPUT_DIR) + @echo "--- Stage: $@ ---" + @cp -f "$(abspath $<)" "$@" + +# stage library sources (optional; also parallelizable) +$(KMOD_OUTPUT_DIR)/%.lib.c: $(KMOD_SOURCE_DIR)/%.lib.c | $(KMOD_OUTPUT_DIR) + @echo "--- Stage: $@ ---" + @cp -f "$(abspath $<)" "$@" + + +.PHONY: kmod +kmod: $(KMOD_OUTPUT_DIR)/Makefile $(all_kmod_c) $(all_lib_c) +ifeq ($(strip $(base_list)),) + @echo "--- No kmod sources; nothing to do ---" +else + @echo "--- Invoking Kbuild for kmod: $(base_list) ---" + $(MAKE) -C "$(KMOD_BUILD_DIR)" M="$(ABS_KMOD_OUTPUT_DIR)" modules +endif + +# quality-of-life: allow 'make scratchpad/kmod/foo.ko' after batch build +$(KMOD_OUTPUT_DIR)/%.ko: kmod + @true + +.PHONY: clean +clean: + @echo "Cleaning: $(KMOD_BUILD_DIR)" + @$(MAKE) -C "$(KMOD_BUILD_DIR)" M="$(ABS_KMOD_OUTPUT_DIR)" clean >/dev/null 2>&1 || true + @echo "Cleaning: $(KMOD_OUTPUT_DIR)" + @rm -rf -- "$(KMOD_OUTPUT_DIR)" diff --git a/shared/tool/makefile/target_kmod.mk b/shared/tool/makefile/target_kmod.mk deleted file mode 100644 index 9aa8eba..0000000 --- a/shared/tool/makefile/target_kmod.mk +++ /dev/null @@ -1,130 +0,0 @@ -# make/target_kmod.mk — build *.kmod.c as kernel modules (single-pass, kmod-only) -# invoked from $REPO_HOME/ -# version 1.4 - -.SUFFIXES: -.DELETE_ON_ERROR: - -#-------------------------------------------------------------------------------- -# defaults for environment variables (override from outer make/env as needed) - -# Kernel build tree, which is part of the Linux system, use running kernel if unset -KMOD_BUILD_DIR ?= /lib/modules/$(shell uname -r)/build - -# Authored source directory (single dir) -KMOD_SOURCE_DIR ?= cc - -# Extra compiler flags passed to Kbuild (e.g., -I $(KMOD_SOURCE_DIR)) -KMOD_CCFLAGS ?= - -# Include *.lib.c into modules (1=yes, 0=no) -KMOD_INCLUDE_LIB ?= 1 - -# KMOD_OUTPUT_DIR is constrained, relative path, on the scratchpad, and ends in kmod -# Require: non-empty, relative, no '..', ends with 'kmod' dir -define assert_kmod_output_dir_ok - $(if $(strip $(1)),,$(error KMOD_OUTPUT_DIR is empty)) - $(if $(filter /%,$(1)),$(error KMOD_OUTPUT_DIR must be relative: '$(1)'),) - $(if $(filter %/../% ../% %/.. ..,$(1)),$(error KMOD_OUTPUT_DIR must not contain '..': '$(1)'),) - $(if $(filter %/kmod %/kmod/ kmod,$(1)),,$(error KMOD_OUTPUT_DIR must end with 'kmod': '$(1)')) -endef -KMOD_OUTPUT_DIR ?= scratchpad/kmod -$(eval $(call assert_kmod_output_dir_ok,$(KMOD_OUTPUT_DIR))) - -# The kernel make needs and absolute path to find the output directory -ABS_KMOD_OUTPUT_DIR := $(CURDIR)/$(KMOD_OUTPUT_DIR) - -#-------------------------------------------------------------------------------- -# derived variables (computed from the above) - -# Authored basenames (without suffix) -base_list := $(patsubst %.kmod.c,%,$(notdir $(wildcard $(KMOD_SOURCE_DIR)/*.kmod.c))) - -# Optional library sources (without suffix) to include inside modules -ifeq ($(KMOD_INCLUDE_LIB),1) -lib_base := $(patsubst %.lib.c,%,$(notdir $(wildcard $(KMOD_SOURCE_DIR)/*.lib.c))) -else -lib_base := -endif - -# Staged sources (kept namespaced to prevent .o collisions) -all_kmod_c := $(addsuffix .kmod.c,$(addprefix $(KMOD_OUTPUT_DIR)/,$(base_list))) -all_lib_c := $(addsuffix .lib.c,$(addprefix $(KMOD_OUTPUT_DIR)/,$(lib_base))) - - - -#-------------------------------------------------------------------------------- -# targets - -.PHONY: usage -usage: - @printf "Usage: make [kmod|clean|information|version]\n" - -.PHONY: version -version: - @echo target_kmod version 1.4 - -.PHONY: information -information: - @echo "KMOD_SOURCE_DIR: " $(KMOD_SOURCE_DIR) - @echo "KMOD_BUILD_DIR: " $(KMOD_BUILD_DIR) - @echo "KMOD_OUTPUT_DIR: " $(KMOD_OUTPUT_DIR) - @echo "base_list: " $(base_list) - @echo "lib_base: " $(lib_base) - @echo "all_kmod_c: " $(all_kmod_c) - @echo "all_lib_c: " $(all_lib_c) - @echo "KMOD_INCLUDE_LIB=" $(KMOD_INCLUDE_LIB) - - -ifeq ($(strip $(base_list)),) - $(warning No *.kmod.c found under $(KMOD_SOURCE_DIR); nothing to build) -endif - -# --- Parallel-safe preparation as real targets --- - -# ensure the staging dir exists (order-only prereq) -$(KMOD_OUTPUT_DIR): - @mkdir -p "$(KMOD_OUTPUT_DIR)" - -# generate the Kbuild control Makefile -$(KMOD_OUTPUT_DIR)/Makefile: | $(KMOD_OUTPUT_DIR) - @{ \ - printf "ccflags-y += %s\n" "$(KMOD_CCFLAGS)"; \ - printf "obj-m := %s\n" "$(foreach m,$(base_list),$(m).o)"; \ - for m in $(base_list); do \ - printf "%s-objs := %s.kmod.o" "$$m" "$$m"; \ - for lb in $(lib_base); do printf " %s.lib.o" "$$lb"; done; \ - printf "\n"; \ - done; \ - } > "$@" - -# stage kmod sources (one rule per file; parallelizable) -$(KMOD_OUTPUT_DIR)/%.kmod.c: $(KMOD_SOURCE_DIR)/%.kmod.c | $(KMOD_OUTPUT_DIR) - @echo "--- Stage: $@ ---" - @cp -f "$(abspath $<)" "$@" - -# stage library sources (optional; also parallelizable) -$(KMOD_OUTPUT_DIR)/%.lib.c: $(KMOD_SOURCE_DIR)/%.lib.c | $(KMOD_OUTPUT_DIR) - @echo "--- Stage: $@ ---" - @cp -f "$(abspath $<)" "$@" - - -.PHONY: kmod -kmod: $(KMOD_OUTPUT_DIR)/Makefile $(all_kmod_c) $(all_lib_c) -ifeq ($(strip $(base_list)),) - @echo "--- No kmod sources; nothing to do ---" -else - @echo "--- Invoking Kbuild for kmod: $(base_list) ---" - $(MAKE) -C "$(KMOD_BUILD_DIR)" M="$(ABS_KMOD_OUTPUT_DIR)" modules -endif - -# quality-of-life: allow 'make scratchpad/kmod/foo.ko' after batch build -$(KMOD_OUTPUT_DIR)/%.ko: kmod - @true - -.PHONY: clean -clean: - @echo "Cleaning: $(KMOD_BUILD_DIR)" - @$(MAKE) -C "$(KMOD_BUILD_DIR)" M="$(ABS_KMOD_OUTPUT_DIR)" clean >/dev/null 2>&1 || true - @echo "Cleaning: $(KMOD_OUTPUT_DIR)" - @rm -rf -- "$(KMOD_OUTPUT_DIR)" diff --git a/shared/tool/version b/shared/tool/version index a132902..aced6ba 100755 --- a/shared/tool/version +++ b/shared/tool/version @@ -1,4 +1,4 @@ -echo "Harmony v2.5 2026-03-09" +echo "Harmony v3.0 2026-05-10" diff --git a/shared/upstream/.gitignore b/shared/upstream/.gitignore new file mode 100644 index 0000000..aa0e8eb --- /dev/null +++ b/shared/upstream/.gitignore @@ -0,0 +1,2 @@ +* +!/.gitignore \ No newline at end of file diff --git a/tester/RT-formatter/RT-formatter b/tester/RT-formatter/RT-formatter new file mode 100644 index 0000000..0451fcb --- /dev/null +++ b/tester/RT-formatter/RT-formatter @@ -0,0 +1,307 @@ +#!/usr/bin/env -S python3 -B +# -*- mode: python; coding: utf-8; python-indent-offset: 2; indent-tabs-mode: nil -*- +""" +RT_Format — Reasoning Technology code formatter (Shallow Tokenizer) + +Commands: + RT_Format write [--lisp] Format files in place (rewrite originals) + RT_Format copy [--lisp] Save backups as ~ then format originals + RT_Format pipe [--lisp] Read from stdin, write to stdout + RT_Format self_test Run built-in tests + RT_Format version Show tool version + RT_Format help | --help Show usage +""" + +import sys ,re ,shutil ,os +from typing import List ,Tuple ,Optional ,TextIO + +RTF_VERSION = "0.4.0-tokenized" + +USAGE = """\ +Usage: + RT_Format write [--lisp] + RT_Format copy [--lisp] + RT_Format pipe [--lisp] + RT_Format self_test + RT_Format version + RT_Format help | --help +""" + +BR_OPEN = "([{<" +BR_CLOSE = ")]}>" +PAIR = dict( zip(BR_OPEN ,BR_CLOSE) ) +REV = dict( zip(BR_CLOSE ,BR_OPEN) ) + +# --------------- Lexer ---------------- + +class RT_Token: + def __init__(self ,kind: str ,text: str): + self.kind = kind + self.text = text + + def __repr__(self): + return f"<{self.kind}:{repr(self.text)}>" + +# The regex prioritizes exact matches. +# Comments include //, #, and /* ... */ blocks. +# Strings include Python '''/""" blocks, plus standard single/double quotes. +TOKEN_REGEX = re.compile( + r'(?P//[^\n]*|#[^\n]*|(?s:/\*.*?\*/))' + r'|(?P"""[\s\S]*?"""|\'\'\'[\s\S]*?\'\'\'|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\')' + r'|(?P[ \t]+)' + r'|(?P\n)' + r'|(?P,)' + r'|(?P[\[\(\{<])' + r'|(?P[\]\)\}>])' + r'|(?P[^ \t\n,\[\(\{<\]\)\}>"\'#/]+|/)' +) + +def tokenize(text: str) -> List[RT_Token]: + tokens = [] + for TM_match in TOKEN_REGEX.finditer(text): + kind = TM_match.lastgroup + text_val = TM_match.group(kind) + tokens.append( RT_Token(kind ,text_val) ) + return tokens + +def group_lines( tokens: List[RT_Token] ) -> List[ List[RT_Token] ]: + lines = [] + current = [] + for TM_tok in tokens: + current.append(TM_tok) + if TM_tok.kind == "NEWLINE": + lines.append(current) + current = [] + if current: + lines.append(current) + return lines + +# --------------- Formatting Passes ---------------- + +def pass_vertical_commas( lines: List[List[RT_Token]] ) -> None: + for TM_idx in range( len(lines) - 1 ): + current_line = lines[TM_idx] + + # Find the last significant token + last_sig_idx = -1 + for TM_i in range( len(current_line) - 1 ,-1 ,-1 ): + if current_line[TM_i].kind not in ("SPACE" ,"NEWLINE" ,"COMMENT"): + last_sig_idx = TM_i + break + + if last_sig_idx>= 0 and current_line[last_sig_idx].kind == "COMMA": + # Remove the trailing comma + comma_tok = current_line.pop(last_sig_idx) + + # Migrate to the next line with code + for TM_j in range( TM_idx + 1 ,len(lines) ): + next_line = lines[TM_j] + first_sig_idx = -1 + for TM_k ,TM_tok in enumerate(next_line): + if TM_tok.kind not in ("SPACE" ,"NEWLINE" ,"COMMENT"): + first_sig_idx = TM_k + break + + if first_sig_idx>= 0: + next_line.insert(first_sig_idx ,comma_tok) + break + +def pass_horizontal_commas( line: List[RT_Token] ) -> None: + new_line = [] + for TM_tok in line: + if TM_tok.kind == "COMMA": + is_vertical = all(t.kind == "SPACE" for t in new_line) + if not is_vertical: + while new_line and new_line[-1].kind == "SPACE": + new_line.pop() + if new_line: + new_line.append( RT_Token("SPACE" ," ") ) + new_line.append(TM_tok) + elif TM_tok.kind == "SPACE": + if new_line and new_line[-1].kind == "COMMA": + continue # Drop space after comma + new_line.append(TM_tok) + else: + new_line.append(TM_tok) + line[:] = new_line + +def pass_tighten_brackets( line: List[RT_Token] ) -> None: + new_line = [] + for TM_tok in line: + if TM_tok.kind == "SPACE": + if new_line and new_line[-1].kind == "BR_OPEN": + continue + new_line.append(TM_tok) + elif TM_tok.kind == "BR_CLOSE": + while new_line and new_line[-1].kind == "SPACE": + new_line.pop() + new_line.append(TM_tok) + else: + new_line.append(TM_tok) + line[:] = new_line + +def get_bracket_spans( line: List[RT_Token] ) -> List[ Tuple[int ,int] ]: + stack = [] + spans = [] + for TM_i ,TM_tok in enumerate(line): + if TM_tok.kind == "BR_OPEN": + stack.append( (TM_tok.text ,TM_i) ) + elif TM_tok.kind == "BR_CLOSE": + if stack and REV[TM_tok.text] == stack[-1][0]: + _ ,pos = stack.pop() + if not stack: + spans.append( (pos ,TM_i) ) + return spans + +def contains_inner_brackets( line: List[RT_Token] ,start: int ,end: int ) -> bool: + for TM_i in range(start + 1 ,end): + if line[TM_i].kind in ("BR_OPEN" ,"BR_CLOSE"): + return True + return False + +def pass_pad_outermost( line: List[RT_Token] ,is_lisp: bool ) -> None: + if is_lisp: + return + + while True: + spans = get_bracket_spans(line) + changed = False + + # Process from right to left to avoid shifting indices + for TM_start ,TM_end in reversed(spans): + if contains_inner_brackets(line ,TM_start ,TM_end): + left_has = (TM_start + 1 = 0 ) and ( line[TM_end - 1].kind == "SPACE" ) + + if not left_has or not right_has: + if not right_has: + line.insert( TM_end ,RT_Token("SPACE" ," ") ) + if not left_has: + line.insert( TM_start + 1 ,RT_Token("SPACE" ," ") ) + changed = True + break # Re-evaluate spans after mutation + if not changed: + break + +# --------------- Public API ---------------- + +def format_tokens( tokens: List[RT_Token] ,is_lisp: bool ) -> str: + lines = group_lines(tokens) + pass_vertical_commas(lines) + + for TM_line in lines: + pass_horizontal_commas(TM_line) + pass_tighten_brackets(TM_line) + pass_pad_outermost(TM_line ,is_lisp) + + return "".join(t.text for TM_line in lines for t in TM_line) + +def rt_format_text(text: str ,is_lisp: bool) -> str: + tokens = tokenize(text) + return format_tokens(tokens ,is_lisp) + +def rt_format_stream(inp: TextIO ,out: TextIO ,is_lisp: bool) -> None: + text = inp.read() + out.write( rt_format_text(text ,is_lisp) ) + +# --------------- Self-test ---------------- + +def run_self_test() -> bool: + ok = True + def chk(src ,exp): + nonlocal ok + got = rt_format_text(src ,False) + if got != exp: + print("FAIL:\n" + src + "\n=>\n" + got + "\nexpected:\n" + exp) + ok = False + + chk("a,b,c" ,"a ,b ,c") + chk("a , b , c" ,"a ,b ,c") + chk(" ,vertical_arg" ," ,vertical_arg") + + chk("int a=0,\n b=1,\n c=2;" ,"int a=0\n ,b=1\n ,c=2;") + + chk("f ( x )" ,"f(x)") + chk("f(x) + g(y)" ,"f(x) + g(y)") + chk(" {" ," {") + + src = "int g(){int a=0,b=1,c=2; return h(a,b,c);}" + exp = "int g(){ int a=0 ,b=1 ,c=2; return h(a ,b ,c); }" + chk(src ,exp) + + chk("outer( inner(a,b) )" ,"outer( inner(a ,b) )") + chk("compute(x, f(y" ,"compute( x ,f(y") # Tolerant fragment fallback omitted for brevity, but structurally sound. + + print("SELFTEST OK" if ok else "SELFTEST FAILED") + return ok + +# --------------- CLI ---------------- + +def write_files( paths: List[str] ,is_lisp: bool ) -> int: + for TM_path in paths: + with open(TM_path ,"r" ,encoding="utf-8") as f: + data = f.read() + formatted = rt_format_text(data ,is_lisp) + with open(TM_path ,"w" ,encoding="utf-8") as f: + f.write(formatted) + return 0 + +def copy_files( paths: List[str] ,is_lisp: bool ) -> int: + for TM_path in paths: + shutil.copy2(TM_path ,TM_path + "~") + return write_files(paths ,is_lisp) + +def get_usage() -> str: + prog_name = os.path.basename( sys.argv[0] ) + return f"""\ +Usage: + {prog_name} write [--lisp] + {prog_name} copy [--lisp] + {prog_name} pipe [--lisp] + {prog_name} self_test + {prog_name} version + {prog_name} help | --help +""" + +def CLI(argv=None) -> int: + args = list( sys.argv[1:] if argv is None else argv ) + usage_text = get_usage() + + if not args or args[0] in {"help" ,"--help" ,"-h"}: + print(usage_text) + return 0 + + is_lisp = "--lisp" in args + args = [TM_a for TM_a in args if TM_a != "--lisp"] + + if not args: + return 0 + + cmd = args[0] + rest = args[1:] + + if cmd == "version": + print(RT_FORMAT_VERSION) + return 0 + if cmd == "self_test": + ok = run_self_test() + return 0 if ok else 1 + if cmd == "pipe": + rt_format_stream(sys.stdin ,sys.stdout ,is_lisp) + return 0 + if cmd == "write": + if not rest: + print("write: missing \n" + usage_text) + return 2 + return write_files(rest ,is_lisp) + if cmd == "copy": + if not rest: + print("copy: missing \n" + usage_text) + return 2 + return copy_files(rest ,is_lisp) + + print(f"Unknown command: {cmd}\n" + usage_text) + return 2 + +if __name__ == "__main__": + sys.exit( CLI() ) \ No newline at end of file diff --git a/tester/RT-formatter/RT-formatter.el b/tester/RT-formatter/RT-formatter.el new file mode 100644 index 0000000..91bc561 --- /dev/null +++ b/tester/RT-formatter/RT-formatter.el @@ -0,0 +1,5 @@ +( defun RT-format-buffer() + (interactive) + (save-excursion + ( shell-command-on-region(point-min)(point-max) + "RT_format pipe" t t)) ) diff --git a/tester/RT-formatter/RT-formatter_alt.el b/tester/RT-formatter/RT-formatter_alt.el new file mode 100644 index 0000000..712c6ec --- /dev/null +++ b/tester/RT-formatter/RT-formatter_alt.el @@ -0,0 +1,30 @@ + +(defun RTfmtt-buffer () + "Format the current buffer using RTfmt." + (interactive) + (if (not (executable-find "RTfmt")) + (message "Error: RTfmt executable not found in PATH.") + (let ((temp-buffer (generate-new-buffer " *RTfmt*")) + (args (list "pipe"))) + (when (derived-mode-p 'emacs-lisp-mode 'lisp-mode) + (setq args (append args (list "--lisp")))) + (unwind-protect + (let ((exit-code (apply #'call-process-region + (point-min) (point-max) + "RTfmt" + nil temp-buffer nil + args))) + (if (zerop exit-code) + (let ((formatted-text (with-current-buffer temp-buffer (buffer-string)))) + (save-excursion + (delete-region (point-min) (point-max)) + (insert formatted-text)) + (message "RTfmt formatting successful.")) + (message "RTfmt failed with exit code %s. Buffer unchanged." exit-code))) + (kill-buffer temp-buffer))))) + +;; ( defun RT-format-buffer() +;; (interactive) +;; (save-excursion +;; ( shell-command-on-region(point-min)(point-max) +;; "RTfmt pipe" t t)) ) diff --git a/tester/RT-formatter/RT-formatter_script.el b/tester/RT-formatter/RT-formatter_script.el new file mode 100644 index 0000000..8da7457 --- /dev/null +++ b/tester/RT-formatter/RT-formatter_script.el @@ -0,0 +1,22 @@ +(defun RTfmt-buffer () + "Format the current buffer using RTfmt." + (interactive) + (if (not (executable-find "RTfmt")) + (message "Error: RTfmt executable not found in PATH.") + (let ((temp-buffer (generate-new-buffer " *RTfmt*")) + (args (list "pipe"))) + (when (derived-mode-p 'emacs-lisp-mode 'lisp-mode) + (setq args (append args (list "--lisp")))) + (unwind-protect + (let ((exit-code (apply #'call-process-region + (point-min) (point-max) + "RTfmt" + nil temp-buffer nil + args))) + (if (zerop exit-code) + (progn + ;; Applies a non-destructive diff, preserving point and markers natively + (replace-buffer-contents temp-buffer) + (message "RTfmt formatting successful.")) + (message "RTfmt failed with exit code %s. Buffer unchanged." exit-code))) + (kill-buffer temp-buffer))))) diff --git a/tester/RT-formatter/RT-formatter_with-compare b/tester/RT-formatter/RT-formatter_with-compare new file mode 100644 index 0000000..ca4367d --- /dev/null +++ b/tester/RT-formatter/RT-formatter_with-compare @@ -0,0 +1,331 @@ +#!/usr/bin/env -S python3 -B +# -*- mode: python; coding: utf-8; python-indent-offset: 2; indent-tabs-mode: nil -*- +""" +RTfmt — Reasoning Technology code formatter (Predicate Tokenizer) + +Commands: + RTfmt write [--lisp] Format files in place (rewrite originals) + RTfmt copy [--lisp] Save backups as ~ then format originals + RTfmt pipe [--lisp] Read from stdin, write to stdout + RTfmt self_test Run built-in tests + RTfmt version Show tool version + RTfmt help | --help Show usage +""" + +import sys ,re ,shutil ,os +from typing import List ,Tuple ,Optional ,TextIO + +RTF_VERSION = "0.5.0-predicate" + +def get_usage() -> str: + prog_name = os.path.basename(sys.argv[0]) + return f"""\ +Usage: + {prog_name} write [--lisp] + {prog_name} copy [--lisp] + {prog_name} pipe [--lisp] + {prog_name} self_test + {prog_name} version + {prog_name} help | --help +""" + +# Removed < and > so they are treated as standard CODE operators +BR_OPEN = "([{" +BR_CLOSE = ")]}" +PAIR = dict( zip(BR_OPEN ,BR_CLOSE) ) +REV = dict( zip(BR_CLOSE ,BR_OPEN) ) + +# --------------- Lexer ---------------- + +class RT_Token: + def __init__(self ,kind: str ,text: str): + self.kind = kind + self.text = text + + def __repr__(self): + return f"<{self.kind}:{repr(self.text)}>" + +TOKEN_REGEX = re.compile( + r'(?P//[^\n]*|#[^\n]*|(?s:/\*.*?\*/))' + r'|(?P"""[\s\S]*?"""|\'\'\'[\s\S]*?\'\'\'|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\')' + r'|(?P[ \t]+)' + r'|(?P\n)' + r'|(?P,)' + r'|(?P[\[\(\{])' + r'|(?P[\]\)\}])' + r'|(?P[^ \t\n,\[\(\{\]\)\}"\'#/]+|/)' +) + +def tokenize(text: str) -> List[RT_Token]: + tokens = [] + for TM_match in TOKEN_REGEX.finditer(text): + kind = TM_match.lastgroup + text_val = TM_match.group(kind) + tokens.append( RT_Token(kind ,text_val) ) + return tokens + +# --------------- Intelligence API ---------------- + +class TokenStream: + def __init__(self ,tokens: List[RT_Token]): + self.tokens = tokens + + def get_token(self ,index: int) -> Optional[RT_Token]: + if 0 <= index < len(self.tokens): + return self.tokens[index] + return None + + def next_sig_index(self ,index: int) -> Optional[int]: + for TM_i in range(index + 1 ,len(self.tokens)): + if self.tokens[TM_i].kind not in ("SPACE" ,"NEWLINE" ,"COMMENT"): + return TM_i + return None + + def is_first_on_line(self ,index: int) -> bool: + for TM_i in range(index - 1 ,-1 ,-1): + k = self.tokens[TM_i].kind + if k == "NEWLINE": + return True + if k != "SPACE": + return False + return True # Start of file + + def indent_of_line(self ,index: int) -> str: + for TM_i in range(index ,-1 ,-1): + if self.tokens[TM_i].kind == "NEWLINE": + if TM_i + 1 < len(self.tokens) and self.tokens[TM_i + 1].kind == "SPACE": + return self.tokens[TM_i + 1].text + return "" + if self.tokens and self.tokens[0].kind == "SPACE": + return self.tokens[0].text + return "" + + def indent_of_left_match(self ,index: int) -> Optional[str]: + tok = self.get_token(index) + if not tok or tok.kind != "BR_CLOSE": + return None + target_opener = REV[tok.text] + depth = 0 + for TM_i in range(index - 1 ,-1 ,-1): + t = self.tokens[TM_i] + if t.kind == "BR_CLOSE": + depth += 1 + elif t.kind == "BR_OPEN": + if depth > 0: + depth -= 1 + elif t.text == target_opener: + return self.indent_of_line(TM_i) + return None + +# --------------- Rule Engine ---------------- + +def rule_migrate_vertical_commas(stream: TokenStream): + TM_i = 0 + while TM_i < len(stream.tokens): + if stream.tokens[TM_i].kind == "COMMA": + is_trailing = False + next_sig = stream.next_sig_index(TM_i) + if next_sig is not None: + for TM_j in range(TM_i + 1 ,next_sig): + if stream.tokens[TM_j].kind == "NEWLINE": + is_trailing = True + break + + if is_trailing: + comma_tok = stream.tokens.pop(TM_i) + next_sig -= 1 # Shifted because of pop + stream.tokens.insert(next_sig ,comma_tok) + continue + TM_i += 1 + +def rule_format_horizontal_commas(stream: TokenStream): + for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): + if stream.tokens[TM_i].kind == "COMMA": + if stream.is_first_on_line(TM_i): + continue + + next_tok = stream.get_token(TM_i + 1) + if next_tok and next_tok.kind == "SPACE": + stream.tokens.pop(TM_i + 1) + + prev_tok = stream.get_token(TM_i - 1) + if prev_tok and prev_tok.kind == "SPACE": + if prev_tok.text != " ": + prev_tok.text = " " + else: + stream.tokens.insert(TM_i ,RT_Token("SPACE" ," ")) + +def rule_fix_closing_indent(stream: TokenStream): + for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): + if stream.tokens[TM_i].kind == "BR_CLOSE" and stream.is_first_on_line(TM_i): + target_indent = stream.indent_of_left_match(TM_i) + if target_indent is not None: + prev = stream.get_token(TM_i - 1) + if prev and prev.kind == "SPACE": + prev.text = target_indent + else: + stream.tokens.insert(TM_i ,RT_Token("SPACE" ,target_indent)) + +def rule_tighten_brackets(stream: TokenStream): + for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): + if stream.tokens[TM_i].kind == "SPACE" and not stream.is_first_on_line(TM_i): + prev_t = stream.get_token(TM_i - 1) + next_t = stream.get_token(TM_i + 1) + if (prev_t and prev_t.kind == "BR_OPEN") or (next_t and next_t.kind == "BR_CLOSE"): + stream.tokens.pop(TM_i) + +def get_bracket_spans(stream: TokenStream) -> List[Tuple[int ,int]]: + stack = [] + spans = [] + for TM_i ,tok in enumerate(stream.tokens): + if tok.kind == "BR_OPEN": + stack.append( (tok.text ,TM_i) ) + elif tok.kind == "BR_CLOSE": + if stack and REV[tok.text] == stack[-1][0]: + _ ,pos = stack.pop() + if not stack: + spans.append( (pos ,TM_i) ) + return spans + +def rule_pad_outermost(stream: TokenStream ,is_lisp: bool): + if is_lisp: + return + while True: + spans = get_bracket_spans(stream) + changed = False + for TM_start ,TM_end in reversed(spans): + has_inner = False + for TM_k in range(TM_start + 1 ,TM_end): + if stream.tokens[TM_k].kind in ("BR_OPEN" ,"BR_CLOSE"): + has_inner = True + break + + if has_inner: + left_has = (TM_start + 1 < len(stream.tokens)) and stream.tokens[TM_start + 1].kind == "SPACE" + right_has = (TM_end - 1 >= 0) and stream.tokens[TM_end - 1].kind == "SPACE" + if not left_has or not right_has: + if not right_has: + stream.tokens.insert(TM_end ,RT_Token("SPACE" ," ")) + if not left_has: + stream.tokens.insert(TM_start + 1 ,RT_Token("SPACE" ," ")) + changed = True + break + if not changed: + break + +# --------------- Public API ---------------- + +def format_tokens(tokens: List[RT_Token] ,is_lisp: bool) -> str: + stream = TokenStream(tokens) + + rule_migrate_vertical_commas(stream) + rule_format_horizontal_commas(stream) + rule_tighten_brackets(stream) + rule_fix_closing_indent(stream) + rule_pad_outermost(stream ,is_lisp) + + return "".join(t.text for t in stream.tokens) + +def rt_format_text(text: str ,is_lisp: bool) -> str: + tokens = tokenize(text) + return format_tokens(tokens ,is_lisp) + +def rt_format_stream(inp: TextIO ,out: TextIO ,is_lisp: bool) -> None: + text = inp.read() + out.write( rt_format_text(text ,is_lisp) ) + +# --------------- Self-test ---------------- + +def run_self_test() -> bool: + ok = True + def chk(src ,exp): + nonlocal ok + got = rt_format_text(src ,False) + if got != exp: + print("FAIL:\n" + src + "\n=>\n" + got + "\nexpected:\n" + exp) + ok = False + + chk("a,b,c" ,"a ,b ,c") + chk("a , b , c" ,"a ,b ,c") + chk(" ,vertical_arg" ," ,vertical_arg") + + chk("int a=0,\n b=1,\n c=2;" ,"int a=0\n ,b=1\n ,c=2;") + + chk("f ( x )" ,"f(x)") + chk("f(x) + g(y)" ,"f(x) + g(y)") + chk(" {" ," {") + + src = "int g(){int a=0,b=1,c=2; return h(a,b,c);}" + exp = "int g(){ int a=0 ,b=1 ,c=2; return h(a ,b ,c); }" + chk(src ,exp) + + chk("outer( inner(a,b) )" ,"outer( inner(a ,b) )") + + # Operator protection check + chk("for(int TM = 0; TM < count; ++TM)" ,"for(int TM = 0; TM < count; ++TM)") + + print("SELFTEST OK" if ok else "SELFTEST FAILED") + return ok + +# --------------- CLI ---------------- +def write_files(paths: List[str] ,is_lisp: bool) -> int: + for TM_path in paths: + with open(TM_path ,"r" ,encoding="utf-8") as f: + data = f.read() + + formatted = rt_format_text(data ,is_lisp) + + # Only touch the file if the content actually changed + if data != formatted: + with open(TM_path ,"w" ,encoding="utf-8") as f: + f.write(formatted) + print(f"Formatted: {TM_path}") + return 0 + +def copy_files(paths: List[str] ,is_lisp: bool) -> int: + for TM_path in paths: + shutil.copy2(TM_path ,TM_path + "~") + return write_files(paths ,is_lisp) + +def CLI(argv=None) -> int: + args = list(sys.argv[1:] if argv is None else argv) + usage_text = get_usage() + + if not args or args[0] in {"help" ,"--help" ,"-h"}: + print(usage_text) + return 0 + + is_lisp = "--lisp" in args + args = [TM_a for TM_a in args if TM_a != "--lisp"] + + if not args: + return 0 + + cmd = args[0] + rest = args[1:] + + if cmd == "version": + print(RTF_VERSION) + return 0 + if cmd == "self_test": + ok = run_self_test() + return 0 if ok else 1 + if cmd == "pipe": + rt_format_stream(sys.stdin ,sys.stdout ,is_lisp) + return 0 + if cmd == "write": + if not rest: + print("write: missing \n" + usage_text) + return 2 + return write_files(rest ,is_lisp) + if cmd == "copy": + if not rest: + print("copy: missing \n" + usage_text) + return 2 + return copy_files(rest ,is_lisp) + + print(f"Unknown command: {cmd}\n" + usage_text) + return 2 + +if __name__ == "__main__": + sys.exit( CLI() ) diff --git a/tester/RT-formatter/RT-formatter_with-compare.el b/tester/RT-formatter/RT-formatter_with-compare.el new file mode 100644 index 0000000..7f8e245 --- /dev/null +++ b/tester/RT-formatter/RT-formatter_with-compare.el @@ -0,0 +1,23 @@ +(defun RTfmt-buffer () + "Format the current buffer using RTfmt." + (interactive) + (if (not (executable-find "RTfmt")) + (message "Error: RTfmt executable not found in PATH.") + (let ((temp-buffer (generate-new-buffer " *RTfmt*")) + (args (list "pipe"))) + (when (derived-mode-p 'emacs-lisp-mode 'lisp-mode) + (setq args (append args (list "--lisp")))) + (unwind-protect + (let ((exit-code (apply #'call-process-region + (point-min) (point-max) + "RTfmt" + nil temp-buffer nil + args))) + (if (zerop exit-code) + ;; Check if the formatted text is actually different + (if (= (compare-buffer-substrings nil nil nil temp-buffer nil nil) 0) + (message "RTfmt: Already perfectly formatted.") + (replace-buffer-contents temp-buffer) + (message "RTfmt formatting successful.")) + (message "RTfmt failed with exit code %s. Buffer unchanged." exit-code))) + (kill-buffer temp-buffer))))) diff --git a/tester/RT-formatter/data_test-0.c b/tester/RT-formatter/data_test-0.c new file mode 100644 index 0000000..c877406 --- /dev/null +++ b/tester/RT-formatter/data_test-0.c @@ -0,0 +1,20 @@ +// commas and simple tight brackets +int g(){ + int a=0 , + b=1 , + c=2; + return h(a ,b ,c); +} + +// balanced outermost-with-nesting -> pad inside outer () +int f(){ return outer(inner(a ,b)); } + +// strings and comments must be unchanged +int s(){ printf("x ,y ,z (still a string)"); /* a ,b ,c */ return 1; } + +// unbalanced open-right with nesting -> pad after first unmatched '(' +int u(){if(doit(foo(1 ,2) // missing )) + return 0;} + +// arrays / subscripts stay tight; commas still RT-style +int a(int i ,int j){ return M[i ,j] + V[i] + W[j]; } diff --git a/tester/RT-formatter/data_test-1.py b/tester/RT-formatter/data_test-1.py new file mode 100644 index 0000000..9b2fa87 --- /dev/null +++ b/tester/RT-formatter/data_test-1.py @@ -0,0 +1,16 @@ +# commas and spacing in defs / calls +def f ( x , y , z ): + return dict( a =1 , b= 2 ), [ 1, 2 ,3 ], ( (1,2) ) + +# outermost-with-nesting -> pad inside outer () +val = outer( inner( a,b ) ) + +# strings/comments untouched +s = "text, with , commas ( not to touch )" # a ,b ,c + +# unbalanced: open-left (closing without opener) -> no padding unless inner bracket before it +def g(): + return result) # likely unchanged + +# unbalanced: open-right (first unmatched opener) with inner bracket following +k = compute(x, f(y diff --git a/tester/RT_format/RT_Format.el b/tester/RT_format/RT_Format.el deleted file mode 100644 index 91bc561..0000000 --- a/tester/RT_format/RT_Format.el +++ /dev/null @@ -1,5 +0,0 @@ -( defun RT-format-buffer() - (interactive) - (save-excursion - ( shell-command-on-region(point-min)(point-max) - "RT_format pipe" t t)) ) diff --git a/tester/RT_format/RT_format.el b/tester/RT_format/RT_format.el deleted file mode 100644 index 712c6ec..0000000 --- a/tester/RT_format/RT_format.el +++ /dev/null @@ -1,30 +0,0 @@ - -(defun RTfmtt-buffer () - "Format the current buffer using RTfmt." - (interactive) - (if (not (executable-find "RTfmt")) - (message "Error: RTfmt executable not found in PATH.") - (let ((temp-buffer (generate-new-buffer " *RTfmt*")) - (args (list "pipe"))) - (when (derived-mode-p 'emacs-lisp-mode 'lisp-mode) - (setq args (append args (list "--lisp")))) - (unwind-protect - (let ((exit-code (apply #'call-process-region - (point-min) (point-max) - "RTfmt" - nil temp-buffer nil - args))) - (if (zerop exit-code) - (let ((formatted-text (with-current-buffer temp-buffer (buffer-string)))) - (save-excursion - (delete-region (point-min) (point-max)) - (insert formatted-text)) - (message "RTfmt formatting successful.")) - (message "RTfmt failed with exit code %s. Buffer unchanged." exit-code))) - (kill-buffer temp-buffer))))) - -;; ( defun RT-format-buffer() -;; (interactive) -;; (save-excursion -;; ( shell-command-on-region(point-min)(point-max) -;; "RTfmt pipe" t t)) ) diff --git a/tester/RT_format/RTfmt b/tester/RT_format/RTfmt deleted file mode 100644 index 0451fcb..0000000 --- a/tester/RT_format/RTfmt +++ /dev/null @@ -1,307 +0,0 @@ -#!/usr/bin/env -S python3 -B -# -*- mode: python; coding: utf-8; python-indent-offset: 2; indent-tabs-mode: nil -*- -""" -RT_Format — Reasoning Technology code formatter (Shallow Tokenizer) - -Commands: - RT_Format write [--lisp] Format files in place (rewrite originals) - RT_Format copy [--lisp] Save backups as ~ then format originals - RT_Format pipe [--lisp] Read from stdin, write to stdout - RT_Format self_test Run built-in tests - RT_Format version Show tool version - RT_Format help | --help Show usage -""" - -import sys ,re ,shutil ,os -from typing import List ,Tuple ,Optional ,TextIO - -RTF_VERSION = "0.4.0-tokenized" - -USAGE = """\ -Usage: - RT_Format write [--lisp] - RT_Format copy [--lisp] - RT_Format pipe [--lisp] - RT_Format self_test - RT_Format version - RT_Format help | --help -""" - -BR_OPEN = "([{<" -BR_CLOSE = ")]}>" -PAIR = dict( zip(BR_OPEN ,BR_CLOSE) ) -REV = dict( zip(BR_CLOSE ,BR_OPEN) ) - -# --------------- Lexer ---------------- - -class RT_Token: - def __init__(self ,kind: str ,text: str): - self.kind = kind - self.text = text - - def __repr__(self): - return f"<{self.kind}:{repr(self.text)}>" - -# The regex prioritizes exact matches. -# Comments include //, #, and /* ... */ blocks. -# Strings include Python '''/""" blocks, plus standard single/double quotes. -TOKEN_REGEX = re.compile( - r'(?P//[^\n]*|#[^\n]*|(?s:/\*.*?\*/))' - r'|(?P"""[\s\S]*?"""|\'\'\'[\s\S]*?\'\'\'|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\')' - r'|(?P[ \t]+)' - r'|(?P\n)' - r'|(?P,)' - r'|(?P[\[\(\{<])' - r'|(?P[\]\)\}>])' - r'|(?P[^ \t\n,\[\(\{<\]\)\}>"\'#/]+|/)' -) - -def tokenize(text: str) -> List[RT_Token]: - tokens = [] - for TM_match in TOKEN_REGEX.finditer(text): - kind = TM_match.lastgroup - text_val = TM_match.group(kind) - tokens.append( RT_Token(kind ,text_val) ) - return tokens - -def group_lines( tokens: List[RT_Token] ) -> List[ List[RT_Token] ]: - lines = [] - current = [] - for TM_tok in tokens: - current.append(TM_tok) - if TM_tok.kind == "NEWLINE": - lines.append(current) - current = [] - if current: - lines.append(current) - return lines - -# --------------- Formatting Passes ---------------- - -def pass_vertical_commas( lines: List[List[RT_Token]] ) -> None: - for TM_idx in range( len(lines) - 1 ): - current_line = lines[TM_idx] - - # Find the last significant token - last_sig_idx = -1 - for TM_i in range( len(current_line) - 1 ,-1 ,-1 ): - if current_line[TM_i].kind not in ("SPACE" ,"NEWLINE" ,"COMMENT"): - last_sig_idx = TM_i - break - - if last_sig_idx>= 0 and current_line[last_sig_idx].kind == "COMMA": - # Remove the trailing comma - comma_tok = current_line.pop(last_sig_idx) - - # Migrate to the next line with code - for TM_j in range( TM_idx + 1 ,len(lines) ): - next_line = lines[TM_j] - first_sig_idx = -1 - for TM_k ,TM_tok in enumerate(next_line): - if TM_tok.kind not in ("SPACE" ,"NEWLINE" ,"COMMENT"): - first_sig_idx = TM_k - break - - if first_sig_idx>= 0: - next_line.insert(first_sig_idx ,comma_tok) - break - -def pass_horizontal_commas( line: List[RT_Token] ) -> None: - new_line = [] - for TM_tok in line: - if TM_tok.kind == "COMMA": - is_vertical = all(t.kind == "SPACE" for t in new_line) - if not is_vertical: - while new_line and new_line[-1].kind == "SPACE": - new_line.pop() - if new_line: - new_line.append( RT_Token("SPACE" ," ") ) - new_line.append(TM_tok) - elif TM_tok.kind == "SPACE": - if new_line and new_line[-1].kind == "COMMA": - continue # Drop space after comma - new_line.append(TM_tok) - else: - new_line.append(TM_tok) - line[:] = new_line - -def pass_tighten_brackets( line: List[RT_Token] ) -> None: - new_line = [] - for TM_tok in line: - if TM_tok.kind == "SPACE": - if new_line and new_line[-1].kind == "BR_OPEN": - continue - new_line.append(TM_tok) - elif TM_tok.kind == "BR_CLOSE": - while new_line and new_line[-1].kind == "SPACE": - new_line.pop() - new_line.append(TM_tok) - else: - new_line.append(TM_tok) - line[:] = new_line - -def get_bracket_spans( line: List[RT_Token] ) -> List[ Tuple[int ,int] ]: - stack = [] - spans = [] - for TM_i ,TM_tok in enumerate(line): - if TM_tok.kind == "BR_OPEN": - stack.append( (TM_tok.text ,TM_i) ) - elif TM_tok.kind == "BR_CLOSE": - if stack and REV[TM_tok.text] == stack[-1][0]: - _ ,pos = stack.pop() - if not stack: - spans.append( (pos ,TM_i) ) - return spans - -def contains_inner_brackets( line: List[RT_Token] ,start: int ,end: int ) -> bool: - for TM_i in range(start + 1 ,end): - if line[TM_i].kind in ("BR_OPEN" ,"BR_CLOSE"): - return True - return False - -def pass_pad_outermost( line: List[RT_Token] ,is_lisp: bool ) -> None: - if is_lisp: - return - - while True: - spans = get_bracket_spans(line) - changed = False - - # Process from right to left to avoid shifting indices - for TM_start ,TM_end in reversed(spans): - if contains_inner_brackets(line ,TM_start ,TM_end): - left_has = (TM_start + 1 = 0 ) and ( line[TM_end - 1].kind == "SPACE" ) - - if not left_has or not right_has: - if not right_has: - line.insert( TM_end ,RT_Token("SPACE" ," ") ) - if not left_has: - line.insert( TM_start + 1 ,RT_Token("SPACE" ," ") ) - changed = True - break # Re-evaluate spans after mutation - if not changed: - break - -# --------------- Public API ---------------- - -def format_tokens( tokens: List[RT_Token] ,is_lisp: bool ) -> str: - lines = group_lines(tokens) - pass_vertical_commas(lines) - - for TM_line in lines: - pass_horizontal_commas(TM_line) - pass_tighten_brackets(TM_line) - pass_pad_outermost(TM_line ,is_lisp) - - return "".join(t.text for TM_line in lines for t in TM_line) - -def rt_format_text(text: str ,is_lisp: bool) -> str: - tokens = tokenize(text) - return format_tokens(tokens ,is_lisp) - -def rt_format_stream(inp: TextIO ,out: TextIO ,is_lisp: bool) -> None: - text = inp.read() - out.write( rt_format_text(text ,is_lisp) ) - -# --------------- Self-test ---------------- - -def run_self_test() -> bool: - ok = True - def chk(src ,exp): - nonlocal ok - got = rt_format_text(src ,False) - if got != exp: - print("FAIL:\n" + src + "\n=>\n" + got + "\nexpected:\n" + exp) - ok = False - - chk("a,b,c" ,"a ,b ,c") - chk("a , b , c" ,"a ,b ,c") - chk(" ,vertical_arg" ," ,vertical_arg") - - chk("int a=0,\n b=1,\n c=2;" ,"int a=0\n ,b=1\n ,c=2;") - - chk("f ( x )" ,"f(x)") - chk("f(x) + g(y)" ,"f(x) + g(y)") - chk(" {" ," {") - - src = "int g(){int a=0,b=1,c=2; return h(a,b,c);}" - exp = "int g(){ int a=0 ,b=1 ,c=2; return h(a ,b ,c); }" - chk(src ,exp) - - chk("outer( inner(a,b) )" ,"outer( inner(a ,b) )") - chk("compute(x, f(y" ,"compute( x ,f(y") # Tolerant fragment fallback omitted for brevity, but structurally sound. - - print("SELFTEST OK" if ok else "SELFTEST FAILED") - return ok - -# --------------- CLI ---------------- - -def write_files( paths: List[str] ,is_lisp: bool ) -> int: - for TM_path in paths: - with open(TM_path ,"r" ,encoding="utf-8") as f: - data = f.read() - formatted = rt_format_text(data ,is_lisp) - with open(TM_path ,"w" ,encoding="utf-8") as f: - f.write(formatted) - return 0 - -def copy_files( paths: List[str] ,is_lisp: bool ) -> int: - for TM_path in paths: - shutil.copy2(TM_path ,TM_path + "~") - return write_files(paths ,is_lisp) - -def get_usage() -> str: - prog_name = os.path.basename( sys.argv[0] ) - return f"""\ -Usage: - {prog_name} write [--lisp] - {prog_name} copy [--lisp] - {prog_name} pipe [--lisp] - {prog_name} self_test - {prog_name} version - {prog_name} help | --help -""" - -def CLI(argv=None) -> int: - args = list( sys.argv[1:] if argv is None else argv ) - usage_text = get_usage() - - if not args or args[0] in {"help" ,"--help" ,"-h"}: - print(usage_text) - return 0 - - is_lisp = "--lisp" in args - args = [TM_a for TM_a in args if TM_a != "--lisp"] - - if not args: - return 0 - - cmd = args[0] - rest = args[1:] - - if cmd == "version": - print(RT_FORMAT_VERSION) - return 0 - if cmd == "self_test": - ok = run_self_test() - return 0 if ok else 1 - if cmd == "pipe": - rt_format_stream(sys.stdin ,sys.stdout ,is_lisp) - return 0 - if cmd == "write": - if not rest: - print("write: missing \n" + usage_text) - return 2 - return write_files(rest ,is_lisp) - if cmd == "copy": - if not rest: - print("copy: missing \n" + usage_text) - return 2 - return copy_files(rest ,is_lisp) - - print(f"Unknown command: {cmd}\n" + usage_text) - return 2 - -if __name__ == "__main__": - sys.exit( CLI() ) \ No newline at end of file diff --git a/tester/RT_format/RTfmt.el b/tester/RT_format/RTfmt.el deleted file mode 100644 index 8da7457..0000000 --- a/tester/RT_format/RTfmt.el +++ /dev/null @@ -1,22 +0,0 @@ -(defun RTfmt-buffer () - "Format the current buffer using RTfmt." - (interactive) - (if (not (executable-find "RTfmt")) - (message "Error: RTfmt executable not found in PATH.") - (let ((temp-buffer (generate-new-buffer " *RTfmt*")) - (args (list "pipe"))) - (when (derived-mode-p 'emacs-lisp-mode 'lisp-mode) - (setq args (append args (list "--lisp")))) - (unwind-protect - (let ((exit-code (apply #'call-process-region - (point-min) (point-max) - "RTfmt" - nil temp-buffer nil - args))) - (if (zerop exit-code) - (progn - ;; Applies a non-destructive diff, preserving point and markers natively - (replace-buffer-contents temp-buffer) - (message "RTfmt formatting successful.")) - (message "RTfmt failed with exit code %s. Buffer unchanged." exit-code))) - (kill-buffer temp-buffer))))) diff --git a/tester/RT_format/RTfmt_with_compare b/tester/RT_format/RTfmt_with_compare deleted file mode 100644 index ca4367d..0000000 --- a/tester/RT_format/RTfmt_with_compare +++ /dev/null @@ -1,331 +0,0 @@ -#!/usr/bin/env -S python3 -B -# -*- mode: python; coding: utf-8; python-indent-offset: 2; indent-tabs-mode: nil -*- -""" -RTfmt — Reasoning Technology code formatter (Predicate Tokenizer) - -Commands: - RTfmt write [--lisp] Format files in place (rewrite originals) - RTfmt copy [--lisp] Save backups as ~ then format originals - RTfmt pipe [--lisp] Read from stdin, write to stdout - RTfmt self_test Run built-in tests - RTfmt version Show tool version - RTfmt help | --help Show usage -""" - -import sys ,re ,shutil ,os -from typing import List ,Tuple ,Optional ,TextIO - -RTF_VERSION = "0.5.0-predicate" - -def get_usage() -> str: - prog_name = os.path.basename(sys.argv[0]) - return f"""\ -Usage: - {prog_name} write [--lisp] - {prog_name} copy [--lisp] - {prog_name} pipe [--lisp] - {prog_name} self_test - {prog_name} version - {prog_name} help | --help -""" - -# Removed < and > so they are treated as standard CODE operators -BR_OPEN = "([{" -BR_CLOSE = ")]}" -PAIR = dict( zip(BR_OPEN ,BR_CLOSE) ) -REV = dict( zip(BR_CLOSE ,BR_OPEN) ) - -# --------------- Lexer ---------------- - -class RT_Token: - def __init__(self ,kind: str ,text: str): - self.kind = kind - self.text = text - - def __repr__(self): - return f"<{self.kind}:{repr(self.text)}>" - -TOKEN_REGEX = re.compile( - r'(?P//[^\n]*|#[^\n]*|(?s:/\*.*?\*/))' - r'|(?P"""[\s\S]*?"""|\'\'\'[\s\S]*?\'\'\'|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\')' - r'|(?P[ \t]+)' - r'|(?P\n)' - r'|(?P,)' - r'|(?P[\[\(\{])' - r'|(?P[\]\)\}])' - r'|(?P[^ \t\n,\[\(\{\]\)\}"\'#/]+|/)' -) - -def tokenize(text: str) -> List[RT_Token]: - tokens = [] - for TM_match in TOKEN_REGEX.finditer(text): - kind = TM_match.lastgroup - text_val = TM_match.group(kind) - tokens.append( RT_Token(kind ,text_val) ) - return tokens - -# --------------- Intelligence API ---------------- - -class TokenStream: - def __init__(self ,tokens: List[RT_Token]): - self.tokens = tokens - - def get_token(self ,index: int) -> Optional[RT_Token]: - if 0 <= index < len(self.tokens): - return self.tokens[index] - return None - - def next_sig_index(self ,index: int) -> Optional[int]: - for TM_i in range(index + 1 ,len(self.tokens)): - if self.tokens[TM_i].kind not in ("SPACE" ,"NEWLINE" ,"COMMENT"): - return TM_i - return None - - def is_first_on_line(self ,index: int) -> bool: - for TM_i in range(index - 1 ,-1 ,-1): - k = self.tokens[TM_i].kind - if k == "NEWLINE": - return True - if k != "SPACE": - return False - return True # Start of file - - def indent_of_line(self ,index: int) -> str: - for TM_i in range(index ,-1 ,-1): - if self.tokens[TM_i].kind == "NEWLINE": - if TM_i + 1 < len(self.tokens) and self.tokens[TM_i + 1].kind == "SPACE": - return self.tokens[TM_i + 1].text - return "" - if self.tokens and self.tokens[0].kind == "SPACE": - return self.tokens[0].text - return "" - - def indent_of_left_match(self ,index: int) -> Optional[str]: - tok = self.get_token(index) - if not tok or tok.kind != "BR_CLOSE": - return None - target_opener = REV[tok.text] - depth = 0 - for TM_i in range(index - 1 ,-1 ,-1): - t = self.tokens[TM_i] - if t.kind == "BR_CLOSE": - depth += 1 - elif t.kind == "BR_OPEN": - if depth > 0: - depth -= 1 - elif t.text == target_opener: - return self.indent_of_line(TM_i) - return None - -# --------------- Rule Engine ---------------- - -def rule_migrate_vertical_commas(stream: TokenStream): - TM_i = 0 - while TM_i < len(stream.tokens): - if stream.tokens[TM_i].kind == "COMMA": - is_trailing = False - next_sig = stream.next_sig_index(TM_i) - if next_sig is not None: - for TM_j in range(TM_i + 1 ,next_sig): - if stream.tokens[TM_j].kind == "NEWLINE": - is_trailing = True - break - - if is_trailing: - comma_tok = stream.tokens.pop(TM_i) - next_sig -= 1 # Shifted because of pop - stream.tokens.insert(next_sig ,comma_tok) - continue - TM_i += 1 - -def rule_format_horizontal_commas(stream: TokenStream): - for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): - if stream.tokens[TM_i].kind == "COMMA": - if stream.is_first_on_line(TM_i): - continue - - next_tok = stream.get_token(TM_i + 1) - if next_tok and next_tok.kind == "SPACE": - stream.tokens.pop(TM_i + 1) - - prev_tok = stream.get_token(TM_i - 1) - if prev_tok and prev_tok.kind == "SPACE": - if prev_tok.text != " ": - prev_tok.text = " " - else: - stream.tokens.insert(TM_i ,RT_Token("SPACE" ," ")) - -def rule_fix_closing_indent(stream: TokenStream): - for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): - if stream.tokens[TM_i].kind == "BR_CLOSE" and stream.is_first_on_line(TM_i): - target_indent = stream.indent_of_left_match(TM_i) - if target_indent is not None: - prev = stream.get_token(TM_i - 1) - if prev and prev.kind == "SPACE": - prev.text = target_indent - else: - stream.tokens.insert(TM_i ,RT_Token("SPACE" ,target_indent)) - -def rule_tighten_brackets(stream: TokenStream): - for TM_i in range(len(stream.tokens) - 1 ,-1 ,-1): - if stream.tokens[TM_i].kind == "SPACE" and not stream.is_first_on_line(TM_i): - prev_t = stream.get_token(TM_i - 1) - next_t = stream.get_token(TM_i + 1) - if (prev_t and prev_t.kind == "BR_OPEN") or (next_t and next_t.kind == "BR_CLOSE"): - stream.tokens.pop(TM_i) - -def get_bracket_spans(stream: TokenStream) -> List[Tuple[int ,int]]: - stack = [] - spans = [] - for TM_i ,tok in enumerate(stream.tokens): - if tok.kind == "BR_OPEN": - stack.append( (tok.text ,TM_i) ) - elif tok.kind == "BR_CLOSE": - if stack and REV[tok.text] == stack[-1][0]: - _ ,pos = stack.pop() - if not stack: - spans.append( (pos ,TM_i) ) - return spans - -def rule_pad_outermost(stream: TokenStream ,is_lisp: bool): - if is_lisp: - return - while True: - spans = get_bracket_spans(stream) - changed = False - for TM_start ,TM_end in reversed(spans): - has_inner = False - for TM_k in range(TM_start + 1 ,TM_end): - if stream.tokens[TM_k].kind in ("BR_OPEN" ,"BR_CLOSE"): - has_inner = True - break - - if has_inner: - left_has = (TM_start + 1 < len(stream.tokens)) and stream.tokens[TM_start + 1].kind == "SPACE" - right_has = (TM_end - 1 >= 0) and stream.tokens[TM_end - 1].kind == "SPACE" - if not left_has or not right_has: - if not right_has: - stream.tokens.insert(TM_end ,RT_Token("SPACE" ," ")) - if not left_has: - stream.tokens.insert(TM_start + 1 ,RT_Token("SPACE" ," ")) - changed = True - break - if not changed: - break - -# --------------- Public API ---------------- - -def format_tokens(tokens: List[RT_Token] ,is_lisp: bool) -> str: - stream = TokenStream(tokens) - - rule_migrate_vertical_commas(stream) - rule_format_horizontal_commas(stream) - rule_tighten_brackets(stream) - rule_fix_closing_indent(stream) - rule_pad_outermost(stream ,is_lisp) - - return "".join(t.text for t in stream.tokens) - -def rt_format_text(text: str ,is_lisp: bool) -> str: - tokens = tokenize(text) - return format_tokens(tokens ,is_lisp) - -def rt_format_stream(inp: TextIO ,out: TextIO ,is_lisp: bool) -> None: - text = inp.read() - out.write( rt_format_text(text ,is_lisp) ) - -# --------------- Self-test ---------------- - -def run_self_test() -> bool: - ok = True - def chk(src ,exp): - nonlocal ok - got = rt_format_text(src ,False) - if got != exp: - print("FAIL:\n" + src + "\n=>\n" + got + "\nexpected:\n" + exp) - ok = False - - chk("a,b,c" ,"a ,b ,c") - chk("a , b , c" ,"a ,b ,c") - chk(" ,vertical_arg" ," ,vertical_arg") - - chk("int a=0,\n b=1,\n c=2;" ,"int a=0\n ,b=1\n ,c=2;") - - chk("f ( x )" ,"f(x)") - chk("f(x) + g(y)" ,"f(x) + g(y)") - chk(" {" ," {") - - src = "int g(){int a=0,b=1,c=2; return h(a,b,c);}" - exp = "int g(){ int a=0 ,b=1 ,c=2; return h(a ,b ,c); }" - chk(src ,exp) - - chk("outer( inner(a,b) )" ,"outer( inner(a ,b) )") - - # Operator protection check - chk("for(int TM = 0; TM < count; ++TM)" ,"for(int TM = 0; TM < count; ++TM)") - - print("SELFTEST OK" if ok else "SELFTEST FAILED") - return ok - -# --------------- CLI ---------------- -def write_files(paths: List[str] ,is_lisp: bool) -> int: - for TM_path in paths: - with open(TM_path ,"r" ,encoding="utf-8") as f: - data = f.read() - - formatted = rt_format_text(data ,is_lisp) - - # Only touch the file if the content actually changed - if data != formatted: - with open(TM_path ,"w" ,encoding="utf-8") as f: - f.write(formatted) - print(f"Formatted: {TM_path}") - return 0 - -def copy_files(paths: List[str] ,is_lisp: bool) -> int: - for TM_path in paths: - shutil.copy2(TM_path ,TM_path + "~") - return write_files(paths ,is_lisp) - -def CLI(argv=None) -> int: - args = list(sys.argv[1:] if argv is None else argv) - usage_text = get_usage() - - if not args or args[0] in {"help" ,"--help" ,"-h"}: - print(usage_text) - return 0 - - is_lisp = "--lisp" in args - args = [TM_a for TM_a in args if TM_a != "--lisp"] - - if not args: - return 0 - - cmd = args[0] - rest = args[1:] - - if cmd == "version": - print(RTF_VERSION) - return 0 - if cmd == "self_test": - ok = run_self_test() - return 0 if ok else 1 - if cmd == "pipe": - rt_format_stream(sys.stdin ,sys.stdout ,is_lisp) - return 0 - if cmd == "write": - if not rest: - print("write: missing \n" + usage_text) - return 2 - return write_files(rest ,is_lisp) - if cmd == "copy": - if not rest: - print("copy: missing \n" + usage_text) - return 2 - return copy_files(rest ,is_lisp) - - print(f"Unknown command: {cmd}\n" + usage_text) - return 2 - -if __name__ == "__main__": - sys.exit( CLI() ) diff --git a/tester/RT_format/RTfmt_with_compare.el b/tester/RT_format/RTfmt_with_compare.el deleted file mode 100644 index 7f8e245..0000000 --- a/tester/RT_format/RTfmt_with_compare.el +++ /dev/null @@ -1,23 +0,0 @@ -(defun RTfmt-buffer () - "Format the current buffer using RTfmt." - (interactive) - (if (not (executable-find "RTfmt")) - (message "Error: RTfmt executable not found in PATH.") - (let ((temp-buffer (generate-new-buffer " *RTfmt*")) - (args (list "pipe"))) - (when (derived-mode-p 'emacs-lisp-mode 'lisp-mode) - (setq args (append args (list "--lisp")))) - (unwind-protect - (let ((exit-code (apply #'call-process-region - (point-min) (point-max) - "RTfmt" - nil temp-buffer nil - args))) - (if (zerop exit-code) - ;; Check if the formatted text is actually different - (if (= (compare-buffer-substrings nil nil nil temp-buffer nil nil) 0) - (message "RTfmt: Already perfectly formatted.") - (replace-buffer-contents temp-buffer) - (message "RTfmt formatting successful.")) - (message "RTfmt failed with exit code %s. Buffer unchanged." exit-code))) - (kill-buffer temp-buffer))))) diff --git a/tester/RT_format/test_0_data.c b/tester/RT_format/test_0_data.c deleted file mode 100644 index c877406..0000000 --- a/tester/RT_format/test_0_data.c +++ /dev/null @@ -1,20 +0,0 @@ -// commas and simple tight brackets -int g(){ - int a=0 , - b=1 , - c=2; - return h(a ,b ,c); -} - -// balanced outermost-with-nesting -> pad inside outer () -int f(){ return outer(inner(a ,b)); } - -// strings and comments must be unchanged -int s(){ printf("x ,y ,z (still a string)"); /* a ,b ,c */ return 1; } - -// unbalanced open-right with nesting -> pad after first unmatched '(' -int u(){if(doit(foo(1 ,2) // missing )) - return 0;} - -// arrays / subscripts stay tight; commas still RT-style -int a(int i ,int j){ return M[i ,j] + V[i] + W[j]; } diff --git a/tester/RT_format/test_1_data.py b/tester/RT_format/test_1_data.py deleted file mode 100644 index 9b2fa87..0000000 --- a/tester/RT_format/test_1_data.py +++ /dev/null @@ -1,16 +0,0 @@ -# commas and spacing in defs / calls -def f ( x , y , z ): - return dict( a =1 , b= 2 ), [ 1, 2 ,3 ], ( (1,2) ) - -# outermost-with-nesting -> pad inside outer () -val = outer( inner( a,b ) ) - -# strings/comments untouched -s = "text, with , commas ( not to touch )" # a ,b ,c - -# unbalanced: open-left (closing without opener) -> no padding unless inner bracket before it -def g(): - return result) # likely unchanged - -# unbalanced: open-right (first unmatched opener) with inner bracket following -k = compute(x, f(y