Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/garbage-collection-01.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
fn garbage() {}
}
// garbage is out of scope and not reachable, so the environment should be removed
9 changes: 9 additions & 0 deletions example/garbage-collection-02.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn higher_order(x) {
return y => x + y;
}

const add10 = higher_order(10);

const result = add10(20);

println(result); // 30
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/conv/atoi.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const ATOI_SYM: &str = "atoi";

pub fn atoi(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn atoi() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: ATOI_SYM.into(),
prms: vec!["s".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/conv/float_to_int.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const FLOAT_TO_INT_SYM: &str = "float_to_int";

pub fn float_to_int(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn float_to_int() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: FLOAT_TO_INT_SYM.into(),
prms: vec!["x".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/bytecode/src/builtin/conv/int_to_float.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};

use crate::{FnType, Value, W};
pub const INT_TO_FLOAT_SYM: &str = "int_to_float";

pub fn int_to_float(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn int_to_float() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: INT_TO_FLOAT_SYM.into(),
prms: vec!["x".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/conv/itoa.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const ITOA_SYM: &str = "itoa";

pub fn itoa(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn itoa() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: ITOA_SYM.into(),
prms: vec!["i".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/math/abs.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{type_of, ByteCodeError, Environment, FnType, Value};
use crate::{type_of, ByteCodeError, FnType, Value, W};

pub const ABS_SYM: &str = "abs";

pub fn abs(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn abs() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: ABS_SYM.into(),
prms: vec!["x".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/math/cos.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const COS_SYM: &str = "cos";

pub fn cos(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn cos() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: COS_SYM.into(),
prms: vec!["x".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/math/log.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const LOG_SYM: &str = "log";

pub fn log(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn log() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: LOG_SYM.into(),
prms: vec!["x".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/math/max.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const MAX_SYM: &str = "max";

pub fn max(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn max() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: MAX_SYM.into(),
prms: vec!["v1".into(), "v2".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/math/min.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{type_of, ByteCodeError, Environment, FnType, Value};
use crate::{type_of, ByteCodeError, FnType, Value, W};

pub const MIN_SYM: &str = "min";

pub fn min(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn min() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: MIN_SYM.into(),
prms: vec!["v1".into(), "v2".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/math/pow.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const POW_SYM: &str = "pow";

pub fn pow(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn pow() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: POW_SYM.into(),
prms: vec!["base".into(), "exp".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/math/sin.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const SIN_SYM: &str = "sin";

pub fn sin(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn sin() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: SIN_SYM.into(),
prms: vec!["x".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/math/sqrt.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const SQRT_SYM: &str = "sqrt";

pub fn sqrt(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn sqrt() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: SQRT_SYM.into(),
prms: vec!["x".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/math/tan.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const TAN_SYM: &str = "tan";

pub fn tan(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn tan() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: TAN_SYM.into(),
prms: vec!["x".into()],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/semaphore/sem_create.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use crate::{Environment, FnType, Semaphore, Value};
use crate::{FnType, Semaphore, Value, W};

pub const SEM_CREATE_SYM: &str = "sem_create";

pub fn sem_create(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn sem_create() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: SEM_CREATE_SYM.into(),
prms: vec![],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/semaphore/sem_set.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Semaphore, Value};
use crate::{FnType, Semaphore, Value, W};

pub const SEM_SET_SYM: &str = "sem_set";

pub fn sem_set(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn sem_set() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: SEM_SET_SYM.into(),
prms: vec![],
addr: 2,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/bytecode/src/builtin/stdin/read_line.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{cell::RefCell, rc::Rc};
use std::rc::Weak;

use anyhow::Result;

use crate::{Environment, FnType, Value};
use crate::{FnType, Value, W};

pub const READ_LINE_SYM: &str = "read_line";

pub fn read_line(global_env: Rc<RefCell<Environment>>) -> Value {
pub fn read_line() -> Value {
Value::Closure {
fn_type: FnType::Builtin,
sym: READ_LINE_SYM.into(),
prms: vec![],
addr: 0,
env: global_env,
env: W(Weak::new()),
}
}

Expand Down
Loading