Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fibonnaci test #3

Merged
merged 66 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
04a6023
+Syntax error handling
AjaniBilby Aug 6, 2023
45fe5bf
+Basic parsing
AjaniBilby Aug 6, 2023
f3f9722
+Layout setup
AjaniBilby Aug 6, 2023
4456eca
+Basic syntax ingesting
AjaniBilby Aug 6, 2023
b61fc15
Merge branch 'main' into fibonnaci-test
AjaniBilby Aug 6, 2023
04a750a
Merge branch 'main' into fibonnaci-test
AjaniBilby Aug 6, 2023
06e08d2
Merge branch 'main' into fibonnaci-test
AjaniBilby Aug 6, 2023
6d7917a
Update ci.yml
AjaniBilby Aug 6, 2023
21e03f0
Merge branch 'main' into fibonnaci-test
AjaniBilby Aug 6, 2023
9874480
+namespace collision check
AjaniBilby Aug 8, 2023
90918c3
~Dependency update
AjaniBilby Aug 8, 2023
7a31d19
~Improved error messages
AjaniBilby Aug 8, 2023
a9b920e
Update parser.ts
AjaniBilby Aug 8, 2023
9205b39
+scaffolding
AjaniBilby Aug 8, 2023
8ec9ce4
+Function signature linking
AjaniBilby Aug 9, 2023
1efed34
~Basic function headers
AjaniBilby Sep 3, 2023
0d00845
+Register reference type for post compilation resolution
AjaniBilby Sep 4, 2023
4bde759
+Variable declaration
AjaniBilby Sep 4, 2023
ac2d656
+local registers
AjaniBilby Sep 4, 2023
806a167
~Corrected local variable encoding
AjaniBilby Sep 4, 2023
151f39a
~Basic variable assignment
AjaniBilby Sep 7, 2023
62c7f2f
~Cleaned up environment
AjaniBilby Sep 10, 2023
28e7984
~Basic constant resolution
AjaniBilby Sep 10, 2023
38e1d22
+Basic type encoding
AjaniBilby Sep 10, 2023
dbc3392
+Unsigned integer types
AjaniBilby Sep 11, 2023
f300c3f
~Implemented auto type detection
AjaniBilby Sep 11, 2023
2ac784c
Deno migration (#4)
AjaniBilby Sep 11, 2023
7c9d56e
Update hello-world.test.ts
AjaniBilby Sep 11, 2023
19242c6
~Removed chalk as a dependency
AjaniBilby Sep 11, 2023
7dff958
~Removed node native deps
AjaniBilby Sep 11, 2023
b9ac786
~Fully integrated deno
AjaniBilby Sep 11, 2023
0e9e716
~Cleaned up repetitive exiting code
AjaniBilby Sep 13, 2023
251b0cb
~Banned certain variable names
AjaniBilby Sep 13, 2023
1d6bc0b
+"as", "instanceof" operator syntax
AjaniBilby Sep 13, 2023
de598a5
Update syntax.d.ts
AjaniBilby Sep 13, 2023
5df2c06
+virtual native types for smaller ints
AjaniBilby Sep 13, 2023
34ddaed
~moved `expression.ts`
AjaniBilby Sep 13, 2023
12e26dc
+expr precedence swapping
AjaniBilby Sep 16, 2023
465b6de
~Basic reassignment
AjaniBilby Sep 18, 2023
d67338c
Update syntax.d.ts
AjaniBilby Sep 18, 2023
d07f8fb
~Allow forward declaration of variables
AjaniBilby Sep 18, 2023
c00e2cd
~Basic variable load and assigning
AjaniBilby Sep 18, 2023
316fc47
~Simplified latent values
AjaniBilby Sep 18, 2023
9ef2fbd
+expr bracket support
AjaniBilby Sep 19, 2023
23d1450
~Moved prefix processing to a post expr_arg process
AjaniBilby Sep 19, 2023
57d362e
~basic infix operations
AjaniBilby Sep 19, 2023
6a62842
~implemented more basic operators
AjaniBilby Sep 20, 2023
b5111c5
~Corrected bad remained code
AjaniBilby Sep 20, 2023
e81a437
+allow raw buffers for code generation
AjaniBilby Sep 20, 2023
ad70c36
~Fixed bad syntax edge case
AjaniBilby Sep 20, 2023
ea164e2
~Fixed crash on buffer source compile errors
AjaniBilby Sep 20, 2023
ea5d670
+basic test scaffold
AjaniBilby Sep 20, 2023
8e9dc30
Update numeric.test.ts
AjaniBilby Sep 20, 2023
370d601
~Better displaying for errors in compiled buffer sources
AjaniBilby Sep 21, 2023
abf8ae5
Update index.ts
AjaniBilby Sep 21, 2023
2ea3b55
+Basic VSCode extension (#5)
AjaniBilby Sep 21, 2023
b61e73a
+Allow reading functions as values
AjaniBilby Sep 21, 2023
08476b7
~Fixed bad error logs
AjaniBilby Sep 21, 2023
4818b96
~Fixed missing type checks
AjaniBilby Sep 21, 2023
3cc644f
+Basic function calls
AjaniBilby Sep 21, 2023
e4ff2a3
~Fixed bad block byte code generation
AjaniBilby Sep 21, 2023
d19c25b
~Fixed compiling past return
AjaniBilby Sep 21, 2023
a61653c
~fixed bad recursive function compilation
AjaniBilby Sep 21, 2023
00b4f2a
+added virtual types
AjaniBilby Sep 21, 2023
61905ff
+fibonacci test case
AjaniBilby Sep 21, 2023
7f5662c
~Updated to new bnf-syntax version
AjaniBilby Sep 22, 2023
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
11 changes: 3 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v2
- uses: denoland/setup-deno@v1
with:
node-version: '18.x'
deno-version: v1.x

- name: Install Dependencies
run: npm install
- name: Build Library
run: tsc
- name: Automated tests
run: npm run test:mocha
run: deno test
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ package-lock.json
.vscode-test

# Build outputs

*.wasm
*.wat
*.wat
*.sa
*.exe
*.out
*.app
9 changes: 7 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"editor.insertSpaces": false,
"files.eol": "\n",
"cSpell.words": [
"iovs"
]
"bitcode",
"Fuwawa",
"impls",
"iovs",
"Yeet"
],
"deno.enable": true
}
29 changes: 29 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"allowJs": true,
"strict": true,
"strictNullChecks": true,
"lib": ["ESNext", "DOM"]
},
"lint": {
"include": ["source/"],
"exclude": ["source/bnf/"],
"rules": {
"tags": ["recommended"],
"include": ["ban-untagged-todo"],
"exclude": ["no-unused-vars"]
}
},
"ignore-fmt": {
"useTabs": true,
"semiColons": true,
"proseWrap": "preserve",
"include": ["source/"],
"exclude": ["source/bnf/"]
},
"lock": false,
"nodeModulesDir": true,
"test": {
"include": ["tests/*", "source/*/*"]
}
}
22 changes: 7 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
"main": "bin/compiler/index.js",
"type": "module",
"files": [
"bin/*",
"bnf/*"
"bin/*"
],
"scripts": {
"build": "run-s build:*",
"build:ts": "tsc",
"build:syntax": "npx bnf-compile ./source/bnf/",
"test": "run-s test:*",
"test:types": "tsc --noEmit",
"test:mocha": "npx mocha"
"build:compiler": "deno compile --output salient.exe --allow-read --allow-write --allow-env --allow-run --allow-sys ./source/cli.ts",
"test": "deno test",
"compile": "deno run --allow-read --allow-write --allow-env --allow-run --allow-sys ./source/cli.ts"
},
"bin": {
"salient": "bin/compiler/index.js"
"salient": "bin/cli.js"
},
"preferGlobal": true,
"engineStrict": true,
Expand All @@ -35,17 +33,11 @@
},
"homepage": "https://salient.moe",
"dependencies": {
"bnf-parser": "^4.0.5",
"chalk": "^5.3.0"
},
"devDependencies": {
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.2",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"bnf-parser": "^4.0.7",
"npm-run-all": "^4.1.5",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^5.2.2"
}
}
8 changes: 4 additions & 4 deletions source/bnf/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export function MapTreeRefs(tree, str, sharedRef) {
ref: Reference.blank(),
bytes: 0
};
while (stack.length > 0) {
while (true) {
const curr = stack.pop();
if (!curr)
continue;
break;
if (curr.ref === sharedRef) {
// Don't calculate forward progression if not needed
if (cursor.bytes !== curr.end)
ProgressCursor(str, curr.end, cursor);
if (cursor.bytes !== curr.start)
ProgressCursor(str, curr.start, cursor);
curr.ref = new ReferenceRange(cursor.ref.clone(), cursor.ref // no alloc fill in
);
stack.push(curr); // revisit node for ref.end mapping (after children)
Expand Down
88 changes: 53 additions & 35 deletions source/bnf/syntax.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,94 @@ program ::= %w* ( stmt_top %w* )* ;
#=============================
# Helper patterns
#=============================
w ::= " " | "\t" | nl | comment ;
nl ::= "\r\n" | "\n" ;
w ::= " " | "\t" | nl | comment ;
nl ::= "\r\n" | "\n" ;

digit ::= "0" -> "9" ;
digit_nz ::= "1" -> "9" ;
letter ::= "a" -> "z" | "A" -> "Z" ;
digit ::= "0" -> "9" ;
digit_nz ::= "1" -> "9" ;
letter ::= "a" -> "z" | "A" -> "Z" ;



#=============================
# Comments
#=============================
comment ::= comment_single | comment_multi ;
comment_single ::= "//" !( nl )* nl? ; # Optional as the comment might be on a EOF
comment_multi ::= "/*" ( "\\*" | !( "*/" )+ )* "*/" ;
comment ::= comment_single | comment_multi ;
comment_single ::= "//" !( nl )* nl? ; # Optional as the comment might be on a EOF
comment_multi ::= "/*" ( "\\*" | !( "*/" )+ )* "*/" ;



#=============================
# Constants
#=============================
constant ::= boolean
| string
| float | integer ;
constant ::= boolean
| string
| float | integer ;

string ::= string_text ;
string_text ::= %"\'" ( ( "\\" !"" ) | !( "\'" ) )* %"\'" ;
string ::= string_text ;
string_text ::= %"\'" ( ( "\\" !"" ) | !( "\'" ) )* %"\'" ;

boolean ::= "true" | "false" ;
boolean ::= "true" | "false" ;

void ::= "void" ;
void ::= "void" ;

integer ::= "-"? ...integer_u ;
integer_u ::= ( digit_nz digit* ) | zero ;
zero ::= "0" ;
float ::= ...integer "." ...integer_u ( "e" ...integer )? ;
integer ::= ...integer_u ;
integer_u ::= ( digit_nz digit* ) | zero ;
zero ::= "0" ;
float ::= ...( integer "." integer_u ( "e" integer )? ) ;



#=============================
# Variables
#=============================
variable ::= ...name ;
name ::= ( letter | "_" )+ ( letter | digit | "_" )* ;
name ::= ...(( letter | "_" )+ ( letter | digit | "_" )*) ;

data_type ::= ...name ;
access ::= name ( %w* accessor )* ;
accessor ::= access_static | access_dynamic | access_comp ;
access_static ::= %"." ...name ;
access_dynamic ::= %"[]" ;
access_comp ::= %"#[]";

declare ::= %( "let" w* ) name %w* (%":" %w* access %w*)? ( %("=" w*) expr )? %(w* ";") ;
assign ::= name %w* %("=" w*) expr %(w* ";") ;



#=============================
# Function
#=============================
function ::= func_head %w* ( func_body | ";" ) ;
func_head ::= %("fn" w+) ...name %( w* "(" w* ) func_args %(w* ")" w* ":" w* data_type) ;
func_head ::= %("fn" w+) ...name %( w* "(" w* ) func_args %(w* ")" w* ":" w*) access ;
func_args ::= ( func_arg %w* ( %( "," w* ) func_arg )* )? ;
func_arg ::= ...name %( w* ":" w* ) data_type ;
func_arg ::= ...name %( w* ":" w* ) access ;
func_body ::= %( "{" w* ) ( func_stmt %w* )* %( w* "}" w* ";"? ) ;
func_stmt ::= func_call ;
func_stmt ::= declare | assign | return | statement ;

func_call ::= access func_call_body;
func_call_body ::= %( w* "(" w* ) ( expr %w* ( %( "," w* ) expr %w* )* )? %( ")" w* ) ;

func_call ::= ...name func_call_body;
func_call_body ::= %( w* "(" w* ) ( expr %w* ( %( "," w* ) expr %w* )* )? %( ")" w* ) ;
return ::= %"return" "_tail"? %w+ expr %";";

#=============================
# Expression
#=============================
expr ::= expr_arg %w* ( ...expr_infix %w* expr_arg %w* )* ;
expr_prefix ::= "!" | "-" ;
expr_infix ::= "&&" | "||" | "==" | "!=" | "<=" | ">=" | "<" | ">"
| "%" | "*" | "/" | "+" | "-"
| "->" ;
expr_arg ::= expr_prefix? %w* ( constant | expr_brackets | expr_val ) ;
expr_val ::= variable func_call_body? ;
expr_brackets ::= %( "(" w* ) expr %( w* ")" ) ;
expr ::= expr_arg %w* ( ...expr_infix %w* expr_arg %w* )* ;
expr_prefix ::= "!" | "-" | "return" ;
expr_infix ::= "&&" | "||" | "^" | "==" | "!=" | "<=" | ">=" | "<" | ">"
| "%" | "*" | "/" | "+" | "-"
| "as" | "instanceof"
| "->" ;
expr_postfix ::= expr_call | expr_get | expr_param ;
expr_param ::= %"#[" %w* arg_list %w* %"]" ;
expr_call ::= %"(" %w* arg_list %w* %")" ;
expr_get ::= %"[" %w* arg_list %w* %"]" ;
expr_arg ::= expr_prefix? %w* ( constant | expr_brackets | if | name ) %w* expr_postfix* ;
expr_brackets ::= %( "(" w* ) expr %( w* ")" ) ;

arg_list ::= ( expr %w* ","? %w* )* ;

if ::= %("if" w*) expr %w* expr %w* ( %"else" %w* expr )? ;

statement ::= expr %(w* ";" w*) ;
Loading