Skip to content

Commit

Permalink
Did a few things:
Browse files Browse the repository at this point in the history
+ Added build scripts; Offered a fix for emacs mode;
+ Added a TODO markdown for keeping track of things;
+ In `irCheck.ml` a variable named effect needed to be renamed as that is reserved in ocaml now
+ Moved `abs` from Prelude to `lib.ml` to take advantage of pattern matching related OCaml types so it can be ad hoc
+ And started writing some tests
  • Loading branch information
yung-turabian committed Feb 8, 2025
1 parent 175be34 commit c49bc11
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 15 deletions.
18 changes: 18 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# TODO (yung-turabian)

<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 1182532d (Bits)
- [-] Add some test cases.
- [ ] Have type inference convert, for example, int to float in a operation like 2.0 + 2? Hide behind an experimental guard if so.
- [ ] Singleton kinds, they classify type cons by reavling their identity.
- [ ] Higher singletons, S(c :: k) where k is a kind and c is a constructor of kind k.
<<<<<<< HEAD
- [ ] If given the ability to create new subkinds, then just force the creation to derive from one of the three 'base' (Type, Row, Presnece) or even one of their subkinds such as "Base."
=======
- [ ] Add some test cases.
>>>>>>> 1765e705 (Created TODO.md)
=======
- [ ] If given the ability to create new subkinds, then just force the creation to derive from one of the three 'base' (Type, Row, Presnece) or even one of their subkinds such as "Base."
>>>>>>> 1182532d (Bits)
5 changes: 5 additions & 0 deletions bld.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

dune build
mv _build/default/bin/links.exe links

6 changes: 3 additions & 3 deletions core/irCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1053,11 +1053,11 @@ struct
(* For each case branch, the corresponding entry goes directly into the field spec map of the inner effect row *)
let inner_effects_map_from_branches = StringMap.map (fun x -> Present x) branch_presence_spec_types in
(* We now add all entries from the outer effects that were not touched by the handler to the inner effects *)
let inner_effects_map = StringMap.fold (fun effect outer_presence_spec map ->
if StringMap.mem effect inner_effects_map_from_branches then
let inner_effects_map = StringMap.fold (fun effect' outer_presence_spec map ->
if StringMap.mem effect' inner_effects_map_from_branches then
map
else
StringMap.add effect outer_presence_spec map
StringMap.add effect' outer_presence_spec map
) inner_effects_map_from_branches outer_effects_map in
let inner_effects = Row (inner_effects_map, outer_effects_var, outer_effects_dualized) in

Expand Down
28 changes: 19 additions & 9 deletions core/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ let project_datetime (f: CalendarShow.t -> int) : located_primitive * Types.data


let env : (string * (located_primitive * Types.datatype * pure)) list = [
"+", numeric_op ( + ) ( +. ) PURE PURE;
"-", numeric_op ( - ) ( -. ) PURE PURE;
"*", numeric_op ( * ) ( *. ) PURE PURE;
"/", numeric_op ( / ) ( /. ) IMPURE PURE;
"^", numeric_op (pow) ( ** ) PURE PURE;
"+", numeric_op ( + ) ( +. ) PURE PURE;
"-", numeric_op ( - ) ( -. ) PURE PURE;
"*", numeric_op ( * ) ( *. ) PURE PURE;
"/", numeric_op ( / ) ( /. ) IMPURE PURE;
"^", numeric_op (pow) ( ** ) PURE PURE;

"mod", int_op ( mod ) IMPURE;

Expand All @@ -260,6 +260,16 @@ let env : (string * (located_primitive * Types.datatype * pure)) list = [

"^^", string_op ( ^ ) PURE;

(* moved abs to make use of ad hoc ability,
ideally there could be a way to bootstrap prelude similar to #786 *)
"abs",
(p1 (fun n -> match n with
| `Int _ -> Value.box_int ( let x = (Value.unbox_int n) in if x > 0 then x else -x )
| `Float _ -> Value.box_float ( let x = (Value.unbox_float n) in if x > 0.0 then x else -.x )
| _ -> raise (runtime_type_error ("Cannot computer absolute value: " ^ Value.string_of_value n))),
datatype "(a::Numeric) -> a",
PURE);

"max_int",
(Value.box_int max_int,
datatype "Int",
Expand Down Expand Up @@ -750,10 +760,10 @@ let env : (string * (located_primitive * Types.datatype * pure)) list = [
PURE);

"negate",
(p1 (fun i -> match i with
| `Int _ -> Value.box_int (- (Value.unbox_int i))
| `Float _ -> Value.box_float (-. (Value.unbox_float i))
| _ -> raise (runtime_type_error ("Cannot negate: " ^ Value.string_of_value i))),
(p1 (fun n -> match n with
| `Int _ -> Value.box_int (- (Value.unbox_int n))
| `Float _ -> Value.box_float (-. (Value.unbox_float n))
| _ -> raise (runtime_type_error ("Cannot negate: " ^ Value.string_of_value n))),
datatype "(a::Numeric) -> a",
PURE);

Expand Down
4 changes: 4 additions & 0 deletions ins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/bash

dune build
sudo mv _build/default/bin/links.exe /usr/local/bin/links
20 changes: 20 additions & 0 deletions links-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@
st))

;; Can be generated with `links --print-keywords`.
<<<<<<< HEAD
(defconst links-backup-keywords
=======
;; TODO We should do that automatically as part of the build process somehow.

;; ./links --print-keywords | awk '{ print "\""$0"\""}'
(defconst links-keywords
>>>>>>> 7518d311 (Fixing emacs script)
'(
"alien"
"as"
Expand Down Expand Up @@ -121,6 +127,20 @@
"with"
))

;;; Added by yung-turabian 2025
(defconst links-keywords
; Not the best test
(if (string-equal
(shell-command-to-string (concat links-executable " --version"))
"Links version 0.9.9 (Burghmuirhead)\n"
)
(split-string
(shell-command-to-string (concat links-executable " --print-keywords"))
"\n" " ")
links-backup-keywords)
)


(defconst links-font-lock-keywords
(list
;; comments
Expand Down
3 changes: 0 additions & 3 deletions prelude.links
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ fun dropWhile(pred, list) {
# else 0
# }

fun abs(i) {
if (i < 0) -i else i
}

sig init : ([a]) ~> [a]
fun init(list) {
Expand Down
36 changes: 36 additions & 0 deletions tests/numeric-operations.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Addition and multiplication [1]
10 + 20 * 30
stdout : 610 : Int

Addition and multiplication [2]
20.0 * 30.0 + 10.0
stdout : 610.0 : Float

Addition, division, subtraction, and multiplication
100.50 + 200.20 / 10.10 - 3.10 * 10.10
stdout : 89.0117821782 : Float

Inproper usage
2 - 3.3
stderr : @..*
exit : 1

Absolute value of integer
abs(-9)
stdout : 9 : Int

Absolute value of float
abs(-9.54)
stdout : 9.54 : Float

Prefix notation
{var plus = (+); plus(1.5, (+)(2.5,3.5))}
stdout : 7.5 : Float

Unary minus
(-1)
stdout : -1 : Int

Unary float minus
(-1.0)
stdout : -1.0 : Float

0 comments on commit c49bc11

Please sign in to comment.