-
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
1 parent
ab5af22
commit 38dd424
Showing
26 changed files
with
193 additions
and
28 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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"build:all": "deno task build:syntax & deno task build:compiler", | ||
"build:syntax": "deno run -A npm:bnf-parser ./source/bnf/", | ||
"build:compiler": "deno compile --output salient.exe -A ./source/cli.ts", | ||
"test": "deno test && deno task test:salient", | ||
"test:all": "deno test && deno task test:salient", | ||
"test:deno": "deno test", | ||
"test:salient": "deno run -A ./source/cli.ts test ./tests", | ||
"cli": "deno run -A ./source/cli.ts", | ||
|
@@ -18,8 +18,7 @@ | |
"imports": { | ||
"~/": "./source/", | ||
"bnf-parser": "npm:bnf-parser@^4.1.3", | ||
"npm-run-all": "npm:npm-run-all@^4.1.5", | ||
"chalk": "npm:chalk@^5.3.0" | ||
"fmt/colors": "https://deno.land/[email protected]/fmt/colors.ts" | ||
}, | ||
"lint": { | ||
"include": ["source/"], | ||
|
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
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import { Compile } from "~/compile.ts"; | ||
import { Panic } from "~/compiler/helper.ts"; | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { resolve, join, relative, dirname } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { existsSync } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import Function from "~/compiler/function.ts"; | ||
import Package from "~/compiler/package.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import type { Scope } from "~/compiler/codegen/scope.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import { IntrinsicType, bool, u8, i8, u16, i16, u32, i32, u64, i64, f32, f64 } from "~/compiler/intrinsic.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import Structure from "~/compiler/structure.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import { LinearType, SolidType, OperandType } from "~/compiler/codegen/expression/type.ts"; | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import { red } from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import { red } from "fmt/colors"; | ||
|
||
import * as WasmTypes from "~/wasm/type.ts"; | ||
import { AssertUnreachable, LatentOffset } from "~/helper.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import * as WasmTypes from "~/wasm/type.ts"; | ||
import Structure from "~/compiler/structure.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import Structure from "~/compiler/structure.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import Function from "~/compiler/function.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import { AssertUnreachable } from "~/helper.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import { IntrinsicValue, f32, f64, i16, i32, i64, i8, u16, u32, u64, u8 } from "~/compiler/intrinsic.ts"; | ||
|
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,152 @@ | ||
import * as colors from "fmt/colors"; | ||
|
||
import type { Term_Data } from "~/bnf/syntax.d.ts"; | ||
import type { File, Namespace } from "~/compiler/file.ts"; | ||
import Structure from "~/compiler/structure.ts"; | ||
import { IsSolidType, SolidType } from "~/compiler/codegen/expression/type.ts"; | ||
import { AssertUnreachable } from "~/helper.ts"; | ||
import { ReferenceRange } from "~/bnf/shared.d.ts"; | ||
import { SourceView } from "~/parser.ts"; | ||
import { Panic } from "~/compiler/helper.ts"; | ||
|
||
export default class Data { | ||
owner: File; | ||
name: string; | ||
ast: Term_Data; | ||
ref: ReferenceRange; | ||
|
||
attributes: Array<{ | ||
offset: number, | ||
name: string, | ||
type: SolidType, | ||
}>; | ||
linked: boolean; | ||
|
||
constructor(owner: File, ast: Term_Data) { | ||
this.owner = owner; | ||
this.name = ast.value[0].value; | ||
this.ast = ast; | ||
this.ref = ast.ref; | ||
|
||
this.attributes = []; | ||
this.linked = false; | ||
} | ||
|
||
link(chain: Data[] = []) { | ||
if (this.linked) return; | ||
if (chain.includes(this)) Panic( | ||
`${colors.red("Error")}: This structure is attempting to compose itself\n` | ||
+ chain.map(x => `${x.name}${x.ref.start.toString()}`).join(' -> ') | ||
+ ` -> ${this.name}${this.ref.start.toString()}` | ||
); | ||
chain.push(this); | ||
|
||
const attrs = Array<{ | ||
name: string, | ||
type: SolidType | ||
ref: ReferenceRange | ||
}>(); | ||
|
||
for (const stmt of this.ast.value[1].value) { | ||
const line = stmt.value[0]; | ||
switch (line.type) { | ||
case "struct_attr": { | ||
const name = line.value[0].value; | ||
const existing = attrs.find(x => x.name === name); | ||
if (existing) { | ||
console.error( | ||
`${colors.red("Error")}: Duplicate attribute name found in struct\n` | ||
+ SourceView(this.owner.path, this.owner.name, existing.ref) | ||
+ SourceView(this.owner.path, this.owner.name, line.value[0].ref) | ||
); | ||
this.owner.markFailure(); | ||
continue; | ||
} | ||
|
||
const scope = this.owner; | ||
const type = scope.get(line.value[1]); | ||
if (!type) { | ||
console.error( | ||
`${colors.red("Error")}: Unable to resolve type\n` | ||
+ SourceView(this.owner.path, this.owner.name, line.value[1].ref) | ||
); | ||
this.owner.markFailure(); | ||
continue; | ||
} | ||
|
||
if (!IsSolidType(type)) { | ||
console.error( | ||
`${colors.red("Error")}: Expected a solid type\n` | ||
+ SourceView(this.owner.path, this.owner.name, line.value[1].ref) | ||
); | ||
console.error(type); | ||
this.owner.markFailure(); | ||
continue; | ||
} | ||
|
||
if (type instanceof Structure) { | ||
console.error( | ||
`${colors.red("Error")}: Cannot have a struct as element of data\n` | ||
+ SourceView(this.owner.path, this.owner.name, line.value[1].ref) | ||
); | ||
console.error(type); | ||
this.owner.markFailure(); | ||
continue; | ||
} | ||
if (type instanceof Data) type.link(chain); | ||
|
||
attrs.push({ name, type, ref: line.ref }); | ||
} break; | ||
case "struct_spread": { | ||
const other = this.owner.get(line.value[0]); | ||
if (other === null) { | ||
console.error( | ||
`${colors.red("Error")}: Unable to resolve type\n` | ||
+ SourceView(this.owner.path, this.owner.name, line.value[0].ref) | ||
); | ||
this.owner.markFailure(); | ||
continue; | ||
} | ||
|
||
if (other instanceof Structure) other.link(); | ||
else if (other instanceof Data) other.link(chain); | ||
else { | ||
console.error( | ||
`${colors.red("Error")}: Resolved type must be another structure\n` | ||
+ SourceView(this.owner.path, this.owner.name, line.value[0].ref) | ||
); | ||
this.owner.markFailure(); | ||
continue; | ||
} | ||
} break; | ||
default: AssertUnreachable(line); | ||
} | ||
} | ||
|
||
this.linked = true; | ||
} | ||
|
||
get(name: string) { | ||
this.link(); // ensure struct is linked | ||
const out = this.attributes.find(x => x.name == name); | ||
return out; | ||
} | ||
|
||
getTypeName() { | ||
return "type " + this.name; | ||
} | ||
|
||
declarationView(): string { | ||
return SourceView(this.owner.path, this.owner.name, this.ast.ref); | ||
} | ||
|
||
merge(other: Namespace) { | ||
console.error( | ||
`${colors.red("Error")}: Cannot share a name space between these two\n` | ||
+ this.declarationView() | ||
+ other.declarationView() | ||
); | ||
|
||
this.owner.markFailure(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type { Term_Access, Term_Function } from "~/bnf/syntax.d.ts"; | ||
import type { File, Namespace } from "./file.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type { File, Namespace } from "./file.ts"; | ||
import { ReferenceRange, SourceView } from "~/parser.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type { File, Namespace } from "./file.ts"; | ||
import { ReferenceRange, SourceView } from "~/parser.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type { Term_Structure } from "~/bnf/syntax.d.ts"; | ||
import type { File, Namespace } from "~/compiler/file.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import type { Term_Block } from "~/bnf/syntax.d.ts"; | ||
import type { File } from "./file.ts"; | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { stripAnsiCode } from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import { stripAnsiCode } from "fmt/colors"; | ||
|
||
export type Byte = number; | ||
export function isByte(value: number): value is Byte { | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import * as Instance from "~/bnf/syntax.js"; | ||
import * as Syntax from "~/bnf/syntax.d.ts"; | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as duration from "https://deno.land/[email protected]/fmt/duration.ts"; | ||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import * as colors from "fmt/colors"; | ||
|
||
import TestCase from "~/compiler/test-case.ts"; | ||
import Package from "~/compiler/package.ts"; | ||
|