Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions assembly.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1 class="massivetext">&#x1F64B; The Little Man Stack Machine</h1>
<a href="assembly.html">Assembly & Execution</a>
<a href="functions.html">Functions</a>
<a href="firth.html">Firth</a>
<a href="sea.html">Sea</a>
<a href="emulator.html">Emulator</a>
<a href="https://github.com/bigskysoftware/littlemanstackmachine.org">Github</a>
</p>
Expand Down Expand Up @@ -465,6 +466,15 @@ <h2>Stack Instructions</h2>
</td>
</tr>
<tr>
<td>
936
</td>
<td>
SREM
</td>
<td>
The Stack Remainder Instruction. This instruction will remove the top two values on the top of the value stack and replace them with the remainder of the division of those values
</td>
<td>
910
</td>
Expand Down
1 change: 1 addition & 0 deletions emulator.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1 class="massivetext">&#x1F64B; The Little Man Stack Machine</h1>
<a href="assembly.html">Assembly & Execution</a>
<a href="functions.html">Functions</a>
<a href="firth.html">Firth</a>
<a href="sea.html">Sea</a>
<a href="emulator.html">Emulator</a>
<a href="https://github.com/bigskysoftware/littlemanstackmachine.org">Github</a>
</p>
Expand Down
1 change: 1 addition & 0 deletions firth.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1 class="massivetext">&#x1F64B; The Little Man Stack Machine</h1>
<a href="assembly.html">Assembly & Execution</a>
<a href="functions.html">Functions</a>
<a href="firth.html">Firth</a>
<a href="sea.html">Sea</a>
<a href="emulator.html">Emulator</a>
<a href="https://github.com/bigskysoftware/littlemanstackmachine.org">Github</a>
</p>
Expand Down
1 change: 1 addition & 0 deletions functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1 class="massivetext">&#x1F64B; The Little Man Stack Machine</h1>
<a href="assembly.html">Assembly & Execution</a>
<a href="functions.html">Functions</a>
<a href="firth.html">Firth</a>
<a href="sea.html">Sea</a>
<a href="emulator.html">Emulator</a>
<a href="https://github.com/bigskysoftware/littlemanstackmachine.org">Github</a>
</p>
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1 class="massivetext">&#x1F64B; The Little Man Stack Machine</h1>
<a href="assembly.html">Assembly & Execution</a>
<a href="functions.html">Functions</a>
<a href="firth.html">Firth</a>
<a href="sea.html">Sea</a>
<a href="emulator.html">Emulator</a>
<a href="https://github.com/bigskysoftware/littlemanstackmachine.org">Github</a>
</p>
Expand Down
88 changes: 72 additions & 16 deletions lmsm-ui-vanilla.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
class LMSMUi {
static LANGUAGES = ['firth', 'sea']

lmsm = null;
language = null;

asmEditor = null;
assemblySourceMap = null;

firthEditor = null;
firthSourceMap = null;
codeEditor = null;
codeEditorMap = null;

speed = 500;

Expand Down Expand Up @@ -48,11 +50,12 @@ class LMSMUi {
}
constructor() {
this.lmsm = this.makeLMSM();
this.language = document.querySelector("#code-language").value;

CodeMirror.defineSimpleMode('lmsm-assembly', {
start: [
{
regex: /(?:CALL|DAT|ADD|SUB|STA|LDI|LDA|BRA|BRZ|BRP|NOOP|INP|OUT|SPUSH|SPOP|SDUP|SDROP|SSWAP|SADD|SSUB|SMUL|SDIV|SMAX|SMIN|JAL|RET|HLT)\b/,
regex: /(?:CALL|DAT|ADD|SUB|STA|LDI|LDA|BRA|BRZ|BRP|NOOP|INP|OUT|SPUSH|SPOP|SDUP|SDROP|SSWAP|SADD|SSUB|SMUL|SDIV|SMAX|SMIN|JAL|RET|HLT|SLT|SGT|SNOT|SEQ|FST|FLD)\b/,
token: 'keyword'
},
{
Expand Down Expand Up @@ -97,15 +100,39 @@ class LMSMUi {
],
});

this.firthEditor = CodeMirror.fromTextArea(document.querySelector('#codeEditorFirth'), {
CodeMirror.defineSimpleMode('sea', {
start: [
{
regex: /(?:extern|return|void|int|for|while|if|else|break|continue)\b/,
token: 'keyword'
},
{
regex: /==|!=|=|\+|-|\*|\/|<=|<|>=|>/,
token: 'operator'
},
{
regex: /\d\d/,
token: 'number',
}
]
})

this.codeEditor = CodeMirror.fromTextArea(document.querySelector('#codeEditorInput'), {
lineNumbers: true,
tabSize: 2,
lint: {
getAnnotations: (x) => {
let diagnostics = []
if (this.firthEditor) {
let compiler = new FirthCompiler();
let compileResult = compiler.compile(this.firthEditor.getValue());
if (this.codeEditor) {
let compiler;
if (this.language === 'firth') {
compiler = new FirthCompiler();
} else if (this.language === 'sea') {
compiler = new SeaCompiler();
} else {
alert("Unknown language: " + this.language)
}
let compileResult = compiler.compile(this.codeEditor.getValue());
for (const error of compileResult.errors) {
diagnostics.push({
from: {
Expand All @@ -125,8 +152,8 @@ class LMSMUi {
}
},
});
this.firthEditor.setSize('100%', '25em');
this.firthEditor.setOption('mode', 'firth');
this.codeEditor.setSize('100%', '25em');
this.codeEditor.setOption('mode', this.language);
}

clearOutput() {
Expand Down Expand Up @@ -235,6 +262,20 @@ class LMSMUi {
detail = "SMAX - The Stack Max Instruction. This instruction will remove the top two values on the top of the value stack and replace them with the maximum of those values";
} else if (935 === nextInstruction) {
detail = "SMIN - The Stack Min Instruction. This instruction will remove the top two values on the top of the value stack and replace them with the minimum of those values";
} else if (936 === nextInstruction) {
detail = "SREM - The Stack Remainder Instruction. This instruction will remove the top two values from the stack and replace them with the remainder of the division of those values";
} else if (937 === nextInstruction) {
detail = "SEQ - The Stack Equal Instruction. This instruction will remove the top two values from the stack and replace them with 1 if they are equal, and 0 otherwise";
} else if (939 === nextInstruction) {
detail = "SGT - The Stack Greater Than Instruction. This instruction will remove the top two values from the stack and replace them with 1 if the first is greater than the second, and 0 otherwise";
} else if (938 === nextInstruction) {
detail = "SLT - The Stack Less Than Instruction. This instruction will remove the top two values on the top of the value stack and replace them with 1 if the first is less than the second, 0 otherwise";
} else if (940 === nextInstruction) {
detail = "SNOT - The Stack Not Instruction. This instruction will remove the top value on the top of the value stack and replace it with 1 if it is 0, 0 otherwise";
} else if (941 === nextInstruction) {
detail = "FST - The Stack Store Instruction. This instruction will remove the top value of the value stack and store into the frame-slot in the accumulator";
} else if (942 === nextInstruction) {
detail = "FLD - The Stack Load Instruction. This instruction will load the value in the memory slot in the accumulator into the accumulator";
} else {
detail = "Unknown instruction - The behavior of this machine instruction is undefined.";
}
Expand All @@ -248,11 +289,26 @@ class LMSMUi {
return this.lmsm.status;
}

setLanguage(language) {
if (!LMSMUi.LANGUAGES.includes(language)) {
alert("Unknown language: " + language);
}
this.language = language;
this.codeEditor.setOption("mode", language);
}

compile() {
this.lmsm = this.makeLMSM();
const code = this.firthEditor.getValue();
const code = this.codeEditor.getValue();

let compiler = new FirthCompiler();
let compiler;
if (this.language === 'firth') {
compiler = new FirthCompiler();
} else if (this.language === 'sea') {
compiler = new SeaCompiler();
} else {
alert("Unknown language: " + this.language);
}
let compileResult = compiler.compile(code);
if (compileResult.errors.length > 0) {
console.error("Compilation Errors:")
Expand All @@ -262,7 +318,7 @@ class LMSMUi {
return;
}

this.firthSourceMap = compileResult.sourceMap;
this.codeEditorMap = compileResult.sourceMap;
this.asmEditor.setValue(compileResult.assembly);

let assembler = new LMSMAssembler();
Expand Down Expand Up @@ -363,16 +419,16 @@ class LMSMUi {
}

if (this.lastActiveFirthLine != null) {
this.firthEditor.getDoc()
this.codeEditor.getDoc()
.removeLineClass(this.lastActiveFirthLine, 'background', 'markCode');
}

if (this.firthSourceMap != null && this.lastActiveAssemblyLine != null) {
let mappedValue = this.firthSourceMap[this.lastActiveAssemblyLine + 1];
if (this.codeEditorMap != null && this.lastActiveAssemblyLine != null) {
let mappedValue = this.codeEditorMap[this.lastActiveAssemblyLine + 1];
if (mappedValue != null) {
// editor is zero-based
this.lastActiveFirthLine = mappedValue - 1;
this.firthEditor.getDoc()
this.codeEditor.getDoc()
.addLineClass(this.lastActiveFirthLine, 'background', 'markCode');
} else {
this.lastActiveFirthLine = null;
Expand Down
17 changes: 12 additions & 5 deletions lmsm-vanilla.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
">
<div class="grid">
<div id="titleBox" class="box center" data-cols="1 5" data-rows="1">
<h1 class="allcaps">🙋 Little Man Stack Machine Emulator</h2>
<h1 class="allcaps">🙋 Little Man Stack Machine Emulator</h1>
</div>
<div id="codeEditorBoxFirth" class="box" data-cols="1" data-rows="2">
<strong class="allcaps block titlebar">Firth</strong>

<div id="firthCodeEditor" class="box" data-cols="1" data-rows="2">
<strong class="allcaps block titlebar">
<select id="code-language" onchange="window.lmsm.setLanguage(event.target.value)">
<option value="firth">Firth</option>
<option value="sea">Sea</option>
</select>
</strong>
<section class="tool-bar">
<label>
<input type="button" onclick="
Expand All @@ -36,9 +42,10 @@ <h1 class="allcaps">🙋 Little Man Stack Machine Emulator</h2>
" value="Compile" />
</label>
</section>
<textarea id="codeEditorFirth"></textarea>
<textarea id="codeEditorInput"></textarea>
</div>
<div id="codeEditorBox" class="box" data-cols="1" data-rows="3">

<div id="assemblyCodeEditor" class="box" data-cols="1" data-rows="3">
<strong class="allcaps block titlebar">LMSM Assembly</strong>
<section class="tool-bar">
<label>
Expand Down
Loading