-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
837 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import styled from '@emotion/styled'; | ||
import { NospaceIR } from '@repo/parser'; | ||
import { useMemo } from 'react'; | ||
|
||
const CodeBlock = styled.code` | ||
white-space: pre-wrap; | ||
`; | ||
|
||
export type ReferenceTableRowProps = { | ||
command: string; | ||
link: string; | ||
}; | ||
|
||
export default function ReferenceTableRow({ | ||
command, | ||
link, | ||
}: ReferenceTableRowProps) { | ||
const [ns, ws] = useMemo(() => { | ||
const ir = NospaceIR.fromNossembly(command); | ||
return [ir.toNospace(), ir.toWhitespace()]; | ||
}, [command]); | ||
|
||
return ( | ||
<tr> | ||
<td> | ||
<a href={link}>{command}</a> | ||
</td> | ||
<td> | ||
<code>{ns}</code> | ||
</td> | ||
<td> | ||
<CodeBlock>{ws}</CodeBlock> | ||
</td> | ||
<td> | ||
<code>{command}</code> | ||
</td> | ||
</tr> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import styled from '@emotion/styled'; | ||
import { NospaceIR } from '@repo/parser'; | ||
import { useMemo } from 'react'; | ||
|
||
const CodeBlock = styled.code` | ||
white-space: pre-wrap; | ||
`; | ||
|
||
export type SyntaxTableProps = { | ||
command: string; | ||
inter?: string; | ||
}; | ||
|
||
export default function SyntaxTable({ command, inter }: SyntaxTableProps) { | ||
const [ns, ws] = useMemo(() => { | ||
const ir = inter ? undefined : NospaceIR.fromNossembly(command); | ||
const nospace = inter | ||
? inter | ||
.replace(/s/g, '\u200B') | ||
.replace(/t/g, '\u200C') | ||
.replace(/n/g, '\u200D') | ||
.replace(/x/g, '\u2060') | ||
: ir!.toNospace(); | ||
const whitespace = inter | ||
? inter.replace(/s/g, ' ').replace(/t/g, '\t').replace(/n/g, '\n') | ||
: ir!.toWhitespace(); | ||
return [nospace, inter?.includes('x') ? undefined : whitespace]; | ||
}, [command]); | ||
|
||
return ( | ||
<table> | ||
<tr> | ||
<th></th> | ||
<th>Command</th> | ||
<th>Unobsfucated</th> | ||
</tr> | ||
<tr> | ||
<td>Nospace</td> | ||
<td> | ||
<code>{ns}</code> | ||
</td> | ||
<td> | ||
{ns.split('').map((x, i) => ( | ||
<> | ||
{i !== 0 && ', '} | ||
<code key={i}> | ||
{x | ||
.replace(/\u200B/g, 'ZWSP') | ||
.replace(/\u200C/g, 'ZWNJ') | ||
.replace(/\u200D/g, 'ZWJ') | ||
.replace(/\u2060/g, 'WJ')} | ||
</code> | ||
</> | ||
))} | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Whitespace</td> | ||
<td>{ws ? <CodeBlock>{ws + '\n'}</CodeBlock> : '-'}</td> | ||
<td> | ||
{ws | ||
? ns.split('').map((x, i) => ( | ||
<> | ||
{i !== 0 && ', '} | ||
{x | ||
.replace(/\u200B/g, 'Space') | ||
.replace(/\u200C/g, 'Tab') | ||
.replace(/\u200D/g, 'Newline')} | ||
</> | ||
)) | ||
: '-'} | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Nossembly</td> | ||
<td> | ||
<code>{command}</code> | ||
</td> | ||
<td>-</td> | ||
</tr> | ||
</table> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: Quick Reference | ||
sidebar: | ||
order: 20 | ||
--- | ||
import ReferenceTableRow from '../../../components/ReferenceTableRow.tsx'; | ||
|
||
This page features a quick reference of all Nospace commands in the one place. You can click into each command for more details. | ||
|
||
<table> | ||
<tr> | ||
<th>Command name</th> | ||
<th>Nospace syntax</th> | ||
<th>Whitespace syntax</th> | ||
<th>Nossembly syntax</th> | ||
</tr> | ||
<ReferenceTableRow command="Add" link="/reference/arithmetic#addition" /> | ||
<ReferenceTableRow command="Assert" link="/reference/types#assert" /> | ||
<ReferenceTableRow command="Call" link="/reference/control-flow#call" /> | ||
<ReferenceTableRow command="Cast" link="/reference/types#cast" /> | ||
<ReferenceTableRow command="Copy" link="/reference/stack#copy" /> | ||
<ReferenceTableRow command="Divide" link="/reference/arithmetic#integer-division" /> | ||
<ReferenceTableRow command="Duplicate" link="/reference/stack#duplicate" /> | ||
<ReferenceTableRow command="End" link="/reference/control-flow#end" /> | ||
<ReferenceTableRow command="Jump" link="/reference/control-flow#jump" /> | ||
<ReferenceTableRow command="JumpNegative" link="/reference/control-flow#jumpnegative" /> | ||
<ReferenceTableRow command="JumpZero" link="/reference/control-flow#jumpzero" /> | ||
<ReferenceTableRow command="Label" link="/reference/control-flow#label" /> | ||
<ReferenceTableRow command="Mod" link="/reference/arithmetic#modulo" /> | ||
<ReferenceTableRow command="Multiply" link="/reference/arithmetic#multiplication" /> | ||
<ReferenceTableRow command="Pop" link="/reference/stack#pop" /> | ||
<ReferenceTableRow command="Push" link="/reference/stack#push" /> | ||
<ReferenceTableRow command="ReadChar" link="/reference/io#readchar" /> | ||
<ReferenceTableRow command="ReadInt" link="/reference/io#readint" /> | ||
<ReferenceTableRow command="Retrieve" link="/reference/heap#retrieve" /> | ||
<ReferenceTableRow command="Return" link="/reference/control-flow#return" /> | ||
<ReferenceTableRow command="Slide" link="/reference/stack#slide" /> | ||
<ReferenceTableRow command="Store" link="/reference/heap#store" /> | ||
<ReferenceTableRow command="Subtract" link="/reference/arithmetic#subtraction" /> | ||
<ReferenceTableRow command="Swap" link="/reference/stack#swap" /> | ||
<ReferenceTableRow command="WriteChar" link="/reference/io#writechar" /> | ||
<ReferenceTableRow command="WriteInt" link="/reference/io#writeint" /> | ||
</table> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
--- | ||
title: Arithmetic | ||
--- | ||
import Example from '../../../components/Example.tsx'; | ||
import SyntaxTable from '../../../components/SyntaxTable.tsx'; | ||
|
||
All artithmetic commands use the `` prefix and operate on two items in the stack. The second from top (first pushed) item is considered to be to the left of the operator, and top item (last pushed) is to the right of the operator. | ||
|
||
## Integer Literals | ||
|
||
Integers are expressed in Nospace as a binary squence of `` and ``s (representing `0` and `1` respectively) | ||
prefixed by a `` or `` indicating signedness (`+` and `-` respectievly) and terminated by a ``. For example, the number `518929412845` is represented as ``. | ||
|
||
## Addition | ||
|
||
The addition command takes two numbers from the top of the stack, adds them together, and pushes the result back to the stack. | ||
|
||
### Syntax | ||
|
||
<SyntaxTable command="Add" /> | ||
|
||
### Parameters | ||
|
||
The addition command takes no parameters | ||
|
||
### Stack parameters | ||
|
||
The following parameters should be pushed in the order expressed below: | ||
|
||
- `Int` representing the left hand side of the operator | ||
- `Int` representing the right hand side of the operator | ||
|
||
### Example | ||
|
||
<Example client:load="react" example={`Push 1 | ||
Push 2 | ||
Add`}/> | ||
|
||
## Subtraction | ||
|
||
The subtract command takes two numbers from the top of the stack, subtracts the one pushed last, and pushes the result back to the stack. | ||
|
||
### Syntax | ||
|
||
<SyntaxTable command="Subtract" /> | ||
|
||
|
||
### Parameters | ||
|
||
The subtract command takes no parameters | ||
|
||
### Stack parameters | ||
|
||
The following parameters should be pushed in the order expressed below: | ||
|
||
- `Int` representing the left hand side of the operator | ||
- `Int` representing the right hand side of the operator | ||
|
||
### Example | ||
|
||
<Example client:load="react" example={`Push 2 | ||
Push 1 | ||
Subtract`}/> | ||
|
||
## Multiplication | ||
|
||
The multiplication command takes two numbers from the top of the stack, multiplies them, and pushes the result back to the stack. | ||
|
||
### Syntax | ||
|
||
<SyntaxTable command="Multiply" /> | ||
|
||
### Parameters | ||
|
||
The multiplication command takes no parameters | ||
|
||
### Stack parameters | ||
|
||
The following parameters should be pushed in the order expressed below: | ||
|
||
- `Int` representing the left hand side of the operator | ||
- `Int` representing the right hand side of the operator | ||
|
||
### Example | ||
|
||
<Example client:load="react" example={`Push 5 | ||
Push 6 | ||
Multiply`}/> | ||
|
||
## Integer Division | ||
|
||
The integer division command takes two numbers from the top of the stack, divides the item pushed last from the one pushed first, and pushes the result back to the stack. | ||
|
||
### Syntax | ||
|
||
<SyntaxTable command="Divide" /> | ||
|
||
### Parameters | ||
|
||
The integer division command takes no parameters | ||
|
||
### Stack parameters | ||
|
||
The following parameters should be pushed in the order expressed below: | ||
|
||
- `Int` representing the left hand side of the operator | ||
- `Int` representing the right hand side of the operator | ||
|
||
### Example | ||
|
||
<Example client:load="react" example={`Push 15 | ||
Push 3 | ||
Divide`}/> | ||
|
||
## Modulo | ||
|
||
The modulo command takes two numbers from the top of the stack, multiplies them, and pushes the result back to the stack. | ||
|
||
### Syntax | ||
|
||
<SyntaxTable command="Mod" /> | ||
|
||
### Parameters | ||
|
||
The modulo command takes no parameters | ||
|
||
### Stack parameters | ||
|
||
The following parameters should be pushed in the order expressed below: | ||
|
||
- `Int` representing the left hand side of the operator | ||
- `Int` representing the right hand side of the operator | ||
|
||
### Example | ||
|
||
<Example client:load="react" example={`Push 5 | ||
Push 7 | ||
Mod`}/> |
Oops, something went wrong.