Skip to content

Commit

Permalink
Multiple system packages (#744)
Browse files Browse the repository at this point in the history
* Find multiple system packages

* Rename wrong method

* Use multiple system packages

* Rename --main-function-interface-file option

* Refactor

* Rename error

* Fix context options

* Refactor

* Rename multiple FFI build scripts error

* Fix error message

* Refactor external package configuration reader

* Fix linting

* Compile with multiple context files

* Fix context names

* Fix bugs

* Fix examples

* Fix package creation

* Fix feature tests

* Fix os features

* Fix os-sync features

* Comment on unmangled context type names

* Fix smoke tests

* Fix other bugs

* Fix example
  • Loading branch information
raviqqe committed Feb 12, 2022
1 parent 38e2bce commit e05a026
Show file tree
Hide file tree
Showing 43 changed files with 618 additions and 442 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/pen/src/application_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ pub static APPLICATION_CONFIGURATION: Lazy<Arc<app::ApplicationConfiguration>> =
main_module: app::MainModuleConfiguration {
source_main_function_name: "main".into(),
object_main_function_name: "_pen_main".into(),
context_type_name: "Context".into(),
new_context_function_name: "UnsafeNew".into(),
main_context_type_name: "context".into(),
system_context_type_name: "Context".into(),
new_system_context_function_name: "UnsafeNew".into(),
},
}
.into()
Expand Down
34 changes: 23 additions & 11 deletions cmd/pen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
.setting(clap::AppSettings::Hidden)
.about("Compiles a main module")
.arg(
clap::Arg::new("main function interface file")
.short('f')
.long("main-function-interface-file")
clap::Arg::new("context interface file")
.short('c')
.long("context-interface-file")
.required(true)
.takes_value(true),
.number_of_values(2),
)
.arg(clap::Arg::new("source file").required(true))
.arg(clap::Arg::new("dependency file").required(true))
Expand Down Expand Up @@ -186,13 +186,25 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
matches.value_of("interface file").unwrap(),
matches.value_of("target"),
),
("compile-main", matches) => main_module_compiler::compile(
matches.value_of("source file").unwrap(),
matches.value_of("dependency file").unwrap(),
matches.value_of("object file").unwrap(),
matches.value_of("main function interface file").unwrap(),
matches.value_of("target"),
),
("compile-main", matches) => {
let context_options = matches
.values_of("context interface file")
.unwrap()
.collect::<Vec<_>>();

main_module_compiler::compile(
matches.value_of("source file").unwrap(),
matches.value_of("dependency file").unwrap(),
matches.value_of("object file").unwrap(),
&context_options
.iter()
.step_by(2)
.cloned()
.zip(context_options.iter().skip(1).step_by(2).cloned())
.collect(),
matches.value_of("target"),
)
}
("compile-prelude", matches) => prelude_module_compiler::compile(
matches.value_of("source file").unwrap(),
matches.value_of("object file").unwrap(),
Expand Down
9 changes: 6 additions & 3 deletions cmd/pen/src/main_module_compiler.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::{compile_configuration::COMPILE_CONFIGURATION, main_package_directory_finder};
use crate::{application_configuration::APPLICATION_CONFIGURATION, infrastructure};
use std::sync::Arc;
use std::{collections::BTreeMap, error::Error, sync::Arc};

pub fn compile(
source_file: &str,
dependency_file: &str,
object_file: &str,
context_interface_file: &str,
context_interface_files: &BTreeMap<&str, &str>,
target_triple: Option<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
let main_package_directory = main_package_directory_finder::find()?;
Expand All @@ -17,7 +17,10 @@ pub fn compile(
&file_path_converter.convert_to_file_path(source_file)?,
&file_path_converter.convert_to_file_path(dependency_file)?,
&file_path_converter.convert_to_file_path(object_file)?,
&file_path_converter.convert_to_file_path(context_interface_file)?,
&context_interface_files
.iter()
.map(|(&key, path)| Ok((key.into(), file_path_converter.convert_to_file_path(path)?)))
.collect::<Result<BTreeMap<_, _>, Box<dyn Error>>>()?,
target_triple,
&COMPILE_CONFIGURATION,
&APPLICATION_CONFIGURATION,
Expand Down
5 changes: 2 additions & 3 deletions cmd/pen/src/package_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ pub fn create(package_directory: &str, library: bool) -> Result<(), Box<dyn std:
&infrastructure,
indoc::indoc!(
"
import Os'Context { Context }
import Os'File
main = \\(ctx Context) none {
File'Write(ctx, File'StdOut(), \"Hello, world!\\n\")
main = \\(ctx context) none {
File'Write(ctx.Os, File'StdOut(), \"Hello, world!\\n\")
none
}
Expand Down
8 changes: 4 additions & 4 deletions examples/cat/main.pen
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import Os'Process

bufferSize = \() number { 4096 }

main = \(ctx Context) none {
if e = run(ctx) as none {
main = \(ctx context) none {
if e = run(ctx.Os) as none {
none
} else {
Print'Line(ctx, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx, 1)
Print'Line(ctx.Os, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx.Os, 1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/echo/main.pen
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import Os'Context { Context }
import Os'Environment
import Os'Process

main = \(ctx Context) none {
if e = run(ctx) as none {
main = \(ctx context) none {
if e = run(ctx.Os) as none {
none
} else {
Print'Line(ctx, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx, 1)
Print'Line(ctx.Os, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx.Os, 1)
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/hello-world/main.pen
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Os'Context { Context }
import Os'File

main = \(ctx Context) none {
_ = File'Write(ctx, File'StdOut(), "Hello, world!\n")
main = \(ctx context) none {
_ = File'Write(ctx.Os, File'StdOut(), "Hello, world!\n")

none
}
8 changes: 4 additions & 4 deletions examples/life-game/main.pen
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import 'lifeGame
rows = \() number { 20 }
columns = \() number { 40 }

main = \(ctx Context) none {
if e = run(ctx) as none {
main = \(ctx context) none {
if e = run(ctx.Os) as none {
none
} else {
Print'Line(ctx, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx, 1)
Print'Line(ctx.Os, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx.Os, 1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/ls/main.pen
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import Os'Process

import 'arguments

main = \(ctx Context) none {
if e = run(ctx) as none {
main = \(ctx context) none {
if e = run(ctx.Os) as none {
none
} else {
Print'Line(ctx, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx, 1)
Print'Line(ctx.Os, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx.Os, 1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/tcp-client/main.pen
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import Os'Process

import 'arguments

main = \(ctx Context) none {
if e = run(ctx) as none {
main = \(ctx context) none {
if e = run(ctx.Os) as none {
none
} else {
Print'Line(ctx, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx, 1)
Print'Line(ctx.Os, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx.Os, 1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/tcp-server/main.pen
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import Os'Process

import 'arguments

main = \(ctx Context) none {
if e = run(ctx) as none {
main = \(ctx context) none {
if e = run(ctx.Os) as none {
none
} else {
Print'Line(ctx, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx, 1)
Print'Line(ctx.Os, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx.Os, 1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/udp-client/main.pen
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import Os'Process

import 'arguments

main = \(ctx Context) none {
if e = run(ctx) as none {
main = \(ctx context) none {
if e = run(ctx.Os) as none {
none
} else {
Print'Line(ctx, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx, 1)
Print'Line(ctx.Os, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx.Os, 1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/udp-server/main.pen
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import Os'Process

import 'arguments

main = \(ctx Context) none {
if e = run(ctx) as none {
main = \(ctx context) none {
if e = run(ctx.Os) as none {
none
} else {
Print'Line(ctx, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx, 1)
Print'Line(ctx.Os, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx.Os, 1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/yes/main.pen
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import Os'Process

import 'arguments

main = \(ctx Context) none {
if e = run(ctx) as none {
main = \(ctx context) none {
if e = run(ctx.Os) as none {
none
} else {
Print'Line(ctx, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx, 1)
Print'Line(ctx.Os, if s = source(e) as string { s } else { "unknown error" })
Process'Exit(ctx.Os, 1)
}
}

Expand Down
4 changes: 2 additions & 2 deletions features/commands/build.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: Building packages
"""pen
import Os'Context { Context }
main = \(ctx Context) none {
main = \(ctx context) none {
none
}
"""
Expand Down Expand Up @@ -46,7 +46,7 @@ Feature: Building packages
"""pen
import Os'Context { Context }
main = \(ctx Context) none {
main = \(ctx context) none {
none
}
"""
Expand Down
4 changes: 2 additions & 2 deletions features/smoke/function.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Feature: Function
}
}
main = \(ctx Context) none {
main = \(ctx context) none {
f(1)()
none
Expand All @@ -46,7 +46,7 @@ Feature: Function
[none \(x none) none { x }(none)]
}
main = \(ctx Context) none {
main = \(ctx context) none {
f()
none
Expand Down
23 changes: 10 additions & 13 deletions features/smoke/list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ Feature: List
Scenario: Force multiple elements of a list
Given a file named "main.pen" with:
"""pen
import Os'Context { Context }
import Os'Process
main = \(ctx Context) none {
main = \(ctx context) none {
if [x, ...xs] = [none ...[none none]] {
x()
} else {
none
} else {
Process'Exit(ctx.Os, 1)
}
none
}
"""
When I successfully run `pen build`
Expand All @@ -30,16 +30,15 @@ Feature: List
Scenario: Force an element in a list of any type
Given a file named "main.pen" with:
"""pen
import Os'Context { Context }
import Os'Process
main = \(ctx Context) none {
main = \(ctx context) none {
if [x, ..._] = [any "foo"] {
x()
none
} else {
Process'Exit(ctx, 1)
Process'Exit(ctx.Os, 1)
}
}
"""
Expand All @@ -59,13 +58,13 @@ Feature: List
]
}
main = \(ctx Context) none {
main = \(ctx context) none {
if [x, ..._] = f([[boolean] [boolean true, false]]) {
x()
none
} else {
Process'Exit(ctx, 1)
Process'Exit(ctx.Os, 1)
}
}
"""
Expand All @@ -75,9 +74,7 @@ Feature: List
Scenario: Compile list comprehension with wrong typing
Given a file named "main.pen" with:
"""pen
import Os'Context
main = \(ctx Context) none {
main = \(ctx context) none {
[none y() for y in [none 1]]
none
Expand Down
Loading

0 comments on commit e05a026

Please sign in to comment.