diff --git a/src/compiler/context/mod.v b/src/compiler/context/mod.v new file mode 100644 index 000000000..e16c33942 --- /dev/null +++ b/src/compiler/context/mod.v @@ -0,0 +1,10 @@ +// Copyright (C) 2024-present Jose Mendoza - All rights reserved. Use of this +// source code is governed by an MIT license that can be found in the LICENSE +// file. + +module context + +pub struct CContext { +pub mut: + options &Options +} diff --git a/src/compiler/prefs/mod.v b/src/compiler/context/options.v similarity index 79% rename from src/compiler/prefs/mod.v rename to src/compiler/context/options.v index 68af18be7..ae853abe7 100644 --- a/src/compiler/prefs/mod.v +++ b/src/compiler/context/options.v @@ -2,7 +2,7 @@ // source code is governed by an MIT license that can be found in the LICENSE // file. -module prefs +module context import os import flag @@ -11,7 +11,7 @@ import flag @[xdoc: 'The Rivet programming language compiler'] @[name: 'rivetc'] @[version: '0.1.0'] -pub struct Prefs { +pub struct Options { mut: input string @[ignore] @@ -19,11 +19,11 @@ mut: } @[inline] -pub fn parse_args(args []string) !&Prefs { - mut prefs, remaining := flag.to_struct[Prefs](args)! +pub fn parse_args(args []string) !&Options { + mut options, remaining := flag.to_struct[Options](args)! - if prefs.show_help { - eprintln(flag.to_doc[Prefs]()!) + if options.show_help { + eprintln(flag.to_doc[Options]()!) exit(0) } @@ -31,16 +31,16 @@ pub fn parse_args(args []string) !&Prefs { input := remaining[0] match true { os.is_file(input) { - prefs.input = input + options.input = input } os.is_dir(input) { mut main_ri := os.join_path(input, 'main.ri') if os.exists(main_ri) { - prefs.input = main_ri + options.input = main_ri } else { main_ri = os.join_path(input, 'src', 'main.ri') if os.exists(main_ri) { - prefs.input = main_ri + options.input = main_ri } else { return error('`${input}` is not a valid input, no file `${main_ri}` found') } @@ -56,5 +56,5 @@ pub fn parse_args(args []string) !&Prefs { return error('only one input is expected') } - return &prefs + return &options } diff --git a/src/compiler/mod.v b/src/compiler/mod.v index 2aedbd1af..9cfced680 100644 --- a/src/compiler/mod.v +++ b/src/compiler/mod.v @@ -4,16 +4,11 @@ module compiler -import compiler.prefs +import compiler.context import compiler.report -pub struct Compiler { -pub mut: - prefs &prefs.Prefs -} - pub fn run(args []string) { - mut c := Compiler{ - prefs: prefs.parse_args(args) or { report.error(err.msg()) } + mut c_ctx := &context.CContext{ + options: context.parse_args(args) or { report.error(err.msg()) } } } diff --git a/src/compiler/tokenizer/mod.v b/src/compiler/tokenizer/mod.v index 5b4f72091..cff2a2b14 100644 --- a/src/compiler/tokenizer/mod.v +++ b/src/compiler/tokenizer/mod.v @@ -4,7 +4,7 @@ module tokenizer -import compiler.prefs +import compiler.context import compiler.token import compiler.util @@ -19,8 +19,8 @@ fn is_new_line(ch u8) bool { @[minify] pub struct Tokenizer { - prefs &prefs.Prefs - text string + ctx &context.CContext + text string mut: file string line int = -1 @@ -34,10 +34,10 @@ mut: tidx int = -1 } -pub fn from_file(prefs_ &prefs.Prefs, path string) &Tokenizer { +pub fn from_file(options_ &options.Options, path string) &Tokenizer { mut t := &Tokenizer{ - prefs: unsafe { prefs_ } - text: util.read_file(path) + options: unsafe { options_ } + text: util.read_file(path) } t.file = path t.tokenize_remaining_text()