Page 1 of 1

Stages 89-91

Posted: Tue Feb 15, 2022 9:01 pm
by frank
These stages were problematic. Due to a change in string reference counting, several string routines in the system library had to be partially rewritten. At the same time, support for the cref (constant reference) parameter qualifier was dropped because of too much complexity at the current stage.

Right now, most string assignment and passing, including function result, is supported for constant, variable and fixed length strings. Strings can be passed by reference (default), by value or by constant.

In addition, error reporting has been improved for (nested) include files.

Example of a parameter declared as const passed to another subroutine:

Code: Select all

decl sub test1(const p:str);
decl sub test2(p:str);

const c = "hello world";

main do
  test1(c);
end;

sub test1(const p:str)
do
  ' -1 because reference to constant string
  print(refc(p));
  ' passing const variable to normal string parameter, thus by value (copy)
  test2(p);
  ' descriptor of p destroyed here
end;

sub test2(p:str)
do
  ' p is variable length string, either a reference or a copy depending on the string passed
  ' if a constant is passed, as in this example, a copy is passed and reference count is 1
  print(refc(p));
  ' string p deallocated here
end;
It is also possible to directly return the result of a function:

Code: Select all

decl func test1():str;
decl func test2():str;

const c = "hello world";

main do
  print(test2());
  ' string result of test2 deallocated here
end;

func test1():str
  ' assign global constant to local string
  dim s:str = c;
do
  ' function result
  test1 = s;
  ' string s deallocated here
end;

func test2():str
do
  ' function result (descriptor address from test1 is passed to test2
  test2 = test1();
end;