Skip to content

Commit

Permalink
Fixed fun lvalue refs; Added implicit refs; Updated README; Added mlp…
Browse files Browse the repository at this point in the history
…x tool.
  • Loading branch information
NICUP14 committed Sep 2, 2024
1 parent 635d56d commit 9d3c31f
Show file tree
Hide file tree
Showing 18 changed files with 513 additions and 210 deletions.
2 changes: 2 additions & 0 deletions BUG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Solved: 19/23

- [ ] `Parser.ref` does not implicit cast-to-ref (add `try_cast_ref`)
- [ ] Functions like `input` are predeferred.
- [X] Using an iterator `i` in a for loop does not compile correctly.
- [X] Nested UFCS expressions (s.equals("Hello".str))
- [X] The type of an overloaded function with a diff type than the first takes the type of the first overloaded function
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CFLAGS += -g
ML = python ../../src/Main.py
MLLIB ?= "../../include"
MLFLAGS ?=
MLFLAGS += -C -c
MLFLAGS += -C

# Recipes
default: clean def
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The language is designed to closely **match c features** along with some **zero-

## Goodies

* [RAII](QUICKSTART.md#raii)
* [Builtins](QUICKSTART.md#builtins)
* [Booleans](QUICKSTART.md#primitive-types)
* [References](QUICKSTART.md#reference-type)
Expand All @@ -46,6 +47,8 @@ The language is designed to closely **match c features** along with some **zero-
* [Imports](QUICKSTART.md#import-statements)
* [Namespaces](QUICKSTART.md#namespace-statements)
* [Hygienic macros](QUICKSTART.md#macros)
* [For-each loops](QUICKSTART.md#for-loops)
* Generic functions
* [Function overloading](QUICKSTART.md#function-overloading)
* [Uniform function call syntax (UFCS)](QUICKSTART.md#uniform-function-call-syntax-ufcs)
* [Multi-line statements](QUICKSTART.md#multi-line-statements)
Expand Down
48 changes: 26 additions & 22 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
# TODO

Solved: 20/32
Solved: 28/40

- [ ] Fix defers and variable assignments for control sturctures (`for`, ...)
- [X] Fix references causing errors in c backend (`&fun(...)`)
- [ ] Suggestive errors for non-existent members
- [X] Separate macro (`delimit(" " , args)`)
- [ ] Function pointer (`&my_fun`)
- [ ] Add for-loop & RAII documentation to QUICKSTART.
- [ ] Add roadmap to README.
- [ ] Add generic functions to QUICKSTART.
- [ ] Document `mlpx` in `MLPX.md` and add it to README.
- [ ] Create `inject_ref` to replace `inject_copy` for `Parser._fun_call`.
- [X] Fix defers and variable assignments for control sturctures (`for`, ...).
- [X] Fix references causing errors in c backend (`&fun(...)`).
- [ ] Suggestive errors for non-existent members.
- [X] Separate macro (`delimit(" " , args)`).
- [ ] Function pointer (`&my_fun`).
- [X] Add for-loop & RAII documentation to QUICKSTART.
- [ ] Improve safety and memory safety!
- [ ] Simplify compiling process (`compile.py`)
- [ ] Add block section to README
- [X] Add namespace section to README
- [X] Replace "minimal" by "easy to learn", "gentle curve" in README
- [X] Add section at the start of README about lang-specific features
- [ ] Add multi-lever pointers/refs. (vtype: List[ckind])
- [X] Simplify compiling process (`mlpx.py`)
- [ ] Add block section to README.
- [X] Add namespace section to README.
- [X] Replace "minimal" by "easy to learn", "gentle curve" in README.
- [X] Add section at the start of README about lang-specific features.
- [ ] Add multi-lever pointers/refs (vtype: List[ckind]).
- [ ] Add const, unsigned and floating point types.
- [X] `end` no longed needed at bottom of module.

- [ ] Global arrays.
- [X] C generator backend (CWalker.py)
- [X] ML generator backend (GenStr.py -> MLWalker.py)
- [ ] ASM generator backend (Gen.py -> GenASM.py)
- [X] C generator backend (CWalker.py).
- [X] ML generator backend (GenStr.py -> MLWalker.py).
- [ ] ASM generator backend (Gen.py -> GenASM.py).
- [X] Fix type system.
- [X] Widen during parsing.
- [X] Static type analysis.
- [X] Check args in function call.
- [X] Include section in README regarding miscellaneous features (references, fixed-len pointers, namespaces)
- [X] Update README (#1) (new builtins, elif, ufcs, alias)
- [X] Update README (#2) (new operators, function overloading, structs)
- [X] Include section in README regarding miscellaneous features (references, fixed-len pointers, namespaces).
- [X] Update README (#1) (new builtins, elif, ufcs, alias).
- [X] Update README (#2) (new operators, function overloading, structs).
- [X] Fix array access.
- [X] Fix array variable offset.
- [X] Implement stack alignment. (align by 16-bytes)
- [X] Define operator token types (binary, unary)
- [X] Implement right-assoc
- [X] Implement stack alignment (align by 16-bytes).
- [X] Define operator token types (binary, unary).
- [X] Implement right-assoc.
- [X] Implement lazy loading (gen).
- [X] Add an output file parameter to the Gen module.
- [X] Improve Def.rev_type_of.
Expand Down
6 changes: 3 additions & 3 deletions include/stdlib/builtin/for.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end

fun lines(arg: c_stream): file_range
let s = empty_str
s = extend(s, 256)
s = extend(&s, 256)

let succ = read_line(arg, s, 256)
ret file_range(arg, c_str(s), succ)
Expand All @@ -56,7 +56,7 @@ end

fun next(arg: file_range&): str
let s = empty_str
s = extend(s, 256)
s = extend(&s, 256)

let succ = read_line(arg.file_range_st, s, 256)
arg.file_range_str = c_str(s)
Expand Down Expand Up @@ -89,7 +89,7 @@ struct c_str_range
end

fun iter(arg: str&): c_str_range
ret c_str_range(c_str(arg), 0, 0, len(arg))
ret c_str_range(c_str(arg), 0, 0, len(&arg))
end

fun iter(arg: c_str): c_str_range
Expand Down
15 changes: 10 additions & 5 deletions include/stdlib/macro.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
macro repeat(_n, _body)
for _repeat_it in range(_n)
_body
end
end
import stdlib.builtin.for

# macro repeat(_n, _body)
# for _repeat_it in range(_n)
# _body
# end
# end

# Inserts a delimiter between arguments
macro delimit(_delim, _arg)
Expand All @@ -24,6 +26,9 @@ macro reverse(_arg1, _arg2, _arg3)
end

# Miscellaneous
macro ref(_arg)
&_arg
end
macro not(_arg)
false if _arg else true
end
Expand Down
36 changes: 16 additions & 20 deletions include/stdlib/string.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Provides a functional-like ML frontend of the sds c library.
# WARNING: Relies on the sds bindings for ML (string-backend.ml).

import stdlib.macro
import stdlib.debug
import stdlib.c.cstdlib
import stdlib.c.cstdarg
Expand Down Expand Up @@ -29,7 +30,7 @@ fun str(s: int8*): str
ret sdsnew(s)
end

fun str(s: str): str
fun str(s: str&): str
ret str(c_str(s))
end

Expand All @@ -51,15 +52,10 @@ end
# Grow the sds to have the specified length. Bytes that were not part of the original length of the sds will be set to zero.
#
# If the specified length is smaller than the current length, no operation is performed.
fun extend(s: str, size: int64): str
fun extend(s: str&, size: int64): str
ret sdsgrowzero(s, size)
end

# Duplicate an sds string.
fun copy(s: str): str
ret sdsdup(move(s))
end

# Modify an sds string in-place to make it empty (zero length).
# However all the existing buffer is not discarded but set as free space
# so that next append operations will not require allocations up to the
Expand All @@ -75,7 +71,7 @@ fun copy(s: str&, t: str&): str
end

# Return the length of the sds string.
fun len(s: str): int64
fun len(s: str&): int64
ret sdslen(s)
end

Expand All @@ -95,7 +91,7 @@ end
# s = sdsnew("Hello World");
# sdsrange(s,1,-1); => "ello World"
fun substr(s: str&, start: int64, send: int64): str
let tmp = str(s)
let tmp = str(&s)
sdsrange(tmp, start, send)
ret tmp
end
Expand All @@ -107,7 +103,7 @@ end
# After the call, the modified sds string is no longer valid and all the
# references must be substituted with the new pointer returned by the call.
fun concat(s: str&, t: str&): str
let tmp = str(s)
let tmp = str(&s)
ret sdscatsds(tmp, t)
end

Expand All @@ -131,7 +127,7 @@ fun concat_from(s: str&, fmt: int8*, ...): str
let listx: va_list
va_start(listx, fmt)

let tmp = str(s)
let tmp = str(&s)
ret sdscatvprintf(tmp, fmt, move(listx))
end

Expand All @@ -149,8 +145,8 @@ end
# printf("%s\n", s);
#
# Output will be just "HelloWorld".
fun trim(s: str, cset: int8*): str
let tmp = str(s)
fun trim(s: str&, cset: int8*): str
let tmp = str(&s)
ret sdstrim(tmp, cset)
end

Expand All @@ -170,11 +166,11 @@ fun compare(s: str&, s2: str&): int32
end

# Returns whether two sds strings are equal.
fun equals(s: str, s2: str): bool
fun equals(s: str&, s2: str&): bool
ret sdscmp(s, s2) == 0
end

fun equals(s: str, cs2: c_str): bool
fun equals(s: str&, cs2: c_str): bool
let s2 = str(cs2)
ret sdscmp(s, s2) == 0
end
Expand Down Expand Up @@ -217,8 +213,8 @@ fun split(cs: c_str, sep: c_str, cnt: c_int*): sds*
end

# Overload; Split 's' with separator in 'sep'. An array of sds strings is returned. *count will be set by reference to the number of tokens returned.
fun split(s: str, sep: str, cnt: c_int*): sds*
let arr: sds* = sdssplitlen(c_str(s), len(s), c_str(sep), len(sep), cnt)
fun split(s: str&, sep: str&, cnt: c_int*): sds*
let arr: sds* = sdssplitlen(c_str(s), len(&s), c_str(sep), len(&sep), cnt)
if arr == null
panic("Cannot split string.")
end
Expand All @@ -227,8 +223,8 @@ fun split(s: str, sep: str, cnt: c_int*): sds*
end

# Overload; Split 's' with separator in 'sep'. An array of sds strings is returned. *count will be set by reference to the number of tokens returned.
fun split(s: str, sep: c_str, cnt: c_int*): sds*
let arr: sds* = sdssplitlen(c_str(s), len(s), sep, strlen(sep), cnt)
fun split(s: str&, sep: c_str, cnt: c_int*): sds*
let arr: sds* = sdssplitlen(c_str(s), len(&s), sep, strlen(sep), cnt)
if arr == null
panic("Cannot split string.")
end
Expand Down Expand Up @@ -259,7 +255,7 @@ end

# Create an sds string from a string using clone.
fun to_str(value: str&): str
ret value.copy
ret ref(value).copy
end

# Create an sds string from a C string literal.
Expand Down
Loading

0 comments on commit 9d3c31f

Please sign in to comment.