From 85efca8b8759f001c94a8f80ca9152c20fa8f471 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Wed, 3 Mar 2021 13:14:28 +0200 Subject: [PATCH] Compiler now reads source file --- source/tlang/compiler/compiler.d | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/tlang/compiler/compiler.d b/source/tlang/compiler/compiler.d index 9dead99..0f95359 100644 --- a/source/tlang/compiler/compiler.d +++ b/source/tlang/compiler/compiler.d @@ -3,6 +3,7 @@ module compiler.compiler; import gogga; import std.conv : to; import compiler.lexer; +import std.stdio : File; void beginCompilation(string[] sourceFiles) { @@ -12,10 +13,19 @@ void beginCompilation(string[] sourceFiles) Lexer[] lexers; foreach(string sourceFile; sourceFiles) { + gprintln("Reading source file '"~sourceFile~"' ..."); + File sourceFileFile; + sourceFileFile.open(sourceFile); /* TODO: Error handling with ANY file I/O */ + ulong fileSize = sourceFileFile.size(); + byte[] fileBytes; + fileBytes.length = fileSize; + fileBytes = sourceFileFile.rawRead(fileBytes); + sourceFileFile.close(); + gprintln("Performing tokenization on '"~sourceFile~"' ..."); /* TODO: Open source file */ - string sourceCode = "hello \"world\";"; + string sourceCode = cast(string)fileBytes; // string sourceCode = "hello \"world\"|| "; //string sourceCode = "hello \"world\"||"; /* TODO: Implement this one */ // string sourceCode = "hello;";