Skip to content

Commit

Permalink
Fibonnaci test (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby authored Sep 22, 2023
1 parent 6025d1d commit 552a0b1
Show file tree
Hide file tree
Showing 78 changed files with 3,690 additions and 538 deletions.
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

0 comments on commit 552a0b1

Please sign in to comment.