Skip to content

Commit 22d5b5e

Browse files
authored
Merge pull request #88 from TroupeLang/revert-84-fork/dev/lib-cleanup
Revert "lib/ cleanup"
2 parents cc0dd3f + ce27f3a commit 22d5b5e

File tree

232 files changed

+2412
-1028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+2412
-1028
lines changed

compiler/src/AddAmbientMethods.hs

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,47 @@
11
-- 2020-05-17, AA
22

33
-- HACK
4-
--
5-
-- This module add a number of standard ambient methods such as `print` to the beginning of the
6-
-- file. This provides some backward compatibility with prior test cases as well as minimizes some
7-
-- clutter.
8-
--
9-
-- If these methods are unused they are eliminated by the optimization passes in the further passes.
10-
11-
-- TODO
12-
--
13-
-- Move this into a '.trp' file of the form
14-
--
15-
-- ```
16-
-- let fun print x = fwrite (stdout authority, (toString x) ^"\n")
17-
-- ...
18-
-- in () end
19-
-- ```
20-
--
21-
-- Which, similar to below, after parsing has the `dummy` value replaced by the actual program. This
22-
-- preamble can then be specified at compile-time.
23-
24-
module AddAmbientMethods(addAmbientMethods) where
4+
-- This module add a number of standard
5+
-- ambient methods such as `print` to the
6+
-- beginning of the file. This provides some
7+
-- backward compatibility with prior test cases
8+
-- as well as minimizes some clutter
9+
10+
-- If these methods are unused they are
11+
-- eliminated by the optimization passes in
12+
-- the further passes.
13+
14+
module AddAmbientMethods(addAmbientMethods) where
2515

2616
import Basics
27-
import Direct
17+
import Direct
2818
import TroupePositionInfo
2919

30-
printStringDecl :: FunDecl
31-
printStringDecl = FunDecl "printString"
20+
printDecl :: FunDecl
21+
printDecl = FunDecl "print"
3222
[Lambda [VarPattern "x"] $
33-
Let [ ValDecl (VarPattern "fd") (App (Var "stdout") [Var "authority"]) NoPos
34-
, ValDecl (VarPattern "x'") (Bin Concat (Var "x") (Lit $ LString "\\n")) NoPos
35-
]
36-
(App (Var "fwrite") [Tuple [Var "fd", Var "x'"]])
23+
Let [ValDecl (VarPattern "out") (App (Var "getStdout") [Var "authority"]) NoPos]
24+
(App (Var "fprintln") [Tuple [Var "out", Var "x"]])
3725
] NoPos
3826

