mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
wip
This commit is contained in:
parent
d0c9c433a6
commit
afbe871e6d
5 changed files with 28 additions and 12 deletions
|
@ -26,7 +26,7 @@ use roc_types::subs::{VarStore, Variable};
|
||||||
/// lookup (if the bounds check passed). That internal function is hardcoded in code gen,
|
/// lookup (if the bounds check passed). That internal function is hardcoded in code gen,
|
||||||
/// which works fine because it doesn't involve any open tag unions.
|
/// which works fine because it doesn't involve any open tag unions.
|
||||||
pub fn builtin_defs(var_store: &VarStore) -> Vec<Def> {
|
pub fn builtin_defs(var_store: &VarStore) -> Vec<Def> {
|
||||||
vec![list_get(var_store), list_first(var_store)]
|
vec![/*list_get(var_store),*/ list_first(var_store)]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List.get : List elem, Int -> Result elem [ OutOfBounds ]*
|
/// List.get : List elem, Int -> Result elem [ OutOfBounds ]*
|
||||||
|
@ -208,7 +208,7 @@ fn no_region<T>(value: T) -> Located<T> {
|
||||||
fn tag(name: &'static str, args: Vec<Expr>, var_store: &VarStore) -> Expr {
|
fn tag(name: &'static str, args: Vec<Expr>, var_store: &VarStore) -> Expr {
|
||||||
Expr::Tag {
|
Expr::Tag {
|
||||||
variant_var: var_store.fresh(),
|
variant_var: var_store.fresh(),
|
||||||
ext_var: var_store.fresh(), // TODO Variable::EMPTY_TAG_UNION should work here
|
ext_var: var_store.fresh(),
|
||||||
name: TagName::Global(name.into()),
|
name: TagName::Global(name.into()),
|
||||||
arguments: args
|
arguments: args
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -301,16 +301,21 @@ mod gen_builtins {
|
||||||
assert_evals_to!("List.isEmpty []", true, bool);
|
assert_evals_to!("List.isEmpty []", true, bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
// #[test]
|
||||||
fn get_0_int_list() {
|
// fn get_0_int_list() {
|
||||||
assert_evals_to!("List.get [ 12, 9, 6, 3 ] 0", (1, 12), (u64, i64));
|
// assert_evals_to!("List.get [ 12, 9, 6, 3 ] 0", (1, 12), (u64, i64));
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn head_int_list() {
|
fn head_int_list() {
|
||||||
assert_evals_to!("List.first [ 12, 9, 6, 3 ]", (1, 12), (u64, i64));
|
assert_evals_to!("List.first [ 12, 9, 6, 3 ]", (1, 12), (u64, i64));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn head_empty_list() {
|
||||||
|
assert_evals_to!("List.first []", (0, 0), (u64, i64));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_int_list() {
|
fn get_int_list() {
|
||||||
assert_evals_to!("List.getUnsafe [ 12, 9, 6 ] 1", 9, i64);
|
assert_evals_to!("List.getUnsafe [ 12, 9, 6 ] 1", 9, i64);
|
||||||
|
@ -402,4 +407,9 @@ mod gen_builtins {
|
||||||
f64
|
f64
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn err_with_payload() {
|
||||||
|
assert_evals_to!("if True then Err 42 else Ok False", (0, 42), (u64, i64));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ macro_rules! assert_llvm_evals_to {
|
||||||
builder.build_return(Some(&ret));
|
builder.build_return(Some(&ret));
|
||||||
|
|
||||||
// Uncomment this to see the module's un-optimized LLVM instruction output:
|
// Uncomment this to see the module's un-optimized LLVM instruction output:
|
||||||
// env.module.print_to_stderr();
|
env.module.print_to_stderr();
|
||||||
|
|
||||||
if main_fn.verify(true) {
|
if main_fn.verify(true) {
|
||||||
fpm.run_on(&main_fn);
|
fpm.run_on(&main_fn);
|
||||||
|
@ -419,7 +419,7 @@ macro_rules! assert_evals_to {
|
||||||
assert_llvm_evals_to!($src, $expected, $ty, (|val| val));
|
assert_llvm_evals_to!($src, $expected, $ty, (|val| val));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
assert_opt_evals_to!($src, $expected, $ty, (|val| val));
|
// assert_opt_evals_to!($src, $expected, $ty, (|val| val));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
|
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
|
||||||
|
@ -428,7 +428,7 @@ macro_rules! assert_evals_to {
|
||||||
assert_llvm_evals_to!($src, $expected, $ty, $transform);
|
assert_llvm_evals_to!($src, $expected, $ty, $transform);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
assert_opt_evals_to!($src, $expected, $ty, $transform);
|
// assert_opt_evals_to!($src, $expected, $ty, $transform);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -642,7 +642,7 @@ define_builtins! {
|
||||||
10 LIST_LEN: "len"
|
10 LIST_LEN: "len"
|
||||||
11 LIST_FOLDL: "foldl"
|
11 LIST_FOLDL: "foldl"
|
||||||
12 LIST_FOLDR: "foldr"
|
12 LIST_FOLDR: "foldr"
|
||||||
13 LIST_GET_UNSAFE: "#getUnsafe"
|
13 LIST_GET_UNSAFE: "getUnsafe"
|
||||||
14 LIST_CONCAT: "concat"
|
14 LIST_CONCAT: "concat"
|
||||||
15 LIST_FIRST: "first"
|
15 LIST_FIRST: "first"
|
||||||
16 LIST_FIRST_ARG: "first#list"
|
16 LIST_FIRST_ARG: "first#list"
|
||||||
|
|
|
@ -60,7 +60,10 @@ impl<'a> Layout<'a> {
|
||||||
|
|
||||||
match content {
|
match content {
|
||||||
var @ FlexVar(_) | var @ RigidVar(_) => {
|
var @ FlexVar(_) | var @ RigidVar(_) => {
|
||||||
panic!("Layout::from_content encountered an unresolved {:?}", var);
|
panic!(
|
||||||
|
"Layout::from_content encountered an unresolved {:?} - subs was {:?}",
|
||||||
|
var, subs
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Structure(flat_type) => layout_from_flat_type(arena, flat_type, subs, pointer_size),
|
Structure(flat_type) => layout_from_flat_type(arena, flat_type, subs, pointer_size),
|
||||||
|
|
||||||
|
@ -501,7 +504,10 @@ fn layout_from_num_content<'a>(content: Content) -> Result<Layout<'a>, ()> {
|
||||||
|
|
||||||
match content {
|
match content {
|
||||||
var @ FlexVar(_) | var @ RigidVar(_) => {
|
var @ FlexVar(_) | var @ RigidVar(_) => {
|
||||||
panic!("Layout::from_content encountered an unresolved {:?}", var);
|
panic!(
|
||||||
|
"Layout::from_num_content encountered an unresolved {:?}",
|
||||||
|
var
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Structure(Apply(symbol, args)) => match symbol {
|
Structure(Apply(symbol, args)) => match symbol {
|
||||||
Symbol::INT_INTEGER => Ok(Layout::Builtin(Builtin::Int64)),
|
Symbol::INT_INTEGER => Ok(Layout::Builtin(Builtin::Int64)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue