Skip to content

Commit

Permalink
remove not and or from Exp
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Apr 28, 2024
1 parent 527d082 commit a7dada8
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 193 deletions.
2 changes: 0 additions & 2 deletions docs/tests/basic/not.ch

This file was deleted.

2 changes: 0 additions & 2 deletions docs/tests/basic/not.ch.out

This file was deleted.

19 changes: 0 additions & 19 deletions docs/tests/globals/boolean.ch
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
print find x {
Boolean(x)
}

assert and []
assert and [true]
assert and [true, true]

assert not and [false]
assert not and [true, false]
assert not and [true, true, false]

assert or [true]
assert or [true, true]
assert or [true, false]
assert or [false, true, false]
assert or [false, false, true, false]

assert not or []
assert not or [false]
assert not or [false, false]
assert not or [false, false, false]
1 change: 0 additions & 1 deletion docs/tests/globals/equal.ch
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
assert equal(1, 1)
assert not equal(1, 2)
32 changes: 1 addition & 31 deletions src/lang/evaluate/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function evaluate(mod: Mod, env: Env, exp: Exp): Value {
return Values.Term(
exp.type,
exp.kind,
exp.args.map(arg => evaluate(mod, env, arg))
exp.args.map((arg) => evaluate(mod, env, arg)),
)
}

Expand Down Expand Up @@ -120,36 +120,6 @@ export function evaluate(mod: Mod, env: Env, exp: Exp): Value {
return Values.fromArray(find(exp.limit, pattern, goals))
}

case "And": {
for (const arg of exp.exps) {
const value = evaluate(mod, env, arg)
Values.assertValue(value, "Boolean", { who: "evaluate And" })
if (value.data === false) {
return Values.Boolean(false)
}
}

return Values.Boolean(true)
}

case "Or": {
for (const arg of exp.exps) {
const value = evaluate(mod, env, arg)
Values.assertValue(value, "Boolean", { who: "evaluate And" })
if (value.data === true) {
return Values.Boolean(true)
}
}

return Values.Boolean(false)
}

case "Not": {
const value = evaluate(mod, env, exp.exp)
Values.assertValue(value, "Boolean", { who: "evaluate Not" })
return Values.Boolean(!value.data)
}

case "If": {
const target = evaluate(mod, env, exp.target)
Values.assertValue(target, "Boolean", { who: "evaluate If" })
Expand Down
51 changes: 0 additions & 51 deletions src/lang/exp/Exp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export type Exp =
| Fn
| Eval
| Find
| And
| Or
| Not
| If
| Match

Expand Down Expand Up @@ -269,54 +266,6 @@ export function Find(
}
}

export type And = {
"@type": "Exp"
"@kind": "And"
exps: Array<Exp>
span: Span
}

export function And(exps: Array<Exp>, span: Span): And {
return {
"@type": "Exp",
"@kind": "And",
exps,
span,
}
}

export type Or = {
"@type": "Exp"
"@kind": "Or"
exps: Array<Exp>
span: Span
}

export function Or(exps: Array<Exp>, span: Span): Or {
return {
"@type": "Exp",
"@kind": "Or",
exps,
span,
}
}

export type Not = {
"@type": "Exp"
"@kind": "Not"
exp: Exp
span: Span
}

export function Not(exp: Exp, span: Span): Not {
return {
"@type": "Exp",
"@kind": "Not",
exp,
span,
}
}

export type If = {
"@type": "Exp"
"@kind": "If"
Expand Down
14 changes: 0 additions & 14 deletions src/lang/format/formatExp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,6 @@ export function formatExp(exp: Exp): string {
)}\n}`
}

case "And": {
const exps = exp.exps.map((arg) => formatExp(arg))
return `and [${exps.join(", ")}]`
}

case "Or": {
const exps = exp.exps.map((arg) => formatExp(arg))
return `or [${exps.join(", ")}]`
}

case "Not": {
return `not ${formatExp(exp.exp)}`
}

case "If": {
const target = formatExp(exp.target)
const thenExp = formatExp(exp.thenExp)
Expand Down
18 changes: 0 additions & 18 deletions src/lang/quote/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,6 @@ export function quote(mod: Mod, env: Env, exp: Exp): Value {
})
}

case "And": {
throw new Errors.LangError(`[quote] can not handle Exps.And`, {
span: exp.span,
})
}

case "Or": {
throw new Errors.LangError(`[quote] can not handle Exps.Or`, {
span: exp.span,
})
}

case "Not": {
throw new Errors.LangError(`[quote] can not handle Exps.Not`, {
span: exp.span,
})
}

case "If": {
throw new Errors.LangError(`[quote] can not handle Exps.If`, {
span: exp.span,
Expand Down
19 changes: 0 additions & 19 deletions src/lang/syntax/grammars/exp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,6 @@ export const operand = {
{ goals: "goals" },
'"}"',
],
"operand:and": [
'"and"',
'"["',
{ elements: { $ap: ["zero_or_more", "exp", '","'] } },
{ last_element: "exp" },
{ $ap: ["optional", '","'] },
'"]"',
],
"operand:and_empty": ['"and"', '"["', '"]"'],
"operand:or": [
'"or"',
'"["',
{ elements: { $ap: ["zero_or_more", "exp", '","'] } },
{ last_element: "exp" },
{ $ap: ["optional", '","'] },
'"]"',
],
"operand:or_empty": ['"or"', '"["', '"]"'],
"operand:not": ['"not"', { exp: "exp" }],
"operand:if": [
'"if"',
{ target: "exp" },
Expand Down
24 changes: 0 additions & 24 deletions src/lang/syntax/matchers/exp_matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,6 @@ export function operand_matcher(tree: pt.Tree): Exp {
span,
)
},
"operand:and": ({ elements, last_element }, { span }) =>
Exps.And(
[
...pt.matchers
.zero_or_more_matcher(elements)
.map(matchers.exp_matcher),
matchers.exp_matcher(last_element),
],
span,
),
"operand:and_empty": ({}, { span }) => Exps.And([], span),
"operand:or": ({ elements, last_element }, { span }) =>
Exps.Or(
[
...pt.matchers
.zero_or_more_matcher(elements)
.map(matchers.exp_matcher),
matchers.exp_matcher(last_element),
],
span,
),
"operand:or_empty": ({}, { span }) => Exps.Or([], span),
"operand:not": ({ exp }, { span }) =>
Exps.Not(matchers.exp_matcher(exp), span),
"operand:if": ({ target, thenExp, elseExp }, { span }) =>
Exps.If(
matchers.exp_matcher(target),
Expand Down
12 changes: 0 additions & 12 deletions src/lang/var-collection/varCollectionFromExp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ export function varCollectionFromExp(exp: Exp): VarCollection {
return createVarCollection()
}

case "And": {
return createVarCollection()
}

case "Or": {
return createVarCollection()
}

case "Not": {
return createVarCollection()
}

case "If": {
return createVarCollection()
}
Expand Down

0 comments on commit a7dada8

Please sign in to comment.