Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 187 additions & 0 deletions docs/reports/2026-11-16-phase4-report.md

Large diffs are not rendered by default.

173 changes: 173 additions & 0 deletions docs/reports/2026-11-16-phase4-rulings.md

Large diffs are not rendered by default.

188 changes: 184 additions & 4 deletions docs/rust-c-differences.md

Large diffs are not rendered by default.

231 changes: 231 additions & 0 deletions docs/superpowers/plans/2026-11-16-pure-java-ast-phase4-spectral.md

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/main/java/uk/ac/starlink/ast/CScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,37 @@ private static int skipSpace(String s, int i) {
return i;
}

/** Whether a value holds a character that is not white space, as C's {@code "%*s"} needs. */
static boolean hasWord(String value) {
for (int i = 0; i < value.length(); i++) {
if (!isCSpace(value.charAt(i))) {
return true;
}
}
return false;
}

/**
* C's {@code sscanf( value, " %lg %n%*s %n" )} reading all of the value: a number, then one
* word after white space. Gives the number and the index of the word, or null.
*/
static double[] numberThenWord(String value) {
int n = value.length();
Num num = strtod(value, skipSpace(value, 0));
if (num == null) {
return null;
}
int off = skipSpace(value, num.end);
int i = off;
while (i < n && !isCSpace(value.charAt(i))) {
i++;
}
if (i == off) {
return null;
}
return skipSpace(value, i) == n ? new double[] {num.value, off} : null;
}

/**
* {@code sscanf(s, " %lf %n")} consuming the whole string: the value, or null if the string is
* not one number with optional surrounding white space.
Expand Down
65 changes: 59 additions & 6 deletions src/main/java/uk/ac/starlink/ast/CmpFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public CmpFrame(Frame frame1, Frame frame2) {
}

/** Creates a CmpFrame, marking its components shared if {@code share} (C's {@code astInitCmpFrame}). */
private CmpFrame(Frame frame1, Frame frame2, boolean share) {
CmpFrame(Frame frame1, Frame frame2, boolean share) {
super();
this.frame1 = Objects.requireNonNull(frame1, "frame1");
this.frame2 = Objects.requireNonNull(frame2, "frame2");
Expand Down Expand Up @@ -172,6 +172,19 @@ void deepCopy() {
perm = perm.clone();
}

/**
* Takes the Object, Mapping, Frame and CmpFrame parts of {@code src}, as C's copy of a CmpFrame
* does: copies of the components and the permutation.
*/
@Override
void castCopyFrom(AstObject src) {
super.castCopyFrom(src);
CmpFrame f = (CmpFrame) src;
frame1 = (Frame) f.frame1.copy();
frame2 = (Frame) f.frame2.copy();
perm = f.perm.clone();
}

// ------------------------------------------------------------------
// Components
// ------------------------------------------------------------------
Expand Down Expand Up @@ -201,6 +214,16 @@ Mapping[] decomposeInto(boolean[] flags) {
return new Mapping[] {frame1, frame2};
}

/** The first component Frame, the CmpFrame's own (C's {@code frame1}). */
final Frame firstFrame() {
return frame1;
}

/** The second component Frame, the CmpFrame's own (C's {@code frame2}). */
final Frame secondFrame() {
return frame2;
}

/** The component Frame holding internal axis {@code internal}, numbered from 1. */
private Frame component(int internal) {
return internal <= frame1.getNaxes() ? frame1 : frame2;
Expand Down Expand Up @@ -342,7 +365,7 @@ public void permAxes(int[] perm) {
}

/** C's {@code PermAxes} (cmpframe.c), given the permutation numbered from 0. */
private void permAxes0(int[] perm0) {
void permAxes0(int[] perm0) {
checkPerm(perm0, "astPermAxes");
int naxes = getNaxes();
int[] old = perm.clone();
Expand Down Expand Up @@ -754,14 +777,20 @@ public double[] resolve(double[] point1, double[] point2, double[] point3, doubl
// ------------------------------------------------------------------

/**
* This CmpFrame cast into the class of another (C's {@code Cast}, cmpframe.c): for a CmpFrame
* class, as {@link Frame#cast} does; for any other, a plain Frame with this CmpFrame's axes and
* the attributes set on its components overlaid, itself cast into that class.
* This CmpFrame cast into the class of another (C's {@code Cast}, cmpframe.c): for a class of
* the CmpFrame family, whether an ancestor of this CmpFrame's class or a descendant, a copy of
* this CmpFrame as an instance of that class ({@link #castCopy}); for any other, a plain Frame
* with this CmpFrame's axes and the attributes set on its components overlaid, itself cast
* into that class.
*/
@Override
Frame cast(Frame obj) {
if (obj instanceof CmpFrame) {
return super.cast(obj);
// C's astCastCopy into the object's own class is a copy, whose attributes are all valid.
if (obj.getClass() == getClass()) {
return (Frame) copy();
}
return castCopy(obj);
}
int naxes = getNaxes();
Frame cfrm = new Frame(naxes);
Expand All @@ -772,6 +801,30 @@ Frame cast(Frame obj) {
return cfrm.cast(obj);
}

/**
* A deep copy of this CmpFrame as an instance of the class of {@code obj}, a class of the
* CmpFrame family, with the attributes that class does not allow cleared (C's {@code
* astCastCopy} followed by {@code astCleanAttribs}). As in C, the class need not be an
* ancestor: a CmpFrame cast into a SpecFluxFrame is a SpecFluxFrame holding copies of the
* CmpFrame's components, whatever their classes (cmpframe.c {@code Cast} calls {@code
* astCastCopy} for any {@code obj} that is a CmpFrame or one of its subclasses). Any other
* class is cast as by {@link Frame#castCopy}.
*/
@Override
Frame castCopy(Frame obj) {
CmpFrame res;
if (obj.getClass() == CmpFrame.class) {
res = transientCmpFrame(frame1, frame2);
} else if (obj.getClass() == SpecFluxFrame.class) {
res = new SpecFluxFrame(frame1, frame2, false);
} else {
return super.castCopy(obj);
}
res.castCopyFrom(this);
res.cleanAttribs();
return res;
}

/**
* Overlays the attributes set on the components onto another Frame (C's {@code Overlay},
* cmpframe.c). If the result is a CmpFrame whose two components each take their axes from a
Expand Down
Loading
Loading