Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jule: update use declarations #115

Merged
merged 34 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6bb53ca
jule: initial update for new use declarations
mertcandav Sep 29, 2024
e362abe
compiler: refactor use declarations of the package
mertcandav Sep 29, 2024
f7b91e8
compiler: push implicit import for runtime
mertcandav Sep 29, 2024
fe38e19
sema: fix built-in define handling for packages
mertcandav Sep 29, 2024
fab2965
sema: fix alias checking for unsafe package
mertcandav Sep 29, 2024
9c496da
sema: fix comptime package lookup
mertcandav Sep 29, 2024
7b02365
compiler: minor refactoring for use declarations
mertcandav Sep 30, 2024
bd33399
std::fs: minor refactoring for use declarations
mertcandav Sep 30, 2024
76561f4
sema: remove lookup for imports from ordinary package lookup
mertcandav Sep 30, 2024
c2d7d82
compiler, std: update use declarations to new style
mertcandav Sep 30, 2024
3f7b895
sema: update cross cycle message by new use declaration style
mertcandav Sep 30, 2024
344e3b5
compiler, std: refactor panic calls
mertcandav Sep 30, 2024
a6839a2
sema: add safety analysis for new use declarations
mertcandav Sep 30, 2024
accfa24
compiler, std: refactor with julefmt
mertcandav Sep 30, 2024
4a2c5e3
tests: refactor and use new use declarations
mertcandav Sep 30, 2024
14c97aa
sema: minor refactoring
mertcandav Sep 30, 2024
89095e2
std/csv: refactoring
mertcandav Sep 30, 2024
e234d54
std/env: refactoring
mertcandav Sep 30, 2024
04c6913
std/fs: refactoring
mertcandav Sep 30, 2024
f331317
std/hash/fnv: refactoring
mertcandav Sep 30, 2024
5b4d18a
std/hash/adler32: refactoring
mertcandav Sep 30, 2024
87873f7
std/strings: refactoring
mertcandav Sep 30, 2024
06dbda6
std/jule/importer: refactoring
mertcandav Sep 30, 2024
d8c3c91
std/jule/types: refactoring
mertcandav Sep 30, 2024
94afcde
std/jule/sema: refactoring
mertcandav Sep 30, 2024
a41b969
std/sync/atomic: refactoring
mertcandav Sep 30, 2024
f1216a2
std/jule/lex: reimplement as std/jule/token
mertcandav Sep 30, 2024
8f5578e
doc: fix broken link
mertcandav Sep 30, 2024
c0ade5c
sema: fix package accessibility analysis
mertcandav Sep 30, 2024
1d5dca4
compiler, std: refactor with julefmt
mertcandav Sep 30, 2024
7124d3b
std: minor refactoring
mertcandav Sep 30, 2024
0b768c7
std: minor refactoring
mertcandav Sep 30, 2024
d882e79
sema: fix built-in define lookup for packages
mertcandav Sep 30, 2024
6a41ebe
Update README.md
mertcandav Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ It contains the reference compiler, API, and standard library.
- Easy low-level programming
- High [interoperability](https://manual.jule.dev/integrated-jule/interoperability/) with C, C++, Objective-C and Objective-C++
- Disable variable shadowing by default, immutability by default, boundary checking, no uninitialized memory
- The [API](https://manual.jule.dev/api/) written in C++ and allows extend Jule thanks to interoperability
- The [API](https://manual.jule.dev/api/) written in Jule and C++ and allows extend Jule with C++ thanks to interoperability

![image](https://github.com/julelang/jule/assets/54983926/e8b28748-9212-4db8-9f7b-0b0d33dc878b)
![image](https://github.com/user-attachments/assets/0a6aee7c-6f0c-4ec1-96f8-d02b7fdc034c)

> [!IMPORTANT]
> Jule does not have a stable version yet and is still being developed to become more stable.
Expand Down
2 changes: 1 addition & 1 deletion api/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

// Declarations of the exported defines of the [std::runtime] package.
// Declarations of the exported defines of the "std/runtime" package.
// Implemented by compiler via generation object code for the package.

#ifndef __JULE_RUNTIME_HPP
Expand Down
4 changes: 2 additions & 2 deletions src/julec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ That's why paths are adjusted accordingly.

# Introduction to JuleC

> Some important parts of the reference compiler are publicly available in the standard library. See [`std::jule`](https://github.com/julelang/jule/tree/master/std/jule) library.
> Some important parts of the reference compiler are publicly available in the standard library. See [`std/jule`](https://github.com/julelang/jule/tree/master/std/jule) library.

<img width="1617" alt="JuleC" src="https://github.com/julelang/jule/assets/54983926/648b9942-8662-4ba0-9ff8-bf66c32e0ba6">

Expand Down Expand Up @@ -40,7 +40,7 @@ This stage is the stage where the compiler generates object code.

### 1. Lexer

The package [``./lex``](https://github.com/julelang/jule/tree/master/std/jule/lex) is Lexer. \
The package [``./token``](https://github.com/julelang/jule/tree/master/std/jule/token) is Lexer. \
Makes lexical analysis and segments Jule source code into tokens.

### 2. Parser
Expand Down
147 changes: 67 additions & 80 deletions src/julec/compile.jule
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,20 @@
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

use env
use opt::{self, OptLevel, Optimizer}
use handle::{AnsiEscape, Logger, Throw}
use obj::{IR}
use cxx for obj::cxx
use std::flag::{FlagSet}
use std::fs::{FsError, OFlag, File, Directory, Status}
use path for std::fs::path
use integrated for std::jule::integrated
use std::jule::sema::{
ImportInfo,
Package,
SemaFlag,
}
use build for std::jule::build::{
self,
LogMsg,
Log,
PathStdlib,
EntryPoint,
InitFn,
Logf,
IsValidCppExt,
}
use types for std::jule::types
use std::process::{ProcessError, Cmd}
use strings for std::strings::{StrBuilder}
use "env"
use "handle"
use "obj"
use "obj/cxx"
use "opt"
use "std/flag"
use "std/fs"
use "std/fs/path"
use "std/jule/build"
use integ "std/jule/integrated"
use "std/jule/sema"
use "std/jule/types"
use "std/process"
use "std/strings"

static mut OutDir = "dist"
static mut OutName = "ir.cpp"
Expand All @@ -40,57 +27,57 @@ fn init() {
env::Compiler = "clang"
}

fn openOutput(&path: str): &File {
fn openOutput(&path: str): &fs::File {
dir := path::Dir(path)

Status.Of(dir) else {
Directory.Create(dir) else {
Throw("a problem occurs when code generation")
fs::Status.Of(dir) else {
fs::Directory.Create(dir) else {
handle::Throw("a problem occurs when code generation")
}
}

ret File.Create(path) else {
Throw("a problem occurs when code generation")
ret fs::File.Create(path) else {
handle::Throw("a problem occurs when code generation")
use nil
}
}

// Remove generated objects for compilation.
fn clearObjects() {
File.Remove(getCompilePath()) else {
fs::File.Remove(getCompilePath()) else {
outln("a problem occurs when object cleaning")
ret
}

// All created objects are cleaned.
// So, deletes directory if empty after cleaned all objects,
// if not, leaves the directory.
Directory.Remove(OutDir) else {}
fs::Directory.Remove(OutDir) else {}
}

// Compie generated IR.
fn compileIr(compiler: str, compilerCmd: str) {
mut cmd := Cmd.New(compiler)
mut cmd := process::Cmd.New(compiler)
cmd.Args = strings::Split(compilerCmd, " ", -1)
cmd.Spawn() else {
match error {
| ProcessError.NotExist:
AnsiEscape.Print(AnsiEscape.RedSeq, "back-end compiler could not used because of compiler path is not exist")
| ProcessError.Denied:
AnsiEscape.Print(AnsiEscape.RedSeq, "back-end compiler could not used because of permission denied")
| process::ProcessError.NotExist:
handle::AnsiEscape.Print(handle::AnsiEscape.RedSeq, "back-end compiler could not used because of compiler path is not exist")
| process::ProcessError.Denied:
handle::AnsiEscape.Print(handle::AnsiEscape.RedSeq, "back-end compiler could not used because of permission denied")
|:
AnsiEscape.Print(AnsiEscape.RedSeq, "back-end compiler could not used because of unknown problem")
handle::AnsiEscape.Print(handle::AnsiEscape.RedSeq, "back-end compiler could not used because of unknown problem")
}
Throw("")
handle::Throw("")
}
status := cmd.Wait()!
if status != 0 {
errorMessage := "\n>>> your backend compiler (" + env::Compiler + `) reports problems
>>> please check errors above
>>> is this a compiler problem, please report us: https://github.com/julelang/jule/issues/new/choose`

AnsiEscape.Print(AnsiEscape.RedSeq, errorMessage)
Throw("")
handle::AnsiEscape.Print(handle::AnsiEscape.RedSeq, errorMessage)
handle::Throw("")
}

clearObjects()
Expand All @@ -101,10 +88,10 @@ fn isCppSourceFile(path: str): bool {
if offset == -1 {
ret false
}
ret IsValidCppExt(path[offset:])
ret build::IsValidCppExt(path[offset:])
}

fn pushCompCmdClang(mut &cmd: StrBuilder) {
fn pushCompCmdClang(mut &cmd: strings::Builder) {
// Disable all warnings.
cmd.WriteStr("-Wno-everything ")

Expand All @@ -130,7 +117,7 @@ fn pushCompCmdClang(mut &cmd: StrBuilder) {
}
}

fn pushCompCmdGcc(mut &cmd: StrBuilder) {
fn pushCompCmdGcc(mut &cmd: strings::Builder) {
// Disable all warnings.
cmd.WriteStr("-w ")

Expand All @@ -156,9 +143,9 @@ fn pushCompCmdGcc(mut &cmd: StrBuilder) {
}

// Generate compile command for backend-compiler.
fn genCompileCmd(sourcePath: str, &ir: &IR): (str, str) {
fn genCompileCmd(sourcePath: str, &ir: &obj::IR): (str, str) {
&compiler := env::CompilerPath
mut cmd := StrBuilder.New(1 << 6)
mut cmd := strings::Builder.New(1 << 6)

match env::Compiler {
| "gcc":
Expand Down Expand Up @@ -202,15 +189,15 @@ fn getCompilePath(): str {
ret path::Join(OutDir, OutName)
}

fn applyTargetIndependentOptimizations(mut &ir: &IR) {
mut opt := Optimizer.New(ir)
fn applyTargetIndependentOptimizations(mut &ir: &obj::IR) {
mut opt := opt::Optimizer.New(ir)
opt.Optimize()
}

fn checkCompilerFlag() {
match env::Compiler {
| "":
Throw("missing option value: --compiler")
handle::Throw("missing option value: --compiler")
| "clang":
if env::CompilerPath == "" {
env::CompilerPath = "clang++"
Expand All @@ -220,34 +207,34 @@ fn checkCompilerFlag() {
env::CompilerPath = "g++"
}
|:
Throw("invalid option value for --compiler: " + env::Compiler)
handle::Throw("invalid option value for --compiler: " + env::Compiler)
}
}

fn checkTargetArch(arch: str) {
if arch != build::DistArch.Amd64 &&
arch != build::DistArch.Arm64 &&
arch != build::DistArch.I386 {
Throw("--target: unsupported/undefined architecture: " + arch)
handle::Throw("--target: unsupported/undefined architecture: " + arch)
}
}

fn checkTargetOs(os: str) {
if os != build::DistOs.Windows &&
os != build::DistOs.Linux &&
os != build::DistOs.Darwin {
Throw("--target: unsupported/undefined operating system: " + os)
handle::Throw("--target: unsupported/undefined operating system: " + os)
}
}

fn checkTargetFlag(&target: str) {
if target == "" {
Throw("missing option value: --target")
handle::Throw("missing option value: --target")
}

parts := strings::Split(target, "-", -1)
if len(parts) != 2 {
Throw("--target: undefined platform target format: " + target)
handle::Throw("--target: undefined platform target format: " + target)
}

os, arch := parts[0], parts[1]
Expand All @@ -265,16 +252,16 @@ fn checkTargetFlag(&target: str) {

fn checkOptFlag(&opt: str) {
if opt == "" {
Throw("missing option value: --opt")
handle::Throw("missing option value: --opt")
}

match opt {
| "L0":
break
| "L1":
opt::PushOptLevel(OptLevel.L1)
opt::PushOptLevel(opt::OptLevel.L1)
|:
Throw("--opt: invalid optimization level: " + opt)
handle::Throw("--opt: invalid optimization level: " + opt)
}
}

Expand All @@ -285,15 +272,15 @@ fn checkCppStdFlag() {
| "cpp20":
break
|:
Throw("--cppstd: invalid cpp standard: " + env::CppStd)
handle::Throw("--cppstd: invalid cpp standard: " + env::CppStd)
}
}

fn checkFlags(&args: []str): []str {
mut opt := "L0"
mut target := "native-native"

mut fs := FlagSet.New()
mut fs := flag::FlagSet.New()

fs.AddVar[str](unsafe { (&str)(&opt) }, "opt", 0, "Optimization level")
fs.AddVar[str](unsafe { (&str)(&target) }, "target", 0, "Target system")
Expand Down Expand Up @@ -322,7 +309,7 @@ fn checkFlags(&args: []str): []str {
fs.AddVar[bool](unsafe { (&bool)(&opt::Dynamic) }, "opt-dynamic", 0, "Dynamic programming optimizations")

mut content := fs.Parse(args) else {
Throw(str(error))
handle::Throw(str(error))
use nil // Avoid error.
}

Expand All @@ -334,46 +321,46 @@ fn checkFlags(&args: []str): []str {
ret content
}

fn setupSemaFlags(mut &flags: SemaFlag) {
fn setupSemaFlags(mut &flags: sema::Flag) {
if env::Shadowing {
flags |= SemaFlag.Shadowing
flags |= sema::Flag.Shadowing
}
}

fn buildIr(&args: []str): &IR {
fn buildIr(&args: []str): &obj::IR {
content := checkFlags(args)

mut semaFlags := SemaFlag.Default
mut semaFlags := sema::Flag.Default
setupSemaFlags(semaFlags)

if len(content) == 0 {
Throw(Logf(LogMsg.MissingCompilePath))
handle::Throw(build::Logf(build::LogMsg.MissingCompilePath))
} else if len(content) > 1 {
Throw("undefined content: " + content[1])
handle::Throw("undefined content: " + content[1])
}
mut path, ok := path::Abs(content[0])
if !ok {
Throw("compile path could not processed because of a problem")
handle::Throw("compile path could not processed because of a problem")
}

// Check standard library.
inf := Status.Of(PathStdlib) else {
Throw(Logf(LogMsg.StdlibNotExist))
inf := fs::Status.Of(build::PathStdlib) else {
handle::Throw(build::Logf(build::LogMsg.StdlibNotExist))
ret nil // Avoid error.
}
if !inf.IsDir() {
Throw(Logf(LogMsg.StdlibNotExist))
handle::Throw(build::Logf(build::LogMsg.StdlibNotExist))
}

mut ir, logs := IR.Build(path, semaFlags)
mut ir, logs := obj::IR.Build(path, semaFlags)

if ir == nil && logs == nil {
Throw(Logf(LogMsg.NoFileInEntryPackage, path))
handle::Throw(build::Logf(build::LogMsg.NoFileInEntryPackage, path))
}

if logs != nil {
Logger.PrintLogs(logs)
Throw("")
handle::Logger.PrintLogs(logs)
handle::Throw("")
}

ret ir
Expand All @@ -391,9 +378,9 @@ fn compileCommand(mut &args: []str) {
const Binded = false

if !env::Test {
mut main := ir.Main.FindFn(EntryPoint, Binded)
mut main := ir.Main.FindFn(build::EntryPoint, Binded)
if main == nil {
Throw(Logf(LogMsg.NoEntryPoint))
handle::Throw(build::Logf(build::LogMsg.NoEntryPoint))
}
}

Expand All @@ -418,7 +405,7 @@ fn compileCommand(mut &args: []str) {

mut file := openOutput(compPath)
file.Write(unsafe { oc.Buf.Buf() }) else {
Throw("object code could not write")
handle::Throw("object code could not write")
}
file.Close()!

Expand Down
2 changes: 1 addition & 1 deletion src/julec/handle/ansi.jule
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 The Jule Programming Language.
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.
struct AnsiEscape {}
struct AnsiEscape{}

impl AnsiEscape {
const ResetSeq = "\033[0m"
Expand Down
Loading
Loading