]> ocean-lang.org Git - ocean-D/blobdiff - Diary
updates
[ocean-D] / Diary
diff --git a/Diary b/Diary
index daa26f8bd9664c516e6d640634113e9c3d0c0df9..c6afd1b9b78ce67b12da83f1b36dc75f69b1bb69 100644 (file)
--- a/Diary
+++ b/Diary
@@ -50,3 +50,104 @@ And a size in bytes?
 
  Currently we initialise or re-initialised when entering scope,
  and only free when exiting program
+
+13nov2021
+ With the beginnings of working functions, and the pending introduction
+ of reference, I need to have a clear understand of function parameter
+ passing: by value or by reference.  How are complex return values
+ handled?
+
+ This needs to cover:
+   intrinsics: numbers strings bool etc
+   structs (and records)
+   arrays - of static known size
+   array slices - of runtime-known size
+   references?  Are these just intrinsics?
+
+ Array slices are easy.  They cannot be passed in by value, and cannot 
+ easily be passed out.  So they always are just references.
+ Passing the array-slice by reference - so the pointer and size can be
+ change - makes no sense.
+
+ Ditto for references - for the same reason.
+
+ So it is likely best to treat arrays the same way - as slices.
+
+ So for arrays, slices, and references, we copy in the pointer (and
+ size), and that is all we copy out.
+ For intrinsics we always copy the whole thing.  For strings we do that
+ for now, but maybe change later.  As they are immutable it doesn't
+ matter much.
+
+ So that just leave structs.
+ If the function wants a pointer, we take a reference.  Otherwise the
+ function gets to take a copy.
+ i.e.  always pass structures by reference, but if the function says it
+ wants just the structure, it transparently copies the content.
+
+ A related question involves arrays in structs.
+  We want a struct to be able to contain an array of fixed size, and
+  also slices - which need to be references.  How does this work?
+  struct foo
+      array:[size]member
+      slice:@[size]member
+
+  Do we allow one array with local-constant size which gets allocated
+  at the end?  Do we allow several and hide the math?
+
+ That all sounds good, but does it work?
+ A case where a ref to a ref is wanted is with linked lists.
+ The insertion point can be in the head, or in a member.
+ To have a function do the insertion, I need to pass a ref to the
+ insertion point, and I don't want 'if head do this, if member do that'
+ code.
+
+ But nor do I really want to allow references to references.
+
+ Maybe I required the 'next' pointer to be a struct containing just a
+ reference.
+ This makes it a little bit harder, which might be a good thing.
+ It also makes the syntax cleaner.  A ref is always passed by value,
+ a struct is always by ref, but might be copied.
+
+ Array is always by ref.
+
+ Returning a struct.... that is more interesting.
+
+15nov2021
+ I'm trying to make returning a struct work, and I'm confusing myself.
+
+ I want interp_exec to optionally take a value* into which it can
+ copy a value - but only if the value would otherwise be destroyed.
+ This is because the alternative is to dup into there, and some things
+ cannot be duped.  This could be used for
+  - funcalls, where the value is in the stack about to be destroy
+  - anything that produced a temporary value.
+ But the destination needs to be initialised, so it needs to be "->free"d first.
+
+ So _interp_exec must always be past a dest buffer.  It can be a temp in which
+ case type is NULL, else it is a variable and dtype is provided.
+
+ interp cases can:
+   1/put a value in rvtype and rv/lrv or
+   2/put a value in ret or
+   3/copy value to dest, and leave rvtype and ret.type as NULL.
+
+   2,3 are achieved by "ret = _interp_exec(... dest, dtype)
+
+ I'm over-thinking.
+ Assign can pass in dest/dtype.  If an interp cases uses it (only Funcall)
+ it must ->free the var, then copy or dup content into it, and set
+ rvtype to NULL.   "use" does not copy to dest, and we don't pass it through
+ blocks.
+
+17nov2021
+ How to pack local variables into a stack frame.
+ I cannot do it until after analysis as that is when I'll know the type and size.
+ I want to know what can overlap.  And I want to know what is in which
+ function.  These are essentially the same thing as functions overlap.
+ I already have a 'depth' - and a next_free list.
+ I could assign sequence numbers to scopes and store start/end
+ I want to do a depth-first walk of the scope tree, and reset the
+ offset as I step up.