Skip to content

Commit

Permalink
Exposed -> Tracked (#990)
Browse files Browse the repository at this point in the history
* add ast replacement utilities

* add replacements during eval

* Exposed -> Tracked

* small refactor

* fix typo

* Refactor, add shardsffi to split thing up

* fix test-runtime
  • Loading branch information
sinkingsugar authored Jun 4, 2024
1 parent 900adb2 commit 649a196
Show file tree
Hide file tree
Showing 20 changed files with 1,766 additions and 391 deletions.
3 changes: 2 additions & 1 deletion cmake/Root.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ add_subdirectory(${SHARDS_DIR}/shards/gfx src/gfx)
# Shards core
add_subdirectory(${SHARDS_DIR}/shards/core src/core)

# Shards core
# Shards lang
add_subdirectory(${SHARDS_DIR}/shards/lang src/lang)
add_subdirectory(${SHARDS_DIR}/shards/langffi src/langffi)

# Rust projects
add_subdirectory(${SHARDS_DIR}/shards/rust src/rust)
Expand Down
4 changes: 2 additions & 2 deletions include/shards/shards.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,8 @@ struct SHVarPayload {
// this marks a variable external and even if references are counted
// it won't be destroyed automatically
#define SHVAR_FLAGS_EXTERNAL (1 << 2)
// this marks the variable exported, can be set inside a (Set) shard
#define SHVAR_FLAGS_EXPOSED (1 << 3)
// this marks the variable tracked, can be set inside a (Set) shard
#define SHVAR_FLAGS_TRACKED (1 << 3)
// this marks the variable as a foreign variable, to prevent destruction
// when used inside seq and table
#define SHVAR_FLAGS_FOREIGN (1 << 4)
Expand Down
4 changes: 2 additions & 2 deletions include/shards/shards.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,14 +1116,14 @@ class WireProvider {

void abortWire(struct SHContext *context, std::string_view errorText);

struct OnExposedVarWarmup {
struct OnTrackedVarWarmup {
entt::id_type id;
std::string_view name;
SHExposedTypeInfo info;
const SHWire *wire;
};

struct OnExposedVarSet {
struct OnTrackedVarSet {
entt::id_type id;
std::string_view name;
SHVar newValue;
Expand Down
10 changes: 5 additions & 5 deletions shards/core/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ SHComposeResult internalComposeWire(const std::vector<Shard *> &wire, SHInstance
}

SHExposedTypeInfo expInfo{key.payload.stringValue, {}, *type, true /* mutable */};
expInfo.exposed = var.flags & SHVAR_FLAGS_EXPOSED;
expInfo.exposed = var.flags & SHVAR_FLAGS_TRACKED;
std::string_view sName(key.payload.stringValue, key.payload.stringLen);
ctx.inherited[sName] = expInfo;
}
Expand Down Expand Up @@ -2102,21 +2102,21 @@ void setString(uint32_t crc, SHString str) {
void abortWire(SHContext *ctx, std::string_view errorText) { ctx->cancelFlow(errorText); }

void triggerVarValueChange(SHContext *context, const SHVar *name, bool isGlobal, const SHVar *var) {
if ((var->flags & SHVAR_FLAGS_EXPOSED) == 0)
if ((var->flags & SHVAR_FLAGS_TRACKED) == 0)
return;

auto &w = context->main;
auto nameStr = SHSTRVIEW((*name));
OnExposedVarSet ev{w->id, nameStr, *var, isGlobal, context->currentWire()};
OnTrackedVarSet ev{w->id, nameStr, *var, isGlobal, context->currentWire()};
w->mesh.lock()->dispatcher.trigger(ev);
}

void triggerVarValueChange(SHWire *w, const SHVar *name, bool isGlobal, const SHVar *var) {
if ((var->flags & SHVAR_FLAGS_EXPOSED) == 0)
if ((var->flags & SHVAR_FLAGS_TRACKED) == 0)
return;

auto nameStr = SHSTRVIEW((*name));
OnExposedVarSet ev{w->id, nameStr, *var, isGlobal, w};
OnTrackedVarSet ev{w->id, nameStr, *var, isGlobal, w};
w->mesh.lock()->dispatcher.trigger(ev);
}

Expand Down
4 changes: 0 additions & 4 deletions shards/lang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ add_rust_library(
PROJECT_PATH ${CMAKE_CURRENT_LIST_DIR}
DEPENDS ${SHARDS_DIR}/include/shards/shards.h
)

add_shards_module(lang
RUST_TARGETS shards-lang-rust
REGISTER_SHARDS lang)
5 changes: 2 additions & 3 deletions shards/lang/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum Commands {
/// by default the output will go to stdout
#[arg(long, short = 'i', action)]
inline: bool,
/// Optinally an output file name
/// Optionally an output file name
#[arg(long, short = 'o')]
output: Option<String>,
},
Expand Down Expand Up @@ -103,8 +103,7 @@ struct Cli {
command: Commands,
}

#[no_mangle]
pub extern "C" fn shards_process_args(
pub fn process_args(
argc: i32,
argv: *const *const c_char,
no_cancellation: bool,
Expand Down
32 changes: 12 additions & 20 deletions shards/lang/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Drop for EvalEnv {
}

impl EvalEnv {
pub(crate) fn new(namespace: Option<RcStrWrapper>, parent: Option<*const EvalEnv>) -> Self {
pub fn new(namespace: Option<RcStrWrapper>, parent: Option<*const EvalEnv>) -> Self {
let mut env = EvalEnv {
parent: None,
namespace: RcStrWrapper::from(""),
Expand Down Expand Up @@ -2106,6 +2106,10 @@ fn add_shard(shard: &Function, line_info: LineInfo, e: &mut EvalEnv) -> Result<(
Ok(())
}

fn get_replacement<'a>(shard: &'a Function, e: &'a EvalEnv) -> Option<Function> {
get_rewrite_func(&shard.name, e).and_then(|rw| rw.rewrite_function(shard))
}

fn create_shard(
shard: &Function,
line_info: LineInfo,
Expand All @@ -2116,14 +2120,8 @@ fn create_shard(
}

let mut replacement_storage = None;
if let Some(rw) = get_rewrite_func(&shard.name, e) {
if let Some(replacement) = rw.rewrite_function(shard) {
replacement_storage = Some(replacement);
}
}

let shard = if let Some(replacement) = &replacement_storage {
replacement
let shard = if let Some(replacement) = get_replacement(shard, e) {
&replacement_storage.insert(replacement)
} else {
shard
};
Expand Down Expand Up @@ -2834,14 +2832,8 @@ fn eval_pipeline(
}

let mut replacement_storage = None;
if let Some(rw) = get_rewrite_func(&func.name, e) {
if let Some(replacement) = rw.rewrite_function(func) {
replacement_storage = Some(replacement);
}
}

let func = if let Some(replacement) = &replacement_storage {
replacement
let func = if let Some(replacement) = get_replacement(func, e) {
&replacement_storage.insert(replacement)
} else {
func
};
Expand Down Expand Up @@ -3802,7 +3794,7 @@ fn eval_assignment(
Ok(())
}

pub(crate) fn eval_statement(
pub fn eval_statement(
stmt: &Statement,
e: &mut EvalEnv,
cancellation_token: Arc<AtomicBool>,
Expand All @@ -3813,7 +3805,7 @@ pub(crate) fn eval_statement(
}
}

pub(crate) fn transform_envs<'a, I>(envs: I, name: &str) -> Result<Wire, ShardsError>
pub fn transform_envs<'a, I>(envs: I, name: &str) -> Result<Wire, ShardsError>
where
I: Iterator<Item = &'a mut EvalEnv>,
{
Expand Down Expand Up @@ -3961,7 +3953,7 @@ lazy_static! {
}

#[derive(Default)]
pub(crate) struct EvalShard {
pub struct EvalShard {
output: ClonedVar,
namespace: ParamVar,
name: ParamVar,
Expand Down
Loading

0 comments on commit 649a196

Please sign in to comment.