mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Attempt to add builtin_defs to CLI
This commit is contained in:
parent
101dc80ae5
commit
2679077de9
4 changed files with 347 additions and 344 deletions
|
@ -3,11 +3,16 @@ extern crate roc_reporting;
|
|||
#[macro_use]
|
||||
extern crate clap;
|
||||
use bumpalo::Bump;
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use inkwell::context::Context;
|
||||
use inkwell::module::Linkage;
|
||||
use inkwell::passes::PassManager;
|
||||
use inkwell::targets::{
|
||||
CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetTriple,
|
||||
};
|
||||
use inkwell::types::BasicType;
|
||||
use inkwell::OptimizationLevel;
|
||||
use roc_can::def::Def;
|
||||
use roc_collections::all::ImMap;
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_gen::llvm::build::{
|
||||
|
@ -18,15 +23,10 @@ use roc_load::file::{LoadedModule, LoadingProblem};
|
|||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::expr::{Env, Expr, PartialProc, Procs};
|
||||
use roc_mono::layout::Layout;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use inkwell::targets::{
|
||||
CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetTriple,
|
||||
};
|
||||
use std::io::{self, ErrorKind};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process;
|
||||
use std::time::SystemTime;
|
||||
use target_lexicon::{Architecture, OperatingSystem, Triple, Vendor};
|
||||
use tokio::process::Command;
|
||||
use tokio::runtime::Builder;
|
||||
|
@ -367,6 +367,49 @@ fn gen(
|
|||
jump_counter: arena.alloc(0),
|
||||
};
|
||||
|
||||
let add_def_to_procs = |def: Def| {
|
||||
use roc_can::expr::Expr::*;
|
||||
use roc_can::pattern::Pattern::*;
|
||||
|
||||
match def.loc_pattern.value {
|
||||
Identifier(symbol) => {
|
||||
match def.loc_expr.value {
|
||||
Closure(annotation, _, _, loc_args, boxed_body) => {
|
||||
let (loc_body, ret_var) = *boxed_body;
|
||||
|
||||
procs.insert_closure(
|
||||
&mut mono_env,
|
||||
Some(symbol),
|
||||
annotation,
|
||||
loc_args,
|
||||
loc_body,
|
||||
ret_var,
|
||||
);
|
||||
}
|
||||
body => {
|
||||
let proc = PartialProc {
|
||||
annotation: def.expr_var,
|
||||
// This is a 0-arity thunk, so it has no arguments.
|
||||
patterns: bumpalo::collections::Vec::new_in(arena),
|
||||
body,
|
||||
};
|
||||
|
||||
procs.user_defined.insert(symbol, proc);
|
||||
procs.module_thunks.insert(symbol);
|
||||
}
|
||||
};
|
||||
}
|
||||
other => {
|
||||
todo!("TODO gracefully handle Declare({:?})", other);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize Procs from builtins
|
||||
for def in roc_can::builtins::builtin_defs() {
|
||||
add_def_to_procs(def);
|
||||
}
|
||||
|
||||
// Add modules' decls to Procs
|
||||
for (_, mut decls) in decls_by_id
|
||||
.drain()
|
||||
|
@ -374,42 +417,9 @@ fn gen(
|
|||
{
|
||||
for decl in decls.drain(..) {
|
||||
use roc_can::def::Declaration::*;
|
||||
use roc_can::expr::Expr::*;
|
||||
use roc_can::pattern::Pattern::*;
|
||||
|
||||
match decl {
|
||||
Declare(def) => match def.loc_pattern.value {
|
||||
Identifier(symbol) => {
|
||||
match def.loc_expr.value {
|
||||
Closure(annotation, _, _, loc_args, boxed_body) => {
|
||||
let (loc_body, ret_var) = *boxed_body;
|
||||
|
||||
procs.insert_closure(
|
||||
&mut mono_env,
|
||||
Some(symbol),
|
||||
annotation,
|
||||
loc_args,
|
||||
loc_body,
|
||||
ret_var,
|
||||
);
|
||||
}
|
||||
body => {
|
||||
let proc = PartialProc {
|
||||
annotation: def.expr_var,
|
||||
// This is a 0-arity thunk, so it has no arguments.
|
||||
patterns: bumpalo::collections::Vec::new_in(arena),
|
||||
body,
|
||||
};
|
||||
|
||||
procs.user_defined.insert(symbol, proc);
|
||||
procs.module_thunks.insert(symbol);
|
||||
}
|
||||
};
|
||||
}
|
||||
other => {
|
||||
todo!("TODO gracefully handle Declare({:?})", other);
|
||||
}
|
||||
},
|
||||
Declare(def) => add_def_to_procs(def),
|
||||
DeclareRec(_defs) => {
|
||||
todo!("TODO support DeclareRec");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue