-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
113 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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 compiler | ||
|
||
import compiler.prefs | ||
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()) } | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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 report | ||
|
||
import term | ||
|
||
enum MsgLevel { | ||
note | ||
warn | ||
error | ||
ice | ||
} | ||
|
||
@[inline] | ||
fn format_msg(msg string, level MsgLevel) string { | ||
return term.bold('rivetc: ') + match level { | ||
.note { | ||
'${term.bold(term.cyan('error:'))}' | ||
} | ||
.warn { | ||
'${term.bold(term.yellow('error:'))}' | ||
} | ||
.error { | ||
'${term.bold(term.red('error:'))}' | ||
} | ||
.ice { | ||
'${term.bold(term.red('internal compiler error:'))}' | ||
} | ||
} + ' ${msg}' | ||
} | ||
|
||
@[inline] | ||
pub fn note(msg string) { | ||
eprintln(format_msg(msg, .note)) | ||
} | ||
|
||
@[inline] | ||
pub fn warn(msg string) { | ||
eprintln(format_msg(msg, .warn)) | ||
} | ||
|
||
@[noreturn] | ||
pub fn error(msg string) { | ||
eprintln(format_msg(msg, .error)) | ||
exit(101) | ||
} | ||
|
||
@[noreturn] | ||
pub fn ic_error(msg string) { | ||
panic(format_msg(msg, .ice)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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 util | ||
|
||
import os | ||
import compiler.report | ||
|
||
pub fn read_file(path string) string { | ||
return skip_bom(os.read_file(path) or { | ||
// we use `ic_error` because this should not happen | ||
report.ic_error(err.msg()) | ||
}) | ||
} | ||
|
||
pub fn skip_bom(file_content string) string { | ||
mut raw_text := file_content | ||
// BOM check | ||
if raw_text.len >= 3 { | ||
unsafe { | ||
c_text := raw_text.str | ||
if c_text[0] == 0xEF && c_text[1] == 0xBB && c_text[2] == 0xBF { | ||
// skip three BOM bytes | ||
offset_from_begin := 3 | ||
raw_text = tos(c_text[offset_from_begin], vstrlen(c_text) - offset_from_begin) | ||
} | ||
} | ||
} | ||
return raw_text | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.