@@ -151,7 +151,13 @@ fn main() -> Result<()> {
151151}
152152
153153fn run_program ( file : & PathBuf ) -> Result < ( ) > {
154- let source = fs:: read_to_string ( file) . expect ( "Failed to read file" ) ;
154+ let source = {
155+ use std:: io:: Read ;
156+ let mut file_handle = std:: fs:: File :: open ( file) . expect ( "Failed to open file" ) ;
157+ let mut buf = String :: new ( ) ;
158+ file_handle. take ( 10 * 1024 * 1024 ) . read_to_string ( & mut buf) . expect ( "Failed to read file" ) ;
159+ buf
160+ } ;
155161 let lexer = Lexer :: new ( & source) ;
156162
157163 let tokens = match lexer. tokenize ( ) {
@@ -189,7 +195,13 @@ fn run_program(file: &PathBuf) -> Result<()> {
189195}
190196
191197fn compile_program ( file : & PathBuf , _output : Option < PathBuf > ) -> Result < ( ) > {
192- let source = fs:: read_to_string ( file) . expect ( "Failed to read file" ) ;
198+ let source = {
199+ use std:: io:: Read ;
200+ let mut file_handle = std:: fs:: File :: open ( file) . expect ( "Failed to open file" ) ;
201+ let mut buf = String :: new ( ) ;
202+ file_handle. take ( 10 * 1024 * 1024 ) . read_to_string ( & mut buf) . expect ( "Failed to read file" ) ;
203+ buf
204+ } ;
193205 let lexer = Lexer :: new ( & source) ;
194206
195207 let tokens = match lexer. tokenize ( ) {
@@ -245,7 +257,13 @@ fn compile_program(file: &PathBuf, _output: Option<PathBuf>) -> Result<()> {
245257}
246258
247259fn run_vm ( file : & PathBuf ) -> Result < ( ) > {
248- let source = fs:: read_to_string ( file) . expect ( "Failed to read file" ) ;
260+ let source = {
261+ use std:: io:: Read ;
262+ let mut file_handle = std:: fs:: File :: open ( file) . expect ( "Failed to open file" ) ;
263+ let mut buf = String :: new ( ) ;
264+ file_handle. take ( 10 * 1024 * 1024 ) . read_to_string ( & mut buf) . expect ( "Failed to read file" ) ;
265+ buf
266+ } ;
249267
250268 // Use the vm::run_vm helper which compiles and runs
251269 match wokelang:: vm:: run_vm ( & source) {
@@ -261,7 +279,13 @@ fn run_vm(file: &PathBuf) -> Result<()> {
261279}
262280
263281fn disassemble ( file : & PathBuf ) -> Result < ( ) > {
264- let source = fs:: read_to_string ( file) . expect ( "Failed to read file" ) ;
282+ let source = {
283+ use std:: io:: Read ;
284+ let mut file_handle = std:: fs:: File :: open ( file) . expect ( "Failed to open file" ) ;
285+ let mut buf = String :: new ( ) ;
286+ file_handle. take ( 10 * 1024 * 1024 ) . read_to_string ( & mut buf) . expect ( "Failed to read file" ) ;
287+ buf
288+ } ;
265289
266290 // Compile to bytecode
267291 let compiled = match wokelang:: vm:: compile ( & source) {
@@ -280,7 +304,13 @@ fn disassemble(file: &PathBuf) -> Result<()> {
280304}
281305
282306fn typecheck_program ( file : & PathBuf ) -> Result < ( ) > {
283- let source = fs:: read_to_string ( file) . expect ( "Failed to read file" ) ;
307+ let source = {
308+ use std:: io:: Read ;
309+ let mut file_handle = std:: fs:: File :: open ( file) . expect ( "Failed to open file" ) ;
310+ let mut buf = String :: new ( ) ;
311+ file_handle. take ( 10 * 1024 * 1024 ) . read_to_string ( & mut buf) . expect ( "Failed to read file" ) ;
312+ buf
313+ } ;
284314 let lexer = Lexer :: new ( & source) ;
285315
286316 let tokens = match lexer. tokenize ( ) {
@@ -314,7 +344,13 @@ fn typecheck_program(file: &PathBuf) -> Result<()> {
314344}
315345
316346fn lint_program ( file : & PathBuf ) -> Result < ( ) > {
317- let source = fs:: read_to_string ( file) . expect ( "Failed to read file" ) ;
347+ let source = {
348+ use std:: io:: Read ;
349+ let mut file_handle = std:: fs:: File :: open ( file) . expect ( "Failed to open file" ) ;
350+ let mut buf = String :: new ( ) ;
351+ file_handle. take ( 10 * 1024 * 1024 ) . read_to_string ( & mut buf) . expect ( "Failed to read file" ) ;
352+ buf
353+ } ;
318354 let lexer = Lexer :: new ( & source) ;
319355
320356 let tokens = match lexer. tokenize ( ) {
@@ -355,7 +391,13 @@ fn lint_program(file: &PathBuf) -> Result<()> {
355391}
356392
357393fn tokenize_file ( file : & PathBuf ) -> Result < ( ) > {
358- let source = fs:: read_to_string ( file) . expect ( "Failed to read file" ) ;
394+ let source = {
395+ use std:: io:: Read ;
396+ let mut file_handle = std:: fs:: File :: open ( file) . expect ( "Failed to open file" ) ;
397+ let mut buf = String :: new ( ) ;
398+ file_handle. take ( 10 * 1024 * 1024 ) . read_to_string ( & mut buf) . expect ( "Failed to read file" ) ;
399+ buf
400+ } ;
359401 let lexer = Lexer :: new ( & source) ;
360402
361403 let tokens = match lexer. tokenize ( ) {
@@ -381,7 +423,13 @@ fn tokenize_file(file: &PathBuf) -> Result<()> {
381423/// - `sexpr` / `sexp`: S-expression representation
382424/// - `json`: JSON serialization via serde_json
383425fn parse_file ( file : & PathBuf , format : & str ) -> Result < ( ) > {
384- let source = fs:: read_to_string ( file) . expect ( "Failed to read file" ) ;
426+ let source = {
427+ use std:: io:: Read ;
428+ let mut file_handle = std:: fs:: File :: open ( file) . expect ( "Failed to open file" ) ;
429+ let mut buf = String :: new ( ) ;
430+ file_handle. take ( 10 * 1024 * 1024 ) . read_to_string ( & mut buf) . expect ( "Failed to read file" ) ;
431+ buf
432+ } ;
385433 let lexer = Lexer :: new ( & source) ;
386434
387435 let tokens = match lexer. tokenize ( ) {
0 commit comments