]> ocean-lang.org Git - ocean-D/blob - Diary
updates
[ocean-D] / Diary
1 06oct2020
2
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
8
9 This could apply separately for "#" and "//" and "/*".  But I only have two
10 type: TK_comment and TK_line_comment.
11
12 I could list these as 'known' but that prevents "///" being recognised
13 as a mark.
14
15 12mar2021
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.
21
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?
24 And a size in bytes?
25
26 17mar2021
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.
35
36 10oct2021
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?
40
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
43  the stack frame.
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.
46
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
49  de-initialized.
50
51  Currently we initialise or re-initialised when entering scope,
52  and only free when exiting program
53
54 13nov2021
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
58  handled?
59
60  This needs to cover:
61    intrinsics: numbers strings bool etc
62    structs (and records)
63    arrays - of static known size
64    array slices - of runtime-known size
65    references?  Are these just intrinsics?
66
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.
71
72  Ditto for references - for the same reason.
73
74  So it is likely best to treat arrays the same way - as slices.
75
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
80  matter much.
81
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.
87
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?
91   struct foo
92       array:[size]member
93       slice:@[size]member
94
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?
97
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'
103  code.
104
105  But nor do I really want to allow references to references.
106
107  Maybe I required the 'next' pointer to be a struct containing just a
108  reference.
109  
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.
113
114  Array is always by ref.
115
116  Returning a struct.... that is more interesting.
117
118 15nov2021
119  I'm trying to make returning a struct work, and I'm confusing myself.
120
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.
128
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.
131
132  interp cases can:
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.
136
137    2,3 are achieved by "ret = _interp_exec(... dest, dtype)
138
139  I'm over-thinking.
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
143  blocks.
144
145 17nov2021
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
153  offset as I step up.