aqua-compiler
Advanced tools
Comparing version 0.0.20 to 0.0.24
import { ISymbol, ISymbolTable, SymbolType } from "./symbol-table"; | ||
export interface ASTNode { | ||
nodeType: string; | ||
type?: string; | ||
children?: ASTNode[]; | ||
value?: any; | ||
name?: string; | ||
@@ -17,2 +19,3 @@ symbol?: ISymbol; | ||
controlStatementId?: number; | ||
functionArgs?: ASTNode[]; | ||
} |
@@ -22,2 +22,3 @@ "use strict"; | ||
const _1 = require("."); | ||
const parser_1 = require("./parser"); | ||
const packageJson = require("../package.json"); | ||
@@ -60,3 +61,5 @@ const fs = require("fs/promises"); | ||
console.log(`== AST ==`); | ||
const ast = (0, _1.parse)(fileData); | ||
const ast = (0, parser_1.parse)(fileData, err => { | ||
console.error(`${err.line}:${err.column}: Error: ${err.msg}`); | ||
}); | ||
console.log(colorJson(ast)); | ||
@@ -63,0 +66,0 @@ } |
@@ -31,2 +31,12 @@ "use strict"; | ||
this.visitors = { | ||
"number": { | ||
post: (node) => { | ||
this.codeEmitter.add(`int ${node.value}`); | ||
}, | ||
}, | ||
"string-literal": { | ||
post: (node) => { | ||
this.codeEmitter.add(`byte \"${node.value}\"`); | ||
}, | ||
}, | ||
"operation": { | ||
@@ -150,2 +160,13 @@ post: (node) => { | ||
"function-call": { | ||
pre: (node) => { | ||
const builtin = this.builtins[node.name]; | ||
if (!builtin) { | ||
// | ||
// If not a builtin function generate code for arguments immediately. | ||
// | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
} | ||
}, | ||
post: (node) => { | ||
@@ -166,2 +187,5 @@ const builtin = this.builtins[node.name]; | ||
appGlobalPut: (node) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
this.codeEmitter.add(`app_global_put`); | ||
@@ -171,5 +195,11 @@ this.codeEmitter.add(`int 0`); // Need to balance the stack here even though this value should never be used. | ||
appGlobalGet: (node) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
this.codeEmitter.add(`app_global_get`); | ||
}, | ||
appGlobalDel: (node) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
this.codeEmitter.add(`app_global_del`); | ||
@@ -179,2 +209,5 @@ this.codeEmitter.add(`int 0`); // Need to balance the stack here even though this value should never be used. | ||
appLocalPut: (node) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
this.codeEmitter.add(`app_local_put`); | ||
@@ -184,5 +217,11 @@ this.codeEmitter.add(`int 0`); // Need to balance the stack here even though this value should never be used. | ||
appLocalGet: (node) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
this.codeEmitter.add(`app_local_get`); | ||
}, | ||
appLocalDel: (node) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
this.codeEmitter.add(`app_local_del`); | ||
@@ -192,8 +231,17 @@ this.codeEmitter.add(`int 0`); // Need to balance the stack here even though this value should never be used. | ||
btoi: (node) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
this.codeEmitter.add(`btoi`); | ||
}, | ||
itob: (node) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
this.codeEmitter.add(`btoi`); | ||
}, | ||
exit: (node) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalGenerateCode(arg); | ||
} | ||
this.codeEmitter.add(`return`); | ||
@@ -200,0 +248,0 @@ }, |
@@ -1,2 +0,1 @@ | ||
export declare function parse(input: string): any; | ||
export interface ICompilerOptions { | ||
@@ -3,0 +2,0 @@ disableVersionStamp?: boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.compileExpression = exports.compile = exports.parse = void 0; | ||
exports.compileExpression = exports.compile = void 0; | ||
const code_emitter_1 = require("./code-emitter"); | ||
const code_generator_1 = require("./code-generator"); | ||
const symbol_resolution_1 = require("./symbol-resolution"); | ||
const parser_1 = require("./parser"); | ||
const packageJson = require("../package.json"); | ||
const parser = require("./parser"); | ||
// | ||
// Parses Aqua code to an AST. | ||
// | ||
function parse(input) { | ||
return parser.parse(input); | ||
} | ||
exports.parse = parse; | ||
// | ||
// Compiles an Aqua script to TEAL. | ||
// | ||
function compile(input, options) { | ||
const ast = parse(input); | ||
let errors = 0; | ||
const ast = (0, parser_1.parse)(input, err => { | ||
console.error(`${err.line}:${err.column}: Error: ${err.msg}`); | ||
errors += 1; | ||
}); | ||
if (errors > 0) { | ||
throw new Error(`Found ${errors} errors.`); | ||
} | ||
const symbolResolution = new symbol_resolution_1.SymbolResolution(); | ||
@@ -39,3 +39,10 @@ symbolResolution.resolveSymbols(ast); | ||
function compileExpression(input) { | ||
const ast = parser.parse(input, { startRule: "expression" }); | ||
let errors = 0; | ||
const ast = (0, parser_1.parseExpression)(input, err => { | ||
console.error(`${err.line}:${err.column}: Error: ${err.msg}`); | ||
errors += 1; | ||
}); | ||
if (errors > 0) { | ||
throw new Error(`Found ${errors} errors.`); | ||
} | ||
const symbolResolution = new symbol_resolution_1.SymbolResolution(); | ||
@@ -42,0 +49,0 @@ symbolResolution.resolveSymbols(ast); |
@@ -1,17 +0,47 @@ | ||
declare function peg$SyntaxError(message: any, expected: any, found: any, location: any): void; | ||
declare class peg$SyntaxError { | ||
constructor(message: any, expected: any, found: any, location: any); | ||
message: any; | ||
expected: any; | ||
found: any; | ||
location: any; | ||
name: string; | ||
import { ASTNode } from "./ast"; | ||
import { OnErrorFn } from "./tokenizer"; | ||
export interface IParser { | ||
program(): ASTNode; | ||
} | ||
declare namespace peg$SyntaxError { | ||
function buildMessage(expected: any, found: any): string; | ||
export declare class Parser implements IParser { | ||
private tokenizer; | ||
private onError; | ||
constructor(code: string, onError: OnErrorFn); | ||
program(): ASTNode; | ||
private declarations; | ||
private declaration; | ||
private function; | ||
private parameters; | ||
private statements; | ||
private syncNextStatement; | ||
private statement; | ||
private variableDeclaration; | ||
private blockStatement; | ||
private returnStatement; | ||
private ifStatement; | ||
private whileStatement; | ||
private forStatement; | ||
private exprStatement; | ||
expression(): ASTNode; | ||
private assignment; | ||
private logical; | ||
private equality; | ||
private comparison; | ||
private term; | ||
private factor; | ||
private unary; | ||
private primary; | ||
private txn; | ||
private gtxn; | ||
private arg; | ||
private addr; | ||
private dot; | ||
private functionCall; | ||
private arguments; | ||
private peek; | ||
private match; | ||
private expect; | ||
private isAtEnd; | ||
} | ||
declare function peg$parse(input: any, options: any): { | ||
nodeType: any; | ||
children: any; | ||
} | {}[]; | ||
export { peg$SyntaxError as SyntaxError, peg$parse as parse }; | ||
export declare function parseExpression(code: string, onError: OnErrorFn): ASTNode; | ||
export declare function parse(code: string, onError: OnErrorFn): ASTNode; |
@@ -63,2 +63,7 @@ "use strict"; | ||
}, | ||
"function-call": (node, symbolTable) => { | ||
for (const arg of node.functionArgs || []) { | ||
this.internalResolveSymbols(arg, symbolTable); | ||
} | ||
}, | ||
}; | ||
@@ -65,0 +70,0 @@ } |
@@ -6,13 +6,12 @@ { | ||
"scripts": { | ||
"build-parser": "pegjs -o src/parser.js --allowed-start-rules start,expression src/grammar.pegjs", | ||
"start": "npm run build-parser && ts-node ./src/cli.ts exec examples/test.aqua", | ||
"start:file": "npm run build-parser && ts-node ./src/cli.ts examples/test.aqua > examples/test.teal", | ||
"start1": "npm run build-parser && ts-node ./src/cli.ts exec examples/function.aqua", | ||
"start2": "npm run build-parser && ts-node ./src/cli.ts exec examples/function-with-args.aqua", | ||
"start:counter": "npm run build-parser && ts-node ./src/cli.ts examples/counter.aqua", | ||
"start:template": "npm run build-parser && ts-node ./src/cli.ts examples/template.aqua", | ||
"start:repl": "npm run build-parser && ts-node ./src/cli.ts", | ||
"start:ast": "npm run build-parser && ts-node ./src/cli.ts ast examples/test.aqua", | ||
"start": "ts-node ./src/cli.ts exec examples/test.aqua", | ||
"start:file": "ts-node ./src/cli.ts examples/test.aqua > examples/test.teal", | ||
"start1": "ts-node ./src/cli.ts exec examples/function.aqua", | ||
"start2": "ts-node ./src/cli.ts exec examples/function-with-args.aqua", | ||
"start:counter": "ts-node ./src/cli.ts examples/counter.aqua", | ||
"start:template": "ts-node ./src/cli.ts examples/template.aqua", | ||
"start:repl": "ts-node ./src/cli.ts", | ||
"start:ast": "ts-node ./src/cli.ts ast examples/test.aqua", | ||
"s": "npm run start", | ||
"start:dev": "npm run build-parser && nodemon", | ||
"start:dev": "nodemon", | ||
"sd": "npm run start:dev", | ||
@@ -27,5 +26,5 @@ "c": "npm run clean", | ||
"t": "npm run test", | ||
"test": "npm run build-parser && jest --runInBand", | ||
"test": "jest --runInBand", | ||
"tw": "npm run test:watch", | ||
"test:watch": "npm run build-parser && jest --watch --runInBand", | ||
"test:watch": "jest --watch --runInBand", | ||
"build-win": "nexe build/cli.js -t windows-x64-14.15.3 -n aqua", | ||
@@ -73,3 +72,3 @@ "build-mac": "nexe build/cli.js -t mac-x64-14.15.3 -n aqua-mac", | ||
}, | ||
"version": "0.0.20" | ||
"version": "0.0.24" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38
179959
3196
1