Skip to content

Commit

Permalink
update monaco
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfl committed Dec 18, 2023
1 parent 0d0dd35 commit 00db459
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 80 deletions.
38 changes: 14 additions & 24 deletions examples/items/mining.minasm
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ uType = @unit.@type
.fi
.fi

.do
.break @unit == uFirst
bFirstDead = uFirst.@dead
.break bFirstDead
jump notFirst
.until
uFirst = null
notFirst:

nFlag = @unit.@flag
end nFlag
# uController = @unit.@controller
Expand All @@ -53,14 +44,18 @@ end nFlag
# .fi

ulocate building core false null xCore yCore bCoreFound dCore
.if uFirst === null
uFirst = @unit

bAuto = switch2.@enabled
.if bAuto == false
mWanted = sorter1.@config
ulocate ore core true mWanted xOre yOre bOreFound
.else

bAuto = switch2.@enabled
.if bAuto == false
mWanted = sorter1.@config
ulocate ore core true mWanted xOre yOre bOreFound
.if bOreFound == false
mWanted = null
.fi
.else
iLoop += 1
.if iLoop > 29
iLoop = 0
mItem = @copper
ulocate ore core true mItem xItem yItem bItemFound
.int testItem
Expand All @@ -82,7 +77,7 @@ ulocate building core false null xCore yCore bCoreFound dCore
mItem = @beryllium
ulocate ore core true mItem xItem yItem bItemFound
.int testItem
sand:
sand:

bSand = switch3.@enabled
.if bSand
Expand All @@ -103,13 +98,8 @@ sand:

control config sorter1 mWanted
.fi
end mWanted === null
.fi

.if bOreFound == false
mWanted = null
end
.fi
end mWanted === null

ucontrol boost true

