Skip to content

Commit

Permalink
Merge branch 'main' into feature/145-add-path-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bhansconnect authored Jan 17, 2024
2 parents 410bd80 + 81399ac commit e6cf1cb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test_latest_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:

- name: Use ./ci/test_latest_release.sh of the latest git main
run: mv -f ./temp/test_latest_release.sh ./ci/

# temp issue with new string interpolation syntax
# TODO remove this when 0.7.2 or 0.8.0 is released
- run: sed -i 's/\$//g' examples/tcp-client.roc

- name: Run all tests with latest roc release + latest basic-cli release
run: EXAMPLES_DIR=./examples/ ./ci/test_latest_release.sh
2 changes: 1 addition & 1 deletion examples/tcp-client.roc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ main =
If you don't have anything listening on port 8085, run:
$ nc -l 8085
If you want an echo server you can run:
$ ncat -e $(which cat) -l 8085
$ ncat -e \$(which cat) -l 8085
"""

Err (TcpPerformErr (TcpReadBadUtf8 _)) ->
Expand Down
2 changes: 1 addition & 1 deletion platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ codegen-units = 1
[lib]
name = "host"
path = "src/lib.rs"
crate-type = ["staticlib", "rlib"]
crate-type = ["staticlib", "lib"]

[[bin]]
name = "host"
Expand Down
1 change: 1 addition & 0 deletions platform/Task.roc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ forever = \task ->
|> InternalTask.fromEffect

## Run a task repeatedly, until it fails with `err` or completes with `done`.
## Check out [this example](https://www.roc-lang.org/examples/TaskLoop/README.html).
loop : state, (state -> Task [Step state, Done done] err) -> Task done err
loop = \state, step ->
looper = \current ->
Expand Down
2 changes: 1 addition & 1 deletion platform/Utc.roc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ nanosPerMilli = 1_000_000
## Convert Utc timestamp to milliseconds
toMillisSinceEpoch : Utc -> U128
toMillisSinceEpoch = \@Utc nanos ->
nanos * nanosPerMilli
nanos // nanosPerMilli

## Convert milliseconds to Utc timestamp
fromMillisSinceEpoch : U128 -> Utc
Expand Down
25 changes: 13 additions & 12 deletions platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
pub fn roc_main_size() -> i64;

#[link_name = "roc__mainForHost_0_caller"]
fn call_Fx(flags: *const u8, closure_data: *const u8, output: *mut u8);
fn call_Fx(flags: *const u8, closure_data: *const u8, output: *mut RocResult<(), i32>);

#[allow(dead_code)]
#[link_name = "roc__mainForHost_0_size"]
Expand Down Expand Up @@ -273,7 +273,7 @@ pub fn init() {
}

#[no_mangle]
pub extern "C" fn rust_main() {
pub extern "C" fn rust_main() -> i32 {
init();
let size = unsafe { roc_main_size() } as usize;
let layout = Layout::array::<u8>(size).unwrap();
Expand All @@ -283,28 +283,29 @@ pub extern "C" fn rust_main() {

roc_main(buffer);

call_the_closure(buffer);
let out = call_the_closure(buffer);

std::alloc::dealloc(buffer, layout);

return out;
}
}

pub unsafe fn call_the_closure(closure_data_ptr: *const u8) -> u8 {
let size = size_Fx_result() as usize;
let layout = Layout::array::<u8>(size).unwrap();
let buffer = std::alloc::alloc(layout) as *mut u8;
pub unsafe fn call_the_closure(closure_data_ptr: *const u8) -> i32 {
// Main always returns an i32. just allocate for that.
let mut out: RocResult<(), i32> = RocResult::ok(());

call_Fx(
// This flags pointer will never get dereferenced
MaybeUninit::uninit().as_ptr(),
closure_data_ptr as *const u8,
buffer as *mut u8,
&mut out,
);

std::alloc::dealloc(buffer, layout);

// TODO return the u8 exit code returned by the Fx closure
0
match out.into() {
Ok(()) => 0,
Err(exit_code) => exit_code,
}
}

#[no_mangle]
Expand Down
4 changes: 3 additions & 1 deletion platform/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ fn main() {

host::roc_main(buffer);

host::call_the_closure(buffer);
let out = host::call_the_closure(buffer);

std::alloc::dealloc(buffer, layout);

std::process::exit(out);
}
}

0 comments on commit e6cf1cb

Please sign in to comment.