1 I want to add functions and procedures soon. I should decide on syntax
4 The args to a function are effectively a struct, so I want it to look
5 the same. C doesn't allow "int a, b, c" in the parameters, which I
6 think is clumsy. struct can be
21 A procedure is different as it doesn't have just a return type,
22 it has a return structure. So many C functions have 'ret' or 'result'
23 variable that it might be nice to follow the Pascal approach of
24 assigning to the function name?? or having
33 A shorter version would be
35 func name(args:types;args:types):type { }
37 func name(args:types;args:types):(result:type;...) {}
40 Can arguments be optional?
41 - yes, if "= value" follows the type
42 Can we have variable number of args
43 - yes. Any arg can be an inline-array. The last arg can
44 have undefined length [].
45 Can named args be passed in
46 - yes, once I have a syntax for manifest structs
48 Arrays seem very different from structs.
49 - they don't have names (as types)
50 - they don't need grouping in function params??
51 Does this make any sense?
52 Maybe I should require the grouping
53 printf("%d %d %d", (1,2,3))
57 Functions can be used before being declared - analysis happens after all is read.
59 'main' is given an array of strings of unknown length.
60 So I need the formal parameter to accept variable-length arrays.
63 and support "argv.len", or do I use
65 which instantiates argc with the length?
68 Arrays have to be passed by reference, they are const if :: used for type.
70 Strings and numbers are immutable.
72 So I need functions to turn strings into number or bool.
73 Just bool() and number() for now.
75 DONE 1/ change 'program' to make everything a string, and use functions to get numbers.
76 DONE 2/ change 'program' to receive an array with bindably size
77 DONE 3/ change 'program' to 'func main' etc
78 DONE4/ allow more functions.
80 What syntax to use for formal types?
81 I will need type parameterisation some day. For now I just need the
82 size of an array to be parameterised.
84 looks like normal type. But it isn't clear if argc is a global constant
87 seem redunant because of course the array index is an int.
90 It is like leaving out the type is
93 So let's go with that.
96 DONE To handle functions, and recursion in particular, I need a concept of a
97 stack frame in the interpreter. This needs to include room for
98 parameters and results and local variables. So a function needs to know
99 the size of its frame, and each variable needs an offset.
100 So I need to switch 'program' over to this approach before adding
102 Then the function frame will have a results frame separate from the
103 main frame, as it can last longer. So each variable needs to be marked