Expand Down
16 changes: 8 additions & 8 deletions image2logic.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,31 @@
<div>
Spliter:
<label>
<input type="radio" name="spliter" value="overlapping" />
Overlapping
<input type="radio" name="spliter" value="greedy" />
Greedy
</label>
<label>
<input type="radio" name="spliter" value="greedy-block" checked="checked" />
Greedy-Block
</label>
<label>
<input type="radio" name="spliter" value="greedy" />
Greedy
<input type="radio" name="spliter" value="overlapping" />
Overlapping
</label>
</div>
<div>
Codegen:
<label>
<input type="radio" name="codegen" value="microop" />
MicroOp (slow)
<input type="radio" name="codegen" value="direct" />
Direct (fast)
</label>
<label>
<input type="radio" name="codegen" value="struct" checked="checked" />
Struct
</label>
<label>
<input type="radio" name="codegen" value="direct" />
Direct (fast)
<input type="radio" name="codegen" value="microop" />
MicroOp (slow)
</label>
</div>
<div>
Expand Down
117 changes: 77 additions & 40 deletions image2logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ function matrixBackground (

/**
* @template T
* @callback Metric
* @param {T} a
* @param {T} [b]
* @returns {number}
* @callback Metric metric function of two data points
* @param {T} a data point
* @param {T} [b] another data point, default to origin point of the coordinate system
* @returns {number} metric
*/


Expand Down Expand Up @@ -182,11 +182,11 @@ function manhattan (a, b = null) {

/**
* @template T
* @callback Grouper
* @param {T[]} data
* @param {number} K
* @param {number[]} tags
* @returns {[(?T)[], number[]]}
* @callback Grouper function to update centroids using existing tags
* @param {T[]} data input data points
* @param {number} K number of groups
* @param {number[]} tags tags for each data point
* @returns {[(?T)[], number[]]} updated centroids, and number of points in each group
*/


Expand Down Expand Up @@ -227,13 +227,14 @@ function euclideanGroup (data, K, tags) {


/**
* @template T
* @param {T[]} data
* @param {number} K
* @param {number} stderror
* @param {Metric<T>} metric
* @param {Grouper<T>} grouper
* @returns {[T[], number[], number[]]}
* Divide data points into K clusters using k-means algorithm.
* @template T data type
* @param {T[]} data input data points
* @param {number} K number of groups
* @param {number} stderror desired standard error of every centroid
* @param {Metric<T>} metric metric function of two data points
* @param {Grouper<T>} grouper function to update centroids using existing tags
* @returns {[T[], number[], number[]]} centroids, tags for each data point, and standard error of each centroid
*/
function kmeans (
data, K, stderror = 1e-6, metric = euclidean, grouper = euclideanGroup) {
Expand Down Expand Up @@ -835,7 +836,7 @@ function matrix2rectsOverlapping (
const result = []
for (let level = 0; level < bulks.length; level++) {
result.push(...bulks[level].sort(
level & 1 === 0 ? -a.compare(b) : a.compare(b)))
(a, b) => level & 1 === 0 ? -a.compare(b) : a.compare(b)))
}
return [result, real]
}
Expand Down Expand Up @@ -1190,8 +1191,30 @@ class CodegenUnordered extends ArrayDisplay {
*/
class BaseBucketHeader extends BaseBucket {
/**
* @param {string} displayName
* @returns {string[]}
* number of instructions in header
* @type {number}
*/
static offset
/**
* number of micro op in one instruction
* @type {number}
*/
static pack
/**
* number of instructions for one function call
* @type {number}
*/
static block
/**
* instructions of drawer function
* @type {string[]}
*/
static header

/**
* Generate header instructions with correct display name.
* @param {string} displayName display name
* @returns {string[]} header instructions with correct display name
*/
static generateHeader (displayName = 'display1') {
const cmds = this.header.slice()
Expand All @@ -1206,8 +1229,10 @@ class BaseBucketHeader extends BaseBucket {
}

/**
* @param {(string | bigint)[]} block
* @param {bigint[]} buffer
* Pack operations into instructions and flush input buffer.
* @param {(string | bigint)[]} block output instruction buffer
* @param {bigint[]} buffer operations
* @returns {boolean} `true` if input buffer is flushed
*/
static flushPack (block, buffer) {
if (buffer.length === 0) {
Expand All @@ -1221,16 +1246,21 @@ class BaseBucketHeader extends BaseBucket {
}

/**
* @param {(string | bigint)[]} block
* @param {bigint[]} buffer
* Pack operations into instructions and flush input buffer when input buffer
* is full; otherwise do nothing.
* @param {(string | bigint)[]} block output instruction buffer
* @param {bigint[]} buffer operations
* @returns {boolean} `true` if input buffer is flushed
*/
static tryFlushPack (block, buffer) {
return buffer.length >= this.pack && this.flushPack(block, buffer)
}

/**
* @param {string[]} cmds
* @param {(string | bigint)[]} buffer
* Translate packed micro ops into valid instructions and flush input buffer.
* @param {string[]} cmds output instruction buffer
* @param {(string | bigint)[]} buffer instructions or packed micro ops
* @returns {boolean} `true` if input buffer is flushed
*/
static flushBlock (cmds, buffer) {
if (buffer.length === 0) {
Expand Down Expand Up @@ -1268,8 +1298,11 @@ class BaseBucketHeader extends BaseBucket {
}

/**
* @param {string[]} cmds
* @param {(string | bigint)[]} buffer
* Translate packed micro ops into valid instructions and flush input buffer
* when input buffer is full; otherwise do nothing.
* @param {string[]} cmds output instruction buffer
* @param {(string | bigint)[]} buffer instructions or packed micro ops
* @returns {boolean} `true` if input buffer is flushed
*/
static tryFlushBlock (cmds, buffer) {
return (buffer.opCount >= this.block ||
Expand Down Expand Up @@ -2144,8 +2177,8 @@ form.addEventListener('change', async function (event) {
const ctxRaw = canvasRaw.getContext('2d')
ctxRaw.fillStyle = 'white'
ctxRaw.fillRect(0, 0, canvasRaw.width, canvasRaw.height)
// CHROME BUG
ctxRaw.getImageData(0, 0, 1, 1)
// CHROME BUG #1335626
// ctxRaw.getImageData(0, 0, 1, 1)
ctxRaw.drawImage(image, 0, 0, imageWidthScaled, imageHeightScaled)

// extract canvas
Expand Down Expand Up @@ -2180,33 +2213,37 @@ form.addEventListener('change', async function (event) {
parseInt(form.elements['blur'].value) || 0)

// convert to commands
/** @type {typeof Codegen} */
let CodegenType
/** @type {boolean} */
let unordered
/** @type {Orthogonalizer} */
let orthogonalizer
switch (form.elements['spliter'].value) {
case 'greedy':
default:
orthogonalizer = matrix2rectsGreedy
CodegenType = CodegenUnordered
unordered = true
break
case 'greedy-block':
orthogonalizer = matrix2rectsGreedy
CodegenType = Codegen
unordered = false
break
case 'overlapping':
default:
orthogonalizer = matrix2rectsOverlapping
CodegenType = Codegen
unordered = false
break
}
/** @type {typeof Codegen} */
let CodegenType
switch (form.elements['codegen'].value) {
case 'microop':
CodegenType =
CodegenType.unordered ? CodegenUnordered : CodegenMicroOp
case 'direct':
default:
CodegenType = unordered ? CodegenUnordered : Codegen
break
case 'struct':
CodegenType =
CodegenType.unordered ? CodegenUnordered : CodegenStruct
CodegenType = unordered ? CodegenUnorderedStruct : CodegenStruct
break
case 'microop':
CodegenType = unordered ? CodegenUnorderedMicroOp : CodegenMicroOp
break
}
/** @type {HTMLCanvasElement} */
Expand Down
16 changes: 8 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

<title>minasm</title>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.39.0/min/vs/editor/editor.main.min.css"
integrity="sha512-/hTKJ6YcK7JBJmV7HzjxM7LDShlTlamVMPdB0CaQRV5NeVS+ZVx8MogcT8Rw0DMRVGT7rNE+mDSc2QEVuJNdNA=="
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/editor/editor.main.min.css"
integrity="sha512-cglMadHaO/jAvqEM51bUj/saVbUkZwVa4PX0bcpWVlND3OrPpYcS/91uhIrgHrXmikanebYApd7UWjbDGEQUqg=="
crossorigin="anonymous" referrerpolicy="no-referrer" data-name="vs/editor/editor.main" />
<link rel="stylesheet" href="common.css" />
<link rel="stylesheet" href="minasm.css" />

<script defer="defer" src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.39.0/min/vs/loader.min.js"
integrity="sha512-A+6SvPGkIN9Rf0mUXmW4xh7rDvALXf/f0VtOUiHlDUSPknu2kcfz1KzLpOJyL2pO+nZS13hhIjLqVgiQExLJrw=="
<script defer="defer" src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/loader.min.js"
integrity="sha512-ZG31AN9z/CQD1YDDAK4RUAvogwbJHv6bHrumrnMLzdCrVu4HeAqrUX7Jsal/cbUwXGfaMUNmQU04tQ8XXl5Znw=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script defer="defer" src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.39.0/min/vs/editor/editor.main.nls.min.js"
integrity="sha512-c0mQUqXqgUruDgR1BGK5/lBbb3aNoeRtvKYz+abKCEXOIzTAjz3XNYrxJUKU4eTG++8NQbP6pmuCPhZq5TOIoQ=="
<script defer="defer" src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/editor/editor.main.nls.min.js"
integrity="sha512-v1Et8DY+94KH4DbAnoYA7xfAg/Kg8vVVXs9m5SiBgXeUMTgjIfg9OrRyr4KgUBgWHi2rtuz270jgTAFHZMDq5w=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script defer="defer" src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.39.0/min/vs/editor/editor.main.min.js"
integrity="sha512-O6/hjFZfZicPsnc9X2JmzEostrtvltTjQe3tpLVEwuf/xdFEk6zzvqQvbdTsZL2suJaTyD/wQeovzAJheDodew=="
<script defer="defer" src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/editor/editor.main.min.js"
integrity="sha512-K0xObUCeqheZ0gTi8VApqJPtzgUJmoJuetzFVIYNE7c+utW/48QN+BEWqHW/tuyc3vV9JtXojnJfRm95UuWstw=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script defer="defer" src="minasm-compiler.js"></script>
<script defer="defer" src="minasm.js"></script>
Expand Down

0 comments on commit 00db459

Please sign in to comment.