├── src
├── VirtualMachine.ts
├── Diagnostic.ts
├── Lexer.ts
├── Tests.ts
└── Assembler.ts
├── index.html
├── tests.html
├── tsconfig.json
├── LICENSE
├── js
├── wee.d.ts
└── wee.js.map
└── README.md
/src/VirtualMachine.ts:
--------------------------------------------------------------------------------
1 | module wee {
2 | export class VirtualMachine {
3 | }
4 | }
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/tests.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 |
2 | {
3 | "compilerOptions": {
4 | "module": "none",
5 | "noImplicitAny": true,
6 | "removeComments": true,
7 | "preserveConstEnums": true,
8 | "outFile": "js/wee.js",
9 | "sourceMap": true,
10 | "declaration": true
11 | },
12 | "include": [
13 | "src/**/*"
14 | ],
15 | "exclude": [
16 | "js"
17 | ]
18 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Mario Zechner
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Diagnostic.ts:
--------------------------------------------------------------------------------
1 | module wee {
2 | /**
3 | * Describes a position within a source text as line/column (both starting at one) and absolute
4 | * character index (starting at 0).
5 | */
6 | export class Position {
7 | constructor (public line: number = 0, public column: number = 0, public index: number = 0) { }
8 | }
9 |
10 | /**
11 | * Describes the location of a segment within a source text.
12 | */
13 | export class Range {
14 | start = new Position();
15 | end = new Position();
16 |
17 | constructor (public source: string) {};
18 |
19 | length () {
20 | return this.end.index - this.start.index;
21 | }
22 | }
23 |
24 | /**
25 | * Severity of a Diagnostic.
26 | */
27 | export enum Severity {
28 | Debug = "Debug",
29 | Info = "Info",
30 | Warning = "Warning",
31 | Error = "Error"
32 | }
33 |
34 | /**
35 | *
36 | */
37 | export class Diagnostic {
38 | constructor (public severity: Severity, public range: Range, public message: string) {};
39 |
40 | toString () {
41 | let lines = this.range.source.split(/\r?\n/);
42 | let result = `${this.severity} (${this.range.start.line}):${this.range.start.column}: ${this.message}\n\n `;
43 | let line = lines[this.range.start.line - 1];
44 | result += line + "\n ";
45 | let startColumn = this.range.start.column;
46 | let endColumn = this.range.start.line != this.range.end.line ? line.length : this.range.end.column;
47 | for (var i = 1; i <= line.length; i++) {
48 | if (i >= startColumn && i < endColumn) {
49 | result += "~";
50 | } else {
51 | result += line.charAt(i - 1) == '\t' ? '\t' : ' ';
52 | }
53 | }
54 | result += "\n";
55 | return result;
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/js/wee.d.ts:
--------------------------------------------------------------------------------
1 | declare module wee {
2 | interface StringMap {
3 | [key: string]: V;
4 | }
5 | interface IndexedMap {
6 | [key: number]: V;
7 | }
8 | class ParserResult {
9 | instructions: Array;
10 | labels: StringMap