Skip to content

Commit

Permalink
mac support, level name, bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Spu7Nix committed Dec 25, 2020
1 parent 60d6213 commit b5b729b
Show file tree
Hide file tree
Showing 14 changed files with 458 additions and 111 deletions.
86 changes: 86 additions & 0 deletions spwn-lang/Cargo.lock

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

3 changes: 2 additions & 1 deletion spwn-lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ logos = "0.11.4"
termcolor = "1.1.2"
smallvec = "1.4.2"


aes = "0.6.0"
block-modes = "0.7.0"
3 changes: 3 additions & 0 deletions spwn-lang/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Flags:
--no-optimize
Removes post-optimization of triggers, making the output more readable,
while also using a lot more objects and groups

--level-name [name]
Targets a specific level
7 changes: 7 additions & 0 deletions spwn-lang/libraries/std/counter.spwn
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,13 @@ impl @counter {
return clone
},

_mod_: (self, num: @number | @counter) {
clone = self.clone()
out = @counter::new()
clone.divide(num, remainder = out)
return out
},

_more_than_: (self, other: @number | @counter) {

if other.type == @number {
Expand Down
2 changes: 1 addition & 1 deletion spwn-lang/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum ValueBody {
Bool(bool),
Expression(Expression),
Str(String),
Import(ImportType),
Import(ImportType, bool),
Array(Vec<Expression>),
Obj(ObjectLiteral),
Macro(Macro),
Expand Down
26 changes: 24 additions & 2 deletions spwn-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ pub fn compile_spwn(
&start_context,
&mut globals,
start_info.clone(),
false,
)?;

if standard_lib.len() != 1 {
Expand Down Expand Up @@ -892,7 +893,18 @@ pub fn import_module(
context: &Context,
globals: &mut Globals,
info: CompilerInfo,
forced: bool,
) -> Result<Returns, RuntimeError> {
if !forced {
if let Some(ret) = globals.prev_imports.get(path) {
merge_impl(&mut globals.implementations, &ret.1);
return Ok(smallvec![(
store_value(ret.0.clone(), 1, globals, context),
context.clone()
)]);
}
}

let mut module_path = match path {
ImportType::Script(p) => globals
.path
Expand Down Expand Up @@ -963,6 +975,7 @@ pub fn import_module(
&start_context,
globals,
info.clone(),
false,
)?;

if standard_lib.len() != 1 {
Expand Down Expand Up @@ -1020,7 +1033,7 @@ pub fn import_module(
merge_impl(&mut globals.implementations, &stored_impl);
}

Ok(if returns.is_empty() {
let out = if returns.is_empty() {
contexts
.iter()
.map(|x| {
Expand All @@ -1035,7 +1048,16 @@ pub fn import_module(
}

returns
})
};

if out.len() == 1 && &out[0].1 == context {
let cloned = clone_and_get_value(out[0].0, 9999, globals, context, true);
let s_impl = globals.implementations.clone();

globals.prev_imports.insert(path.clone(), (cloned, s_impl));
}

Ok(out)
}

// const ID_MAX: u16 = 999;
Expand Down
31 changes: 26 additions & 5 deletions spwn-lang/src/compiler_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ pub fn store_value(
index
}

pub fn clone_value(
pub fn clone_and_get_value(
index: usize,
lifetime: u16,
globals: &mut Globals,
context: &Context,
constant: bool,
) -> StoredValue {
) -> Value {
let mut old_val = globals.stored_values[index].clone();

match &mut old_val {
Expand Down Expand Up @@ -184,6 +184,19 @@ pub fn clone_value(
_ => (),
};

old_val
}


pub fn clone_value(
index: usize,
lifetime: u16,
globals: &mut Globals,
context: &Context,
constant: bool,
) -> StoredValue {
let old_val = clone_and_get_value(index, lifetime, globals, context, constant);

//clone all inner values
//do the thing
//bing bang
Expand Down Expand Up @@ -216,7 +229,7 @@ pub type FnIDPtr = usize;

pub type Returns = SmallVec<[(StoredValue, Context); CONTEXT_MAX]>;

#[derive(PartialEq, Eq, Debug, Clone)]
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
pub enum ImportType {
Script(PathBuf),
Lib(String)
Expand Down Expand Up @@ -284,6 +297,10 @@ impl Context {
}

}
// pub fn compare_contexts(context1: Context, context2: Context, globals: &mut Globals) -> bool {
// // returns true if the contexts are equal/mergable

// }

//will merge one set of context, returning false if no mergable contexts were found
pub fn merge_contexts(contexts: &mut SmallVec<[Context; CONTEXT_MAX]>, globals: &mut Globals) -> bool {
Expand Down Expand Up @@ -899,6 +916,8 @@ pub struct Globals {
pub func_ids: Vec<FunctionID>,
pub objects: Vec<GDObj>,

pub prev_imports: HashMap<ImportType, (Value, Implementations)>,

pub trigger_order: usize,

pub uid_counter: usize,
Expand Down Expand Up @@ -958,6 +977,8 @@ impl Globals {
lowest_y: HashMap::new(),

type_ids: HashMap::new(),

prev_imports: HashMap::new(),
type_id_count: 0,
trigger_order: 0,
uid_counter: 0,
Expand Down Expand Up @@ -1769,9 +1790,9 @@ impl ast::Variable {
})
.collect();
}
ast::ValueBody::Import(i) => {
ast::ValueBody::Import(i, f) => {
//let mut new_contexts = context.clone();
start_val = import_module(i, &context, globals, info.clone())?;
start_val = import_module(i, &context, globals, info.clone(), *f)?;
}

ast::ValueBody::TypeIndicator(name) => {
Expand Down
1 change: 1 addition & 0 deletions spwn-lang/src/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn document_lib(path: &str) -> Result<String, RuntimeError> {
&start_context,
&mut globals,
CompilerInfo::new(),
false,
)?;

if module.len() > 1 {
Expand Down
2 changes: 1 addition & 1 deletion spwn-lang/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl SpwnFmt for ValueBody {
Bool(x) => format!("{}", x),
Expression(x) => format!("({})", x.fmt(ind)),
Str(x) => format!("\"{}\"", x),
Import(x) => format!("import {:?}", x),
Import(x, f) => format!("import{} {:?}", if *f { "!" } else { "" }, x),
Obj(x) => {
(match x.mode {
ObjectMode::Object => "obj".to_string(),
Expand Down
Loading

0 comments on commit b5b729b

Please sign in to comment.