Skip to content

Commit

Permalink
Small changes to fix rectangular slab codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Gillespie authored and Mark Gillespie committed Oct 30, 2023
1 parent 8babea9 commit 2e2618a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
8 changes: 4 additions & 4 deletions block-library/blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@
{ "begin":0, "end":0, "cps":[[-0.300,-0.500,0.000],[-0.300,-0.402,0.000],[-0.305,-0.263,-0.093],[-0.271,-0.193,-0.088],[-0.212,-0.070,-0.079],[-0.123,-0.011,-0.047],[0.008,-0.012,0.000],[0.126,-0.013,0.042],[0.224,-0.101,0.096],[0.261,-0.204,0.096],[0.298,-0.309,0.096],[0.300,-0.402,0.000],[0.300,-0.500,0.000]], "oriented": false },
{ "begin":2, "end":4, "cps":[[-1.000,-0.222,0.000],[-0.861,-0.222,0.000],[-0.329,-0.222,0.277],[0.000,-0.222,-0.000],[0.329,-0.222,-0.277],[0.861,-0.222,0.000],[1.000,-0.222,0.000]], "oriented": true }
],
"machine":["roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"machine":["xfer [Nx] [Hxy]", "roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"human":[]
},
{
Expand Down Expand Up @@ -650,7 +650,7 @@
{ "begin":0, "end":0, "cps":[[-0.300,-0.500,0.000],[-0.300,-0.402,0.000],[-0.305,-0.263,-0.093],[-0.271,-0.193,-0.088],[-0.212,-0.070,-0.079],[-0.123,-0.011,-0.047],[0.008,-0.012,0.000],[0.126,-0.013,0.042],[0.224,-0.101,0.096],[0.261,-0.204,0.096],[0.298,-0.309,0.096],[0.300,-0.402,0.000],[0.300,-0.500,0.000]], "oriented": false },
{ "begin":4, "end":2, "cps":[[1.000,-0.222,0.000],[0.861,-0.222,0.000],[0.329,-0.222,-0.277],[0.000,-0.222,-0.000],[-0.329,-0.222,0.277],[-0.861,-0.222,0.000],[-1.000,-0.222,0.000]], "oriented": true }
],
"machine":["roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"machine":["xfer [Nx] [Hxy]", "roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"human":[]
},
{
Expand Down Expand Up @@ -678,7 +678,7 @@
{ "begin":0, "end":0, "cps":[[0.300,-0.500,0.000],[0.300,-0.402,0.000],[0.305,-0.263,-0.093],[0.271,-0.193,-0.088],[0.212,-0.070,-0.079],[0.123,-0.011,-0.047],[-0.008,-0.012,0.000],[-0.126,-0.013,0.042],[-0.224,-0.101,0.096],[-0.261,-0.204,0.096],[-0.298,-0.309,0.096],[-0.300,-0.402,0.000],[-0.300,-0.500,0.000]], "oriented": false },
{ "begin":2, "end":4, "cps":[[-1.000,-0.222,0.000],[-0.861,-0.222,0.000],[-0.329,-0.222,-0.277],[-0.000,-0.222,-0.000],[0.329,-0.222,0.277],[0.861,-0.222,0.000],[1.000,-0.222,0.000]], "oriented": true }
],
"machine":["roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"machine":["xfer [Nx] [Hxy]", "roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"human":[]
},
{
Expand Down Expand Up @@ -706,7 +706,7 @@
{ "begin":0, "end":0, "cps":[[0.300,-0.500,0.000],[0.300,-0.402,0.000],[0.305,-0.263,-0.093],[0.271,-0.193,-0.088],[0.212,-0.070,-0.079],[0.123,-0.011,-0.047],[-0.008,-0.012,0.000],[-0.126,-0.013,0.042],[-0.224,-0.101,0.096],[-0.261,-0.204,0.096],[-0.298,-0.309,0.096],[-0.300,-0.402,0.000],[-0.300,-0.500,0.000]], "oriented": false },
{ "begin":4, "end":2, "cps":[[1.000,-0.222,0.000],[0.861,-0.222,0.000],[0.329,-0.222,0.277],[-0.000,-0.222,-0.000],[-0.329,-0.222,-0.277],[-0.861,-0.222,0.000],[-1.000,-0.222,0.000]], "oriented": true }
],
"machine":["roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"machine":["xfer [Nx] [Hxy]", "roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"human":[]
},
{
Expand Down
8 changes: 4 additions & 4 deletions block-library/instructions.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"bind-off-through-down.left": {
"machine": ["roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"machine": ["xfer [Nx] [Hxy]", "roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"human": []
},
"bind-off-through-down.right": {
"machine": ["roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"machine": ["xfer [Nx] [Hxy]", "roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"human": []
},
"bind-off-through-up.left.001": {
"machine": ["roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"machine": ["xfer [Nx] [Hxy]", "roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"human": []
},
"bind-off-through-up.right.001": {
"machine": ["roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"machine": ["xfer [Nx] [Hxy]", "roll [HFxy] [HBxy]", "pause Please bind off the final row"],
"human": []
},
"cast-on.left": {
Expand Down
25 changes: 23 additions & 2 deletions code/sk.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,36 @@ export function noPassGrouping(fragmentList) {

// Take a list of program fragments and group them into passes before emitting the resulting code
// Consecutive fragments with the same id have their instructions interleaved into unified passes
// Fragments are in the form { "id": "fragName", "instructions": ["list", "of", "instructions"] }
// Also does the following:
// drops any releases that happen at the beginning of the program (artifacts from cast on row)
// drops empty fragments
export function groupPasses(fragmentList) {
// console.log(fragmentList)

let solidk = "";
let iF = 0;
let atProgramStart = true;
while (iF < fragmentList.length) {
let currID = fragmentList[iF]["id"];

// only perform releases associated with yarn-next-row after program has started making stitches
if (atProgramStart && currID.startsWith("yarn-next-row")) {
iF++;
continue;
}

let passFragments = [];
let lookahead = 0;
// accumulate all following fragments with the same id
while (iF + lookahead < fragmentList.length
&& fragmentList[iF + lookahead]["id"] === currID) {
passFragments.push(fragmentList[iF + lookahead]["instructions"]);
&& (fragmentList[iF + lookahead]["id"] === currID || fragmentList[iF + lookahead]["instructions"].length == 0)) {
if (fragmentList[iF + lookahead]["instructions"].length > 0) passFragments.push(fragmentList[iF + lookahead]["instructions"]);
lookahead++;
}

// console.log(currID, atProgramStart, passFragments);

// interleave fragments
for (let iI = 0; iI < passFragments[0].length; ++iI) {
for (let iF = 0; iF < passFragments.length; ++iF) {
Expand All @@ -143,6 +159,11 @@ export function groupPasses(fragmentList) {
solidk += "\n";
}
iF += lookahead;
if ( ! (currID.startsWith("pause")
|| currID.startsWith("comment")
|| currID.startsWith("yarn-in")
|| currID.startsWith("cast-on")
) ) atProgramStart = false;
}
return solidk;
}
Expand Down

0 comments on commit 2e2618a

Please sign in to comment.