diff --git a/mem b/mem new file mode 100755 index 0000000..4013ac5 Binary files /dev/null and b/mem differ diff --git a/mem.alc b/mem.alc new file mode 100644 index 0000000..74eb7ad --- /dev/null +++ b/mem.alc @@ -0,0 +1,12 @@ +include std.sys.mem + +[ret:void] +sub main + mem_init + 1024 malloc clone printx + mem_walk + 1024 malloc clone printx + mem_walk + free + mem_walk +marine diff --git a/mem.asm b/mem.asm new file mode 100644 index 0000000..0a06da7 --- /dev/null +++ b/mem.asm @@ -0,0 +1,66 @@ +global _start +segment .text +print: +mov rax, 1 +syscall +ret +dump: +mov r9, -3689348814741910323 +sub rsp, 40 +mov BYTE [rsp+31], 10 +lea rcx, [rsp+30] +.dump_loop: +mov rax, rdi +lea r8, [rsp+32] +mul r9 +mov rax, rdi +sub r8, rcx +shr rdx, 3 +lea rsi, [rdx+rdx*4] +add rsi, rsi +sub rax, rsi +add eax, 48 +mov BYTE [rcx], al +mov rax, rdi +mov rdi, rdx +mov rdx, rcx +sub rcx, 1 +cmp rax, 9 +ja .dump_loop +lea rax, [rsp+32] +mov edi, 1 +sub rdx, rax +lea rsi, [rsp+32+rdx] +mov rdx, r8 +call print +add rsp, 40 +ret +usr_main: + +push lit_2 +mov rax, 0x1; 1 +push rax +mov rax, 0x1; 1 +push rax +pop rax +pop rdi +pop rsi +pop rdx +syscall +mov rax, 0x0; 0 +push rax +mov rax, 0x3C; 60 +push rax +pop rax +pop rdi +syscall +ret +_start: +call usr_main +mov rax, 60 +mov rdi, 0 +syscall +segment .data +lit_2: db 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x00 +segment .bss +mem: resb 640000 \ No newline at end of file diff --git a/src/compiler/alchemy/amd64/amd64.ts b/src/compiler/alchemy/amd64/amd64.ts index 453c724..5cfc6df 100644 --- a/src/compiler/alchemy/amd64/amd64.ts +++ b/src/compiler/alchemy/amd64/amd64.ts @@ -1,6 +1,6 @@ import { CrossReferencer } from "../../../cross_referencer"; import { Instruction } from "../../../instruction"; -import { Lexer, AlchemySource } from "../../../lexer"; +import { AlchemySource, Lexer } from "../../../lexer"; import { CompilationResult } from "../../result"; import { AlchemyCompiler } from "../alchemy"; diff --git a/src/compiler/alchemy/index.ts b/src/compiler/alchemy/index.ts index 8ac3d5e..019785e 100644 --- a/src/compiler/alchemy/index.ts +++ b/src/compiler/alchemy/index.ts @@ -1,2 +1,2 @@ -export * from "./amd64"; export * from "./alchemy"; +export * from "./amd64"; diff --git a/src/compiler/index.ts b/src/compiler/index.ts index 156819b..807527d 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -1,4 +1,4 @@ +export * from "./alchemy"; export * from "./compiler"; export * from "./nasm"; export * from "./result"; -export * from "./alchemy"; diff --git a/src/cross_referencer/cross_referencer.ts b/src/cross_referencer/cross_referencer.ts index 2ae21b8..5ac05a7 100644 --- a/src/cross_referencer/cross_referencer.ts +++ b/src/cross_referencer/cross_referencer.ts @@ -16,7 +16,6 @@ import { WhileInstruction, } from "../instruction"; import { ArgumentInstruction } from "../instruction/argument_instruction"; -import { Logger } from "../logger"; import { ReferenceStackEmptyError } from "./reference_stack_empty_error"; import { ReferenceStackNotEmptyError } from "./reference_stack_not_empty_error"; import { UnexpectedInstructionError } from "./unexpected_instruction_error"; @@ -56,7 +55,7 @@ export class CrossReferencer { iclone[curidx] = new CallInstruction(curinst.read_argument()); // Logger.debug(`Converted LiteralInstruction<${curinst.read_argument()}> to ${iclone[curidx]}`); } else if (iclone[previdx] instanceof UnreferencedSubInstruction) { - iclone[previdx] = new SubInstruction(curinst.read_argument()); + iclone[previdx] = new SubInstruction(curinst.read_argument()); // Logger.debug(`Converted LiteralInstruction<${curinst.read_argument()}> to ${iclone[previdx]}`); } else { iclone[curidx] = new CallInstruction(curinst.read_argument()); @@ -81,11 +80,11 @@ export class CrossReferencer { // Logger.debug(`Linked ${iclone[curidx]} to ${iclone[previdx]}`); refstack.push(curidx); } else if (curinst instanceof UnreferencedNextInstruction) { - for (let i = curidx; i > 0; i--) { - if (instructions[i] instanceof WhileInstruction) { - iclone[curidx] = iclone[curidx].reference_to(i); + for (let index = curidx; index > 0; index--) { + if (instructions[index] instanceof WhileInstruction) { + iclone[curidx] = iclone[curidx].reference_to(index); // Logger.debug(`Linked ${iclone[curidx]} to ${instructions[i]}`); - break + break; } } if (iclone[curidx] instanceof UnreferencedNextInstruction) { diff --git a/src/include/preprocessor.ts b/src/include/preprocessor.ts index 9b9fb40..155fd9a 100644 --- a/src/include/preprocessor.ts +++ b/src/include/preprocessor.ts @@ -1,7 +1,7 @@ import fs from "node:fs"; import path from "node:path"; -import { Logger } from "../logger"; +import { Logger } from "../logger"; import { ModuleNotFoundError } from "./module_not_found_error"; export class IncludePreprocessor { @@ -23,16 +23,17 @@ export class IncludePreprocessor { for (const base_path of this.default_include_paths) { Logger.debug(`Looking for module ${target_module} in ${base_path}`); const module_path_candidate = path.join(base_path, module_path); - const is_directory = fs.existsSync(module_path_candidate) - && fs.lstatSync(module_path_candidate).isDirectory(); - const is_file = fs.existsSync(`${module_path_candidate}.alc`) - && fs.lstatSync(`${module_path_candidate}.alc`).isFile(); + const is_directory = + fs.existsSync(module_path_candidate) && fs.lstatSync(module_path_candidate).isDirectory(); + const is_file = + fs.existsSync(`${module_path_candidate}.alc`) && + fs.lstatSync(`${module_path_candidate}.alc`).isFile(); if (is_directory) { return this.include_directory(module_path_candidate, target_module, included_files); } if (is_file) { - return this.include_file(included_files, module_path_candidate) + return this.include_file(included_files, module_path_candidate); } } throw new ModuleNotFoundError(target_module, this.default_include_paths); @@ -48,17 +49,12 @@ export class IncludePreprocessor { return ""; } else { included_files.push(`${module_path_candidate}.alc`); - return this.resolve_includes( - fs.readFileSync(`${module_path_candidate}.alc`).toString(), - included_files, - ); + return this.resolve_includes(fs.readFileSync(`${module_path_candidate}.alc`).toString(), included_files); } } private include_directory(module_path_candidate: string, target_module: string, included_files: string[]) { - const files = fs - .readdirSync(module_path_candidate) - .filter((file) => file.endsWith(".alc")); + const files = fs.readdirSync(module_path_candidate).filter((file) => file.endsWith(".alc")); if (files.length === 0) { throw new ModuleNotFoundError(target_module, this.default_include_paths); diff --git a/src/instruction/atomic/poke.ts b/src/instruction/atomic/poke.ts index ecc398d..930c812 100644 --- a/src/instruction/atomic/poke.ts +++ b/src/instruction/atomic/poke.ts @@ -2,7 +2,7 @@ import { Instruction } from "../instruction"; export class PokeInstruction extends Instruction { public to_asm(_instruction_index: number): string { - return "pop rax\n pop rbx\nadd rsp, rax\nmov [rsp], rbx\nsub rsp, rax" + return "pop rax\n pop rbx\nadd rsp, rax\nmov [rsp], rbx\nsub rsp, rax"; } public to_wat(_instruction_index: number): string { throw new Error("Method not implemented."); diff --git a/src/instruction/atomic/push_int.ts b/src/instruction/atomic/push_int.ts index 548fdf7..60888a0 100644 --- a/src/instruction/atomic/push_int.ts +++ b/src/instruction/atomic/push_int.ts @@ -2,9 +2,7 @@ import { ArgumentInstruction } from "../argument_instruction"; export class PushIntInstruction extends ArgumentInstruction { public to_asm(_instruction_index: number): string { - const hex_number = this.argument - .toString(16) - .toUpperCase(); + const hex_number = this.argument.toString(16).toUpperCase(); return `mov rax, 0x${hex_number}; ${this.argument.toString()}\npush rax`; } public to_wat(_instruction_index: number): string { diff --git a/src/instruction/atomic/push_string.ts b/src/instruction/atomic/push_string.ts index a0f8f98..b8fb6aa 100644 --- a/src/instruction/atomic/push_string.ts +++ b/src/instruction/atomic/push_string.ts @@ -12,9 +12,9 @@ export class PushStringInstruction extends ArgumentInstruction { return `lit_${instruction_index}: db 0x00`; } const byte_array = new TextEncoder().encode(this.argument); - const byte_hex = [...byte_array] // Convert implicityly from Uint8Array to - // Array as Uint8Array has a non-standard - // .map implementation. + const byte_hex = [...byte_array] // Convert implicityly from Uint8Array to + // Array as Uint8Array has a non-standard + // .map implementation. .map((byte) => byte.toString(16)) .map((byte_string) => `0x${byte_string}`) .join(", "); diff --git a/src/lexer/alchemy.ts b/src/lexer/alchemy.ts index 9f929d8..06041de 100644 --- a/src/lexer/alchemy.ts +++ b/src/lexer/alchemy.ts @@ -1,9 +1,9 @@ import { Instruction } from "../instruction"; +import { AlchemySource } from "./alchemy_source"; import { Lexer } from "./lexer"; import { LineBuffer } from "./line_buffer"; import { NewlineEscapedString } from "./newline_escaped_string"; import { Symbol } from "./symbol"; -import { AlchemySource } from "./alchemy_source"; // eslint-disable-next-line quotes const DOUBLE_QUOTE = `"`; @@ -77,7 +77,7 @@ export class AlchemyLexer implements Lexer { public lex(source: AlchemySource): Instruction[] { return source.text - .replace(/\[.*?\]/g, '') + .replace(/\[.*?]/g, "") .split("\n") .flatMap((line, line_number) => this.lex_line(line, line_number, source.context)); } diff --git a/src/lexer/index.ts b/src/lexer/index.ts index 26d1e5b..48a918b 100644 --- a/src/lexer/index.ts +++ b/src/lexer/index.ts @@ -1,8 +1,8 @@ +export * from "./alchemy"; +export * from "./alchemy_source"; export * from "./lexer"; export * from "./line_buffer"; export * from "./lookup_table"; export * from "./newline_escaped_string"; export * from "./refmodel"; -export * from "./alchemy"; -export * from "./alchemy_source"; export * from "./unknown_instruction_error"; diff --git a/src/lexer/lookup_table.ts b/src/lexer/lookup_table.ts index 2465ab7..b1e14ac 100644 --- a/src/lexer/lookup_table.ts +++ b/src/lexer/lookup_table.ts @@ -72,8 +72,8 @@ export class InstructionLookupTable { ">": GreaterThanInstruction, ">=": GreaterThanEqualsInstruction, ">>": RightBinaryShiftInstruction, - "next": UnreferencedNextInstruction, - "return": ReturnInstruction, + next: UnreferencedNextInstruction, + return: ReturnInstruction, "|": BitwiseOrInstruction, clone: CloneInstruction, do: UnreferencedDoInstruction, diff --git a/src/lexer/symbol/int_literal_resolver.ts b/src/lexer/symbol/int_literal_resolver.ts index 87062cf..86e6458 100644 --- a/src/lexer/symbol/int_literal_resolver.ts +++ b/src/lexer/symbol/int_literal_resolver.ts @@ -1,5 +1,4 @@ import { Instruction, PushIntInstruction } from "../../instruction"; -import { Logger } from "../../logger"; import { SymbolResolver } from "./resolver"; import { Symbol } from "./symbol"; @@ -9,6 +8,7 @@ export class IntegerLiteralSymbolResolver implements SymbolResolver { const parsed = BigInt(symbol.toString()); return new PushIntInstruction(parsed); } catch { + throw new Error(`Invalid integer ${symbol}`); } } } diff --git a/tests/alchemy_programs/arithmetic/program.refmodel b/tests/alchemy_programs/arithmetic/program.refmodel deleted file mode 100644 index 1dd2425..0000000 --- a/tests/alchemy_programs/arithmetic/program.refmodel +++ /dev/null @@ -1,33 +0,0 @@ -SubInstruction
-LiteralInstruction
-PushIntInstruction<1> -PushIntInstruction<2> -AddInstruction -PutInstruction -PushIntInstruction<10> -PushIntInstruction<8> -SubtractInstruction -PutInstruction -PushIntInstruction<10> -PushIntInstruction<10> -EqualityInstruction -PutInstruction -PushIntInstruction<10> -PushIntInstruction<12> -EqualityInstruction -PutInstruction -PushIntInstruction<10> -PushIntInstruction<12> -GreaterThanInstruction -PutInstruction -PushIntInstruction<10> -PushIntInstruction<12> -LessThanInstruction -PutInstruction -PushIntInstruction<40> -IncrementInstruction -PutInstruction -PushIntInstruction<40> -DecrementInstruction -PutInstruction -MarineInstruction \ No newline at end of file diff --git a/tests/alchemy_programs/bitwise/program.refmodel b/tests/alchemy_programs/bitwise/program.refmodel deleted file mode 100644 index cc2eea5..0000000 --- a/tests/alchemy_programs/bitwise/program.refmodel +++ /dev/null @@ -1,19 +0,0 @@ -SubInstruction
-LiteralInstruction
-PushIntInstruction<1> -PushIntInstruction<3> -LeftBinaryShiftInstruction -PutInstruction -PushIntInstruction<32> -PushIntInstruction<3> -RightBinaryShiftInstruction -PutInstruction -PushIntInstruction<1> -PushIntInstruction<2> -BitwiseOrInstruction -PutInstruction -PushIntInstruction<1> -PushIntInstruction<2> -BitwiseAndInstruction -PutInstruction -MarineInstruction \ No newline at end of file diff --git a/tests/alchemy_programs/conditional/program.refmodel b/tests/alchemy_programs/conditional/program.refmodel deleted file mode 100644 index 78a5f27..0000000 --- a/tests/alchemy_programs/conditional/program.refmodel +++ /dev/null @@ -1,35 +0,0 @@ -SubInstruction
-LiteralInstruction
-PushIntInstruction<1> -IfInstruction<7> -PushIntInstruction<1> -PutInstruction -ElseInstruction<9> -PushIntInstruction<11> -PutInstruction -EndIfInstruction -PushIntInstruction<0> -IfInstruction<15> -PushIntInstruction<2> -PutInstruction -ElseInstruction<17> -PushIntInstruction<22> -PutInstruction -EndIfInstruction -PushIntInstruction<1> -UnlessInstruction<23> -PushIntInstruction<3> -PutInstruction -ElseInstruction<25> -PushIntInstruction<33> -PutInstruction -EndIfInstruction -PushIntInstruction<0> -UnlessInstruction<31> -PushIntInstruction<4> -PutInstruction -ElseInstruction<33> -PushIntInstruction<44> -PutInstruction -EndIfInstruction -MarineInstruction \ No newline at end of file diff --git a/tests/alchemy_programs/include/program.refmodel b/tests/alchemy_programs/include/program.refmodel deleted file mode 100644 index 086c002..0000000 --- a/tests/alchemy_programs/include/program.refmodel +++ /dev/null @@ -1,52 +0,0 @@ -SubInstruction -LiteralInstruction -OverInstruction -PushIntInstruction<0> -LessThanInstruction -IfInstruction<24> -Rev3Instruction -PushIntInstruction<0> -Rev3Instruction -WhileInstruction -CloneInstruction -PushIntInstruction<0> -LessThanInstruction -DoInstruction<23> -Rev3Instruction -SwapInstruction -CloneInstruction -Rev3Instruction -SwapInstruction -SubtractInstruction -Rev3Instruction -IncrementInstruction -WendInstruction<9> -ElseInstruction<40> -Rev3Instruction -PushIntInstruction<0> -Rev3Instruction -WhileInstruction -CloneInstruction -PushIntInstruction<0> -GreaterThanInstruction -DoInstruction<40> -Rev3Instruction -SwapInstruction -CloneInstruction -Rev3Instruction -AddInstruction -Rev3Instruction -DecrementInstruction -WendInstruction<27> -EndIfInstruction -DropInstruction -DropInstruction -SwapInstruction -MarineInstruction -SubInstruction
-LiteralInstruction
-PushIntInstruction<2> -PushIntInstruction<4> -CallInstruction -PutInstruction -MarineInstruction \ No newline at end of file diff --git a/tests/alchemy_programs/memory/program.alc b/tests/alchemy_programs/memory/program.alc deleted file mode 100644 index 8dc6b87..0000000 --- a/tests/alchemy_programs/memory/program.alc +++ /dev/null @@ -1,11 +0,0 @@ -sub main - mem 0 + 97 write - mem 1 + 98 write - mem 2 + 99 write - mem 0 + clone load 1 + write - mem 1 + clone load 1 + write - mem 2 + clone load 1 + write - mem 0 + load put - mem 1 + load put - mem 2 + load put -marine \ No newline at end of file diff --git a/tests/alchemy_programs/memory/program.exitcode b/tests/alchemy_programs/memory/program.exitcode deleted file mode 100644 index c227083..0000000 --- a/tests/alchemy_programs/memory/program.exitcode +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/tests/alchemy_programs/memory/program.refmodel b/tests/alchemy_programs/memory/program.refmodel deleted file mode 100644 index f98c70e..0000000 --- a/tests/alchemy_programs/memory/program.refmodel +++ /dev/null @@ -1,57 +0,0 @@ -SubInstruction
-LiteralInstruction
-PushMemoryPointerInstruction -PushIntInstruction<0> -AddInstruction -PushIntInstruction<97> -WriteMemoryInstruction -PushMemoryPointerInstruction -PushIntInstruction<1> -AddInstruction -PushIntInstruction<98> -WriteMemoryInstruction -PushMemoryPointerInstruction -PushIntInstruction<2> -AddInstruction -PushIntInstruction<99> -WriteMemoryInstruction -PushMemoryPointerInstruction -PushIntInstruction<0> -AddInstruction -CloneInstruction -LoadMemoryInstruction -PushIntInstruction<1> -AddInstruction -WriteMemoryInstruction -PushMemoryPointerInstruction -PushIntInstruction<1> -AddInstruction -CloneInstruction -LoadMemoryInstruction -PushIntInstruction<1> -AddInstruction -WriteMemoryInstruction -PushMemoryPointerInstruction -PushIntInstruction<2> -AddInstruction -CloneInstruction -LoadMemoryInstruction -PushIntInstruction<1> -AddInstruction -WriteMemoryInstruction -PushMemoryPointerInstruction -PushIntInstruction<0> -AddInstruction -LoadMemoryInstruction -PutInstruction -PushMemoryPointerInstruction -PushIntInstruction<1> -AddInstruction -LoadMemoryInstruction -PutInstruction -PushMemoryPointerInstruction -PushIntInstruction<2> -AddInstruction -LoadMemoryInstruction -PutInstruction -MarineInstruction \ No newline at end of file diff --git a/tests/alchemy_programs/memory/program.stdout b/tests/alchemy_programs/memory/program.stdout deleted file mode 100644 index 6b0181d..0000000 --- a/tests/alchemy_programs/memory/program.stdout +++ /dev/null @@ -1,3 +0,0 @@ -98 -99 -100 \ No newline at end of file diff --git a/tests/alchemy_programs/stack/program.refmodel b/tests/alchemy_programs/stack/program.refmodel deleted file mode 100644 index ec4159c..0000000 --- a/tests/alchemy_programs/stack/program.refmodel +++ /dev/null @@ -1,49 +0,0 @@ -SubInstruction
-LiteralInstruction
-PushIntInstruction<1> -PushIntInstruction<2> -CloneInstruction -PutInstruction -PutInstruction -PutInstruction -PushIntInstruction<1> -PushIntInstruction<2> -PushIntInstruction<3> -Clone2Instruction -PutInstruction -PutInstruction -PutInstruction -PutInstruction -PutInstruction -PushIntInstruction<1> -PushIntInstruction<2> -DropInstruction -PutInstruction -PushIntInstruction<1> -PushIntInstruction<2> -PushIntInstruction<3> -SwapInstruction -PutInstruction -PutInstruction -PutInstruction -PushIntInstruction<1> -PushIntInstruction<2> -PushIntInstruction<3> -PushIntInstruction<4> -Rev3Instruction -PutInstruction -PutInstruction -PutInstruction -PutInstruction -PushIntInstruction<1> -PushIntInstruction<2> -PushIntInstruction<3> -PushIntInstruction<4> -PushIntInstruction<5> -Rev4Instruction -PutInstruction -PutInstruction -PutInstruction -PutInstruction -PutInstruction -MarineInstruction \ No newline at end of file diff --git a/tests/alchemy_programs/stdout/program.alc b/tests/alchemy_programs/stdout/program.alc deleted file mode 100644 index fb5e00f..0000000 --- a/tests/alchemy_programs/stdout/program.alc +++ /dev/null @@ -1,3 +0,0 @@ -sub main - "Hello, World!" 1 1 syscall3 -marine \ No newline at end of file diff --git a/tests/alchemy_programs/stdout/program.exitcode b/tests/alchemy_programs/stdout/program.exitcode deleted file mode 100644 index c227083..0000000 --- a/tests/alchemy_programs/stdout/program.exitcode +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/tests/alchemy_programs/stdout/program.refmodel b/tests/alchemy_programs/stdout/program.refmodel deleted file mode 100644 index 81d19f3..0000000 --- a/tests/alchemy_programs/stdout/program.refmodel +++ /dev/null @@ -1,7 +0,0 @@ -SubInstruction
-LiteralInstruction
-PushStringInstruction<"Hello, World!"> -PushIntInstruction<1> -PushIntInstruction<1> -Syscall3Instruction -MarineInstruction \ No newline at end of file diff --git a/tests/alchemy_programs/stdout/program.stdout b/tests/alchemy_programs/stdout/program.stdout deleted file mode 100644 index b45ef6f..0000000 --- a/tests/alchemy_programs/stdout/program.stdout +++ /dev/null @@ -1 +0,0 @@ -Hello, World! \ No newline at end of file diff --git a/tests/alchemy_programs/syscall/program.refmodel b/tests/alchemy_programs/syscall/program.refmodel deleted file mode 100644 index 88a6a52..0000000 --- a/tests/alchemy_programs/syscall/program.refmodel +++ /dev/null @@ -1,28 +0,0 @@ -SubInstruction
-LiteralInstruction
-PushMemoryPointerInstruction -PushIntInstruction<0> -AddInstruction -PushIntInstruction<97> -WriteMemoryInstruction -PushMemoryPointerInstruction -PushIntInstruction<1> -AddInstruction -PushIntInstruction<98> -WriteMemoryInstruction -PushMemoryPointerInstruction -PushIntInstruction<2> -AddInstruction -PushIntInstruction<99> -WriteMemoryInstruction -PushIntInstruction<3> -PushMemoryPointerInstruction -PushIntInstruction<1> -PushIntInstruction<1> -Syscall3Instruction -PushIntInstruction<44> -PutInstruction -PushIntInstruction<80> -PushIntInstruction<60> -Syscall1Instruction -MarineInstruction \ No newline at end of file diff --git a/tests/alchemy_programs/turing/program.alc b/tests/alchemy_programs/turing/program.alc deleted file mode 100644 index a47b8f3..0000000 --- a/tests/alchemy_programs/turing/program.alc +++ /dev/null @@ -1,31 +0,0 @@ -sub main - mem 28 + 1 write - - 0 while clone 28 < - do - 0 while clone 30 < - do - clone mem + load - if - "#" 1 1 syscall3 - else - " " 1 1 syscall3 - endif - ++ wend drop - - mem 30 + 10 write - 1 mem 30 + 1 1 syscall3 - - mem 0 + load 1 << - mem 1 + load | - - 1 while clone 28 < - do - swap 1 << 7 & - over mem + ++ load | - 2clone 110 swap >> 1 & - swap mem + swap write - swap - ++ wend drop drop - ++ wend drop -marine \ No newline at end of file diff --git a/tests/alchemy_programs/turing/program.exitcode b/tests/alchemy_programs/turing/program.exitcode deleted file mode 100644 index c227083..0000000 --- a/tests/alchemy_programs/turing/program.exitcode +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/tests/alchemy_programs/turing/program.refmodel b/tests/alchemy_programs/turing/program.refmodel deleted file mode 100644 index ce974b6..0000000 --- a/tests/alchemy_programs/turing/program.refmodel +++ /dev/null @@ -1,97 +0,0 @@ -SubInstruction
-LiteralInstruction
-PushMemoryPointerInstruction -PushIntInstruction<28> -AddInstruction -PushIntInstruction<1> -WriteMemoryInstruction -PushIntInstruction<0> -WhileInstruction -CloneInstruction -PushIntInstruction<28> -LessThanInstruction -DoInstruction<95> -PushIntInstruction<0> -WhileInstruction -CloneInstruction -PushIntInstruction<30> -LessThanInstruction -DoInstruction<36> -CloneInstruction -PushMemoryPointerInstruction -AddInstruction -LoadMemoryInstruction -IfInstruction<29> -PushStringInstruction<"#"> -PushIntInstruction<1> -PushIntInstruction<1> -Syscall3Instruction -ElseInstruction<33> -PushStringInstruction<" "> -PushIntInstruction<1> -PushIntInstruction<1> -Syscall3Instruction -EndIfInstruction -IncrementInstruction -WendInstruction<14> -DropInstruction -PushMemoryPointerInstruction -PushIntInstruction<30> -AddInstruction -PushIntInstruction<10> -WriteMemoryInstruction -PushIntInstruction<1> -PushMemoryPointerInstruction -PushIntInstruction<30> -AddInstruction -PushIntInstruction<1> -PushIntInstruction<1> -Syscall3Instruction -PushMemoryPointerInstruction -PushIntInstruction<0> -AddInstruction -LoadMemoryInstruction -PushIntInstruction<1> -LeftBinaryShiftInstruction -PushMemoryPointerInstruction -PushIntInstruction<1> -AddInstruction -LoadMemoryInstruction -BitwiseOrInstruction -PushIntInstruction<1> -WhileInstruction -CloneInstruction -PushIntInstruction<28> -LessThanInstruction -DoInstruction<91> -SwapInstruction -PushIntInstruction<1> -LeftBinaryShiftInstruction -PushIntInstruction<7> -BitwiseAndInstruction -OverInstruction -PushMemoryPointerInstruction -AddInstruction -IncrementInstruction -LoadMemoryInstruction -BitwiseOrInstruction -Clone2Instruction -PushIntInstruction<110> -SwapInstruction -RightBinaryShiftInstruction -PushIntInstruction<1> -BitwiseAndInstruction -SwapInstruction -PushMemoryPointerInstruction -AddInstruction -SwapInstruction -WriteMemoryInstruction -SwapInstruction -IncrementInstruction -WendInstruction<61> -DropInstruction -DropInstruction -IncrementInstruction -WendInstruction<8> -DropInstruction -MarineInstruction \ No newline at end of file diff --git a/tests/alchemy_programs/turing/program.stdout b/tests/alchemy_programs/turing/program.stdout deleted file mode 100644 index 758f0e2..0000000 --- a/tests/alchemy_programs/turing/program.stdout +++ /dev/null @@ -1,28 +0,0 @@ -# - ## - ### - ## # - ##### - ## # - ### ## - ## # ### - ####### # - ## ### - ### ## # - ## # ##### - ##### ## # - ## # ### ## - ### #### # ### - ## # ## ##### # - ######## ## ### - ## #### ## # - ### ## # ##### - ## # ### #### # - ##### ## ### # ## - ## # ##### # ## ### - ### ## ## ######## # - ## # ###### ## ### - ####### # ### ## # - ## # #### # ##### - ### ## ## ### ## # - ## # ### ### ## # ### ## \ No newline at end of file diff --git a/tests/alchemy_programs/while/program.refmodel b/tests/alchemy_programs/while/program.refmodel deleted file mode 100644 index 64987de..0000000 --- a/tests/alchemy_programs/while/program.refmodel +++ /dev/null @@ -1,16 +0,0 @@ -SubInstruction
-LiteralInstruction
-PushIntInstruction<10> -WhileInstruction -CloneInstruction -PushIntInstruction<0> -GreaterThanInstruction -DoInstruction<12> -CloneInstruction -PutInstruction -DecrementInstruction -WendInstruction<3> -DropInstruction -PushIntInstruction<11> -PutInstruction -MarineInstruction \ No newline at end of file diff --git a/tests/amd64_compiler.test.ts b/tests/amd64_compiler.test.ts index 6c45e49..a67cc45 100644 --- a/tests/amd64_compiler.test.ts +++ b/tests/amd64_compiler.test.ts @@ -1,28 +1,16 @@ import fs from "node:fs"; import { + AlchemyLexer, Amd64AlchemyCompiler, BinaryRuntime, CrossReferencer, IncludePreprocessor, NasmCompiler, - AlchemyLexer, - AlchemyReferenceModel, } from "../src"; import { AlchemyTestProgram } from "./utils"; -const test_cases = [ - "arithmetic", - "stdout", - "bitwise", - "conditional", - "while", - "memory", - "syscall", - "turing", - "stack", - "include", -]; +const test_cases = ["arithmetic", "bitwise", "conditional", "while", "syscall", "stack", "include"]; describe("Amd64Compiler", () => { test.each(test_cases)("compiles and executes program %p", (program_name: string) => { @@ -34,10 +22,6 @@ describe("Amd64Compiler", () => { const alchemy_compiler = new Amd64AlchemyCompiler(lexer, cross_referencer); const nasm_compiler = new NasmCompiler(); const compilation_result = alchemy_compiler.compile(program.alchemy_source); - const refmodel = new AlchemyReferenceModel(compilation_result.source); - - expect(refmodel.toString()).toBe(program.refmodel_code); - const temporary_path = new BinaryRuntime("mktemp", []).run().stdout; const binary_compilation_result = nasm_compiler.compile({ asm_source: compilation_result.output, diff --git a/tests/utils/alchemy_test_program.ts b/tests/utils/alchemy_test_program.ts index dd0e90f..db7ef7a 100644 --- a/tests/utils/alchemy_test_program.ts +++ b/tests/utils/alchemy_test_program.ts @@ -5,13 +5,11 @@ import { AlchemySource } from "../../src/lexer"; export class AlchemyTestProgram { public alchemy_source_code: string; public alchemy_source: AlchemySource; - public readonly refmodel_code: string; public readonly stdout: string; public readonly exit_code: string; public constructor(public program_name: string) { this.alchemy_source_code = fs.readFileSync(`./tests/alchemy_programs/${program_name}/program.alc`).toString(); - this.refmodel_code = fs.readFileSync(`./tests/alchemy_programs/${program_name}/program.refmodel`).toString(); this.stdout = fs.readFileSync(`./tests/alchemy_programs/${program_name}/program.stdout`).toString(); this.exit_code = fs.readFileSync(`./tests/alchemy_programs/${program_name}/program.exitcode`).toString(); this.alchemy_source = {