Topological sort: Difference between revisions
Content added Content deleted
Line 512: | Line 512: | ||
staload UN = "prelude/SATS/unsafe.sats" |
staload UN = "prelude/SATS/unsafe.sats" |
||
(* Macros for list construction. *) |
|||
#define NIL list_nil () |
#define NIL list_nil () |
||
#define :: list_cons |
#define :: list_cons |
||
(*------------------------------------------------------------------*) |
|||
(* A shorthand for list reversal. This could also have been written as |
(* A shorthand for list reversal. This could also have been written as |
||
⚫ | |||
a macro, and less verbosely, but a template function usually is |
|||
⚫ | |||
fn {a : t@ype} |
fn {a : t@ype} |
||
rev {n : int} |
rev {n : int} |
||
Line 525: | Line 527: | ||
that result to a "regular" list. *) |
that result to a "regular" list. *) |
||
list_vt2t (list_reverse<a> lst) |
list_vt2t (list_reverse<a> lst) |
||
(*------------------------------------------------------------------*) |
|||
(* Some shorthands for string operations. These are written as |
|||
macros. *) |
|||
macdef substr (s, i, n) = |
|||
(* string_make_substring returns a linear strnptr, but we want a |
|||
"regular" string. *) |
|||
⚫ | |||
macdef copystr (s) = |
|||
(* string0 copy returns a linear strptr, but we want a "regular" |
|||
string. *) |
|||
strptr2string (string0_copy (,(s))) |
|||
(*------------------------------------------------------------------*) |
(*------------------------------------------------------------------*) |
||
Line 676: | Line 692: | ||
val j = skip_ident (text, n, i) |
val j = skip_ident (text, n, i) |
||
val () = $effmask_exn assertloc (i < j) |
val () = $effmask_exn assertloc (i < j) |
||
val nodename = |
val nodename = substr (text, i, j - i) |
||
strnptr2string |
|||
⚫ | |||
in |
in |
||
loop (nodename :: row, j) |
loop (nodename :: row, j) |
||
Line 742: | Line 756: | ||
c := $extfcall (int, "getchar") |
c := $extfcall (int, "getchar") |
||
end; |
end; |
||
copystr ($UN.cast{string} (addr@ buf)) |
|||
end |
end |
||
Line 1,127: | Line 1,141: | ||
nodenames_array[i] |
nodenames_array[i] |
||
(* A shorthand |
(* A shorthand for mapping from nodenum to string. *) |
||
defined above as a template function instead of a macro. *) |
|||
macdef map (lst) = |
macdef map (lst) = |
||
list_vt2t (list_map<nodenum n><String1> ,(lst)) |
list_vt2t (list_map<nodenum n><String1> ,(lst)) |