]> ocean-lang.org Git - ocean-D/commitdiff
updates
authorNeilBrown <neilb@suse.com>
Wed, 1 May 2019 09:02:57 +0000 (19:02 +1000)
committerNeilBrown <neilb@suse.com>
Wed, 1 May 2019 09:02:57 +0000 (19:02 +1000)
Ocean-types

index b29b64c2729192aac89af8a010d8cf502e3b1f64..c25bd1be7ca16f3a9b418f97e7d938b8917e36f7 100644 (file)
@@ -24,6 +24,19 @@ Types can be constructed with
    (args:: args)  procedure type
    (args:: type)    function type
 
    (args:: args)  procedure type
    (args:: type)    function type
 
+  I think that for pointer/array constructor, the decoration comes first.
+    foo: [5]int
+  is an array of 5 integers, so foo[5] is an int
+    foo: @bar
+  is an owned pointer to bar, so "foo@" is a bar.
+    foo: @[5]int
+  is an owner pointer to 5 integers while
+    foo:[5]^int
+  is an array of 5 borrowed pointers to integers.
+  Having the result type at the end fits better with the function type.
+   foo:(int, int)string
+  then foo(1,2) returns a string.
+
 
 The content of struct and record are a list of:
    fieldname: type
 
 The content of struct and record are a list of:
    fieldname: type
@@ -188,6 +201,9 @@ I need a list of steps again:
 
  - Add arrays:
       name : type[size]
 
  - Add arrays:
       name : type[size]
+        e.g. int[4] or foo@[3]
+          What is int[5][20] ?? it is an array of int[5], which is backwards.
+          So maybe I want [5][20]int ??
     declares an array of that type/size
       name : [] = [ 1,2,3 ]
     declares an array of 3 numbers.
     declares an array of that type/size
       name : [] = [ 1,2,3 ]
     declares an array of 3 numbers.
@@ -221,3 +237,44 @@ Questions:
   If I declare "struct foo ..." do I use "foo" or "struct foo" to ref the type?
   I think just "foo".
   So structs, records, enums, and classes must have distinct names.
   If I declare "struct foo ..." do I use "foo" or "struct foo" to ref the type?
   I think just "foo".
   So structs, records, enums, and classes must have distinct names.
+
+ When do I differentiate between compile-time constants and run-time values?
+ When declaring an array, do I require the size to be constant?
+ In a struct I do ... at time of declaration I calculate the size.
+ For foo:[sqr(a)]int
+ I do that too - and it is at run-time.
+ So during parsing, I need to describe the array with a member-type and executable size.
+ When that is evaluated, a type is created.
+ So we really need an executable which returns a type.
+ But ... we need to know the type when doing type analysis.  So while variable size
+ is OK, the compiler needs to know what it is.  Maybe the size needs to be a constant, as in
+ a names assiged with "size ::= 4*5".  This gives the compiler some chance of comparing
+ types of array - and doing range checking on indexes.
+
+ We currently call var_init to set the type of a variable during type
+ analysis - which makes sense.
+ But for an array we don't have the final type until run-time.  So we need an
+ intermediate type.
+ So (for now) the size of an array is either a NUMBER or an IDENTIFIER which must be a
+  constant var.
+ I need a point where the type is instantiated - where the variable is evaluated
+  and the size is set.  I guess this happens when the 'struct var' is evaluated...
+  no, when a Declare binode is evaluated.
+
+ What happens if I have
+    a:[foo]number = thing
+ I guess the type analysis needs to afirm that thing has the correct type,
+ then a doesn't need to be initialized.
+
+ If I find
+    a[4] = "hello"
+ and 'a' hasn't been declared .... obviously an error.
+
+ When/what/how.
+  For field access, I need to know the type of the variable.
+  But I can delay the look up until type analysis.
+  So a[4] is Index(a, 4) - a binode
+     a.foo is Field(a, "foo") -  need a new exec type - Fieldname
+     a(args) is Call(a, args) - need a new Binode type - Tuple.
+
+So I have to delay 'const' assessment to later too.