feat: execute source control flow and exact real arithmetic
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:endor:ast:sha256:c7c10c6a61158810fa55044f1aa79f3558ac18ca3be59cbf7f2499b5add8df5b",
|
||||
"$id": "urn:endor:ast:sha256:21b0349ac295d9bc8cedcad8f07d8e2d45cf220e19e7c2fad10269555fcfd71a",
|
||||
"$ref": "#/$defs/AstDocument",
|
||||
"$defs": {
|
||||
"Span": {
|
||||
@@ -27,7 +27,7 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"const": "urn:endor:ast:sha256:c7c10c6a61158810fa55044f1aa79f3558ac18ca3be59cbf7f2499b5add8df5b"
|
||||
"const": "urn:endor:ast:sha256:21b0349ac295d9bc8cedcad8f07d8e2d45cf220e19e7c2fad10269555fcfd71a"
|
||||
},
|
||||
"root": {
|
||||
"$ref": "#/$defs/AstRoot"
|
||||
@@ -354,6 +354,38 @@
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"kind": {
|
||||
"const": "If"
|
||||
},
|
||||
"data": {
|
||||
"$ref": "#/$defs/IfStatement"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"kind",
|
||||
"data"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"kind": {
|
||||
"const": "While"
|
||||
},
|
||||
"data": {
|
||||
"$ref": "#/$defs/WhileStatement"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"kind",
|
||||
"data"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -468,6 +500,56 @@
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"IfStatement": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"condition": {
|
||||
"$ref": "#/$defs/Expr"
|
||||
},
|
||||
"body": {
|
||||
"$ref": "#/$defs/Block"
|
||||
},
|
||||
"otherwise": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/$defs/Block"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"span": {
|
||||
"$ref": "#/$defs/Span"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"condition",
|
||||
"body",
|
||||
"span"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"WhileStatement": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"condition": {
|
||||
"$ref": "#/$defs/Expr"
|
||||
},
|
||||
"body": {
|
||||
"$ref": "#/$defs/Block"
|
||||
},
|
||||
"span": {
|
||||
"$ref": "#/$defs/Span"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"condition",
|
||||
"body",
|
||||
"span"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"ReturnStatement": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -742,7 +824,13 @@
|
||||
"Add",
|
||||
"Subtract",
|
||||
"Multiply",
|
||||
"Divide"
|
||||
"Divide",
|
||||
"Equal",
|
||||
"NotEqual",
|
||||
"Less",
|
||||
"LessEqual",
|
||||
"Greater",
|
||||
"GreaterEqual"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Generated by scripts/generate_ast.py from Endor.asdl. Do not edit.
|
||||
|
||||
export const AST_SCHEMA_ID = "urn:endor:ast:sha256:c7c10c6a61158810fa55044f1aa79f3558ac18ca3be59cbf7f2499b5add8df5b" as const;
|
||||
export const AST_SCHEMA_ID = "urn:endor:ast:sha256:21b0349ac295d9bc8cedcad8f07d8e2d45cf220e19e7c2fad10269555fcfd71a" as const;
|
||||
export interface Span { start: number; end: number; }
|
||||
export type AstDocument = { schema: typeof AST_SCHEMA_ID; root: AstRoot; };
|
||||
export type AstRoot = { kind: "Module"; data: Program; } | { kind: "Expression"; data: Expr; } | { kind: "Interactive"; data: InteractiveInput; };
|
||||
@@ -13,16 +13,18 @@ export type Function = { name: Name; parameters: Array<Parameter>; return_type:
|
||||
export type Parameter = { name: Name; type_name: Name; span: Span; };
|
||||
export type Block = { statements: Array<Stmt>; span: Span; };
|
||||
export type Stmt = { kind: StmtKind; span: Span; };
|
||||
export type StmtKind = { kind: "Binding"; data: Binding; } | { kind: "Assignment"; data: Assignment; } | { kind: "MemberAssignment"; data: MemberAssignment; } | { kind: "Return"; data: ReturnStatement; } | { kind: "Expression"; data: Expr; } | { kind: "Declaration"; data: Decl; };
|
||||
export type StmtKind = { kind: "Binding"; data: Binding; } | { kind: "Assignment"; data: Assignment; } | { kind: "MemberAssignment"; data: MemberAssignment; } | { kind: "If"; data: IfStatement; } | { kind: "While"; data: WhileStatement; } | { kind: "Return"; data: ReturnStatement; } | { kind: "Expression"; data: Expr; } | { kind: "Declaration"; data: Decl; };
|
||||
export type Binding = { name: Name; value: Expr; span: Span; };
|
||||
export type Assignment = { name: Name; value: Expr; span: Span; };
|
||||
export type MemberAssignment = { object: Expr; name: Name; value: Expr; span: Span; };
|
||||
export type IfStatement = { condition: Expr; body: Block; otherwise?: Block | null; span: Span; };
|
||||
export type WhileStatement = { condition: Expr; body: Block; span: Span; };
|
||||
export type ReturnStatement = { value?: Expr | null; span: Span; };
|
||||
export type InteractiveInput = { statements: Array<Stmt>; span: Span; };
|
||||
export type Expr = { kind: ExprKind; span: Span; };
|
||||
export type ExprKind = { kind: "Name"; data: string; } | { kind: "Number"; data: string; } | { kind: "String"; data: string; } | { kind: "Symbol"; data: Name; } | { kind: "Await"; data: Expr; } | { kind: "Unary"; data: { operation: UnaryOp; operand: Expr; }; } | { kind: "Binary"; data: { operation: BinaryOp; left: Expr; right: Expr; }; } | { kind: "Member"; data: { object: Expr; name: Name; }; } | { kind: "Call"; data: { callee: Expr; arguments: Array<Expr>; }; };
|
||||
export type UnaryOp = "Negate";
|
||||
export type BinaryOp = "Add" | "Subtract" | "Multiply" | "Divide";
|
||||
export type BinaryOp = "Add" | "Subtract" | "Multiply" | "Divide" | "Equal" | "NotEqual" | "Less" | "LessEqual" | "Greater" | "GreaterEqual";
|
||||
export interface Visitor {
|
||||
visitSpan?(node: Span): boolean | void;
|
||||
visitAstDocument?(node: AstDocument): boolean | void;
|
||||
@@ -40,6 +42,8 @@ visitStmtKind?(node: StmtKind): boolean | void;
|
||||
visitBinding?(node: Binding): boolean | void;
|
||||
visitAssignment?(node: Assignment): boolean | void;
|
||||
visitMemberAssignment?(node: MemberAssignment): boolean | void;
|
||||
visitIfStatement?(node: IfStatement): boolean | void;
|
||||
visitWhileStatement?(node: WhileStatement): boolean | void;
|
||||
visitReturnStatement?(node: ReturnStatement): boolean | void;
|
||||
visitInteractiveInput?(node: InteractiveInput): boolean | void;
|
||||
visitExpr?(node: Expr): boolean | void;
|
||||
@@ -135,6 +139,12 @@ break;
|
||||
case "MemberAssignment":
|
||||
walkMemberAssignment(node.data, visitor);
|
||||
break;
|
||||
case "If":
|
||||
walkIfStatement(node.data, visitor);
|
||||
break;
|
||||
case "While":
|
||||
walkWhileStatement(node.data, visitor);
|
||||
break;
|
||||
case "Return":
|
||||
walkReturnStatement(node.data, visitor);
|
||||
break;
|
||||
@@ -165,6 +175,19 @@ walkName(node.name, visitor);
|
||||
walkExpr(node.value, visitor);
|
||||
walkSpan(node.span, visitor);
|
||||
}
|
||||
export function walkIfStatement(node: IfStatement, visitor: Visitor): void {
|
||||
if (visitor.visitIfStatement?.(node) === false) return;
|
||||
walkExpr(node.condition, visitor);
|
||||
walkBlock(node.body, visitor);
|
||||
if (node.otherwise != null) walkBlock(node.otherwise, visitor);
|
||||
walkSpan(node.span, visitor);
|
||||
}
|
||||
export function walkWhileStatement(node: WhileStatement, visitor: Visitor): void {
|
||||
if (visitor.visitWhileStatement?.(node) === false) return;
|
||||
walkExpr(node.condition, visitor);
|
||||
walkBlock(node.body, visitor);
|
||||
walkSpan(node.span, visitor);
|
||||
}
|
||||
export function walkReturnStatement(node: ReturnStatement, visitor: Visitor): void {
|
||||
if (visitor.visitReturnStatement?.(node) === false) return;
|
||||
if (node.value != null) walkExpr(node.value, visitor);
|
||||
|
||||
Reference in New Issue
Block a user