Skip to content

Commit 2fecb58

Browse files
committed
Replace 'type(X)' with 'matching(X)' in the interpreter
Closes #5 GitHub issue (as far as the interpreter is concerned) Note that the 'type' syntactic sugar is not implemented in this commit.
1 parent ff072de commit 2fecb58

6 files changed

+10
-10
lines changed

src/interpreter.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,8 @@ Tree *Interpreter::Instructions(Context_p context, Tree_p what)
757757

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

765764
// This variable records if we evaluated the callee
@@ -1029,10 +1028,10 @@ Tree *Interpreter::TypeCheck(Scope *scope, Tree *type, Tree *value)
10291028
}
10301029
else
10311030
{
1032-
// Check a type like 'type (X, Y)'
1031+
// Check a type like 'matching (X, Y)'
10331032
if (Prefix *ptype = type->AsPrefix())
10341033
if (Name *ptypename = ptype->left->AsName())
1035-
if (ptypename->value == "type")
1034+
if (ptypename->value == "matching")
10361035
return formTypeCheck(scope, ptype->right, value);
10371036

10381037
record(interpreter_typecheck, "No code for %t, opcode is %O",

src/xl.syntax

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ INFIX
2828
600 :
2929

3030
PREFIX
31+
20 matching
3132
30 type class module function method procedure to operation
3233
30 data macro generic polymorphic iterator
3334
30 fast small global thread static

tests/02.Arithmetic/08-complex-add.xl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
complex is type((re:real, im:real))
1+
complex is matching((re:real, im:real))
22
Z1:complex + Z2:complex as complex is (Z1.re + Z2.re, Z1.im + Z2.im)
33

44
(3,4) + (5, 6)
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type (complex (re:real, im:real)) (8.0, 10.0)
1+
matching (complex (re:real, im:real)) (8.0, 10.0)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// FILTER=sed -e 's/) )/))/g'
2-
complex is type(complex(re:real, im:real))
2+
complex is matching(complex(re:real, im:real))
33
Z1:complex + Z2:complex as complex is complex(Z1.re + Z2.re, Z1.im + Z2.im)
44

55
(complex(3,4) + complex(5, 6))

tests/02.Arithmetic/09-complex-arithmetic.xl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
complex is type(re:real, im:real)
1+
complex is matching(re:real, im:real)
22
Z1:complex + Z2:complex is (Z1.re + Z2.re, Z1.im + Z2.im)
33
Z1:complex + Z2:real is (Z1.re + Z2, Z1.im)
44
Z1:complex - Z2:complex is (Z1.re - Z2.re, Z1.im - Z2.im)
@@ -11,7 +11,7 @@ Z1:complex / Z2:complex is
1111
denom is Z2.re^2 + Z2.im^2
1212
numer / denom
1313

14-
write Z:complex is write "(", Z.re, ",", Z.im, ")"
14+
write Z:complex is write "(", Z.re, ",", Z.im, ")"
1515
print T, C:complex is print T, "(", C.re, ", ", C.im, ")"
1616

1717
print "(3,4) + (5,6)=", (3,4) + (5,6)

0 commit comments

Comments
 (0)