3 I want to have a language where '//' is a token - integer division.
4 I want three options in scanner:
5 1/ parse the comment and report it as a token
6 2/ parse the comment and don't report it as a token (i.e. 'ignored')
7 3/ don't parse it, report as TK_mark
9 This could apply separately for "#" and "//" and "/*". But I only have two
10 type: TK_comment and TK_line_comment.
12 I could list these as 'known' but that prevents "///" being recognised
16 How to split values from type so they can be small - only one type
17 pointer for an array, for example.
18 Currently a "value" contains both a 'type' and a union of options:
19 str, num, bool, label, array(recursive), structure
20 where some of these include type information.
22 To split this I need to keep type and attach it to a var and pass
23 around with a value. So that value needs to be a pointer to a union?
27 I need to have transient values - registers? - for holding the
28 intermediate result of a computation before assigning to a variable.
29 This is/was 'struct lrval' which was a val and a *lval.
30 Now that a 'struct value' is always a pointer, the 'struct value' can be
31 either the rval or lval, but I need to be able to store
32 content as well - the old 'struct value val'.
33 Maybe I want 'struct value' to still contain the thing (not a pointer)
34 and use 'char ptr[1]' for generic content.
37 arrays can have a 'const' as the size - and they can be calculated
38 from the current value of variables. So how do we allocate them?
39 In particular, how do we handle them appearing in recursive functions?
41 For variables with a fixed size - known at function-start at least -
42 we can allocate a stack frame for all of them, and the index off
44 I guess var-sized arrays have a pointer in the stack frame, are
45 allocated when they come into scope, and freed when they go out.
47 So I need var-alloc for these to be quite different to other vars
48 All vars need to be initialized when they come into scope, and
51 Currently we initialise or re-initialised when entering scope,
52 and only free when exiting program
55 With the beginnings of working functions, and the pending introduction
56 of reference, I need to have a clear understand of function parameter
57 passing: by value or by reference. How are complex return values
61 intrinsics: numbers strings bool etc
63 arrays - of static known size
64 array slices - of runtime-known size
65 references? Are these just intrinsics?
67 Array slices are easy. They cannot be passed in by value, and cannot
68 easily be passed out. So they always are just references.
69 Passing the array-slice by reference - so the pointer and size can be
70 change - makes no sense.
72 Ditto for references - for the same reason.
74 So it is likely best to treat arrays the same way - as slices.
76 So for arrays, slices, and references, we copy in the pointer (and
77 size), and that is all we copy out.
78 For intrinsics we always copy the whole thing. For strings we do that
79 for now, but maybe change later. As they are immutable it doesn't
82 So that just leave structs.
83 If the function wants a pointer, we take a reference. Otherwise the
84 function gets to take a copy.
85 i.e. always pass structures by reference, but if the function says it
86 wants just the structure, it transparently copies the content.
88 A related question involves arrays in structs.
89 We want a struct to be able to contain an array of fixed size, and
90 also slices - which need to be references. How does this work?
95 Do we allow one array with local-constant size which gets allocated
96 at the end? Do we allow several and hide the math?
98 That all sounds good, but does it work?
99 A case where a ref to a ref is wanted is with linked lists.
100 The insertion point can be in the head, or in a member.
101 To have a function do the insertion, I need to pass a ref to the
102 insertion point, and I don't want 'if head do this, if member do that'
105 But nor do I really want to allow references to references.
107 Maybe I required the 'next' pointer to be a struct containing just a
110 This makes it a little bit harder, which might be a good thing.
111 It also makes the syntax cleaner. A ref is always passed by value,
112 a struct is always by ref, but might be copied.
114 Array is always by ref.
116 Returning a struct.... that is more interesting.
119 I'm trying to make returning a struct work, and I'm confusing myself.
121 I want interp_exec to optionally take a value* into which it can
122 copy a value - but only if the value would otherwise be destroyed.
123 This is because the alternative is to dup into there, and some things
124 cannot be duped. This could be used for
125 - funcalls, where the value is in the stack about to be destroy
126 - anything that produced a temporary value.
127 But the destination needs to be initialised, so it needs to be "->free"d first.
129 So _interp_exec must always be past a dest buffer. It can be a temp in which
130 case type is NULL, else it is a variable and dtype is provided.
133 1/put a value in rvtype and rv/lrv or
134 2/put a value in ret or
135 3/copy value to dest, and leave rvtype and ret.type as NULL.
137 2,3 are achieved by "ret = _interp_exec(... dest, dtype)
140 Assign can pass in dest/dtype. If an interp cases uses it (only Funcall)
141 it must ->free the var, then copy or dup content into it, and set
142 rvtype to NULL. "use" does not copy to dest, and we don't pass it through
146 How to pack local variables into a stack frame.
147 I cannot do it until after analysis as that is when I'll know the type and size.
148 I want to know what can overlap. And I want to know what is in which
149 function. These are essentially the same thing as functions overlap.
150 I already have a 'depth' - and a next_free list.
151 I could assign sequence numbers to scopes and store start/end
152 I want to do a depth-first walk of the scope tree, and reset the
156 propagate_types() returns a type, but this isn't really enough.
157 It also receives and sets flags, but these are confused.
159 - was there an error - should be give up
160 - was there progress - should we try again
161 - Is Bool a valid alternative to 'type' - attribute of type passed in
162 - Is value and lval - or constlval - attribute of type returned
163 - Can value be calculated at compile time - attribute of type returned.
164 - Can value be memcopied - will be freed if not used. ?? attribute of type returned.