-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Closes #2781 * This PR only implements the Rust runtime. The Rust backend / code generation need to be implemented in a separate PR. * The tests are unit tests for different modules and tests with "manually" compiled Juvix programs. * Adds building & testing of the Rust runtime to the CI.
- Loading branch information
Showing
77 changed files
with
810 additions
and
81 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 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 |
---|---|---|
|
@@ -56,7 +56,7 @@ TAGS | |
# other | ||
.DS_Store | ||
|
||
/runtime/include/ | ||
/runtime/c/include/ | ||
_build/ | ||
_build.*/ | ||
*.agdai | ||
|
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
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
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 |
---|---|---|
@@ -1,55 +1,21 @@ | ||
all: release debug includes | ||
|
||
release: wasm32-wasi native64 | ||
export | ||
|
||
debug: wasm32-wasi-debug native64-debug | ||
.PHONY: all | ||
all: juvix_c juvix_rust | ||
|
||
HEADERS := $(patsubst src/%,include/%,$(shell find src -name '*.h')) | ||
.PHONY: juvix_c | ||
juvix_c: | ||
cd c && $(MAKE) -j 4 -s | ||
|
||
includes: $(HEADERS) | ||
|
||
$(HEADERS) : include/%.h : src/%.h | ||
@mkdir -p `dirname $@` | ||
@cp $< $@ | ||
|
||
wasm32: | ||
$(MAKE) -f Makefile.generic CONFIG=WASM32+RELEASE | ||
|
||
wasm32-wasi: | ||
$(MAKE) -f Makefile.generic CONFIG=WASM32-WASI+RELEASE | ||
|
||
native32: | ||
$(MAKE) -f Makefile.generic CONFIG=NATIVE32+RELEASE | ||
|
||
native64: | ||
$(MAKE) -f Makefile.generic CONFIG=NATIVE64+RELEASE | ||
|
||
x86_32: | ||
$(MAKE) -f Makefile.generic CONFIG=X86_32+RELEASE | ||
|
||
wasm32-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=WASM32+DEBUG | ||
|
||
wasm32-wasi-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=WASM32-WASI+DEBUG | ||
|
||
native32-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=NATIVE32+DEBUG | ||
|
||
native64-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=NATIVE64+DEBUG | ||
|
||
x86_32-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=X86_32+DEBUG | ||
|
||
asm: | ||
$(MAKE) -f Makefile.generic CONFIG=ASM+DEBUG | ||
|
||
format: | ||
@clang-format -i `find src -name '*.c' -or -name '*.h'` | ||
.PHONY: juvix_rust | ||
juvix_rust: | ||
cd rust && cargo build --release | ||
|
||
.PHONY: clean | ||
clean: | ||
@-rm -rf _build* | ||
@-rm -rf include | ||
cd c && $(MAKE) clean | ||
|
||
.PHONY: release debug includes wasm32 wasm32-wasi native32 native64 x86_32 wasm32-debug wasm32-wasi-debug native32-debug native64-debug x86_32-debug asm format clean | ||
.PHONY: format | ||
format: | ||
cd c && $(MAKE) format |
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,56 @@ | ||
all: release debug includes | ||
|
||
release: wasm32-wasi native64 | ||
|
||
debug: wasm32-wasi-debug native64-debug | ||
|
||
HEADERS := $(patsubst src/%,include/%,$(shell find src -name '*.h')) | ||
CFORMAT := clang-format | ||
|
||
includes: $(HEADERS) | ||
|
||
$(HEADERS) : include/%.h : src/%.h | ||
@mkdir -p `dirname $@` | ||
@cp $< $@ | ||
|
||
wasm32: | ||
$(MAKE) -f Makefile.generic CONFIG=WASM32+RELEASE | ||
|
||
wasm32-wasi: | ||
$(MAKE) -f Makefile.generic CONFIG=WASM32-WASI+RELEASE | ||
|
||
native32: | ||
$(MAKE) -f Makefile.generic CONFIG=NATIVE32+RELEASE | ||
|
||
native64: | ||
$(MAKE) -f Makefile.generic CONFIG=NATIVE64+RELEASE | ||
|
||
x86_32: | ||
$(MAKE) -f Makefile.generic CONFIG=X86_32+RELEASE | ||
|
||
wasm32-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=WASM32+DEBUG | ||
|
||
wasm32-wasi-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=WASM32-WASI+DEBUG | ||
|
||
native32-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=NATIVE32+DEBUG | ||
|
||
native64-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=NATIVE64+DEBUG | ||
|
||
x86_32-debug: | ||
$(MAKE) -f Makefile.generic CONFIG=X86_32+DEBUG | ||
|
||
asm: | ||
$(MAKE) -f Makefile.generic CONFIG=ASM+DEBUG | ||
|
||
format: | ||
@$(CFORMAT) -i `find src -name '*.c' -or -name '*.h'` | ||
|
||
clean: | ||
@-rm -rf _build* | ||
@-rm -rf include | ||
|
||
.PHONY: release debug includes wasm32 wasm32-wasi native32 native64 x86_32 wasm32-debug wasm32-wasi-debug native32-debug native64-debug x86_32-debug asm format clean |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
/target | ||
Cargo.lock | ||
*~ |
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,8 @@ | ||
[package] | ||
name = "juvix" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
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,70 @@ | ||
// Closure application | ||
|
||
use super::defs::*; | ||
use super::memory::*; | ||
|
||
pub enum AppResult { | ||
// Call(fid) | ||
Call(Word, Vec<Word>), | ||
// Return(result_closure) | ||
Return(Word), | ||
// Continue(fid, args_left) | ||
Continue(Word, Vec<Word>, Vec<Word>), | ||
} | ||
|
||
impl Memory { | ||
pub fn apply(self: &mut Memory, cl: Word, cargs: &[Word]) -> AppResult { | ||
let argsnum = self.get_closure_largs(cl); | ||
if argsnum == cargs.len() { | ||
let (fid, args) = self.call_closure(cl, cargs); | ||
AppResult::Call(fid, args) | ||
} else if argsnum > cargs.len() { | ||
AppResult::Return(self.extend_closure(cl, cargs)) | ||
} else { | ||
let (fid, args) = self.call_closure(cl, &cargs[0..argsnum]); | ||
AppResult::Continue(fid, args, Vec::from(&cargs[argsnum..cargs.len()])) | ||
} | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! tapply { | ||
($lab:lifetime, $program:ident, $mem:ident, $fid:ident, $args:ident, $cl0:expr, $cargs0:expr) => { | ||
let mut cl = $cl0; | ||
let mut cargs = $cargs0; | ||
loop { | ||
match $mem.apply( cl, &cargs) { | ||
apply::AppResult::Call(fid1, args1) => { | ||
$fid = fid1; | ||
$args = args1; | ||
continue $lab; | ||
} | ||
apply::AppResult::Return(r) => break $lab r, | ||
apply::AppResult::Continue(fid1, args1, cargs1) => { | ||
cl = $program($mem, fid1, args1); | ||
cargs = cargs1; | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! apply { | ||
($program:ident, $mem:ident, $cl0:expr, $cargs0:expr) => {{ | ||
let mut cl = $cl0; | ||
let mut cargs = $cargs0; | ||
loop { | ||
match $mem.apply(cl, &cargs) { | ||
apply::AppResult::Call(fid, args) => { | ||
break $program($mem, fid, args); | ||
} | ||
apply::AppResult::Return(r) => break r, | ||
apply::AppResult::Continue(fid1, args1, cargs1) => { | ||
cl = $program($mem, fid1, args1); | ||
cargs = cargs1; | ||
} | ||
} | ||
} | ||
}}; | ||
} |
Oops, something went wrong.