Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1.31 KB

File metadata and controls

41 lines (29 loc) · 1.31 KB

Print

When all you want to do is see something…

Use print keyword to begin a list of expressions whose results will be printed.

print 42; will print 42 to standard out (or whatever you’ve defined the int formatter to do).

How it works

print is sort of like a fancy macro. It just gets converted into other code. Specifically, it is as if each argument is applied to one of the following templates. What template the argument is applied to depends on the type of the argument.

NOTE: Expansions may not match exactly; see sema_templates.g (embedded in Glint’s sema.cc).

For a byte argument:

putchar arg;

For a [byte] (dynamic array of byte), [byte view] (array view of byte), or [byte 4] (fixed array of byte) argument:

cfor
    i :: 0;
    i < arg.size;
    i += 1;
  putchar @arg[i];

NOTE: Still unsure if fixed array of byte should call putchar on each element or just call puts

For a byte.ptr argument:

puts arg;

For a void argument: a void argument to print is an error.

For every other type argument, insert a call to format (defined by user), print the returned dynamic byte array, and then free the dynamic array.

{tmp :: format(arg); print tmp; -tmp;};