From 509e0c8cd5c64e608032aa95a51dd5096185c338 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 10 Nov 2021 21:36:24 +1100 Subject: [PATCH 1/1] updates --- 00-TODO | 11 +++++++++++ Diary | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ Ocean-IO | 33 ++++++++++++++++++++++++++++++++ Ocean-methods | 35 ++++++++++++++++++++++++++++++++++ Ocean-numbers | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 179 insertions(+) create mode 100644 Diary create mode 100644 Ocean-IO create mode 100644 Ocean-methods create mode 100644 Ocean-numbers diff --git a/00-TODO b/00-TODO index ac474b2..13ea9e6 100644 --- a/00-TODO +++ b/00-TODO @@ -1,6 +1,17 @@ This is a living document - delete things when done. Avoid discussion. Current version (Cataract Creek) +- functions to return type with 'use' +- functions to return structure with name assignment - bare 'use'? +- '?' prefix operator returns Boolean +- reference to struct (@foo), with @new, @free, @nil +- more number types, no units yet + +Later +- string manipulation +- file i/o +- enum +- basic methods - structs - const fields ... what does that mean? Assign once as initialization? Can be used for array size? What else? diff --git a/Diary b/Diary new file mode 100644 index 0000000..daa26f8 --- /dev/null +++ b/Diary @@ -0,0 +1,52 @@ +06oct2020 + +I want to have a language where '//' is a token - integer division. +I want three options in scanner: + 1/ parse the comment and report it as a token + 2/ parse the comment and don't report it as a token (i.e. 'ignored') + 3/ don't parse it, report as TK_mark + +This could apply separately for "#" and "//" and "/*". But I only have two +type: TK_comment and TK_line_comment. + +I could list these as 'known' but that prevents "///" being recognised +as a mark. + +12mar2021 +How to split values from type so they can be small - only one type + pointer for an array, for example. +Currently a "value" contains both a 'type' and a union of options: + str, num, bool, label, array(recursive), structure +where some of these include type information. + +To split this I need to keep type and attach it to a var and pass +around with a value. So that value needs to be a pointer to a union? +And a size in bytes? + +17mar2021 + I need to have transient values - registers? - for holding the + intermediate result of a computation before assigning to a variable. + This is/was 'struct lrval' which was a val and a *lval. + Now that a 'struct value' is always a pointer, the 'struct value' can be + either the rval or lval, but I need to be able to store + content as well - the old 'struct value val'. + Maybe I want 'struct value' to still contain the thing (not a pointer) + and use 'char ptr[1]' for generic content. + +10oct2021 + arrays can have a 'const' as the size - and they can be calculated + from the current value of variables. So how do we allocate them? + In particular, how do we handle them appearing in recursive functions? + + For variables with a fixed size - known at function-start at least - + we can allocate a stack frame for all of them, and the index off + the stack frame. + I guess var-sized arrays have a pointer in the stack frame, are + allocated when they come into scope, and freed when they go out. + + So I need var-alloc for these to be quite different to other vars + All vars need to be initialized when they come into scope, and + de-initialized. + + Currently we initialise or re-initialised when entering scope, + and only free when exiting program diff --git a/Ocean-IO b/Ocean-IO new file mode 100644 index 0000000..ed8a608 --- /dev/null +++ b/Ocean-IO @@ -0,0 +1,33 @@ +file io + +File io will use methods on a file object. some are obvious like +binary read/write once we have records and text once we have string buffers. + +An interesting aspect is sprintf functionality, which isn't necessarily +file related at all. + +In C the format provides + - min width and alignment + - precision aka max width of some part + - data type: int long pointer float etc + - conversion style: caps base padchar + +some of these can come from numeric args. + +In ocean there is a conversion interface that accepts width, precision and +style. Only things with this interface can be formatted. +Interface can be called directly. It returns a string with same interface +Format string can contain same info and method will be called on each +arg as appropriate. +So a value can be formatted twice, once by explicit call to method once +by implicit. + +function can register a compile-time handler to verify the format string + +Everything from % to a space is processed. + - leading - means left justify + - 0 means 0 pad + - N means min width + - .M means precision + - $P means which arg + - remainder is style diff --git a/Ocean-methods b/Ocean-methods new file mode 100644 index 0000000..8876f55 --- /dev/null +++ b/Ocean-methods @@ -0,0 +1,35 @@ +Methods in Ocean + +methods are any function that is found from a given value. +It can be associated with the type or the value + +An interface is a set of methods. A concrete type can export an +interface and a formal type can require an interface. + +A value can be combined with a concrete interface to override or augment +what it's type natively has. Value methods are not so easily +overridden. + +The first arg of a method must match the owner, and other args can be of +that type + +Interface names are per module. +Method names are per interface. When a variable supports multiple +interfaces and names don't conflict, interface name can be left out. + +maybe value method use . and type methods use : ?? + that would make "case functionname :" tricky to parse. + + +Thought: + Rather than anon structs, allow struct AND references to be marked as 'follow' + so anything behind the object appears in the parent. + Then foo.method can possible follow a chain of pointers from foo to find the method. + + foo might be an inode and have a pointer to a superblock, which has a + pointer to a methods struture contains 'getattr'. Then 'foo.getattr' + transparently becomes 'foo.super.super_methods.getattr. + + Question. In what circumstances is 'foo' passed as first argument? + Probably it happens by default, but some syntactic escape allows something else + to be passed. Maybe foo::something() ?? diff --git a/Ocean-numbers b/Ocean-numbers new file mode 100644 index 0000000..85b78b3 --- /dev/null +++ b/Ocean-numbers @@ -0,0 +1,48 @@ +Numeric types in ocean... + +Currently (nov 2021) I have 'number' which is arbitrary precision rational. + +I obviously need more. + +I need to be able to specify range of numbers, at least in structs/arrays. +This includes: + number of bits, or maximum + whether signed + floating-point options + +I need to know if overflow wraps, clips, or errors. +Certainly I need cyclic unsigned numbers. +Others probably need to report an error if correctness cannot +be proved. +Errors can be ignored, but this must be explicit. + +So: integer, natural, cyclic, floating + +These can abbreviate to 3 letters or 1 with a number + int nat i8 c32 f32 f64 + +Units can be included as suffix of literal (30cm) or attribute of +type (i32/cm) +units and combinations are declared + units cm kg m/s=mps +addition requires matching units or unitless +multiplication combines units if known to be valid + +Track range of varables and decide type based on range when not explicit? + +Need a notion of flag sets + +set foo + bar, bat, bat + +x : foo +.bar can be added to or remove from x +x.bar tests and can be assigned like a bool. +x + .bat can set + + +enum bar + a, b, c + +can use .a when context confirms type + -- 2.43.0