Browse Source

Remove makeForm(). Use Closure.fixed property to change assert/refute closures into a special forms.

master
Ian Piumarta 1 year ago
parent
commit
4a3abfc8c1
2 changed files with 57 additions and 5 deletions
  1. +53
    -3
      test.ref
  2. +4
    -2
      test.txt

+ 53
- 3
test.ref View File

@ -12,7 +12,18 @@ Point.new(x: 3, y: 4) => <>
| y: 4 | y: 4
| x: 3 | x: 3
twice 21 is 42 twice 21 is 42
double => <closure>
double => <<Closure>>
| environment: nil
| function: <<Lambda>>
| | body: <<Object>>
| | | 0: <<Binop>>
| | | | operation: 13
| | | | 0: <<GetVar>>
| | | | | name: x
| | | | 1: <<GetVar>>
| | | | | name: x
| | parameters: <<Object>>
| | | 0: x
Point.new(x:3, y:4).magnitude() => 5.000000 Point.new(x:3, y:4).magnitude() => 5.000000
<<?>> <<?>>
| self: nil => | self: nil =>
@ -50,7 +61,7 @@ ok
---- ----
MyType.__eval__() invoked MyType.__eval__() invoked
42 42
<closure>
<<Closure>>
==== ====
42 42
hello hello
@ -130,7 +141,44 @@ f 102 ( 40 ) 41 32 { 123 32 p 112 r 114 i 105 n 110 t 116 ( 40 _ 95 _ 95 e 1
42 42
6 * 7 6 * 7
MACRO table <<Object>> MACRO table <<Object>>
| test: <closure>
| test: <<Closure>>
| | environment: nil
| | function: <<Lambda>>
| | | body: <<Object>>
| | | | 0: <<Call>>
| | | | | arguments: <<Object>>
| | | | | | 0: MACRO EVAL test with
| | | | | | 1: <<GetVar>>
| | | | | | | name: x
| | | | | | 2: and
| | | | | | 3: <<GetVar>>
| | | | | | | name: y
| | | | | | 4:
| | | | | function: <<GetVar>>
| | | | | | name: print
| | | | 1: <<Unyop>>
| | | | | operation: 3
| | | | | 0: <<Block>>
| | | | | | body: <<Object>>
| | | | | | | 0: <<Call>>
| | | | | | | | arguments: <<Object>>
| | | | | | | | | 0: REPLACEMENT
| | | | | | | | | 1: <<Unyop>>
| | | | | | | | | | operation: 4
| | | | | | | | | | 0: <<GetVar>>
| | | | | | | | | | | name: x
| | | | | | | | | 2:
| | | | | | | | function: <<GetVar>>
| | | | | | | | | name: print
| | | | | | | 1: <<Unyop>>
| | | | | | | | operation: 4
| | | | | | | | 0: <<GetVar>>
| | | | | | | | | name: y
| | | parameters: <<Object>>
| | | | 0: x
| | | | 1: y
define testfun define testfun
MACRO EVAL test with 1 and 2 MACRO EVAL test with 1 and 2
MACRO EVAL test with three and four MACRO EVAL test with three and four
@ -142,6 +190,8 @@ REPLACEMENT three
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
65 66 67 68 69 65 66 67 68 69
1 two 3 four 1 two 3 four
test.txt:331: *: illegal operand types Integer and String
11: n * factorial(n - 1) 11: n * factorial(n - 1)
10: if (n < 2) "1" else n * factorial(n - 1) 10: if (n < 2) "1" else n * factorial(n - 1)
9: factorial(n - 1) 9: factorial(n - 1)

+ 4
- 2
test.txt View File

@ -97,7 +97,7 @@ assert(x) {
} }
} }
makeForm(assert);
assert.fixed = #t; // do not evaluate arguments (x will be an AST suitable for eval())
refute(x) { refute(x) {
if (eval(x)) { if (eval(x)) {
@ -106,7 +106,9 @@ refute(x) {
} }
} }
makeForm(refute);
refute.fixed = #t;
refute;
assert(1 == 1); assert(1 == 1);
refute(1 == 0); refute(1 == 0);

Loading…
Cancel
Save