Skip to content

Commit

Permalink
Replace 'type(X)' with 'matching(X)' in the interpreter
Browse files Browse the repository at this point in the history
Closes #5 GitHub issue (as far as the interpreter is concerned)

Note that the 'type' syntactic sugar is not implemented in this commit.
  • Loading branch information
c3d committed Feb 25, 2020
1 parent ff072de commit 2fecb58
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,8 @@ Tree *Interpreter::Instructions(Context_p context, Tree_p what)

if (Name *name = callee->AsName())
// A few cases where we don't interpret the result
if (name->value == "type" ||
name->value == "extern" ||
name->value == "data")
if (name->value == "matching" ||
name->value == "extern")
return what;

// This variable records if we evaluated the callee
Expand Down Expand Up @@ -1029,10 +1028,10 @@ Tree *Interpreter::TypeCheck(Scope *scope, Tree *type, Tree *value)
}
else
{
// Check a type like 'type (X, Y)'
// Check a type like 'matching (X, Y)'
if (Prefix *ptype = type->AsPrefix())
if (Name *ptypename = ptype->left->AsName())
if (ptypename->value == "type")
if (ptypename->value == "matching")
return formTypeCheck(scope, ptype->right, value);

record(interpreter_typecheck, "No code for %t, opcode is %O",
Expand Down
1 change: 1 addition & 0 deletions src/xl.syntax
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ INFIX
600 :

PREFIX
20 matching
30 type class module function method procedure to operation
30 data macro generic polymorphic iterator
30 fast small global thread static
Expand Down
2 changes: 1 addition & 1 deletion tests/02.Arithmetic/08-complex-add.xl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
complex is type((re:real, im:real))
complex is matching((re:real, im:real))
Z1:complex + Z2:complex as complex is (Z1.re + Z2.re, Z1.im + Z2.im)

(3,4) + (5, 6)
2 changes: 1 addition & 1 deletion tests/02.Arithmetic/08b-complex-add-with-prefix.ref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
type (complex (re:real, im:real)) (8.0, 10.0)
matching (complex (re:real, im:real)) (8.0, 10.0)
2 changes: 1 addition & 1 deletion tests/02.Arithmetic/08b-complex-add-with-prefix.xl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// FILTER=sed -e 's/) )/))/g'
complex is type(complex(re:real, im:real))
complex is matching(complex(re:real, im:real))
Z1:complex + Z2:complex as complex is complex(Z1.re + Z2.re, Z1.im + Z2.im)

(complex(3,4) + complex(5, 6))
4 changes: 2 additions & 2 deletions tests/02.Arithmetic/09-complex-arithmetic.xl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
complex is type(re:real, im:real)
complex is matching(re:real, im:real)
Z1:complex + Z2:complex is (Z1.re + Z2.re, Z1.im + Z2.im)
Z1:complex + Z2:real is (Z1.re + Z2, Z1.im)
Z1:complex - Z2:complex is (Z1.re - Z2.re, Z1.im - Z2.im)
Expand All @@ -11,7 +11,7 @@ Z1:complex / Z2:complex is
denom is Z2.re^2 + Z2.im^2
numer / denom

write Z:complex is write "(", Z.re, ",", Z.im, ")"
write Z:complex is write "(", Z.re, ",", Z.im, ")"
print T, C:complex is print T, "(", C.re, ", ", C.im, ")"

print "(3,4) + (5,6)=", (3,4) + (5,6)
Expand Down

0 comments on commit 2fecb58

Please sign in to comment.