From 50f43eb83300d1cc45d3bebb582c7917895b7300 Mon Sep 17 00:00:00 2001 From: StunxFS Date: Thu, 14 Nov 2024 12:01:15 -0400 Subject: [PATCH] again, use V --- .github/workflows/compiler_tests.yml | 10 +++--- Makefile | 5 --- fut-out/.gitkeep | 0 src/Prefs.fu | 24 ------------- src/Utils.fu | 18 ---------- src/main.v | 11 ++++++ src/ric.fu | 13 ------- src/token/token.v | 4 +++ src/util/util.v | 52 ++++++++++++++++++++++++++++ v.mod | 7 ++++ 10 files changed, 79 insertions(+), 65 deletions(-) delete mode 100644 Makefile delete mode 100644 fut-out/.gitkeep delete mode 100644 src/Prefs.fu delete mode 100644 src/Utils.fu create mode 100644 src/main.v delete mode 100644 src/ric.fu create mode 100644 src/token/token.v create mode 100644 src/util/util.v create mode 100644 v.mod diff --git a/.github/workflows/compiler_tests.yml b/.github/workflows/compiler_tests.yml index 93c6a9ab4..f6f4f02c4 100644 --- a/.github/workflows/compiler_tests.yml +++ b/.github/workflows/compiler_tests.yml @@ -15,8 +15,8 @@ jobs: - name: Build Rivet compiler run: | - wget https://github.com/fusionlanguage/fut/releases/download/fut-3.2.7/fut_3.2.7-1_amd64.deb - sudo dpkg -i fut_3.2.7-1_amd64.deb - sudo apt install libgtk-4-dev - make - ./rivetc -h + git clone https://github.com/vlang/v + cd v && make + sudo ./v symlink + cd .. + v . -o rivetc && ./rivetc diff --git a/Makefile b/Makefile deleted file mode 100644 index cdec7b5aa..000000000 --- a/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: - @echo "Generating C code from Fut code..." - @fut -o fut-out/rivetc.c src/*.fu - @echo "Compiling C code..." - @gcc -o rivetc fut-out/* -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 \ No newline at end of file diff --git a/fut-out/.gitkeep b/fut-out/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/Prefs.fu b/src/Prefs.fu deleted file mode 100644 index aa6524707..000000000 --- a/src/Prefs.fu +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -class Prefs { - public static Prefs# ParseArgs(List args) { - Prefs# prefs = new Prefs(); - foreach (string arg in args) { - switch (arg) { - case "-h": - case "--help": - Console.WriteLine(Utils.GetHelpText()); - break; - - default: - if (arg.StartsWith("-")) { - Utils.Error($"unknown option {arg}"); - } - break; - } - } - return prefs; - } -} \ No newline at end of file diff --git a/src/Utils.fu b/src/Utils.fu deleted file mode 100644 index a08f842fd..000000000 --- a/src/Utils.fu +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -static class Utils { - public static void Error(string msg) { - Console.WriteLine($"[rivetc error] {msg}"); - } - - public static string GetCompilerVersion() { - return "0.1.0"; - } - - public static string() GetHelpText() { - return $"rivetc - The Rivet programming language compiler v{GetCompilerVersion()}\n\n"+ - " rivetc [OPTIONS] INPUT"; - } -} \ No newline at end of file diff --git a/src/main.v b/src/main.v new file mode 100644 index 000000000..23a43dfe4 --- /dev/null +++ b/src/main.v @@ -0,0 +1,11 @@ +// 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 main + +import util + +fn main() { + util.ic_error("hello") +} diff --git a/src/ric.fu b/src/ric.fu deleted file mode 100644 index c16759ad5..000000000 --- a/src/ric.fu +++ /dev/null @@ -1,13 +0,0 @@ -// 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. - -public static class Main { - public static void Main(string[] args) { - List() args_; - foreach (string arg in args) { - args_.Add(arg); - } - Prefs# prefs = Prefs.ParseArgs(args_); - } -} diff --git a/src/token/token.v b/src/token/token.v new file mode 100644 index 000000000..223b9bb20 --- /dev/null +++ b/src/token/token.v @@ -0,0 +1,4 @@ +// 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. + diff --git a/src/util/util.v b/src/util/util.v new file mode 100644 index 000000000..285848cb6 --- /dev/null +++ b/src/util/util.v @@ -0,0 +1,52 @@ +// 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 term + +enum MsgLevel { + note + warn + error + ice +} + +@[inline] +fn format_msg(msg string, level MsgLevel) string { + return match level { + .note { + "${term.bold('rivetc: ')}${term.bold(term.cyan('error:'))} ${msg}" + } + .warn { + "${term.bold('rivetc: ')}${term.bold(term.yellow('error:'))} ${msg}" + } + .error { + "${term.bold('rivetc: ')}${term.bold(term.red('error:'))} ${msg}" + } + .ice { + "${term.bold('rivetc: ')}${term.bold(term.red('internal compiler error:'))} ${msg}" + } + } +} + +pub fn note(msg string) { + eprintln(format_msg(msg, .note)) +} + +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) { + eprintln(format_msg(msg, .ice)) + exit(102) +} diff --git a/v.mod b/v.mod new file mode 100644 index 000000000..5d10498b1 --- /dev/null +++ b/v.mod @@ -0,0 +1,7 @@ +Module { + name: 'rivetc' + description: 'The Rivet Programming Language' + version: '0.1.0' + license: 'MIT' + dependencies: [] +}