Skip to content

Commit 15b49f4

Browse files
committed
Implement call to not builtin
1 parent fdbb004 commit 15b49f4

10 files changed

Lines changed: 85 additions & 0 deletions

spec/not_eq_true.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(not (eq `foo` `foo`))

spec/not_eq_true.expr.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as ReqlangExpr from "@reqlang-expr-tspl/runtime";
2+
3+
const expression: ReqlangExpr.Expression = (ctx) => {
4+
return !("foo" as ReqlangExpr.ExprValue === "foo" as ReqlangExpr.ExprValue);
5+
};
6+
7+
const args = ReqlangExpr.getArgs();
8+
9+
const env = new ReqlangExpr.Env(
10+
args.vars,
11+
args.prompts,
12+
args.secrets,
13+
args.client
14+
);
15+
16+
const context = {
17+
env,
18+
builtins: ReqlangExpr.builtinFns,
19+
};
20+
21+
const value = expression(context);
22+
23+
console.log(JSON.stringify(value));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
false

spec/not_false.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(not false)

spec/not_false.expr.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as ReqlangExpr from "@reqlang-expr-tspl/runtime";
2+
3+
const expression: ReqlangExpr.Expression = (ctx) => {
4+
return !false;
5+
};
6+
7+
const args = ReqlangExpr.getArgs();
8+
9+
const env = new ReqlangExpr.Env(
10+
args.vars,
11+
args.prompts,
12+
args.secrets,
13+
args.client
14+
);
15+
16+
const context = {
17+
env,
18+
builtins: ReqlangExpr.builtinFns,
19+
};
20+
21+
const value = expression(context);
22+
23+
console.log(JSON.stringify(value));

spec/not_false.expr.ts.interpreted

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true

spec/not_true.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(not true)

spec/not_true.expr.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as ReqlangExpr from "@reqlang-expr-tspl/runtime";
2+
3+
const expression: ReqlangExpr.Expression = (ctx) => {
4+
return !true;
5+
};
6+
7+
const args = ReqlangExpr.getArgs();
8+
9+
const env = new ReqlangExpr.Env(
10+
args.vars,
11+
args.prompts,
12+
args.secrets,
13+
args.client
14+
);
15+
16+
const context = {
17+
env,
18+
builtins: ReqlangExpr.builtinFns,
19+
};
20+
21+
const value = expression(context);
22+
23+
console.log(JSON.stringify(value));

spec/not_true.expr.ts.interpreted

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
false

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ fn transpile_expr(expr: &Expr) -> String {
8787
let arg2 = args.get(1).unwrap();
8888

8989
format!("({arg1} as ReqlangExpr.ExprValue === {arg2} as ReqlangExpr.ExprValue)")
90+
} else if callee == "not" {
91+
let args: Vec<String> = expr_call
92+
.args
93+
.iter()
94+
.map(|expr| transpile_expr(&expr.0))
95+
.collect();
96+
97+
let arg1 = args.first().unwrap();
98+
99+
format!("!{arg1}")
90100
} else {
91101
let args: Vec<String> = expr_call
92102
.args

0 commit comments

Comments
 (0)