39-
printDecl :: FunDecl
40-
printDecl = FunDecl "print"
41-
[Lambda [ VarPattern "x" ] $
42-
(App (Var "printString") [App (Var "toString") [Var "x"]])
27+
printWithLabelsDecl :: FunDecl
28+
printWithLabelsDecl = FunDecl "printWithLabels"
29+
[Lambda [VarPattern "x"] $
30+
Let [ValDecl (VarPattern "out") (App (Var "getStdout") [Var "authority"]) NoPos]
31+
(App (Var "fprintlnWithLabels") [Tuple [Var "out", Var "x"]])
4332
] NoPos
4433

45-
printLDecl :: FunDecl
46-
printLDecl = FunDecl "printL"
47-
[Lambda [ VarPattern "x" ] $
48-
(App (Var "printString") [App (Var "toStringL") [Var "x"]])
49-
] NoPos
5034

51-
inputLineDecl :: FunDecl
52-
inputLineDecl = FunDecl "inputLine"
53-
[Lambda [ VarPattern "_" ] $
54-
Let [ValDecl (VarPattern "fd") (App (Var "stdin") [Var "authority"]) NoPos]
55-
(App (Var "freadln") [App (Var "stdin") [Var "authority"]])
35+
printStringDecl :: FunDecl
36+
printStringDecl = FunDecl "printString"
37+
[Lambda [VarPattern "x"] $
38+
Let [ValDecl (VarPattern "out") (App (Var "getStdout") [Var "authority"]) NoPos]
39+
(App (Var "fwrite") [Tuple [Var "out", Bin Concat (Var "x") (Lit (LString "\\n"))]])
5640
] NoPos
5741

58-
addAmbientMethods :: Prog -> Prog
59-
addAmbientMethods (Prog imports atoms t) =
60-
let t' = Let [FunDecs [printStringDecl,printDecl,printLDecl,inputLineDecl]] t
61-
in Prog imports atoms t'
42+
43+
44+
addAmbientMethods :: Prog -> Prog
45+
addAmbientMethods (Prog imports atoms t) =
46+
let t' = Let [FunDecs [printDecl,printWithLabelsDecl,printStringDecl]] t
47+
in Prog imports atoms t'

compiler/src/IR.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ instance WellFormedIRCheck IRExpr where
261261
-- code over wire. Such malformed code would result
262262
-- in a JS output returning a runtime error (which should
263263
-- generally be avoided)
264-
if fname `elem`[
264+
if fname `elem`[
265265
"$$authorityarg"
266266
, "adv"
267267
, "ladv"
@@ -285,13 +285,16 @@ instance WellFormedIRCheck IRExpr where
285285
, "endorse"
286286
, "floor"
287287
, "flowsTo"
288-
, "freadln"
289-
, "fwrite"
288+
, "fprintln"
289+
, "fprintlnWithLabels"
290+
, "fwrite"
290291
, "getTime"
291292
, "getType"
292293
, "getNanoTime"
294+
, "getStdout"
293295
, "_getSystemProcess"
294296
, "guard"
297+
, "inputLine"
295298
, "intToString"
296299
, "listToTuple"
297300
, "lowermbox"
@@ -302,13 +305,13 @@ instance WellFormedIRCheck IRExpr where
302305
, "newlabel"
303306
, "node"
304307
, "_pc"
305-
, "_bl"
306308
, "pcpop"
307309
, "peek"
308310
, "pinipush"
309311
, "pinipushto"
310312
, "pinipop"
311313
, "pcpush"
314+
, "question"
312315
, "raisembox"
313316
, "raiseTrust"
314317
, "random"
@@ -330,9 +333,6 @@ instance WellFormedIRCheck IRExpr where
330333
, "spawn"
331334
, "sqrt"
332335
, "substring"
333-
, "stdin"
334-
, "stdout"
335-
, "stderr"
336336
, "stringToInt"
337337
, "strlen"
338338
, "restore"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import List
2-
printL (List.map ( fn i => i + 1) [1,2,3])
2+
printWithLabels (List.map ( fn i => i + 1) [1,2,3])
33

44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let fun foo () =
2-
receive [hn x => printL ("foo received", x)]
2+
receive [hn x => printWithLabels ("foo received", x)]
33
val p = spawn foo
44
in send (p, "hello")
55
end

examples/fromuserguide/basic_spawn.trp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import List
2-
let fun printwait x = let val _ = printL x in sleep 10 end
2+
let fun printwait x = let val _ = printWithLabels x in sleep 10 end
33
fun foo () = List.map printwait [1,2,3]
44
fun bar () = List.map printwait ["A", "B", "C"]
55
in (spawn foo, spawn bar)

examples/fromuserguide/basic_updateableserver.trp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import ThreadUtil
2-
1+
import timeout
32
let fun v_one n =
43
receive [ hn ("REQUEST", senderid) =>
54
let val _ = send (senderid, n)
@@ -27,8 +26,7 @@ let fun v_one n =
2726
val _ = send (service, ("UPDATE", v_two))
2827
val _ = send (service, ("COMPUTE", self(), fn x => x * x, 42))
2928
val _ = receive [ hn x => print x]
30-
in ThreadUtil.spawnTimeout (fn () => print "force terminating the server example after 1s";
31-
exit (authority, 0))
32-
1000
29+
in exitAfterTimeout
30+
authority 1000 0 "force terminating the server example after 1s"
3331
end
3432

examples/fromuserguide/ifc_type_labels.trp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ let val x = 100 raisedTo `{alice}`
55
val a = if y > 10 then z else "not an integer"
66
in a
77
end
8-
val _ = printL a
8+
val _ = printWithLabels a
99
val _ = debugpc()
1010
val w = a + x
11-
val _ = printL w
11+
val _ = printWithLabels w
1212
in debugpc()
1313
end
1414

lib/DeclassifyUtil.trp

Lines changed: 0 additions & 110 deletions
This file was deleted.

lib/Hash.trp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ let
1010
*)
1111
fun hashString s =
1212
(* String hash with fast paths for small strings *)
13-
let val len = String.size s
14-
val radix = 127
15-
val codeAt = String.sub' s
13+
let val len = strlen s
14+
val radix = 127
15+
fun charCodeAt i = String.subCode (s,i)
1616
in case len of 0 => 0
17-
| 1 => codeAt 0
18-
| 2 => (radix * codeAt 0 + codeAt 1) andb Number.maxInt32
17+
| 1 => charCodeAt 0
18+
| 2 => (radix * charCodeAt 0 + charCodeAt 1) andb Number.maxInt32
1919
| _ => let fun go idx acc =
2020
if len <= idx then acc
21-
else go (idx + 1) ((acc * radix + codeAt idx) andb Number.maxInt32)
21+
else go (idx + 1) ((acc * radix + charCodeAt idx) andb Number.maxInt32)
2222
in go 0 0
2323
end
2424
end

lib/List.trp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ let (* -- List Access -- *)
7272
(** Same as `List.map` but `f` is applied to the index of the element as first argument
7373
(counting from 0), and the element itself as second argument. Not tail-recursive. *)
7474
fun mapi f list =
75-
let fun mapi_aux j [] = []
76-
| mapi_aux j x::xs = (f (j,x)) :: (mapi_aux (j+1) xs)
77-
in mapi_aux 0 list
75+
let fun mapj j [] = []
76+
| mapj j x::xs = (f (j,x)) :: (mapj (j+1) xs)
77+
in mapj 0 list
7878
end
7979

8080
(* TODO: revMap *)
@@ -83,9 +83,6 @@ let (* -- List Access -- *)
8383
fun foldl f y [] = y
8484
| foldl f y x::xs = foldl f (f (x,y)) xs
8585

86-
(** Left-fold of `f` on a non-empty list using the head as the initial value. *)
87-
fun foldl1 f x::xs = foldl f x xs
88-
8986
(* TODO: foldr *)
9087

9188
(** Returns the sublist of elements that satisfy `f`. Not tail-recursive. *)
@@ -186,7 +183,6 @@ let (* -- List Access -- *)
186183
map,
187184
mapi,
188185
foldl,
189-
foldl1,
190186
filter,
191187
filteri,
192188
partition,

0 commit comments

Comments
 (0)