Spec changed; Changes introduced; fixed minor bugs

This commit is contained in:
Dmitry Boulytchev 2021-02-01 10:39:12 +03:00
parent 7c7ef67e1d
commit 59f78fe38a
6 changed files with 49 additions and 23 deletions

20
Changes Normal file
View file

@ -0,0 +1,20 @@
LaMa 1.10
---------
Version 1.10 clears some inconsistnces in 1.00. The language is *not* top-down compatible
with 1.00, but the conversion is simple.
# Language features:
- Removed keywords: local, repeat, until, boxed, unboxed, length, string;
- Added keywords: var, val, box;
- local variable declarations syntax changed: local x... -> var x...;
- repeat ... until syntax changed: now do .. while .. od. Note the inversion in
the condition while converting from repeat... to do..while...;
- .length and .string are now regular functions; hence a conventional synax string (x) and
length (x) is possible;
- pattern syntax changed: #boxed -> #box, #unboxed -> #val, #string -> #str;
- scope expressions are integrated with ( ... ) primaries; thus,
nested scopes are introduced with *round* brackets;
- no more List.singleton is needed since there is no more confilict between one-element lists
and scoped expressions.

View file

@ -229,11 +229,11 @@ let compile cmd env imports code =
| [] -> env, [] | [] -> env, []
| instr :: scode' -> | instr :: scode' ->
let stack = "" (* env#show_stack*) in let stack = "" (* env#show_stack*) in
(* Printf.printf "insn=%s, stack=%s\n%!" (GT.show(insn) instr) (env#show_stack); *) (* Printf.printf "insn=%s, stack=%s\n%!" (GT.show(insn) instr) (env#show_stack); *)
let env', code' = let env', code' =
if env#is_barrier if env#is_barrier
then match instr with then match instr with
| LABEL s -> if env#has_stack s then (env#drop_barrier)#retrieve_stack s, [Label s] else env, [] | LABEL s -> if env#has_stack s then (env#drop_barrier)#retrieve_stack s, [Label s] else env#drop_stack, []
| FLABEL s -> env#drop_barrier, [Label s] | FLABEL s -> env#drop_barrier, [Label s]
| SLABEL s -> env, [Label s] | SLABEL s -> env, [Label s]
| _ -> env, [] | _ -> env, []
@ -629,11 +629,14 @@ class env prg =
method is_barrier = barrier method is_barrier = barrier
(* set barrier *) (* set barrier *)
method set_barrier = {< stack = []; barrier = true >} method set_barrier = {< barrier = true >}
(* drop barrier *) (* drop barrier *)
method drop_barrier = {< barrier = false >} method drop_barrier = {< barrier = false >}
(* drop stack *)
method drop_stack = {< stack = [] >}
(* associates a stack to a label *) (* associates a stack to a label *)
method set_stack l = (*Printf.printf "Setting stack for %s\n" l;*) method set_stack l = (*Printf.printf "Setting stack for %s\n" l;*)
{< stackmap = M.add l stack stackmap >} {< stackmap = M.add l stack stackmap >}

View file

@ -1 +1 @@
let version = "Version 1.10, f1430a1cd, Sun Jan 31 22:57:12 2021 +0300" let version = "Version 1.10, 7c7ef67e1, Mon Feb 1 09:52:28 2021 +0300"

View file

@ -1,15 +1,16 @@
printf ("if, case, for, while, repeat etc. are all expressions.\n"); printf ("if, case, for, while etc. are all expressions.\n");
printf ("Case-expression: %s\n", case A (1, 2, 3) of A (x, y, z) -> z esac.string); printf ("Case-expression: %s\n", case A (1, 2, 3) of A (x, y, z) -> z esac.string);
printf ("If-expression: %s\n", (if true then 2 else 3 fi + printf ("If-expression: %s\n", (if true then 2 else 3 fi +
if false then 6 else 7 fi).string); if false then 6 else 7 fi).string);
printf ("Scope-expression: %s\n", {local i, s = 0; printf ("Scope-expression: %s\n", (var i, s = 0;
for i := 0, i < 10, i := i + 1 do for i := 0, i < 10, i := i + 1 do
s := s + i s := s + i
od; od;
s s
}.string ).string
) )

View file

@ -1,21 +1,23 @@
fun show (x) { fun show (x) {
fun show (level, x) { fun show (level, x) {
for local i; i := 0, i<level, i := i + 1 do for var i; i := 0, i<level, i := i + 1 do
printf (" ") printf (" ")
od; od;
case x of case x of
#unboxed -> printf ("integer %d\n", x); #val -> printf ("integer %d\n", x)
return | #array -> printf ("array\n")
| #array -> printf ("array\n") | #str -> printf ("string\n")
| #string -> printf ("string\n") | #sexp -> printf ("S-expression\n")
| #sexp -> printf ("S-expression\n") | #fun -> printf ("closure 0x%x\n", x[0])
| #fun -> printf ("closure 0x%x\n", x[0])
esac; esac;
for local i; i := case x of #fun -> 1 | _ -> 0 esac, i < x.length, i := i + 1 do case x of
show (level + 2, x[i]) #val -> skip
od | _ -> for var i; i := case x of #fun -> 1 | _ -> 0 esac, i < x.length, i := i + 1 do
show (level + 2, x[i])
od
esac
} }
show (0, x) show (0, x)

View file

@ -1,18 +1,18 @@
local samples = [ var samples = [
{"a", "b", "c"}, {"a", "b", "c"},
"string", "string",
[], [],
Fruit ("apple"), Fruit ("apple"),
fun (){skip} fun () {skip}
]; ];
fun show () { fun show () {
-- Note: it would be much better to use iterArray from standard unit Array; -- Note: it would be much better to use iterArray from standard unit Array;
-- in that case, however, we wouldn't be able to showcase -- in that case, however, we wouldn't be able to showcase
-- for-loops and []-expressions. -- for-loops and []-expressions.
for local i; i := 0, i < samples.length, i := i+1 do for var i; i := 0, i < samples.length, i := i+1 do
printf (" %s has %d subvalue(s):\n", samples[i].string, samples[i].length); printf (" %s has %d subvalue(s):\n", samples[i].string, samples[i].length);
for local j; j := 0, j < samples[i].length, j := j+1 do for var j; j := 0, j < samples[i].length, j := j+1 do
printf (" subvalue [%d] = %s\n", j, samples[i][j].string) printf (" subvalue [%d] = %s\n", j, samples[i][j].string)
od od
od od
@ -29,5 +29,5 @@ printf ("And the subvalues of a composite value can be reassigned.\n");
samples [2] := [1, 2, 3]; samples [2] := [1, 2, 3];
samples [0][1] := {}; samples [0][1] := {};
show () show ()