@@ -2,7 +2,6 @@ const std = @import("std");
22const activeTag = std .meta .activeTag ;
33
44const Token = @import ("token.zig" ).Token ;
5- const Callable = @import ("interpreter/callable.zig" ).Callable ;
65
76pub const Statement = union (enum ) {
87 // Expressions
@@ -209,29 +208,9 @@ pub const Value = union(enum) {
209208 int : i64 ,
210209 string : []const u8 ,
211210 boolean : bool ,
212- function : Callable ,
213211 null ,
214212 unit ,
215213
216- // pointer so that copies of a value share identity (u2 = u1 means u1.field == u2.field)
217- // var u1 = User("Bob");
218- // var u2 = u1;
219- // if (u1.name == u2.name) { ... } // true
220- struct_instance : * StructInstance ,
221-
222- // Index of the VM function
223- // Stored in the function table in Program
224- vm_function : u16 ,
225-
226- pub const StructInstance = struct {
227- type_name : []const u8 ,
228- field_names : []const []const u8 ,
229- body_field_values : []Value ,
230- body_field_names : []const []const u8 ,
231- field_values : []Value ,
232- kind : StructKind ,
233- };
234-
235214 pub fn eql (self : Value , other : Value ) bool {
236215 const self_tag = activeTag (self );
237216 const other_tag = activeTag (other );
@@ -244,23 +223,6 @@ pub const Value = union(enum) {
244223 .string = > | a | std .mem .eql (u8 , a , other .string ),
245224 .boolean = > | a | a == other .boolean ,
246225 .null , .unit = > true ,
247- .vm_function = > | a | a == other .vm_function ,
248- .struct_instance = > | a | {
249- const b = other .struct_instance ;
250- if (a .kind == .plain ) {
251- return a == b ;
252- }
253- if (! std .mem .eql (u8 , a .type_name , b .type_name )) {
254- return false ;
255- }
256- for (a .field_values , b .field_values ) | av , bv | {
257- if (! av .eql (bv )) {
258- return false ;
259- }
260- }
261- return true ;
262- },
263- else = > false ,
264226 };
265227 }
266228
@@ -277,10 +239,7 @@ pub const Value = union(enum) {
277239 .null , .unit = > false ,
278240 .boolean = > | b | b ,
279241 .int = > | n | n != 0 ,
280- .function = > true ,
281242 .string = > | s | s .len > 0 ,
282- .vm_function = > true ,
283- .struct_instance = > | _ | true ,
284243 };
285244 }
286245
@@ -296,31 +255,8 @@ pub const Value = union(enum) {
296255 .int = > | n | try writer .print ("{d}" , .{n }),
297256 .string = > | s | try writer .print ("\" {s}\" " , .{s }),
298257 .boolean = > | b | try writer .print ("{any}" , .{b }),
299- .function = > | f | switch (f ) {
300- .user = > | u | try writer .print ("fn<{s}>" , .{u .declaration .name .lexeme }),
301- .builtin = > | bi | try writer .print ("fn<{s}>" , .{bi .name }),
302- .struct_constructor = > | sc | try writer .print ("fn<{s}>" , .{sc .name }),
303- },
304- .vm_function = > try writer .writeAll ("fn" ),
305258 .null = > try writer .writeAll ("null" ),
306259 .unit = > try writer .writeAll ("unit" ),
307- .struct_instance = > | si_ptr | {
308- const si = si_ptr .* ;
309- switch (si .kind ) {
310- .plain = > try writer .print ("<{s}>" , .{si .type_name }),
311- .case = > {
312- try writer .print ("{s}(" , .{si .type_name });
313- for (si .field_names , si .field_values , 0.. ) | name , value , i | {
314- if (i > 0 ) {
315- try writer .writeAll (", " );
316- }
317- try writer .print ("{s}=" , .{name });
318- try value .format (writer );
319- }
320- try writer .writeAll (")" );
321- },
322- }
323- },
324260 }
325261 }
326262};
0 commit comments