From 59f78fe38a990bd40138bf4dedfc4585097b25a0 Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Mon, 1 Feb 2021 10:39:12 +0300 Subject: [PATCH] Spec changed; Changes introduced; fixed minor bugs --- Changes | 20 ++++++++++++++++++++ src/X86.ml | 9 ++++++--- src/version.ml | 2 +- tutorial/Expressions.lama | 9 +++++---- tutorial/PatternMatching.lama | 22 ++++++++++++---------- tutorial/Values.lama | 10 +++++----- 6 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 Changes diff --git a/Changes b/Changes new file mode 100644 index 000000000..72dcfbacd --- /dev/null +++ b/Changes @@ -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. diff --git a/src/X86.ml b/src/X86.ml index 18d9b4f7e..acc2963e1 100644 --- a/src/X86.ml +++ b/src/X86.ml @@ -229,11 +229,11 @@ let compile cmd env imports code = | [] -> env, [] | instr :: scode' -> 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' = if env#is_barrier 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] | SLABEL s -> env, [Label s] | _ -> env, [] @@ -629,11 +629,14 @@ class env prg = method is_barrier = barrier (* set barrier *) - method set_barrier = {< stack = []; barrier = true >} + method set_barrier = {< barrier = true >} (* drop barrier *) method drop_barrier = {< barrier = false >} + (* drop stack *) + method drop_stack = {< stack = [] >} + (* associates a stack to a label *) method set_stack l = (*Printf.printf "Setting stack for %s\n" l;*) {< stackmap = M.add l stack stackmap >} diff --git a/src/version.ml b/src/version.ml index 3963eb04f..d080f8174 100644 --- a/src/version.ml +++ b/src/version.ml @@ -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" diff --git a/tutorial/Expressions.lama b/tutorial/Expressions.lama index 6fb4a8040..98f2c8796 100644 --- a/tutorial/Expressions.lama +++ b/tutorial/Expressions.lama @@ -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 ("If-expression: %s\n", (if true then 2 else 3 fi + 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 s := s + i od; s - }.string + ).string ) + diff --git a/tutorial/PatternMatching.lama b/tutorial/PatternMatching.lama index 51a3bda8f..ae075cf0d 100644 --- a/tutorial/PatternMatching.lama +++ b/tutorial/PatternMatching.lama @@ -1,21 +1,23 @@ fun show (x) { fun show (level, x) { - for local i; i := 0, i printf ("integer %d\n", x); - return - | #array -> printf ("array\n") - | #string -> printf ("string\n") - | #sexp -> printf ("S-expression\n") - | #fun -> printf ("closure 0x%x\n", x[0]) + #val -> printf ("integer %d\n", x) + | #array -> printf ("array\n") + | #str -> printf ("string\n") + | #sexp -> printf ("S-expression\n") + | #fun -> printf ("closure 0x%x\n", x[0]) esac; - for local i; i := case x of #fun -> 1 | _ -> 0 esac, i < x.length, i := i + 1 do - show (level + 2, x[i]) - od + case x of + #val -> skip + | _ -> 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) diff --git a/tutorial/Values.lama b/tutorial/Values.lama index 95f7a90d3..d8fbba3c8 100644 --- a/tutorial/Values.lama +++ b/tutorial/Values.lama @@ -1,18 +1,18 @@ -local samples = [ +var samples = [ {"a", "b", "c"}, "string", [], Fruit ("apple"), - fun (){skip} + fun () {skip} ]; fun show () { -- Note: it would be much better to use iterArray from standard unit Array; -- in that case, however, we wouldn't be able to showcase -- 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); - 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) od od @@ -29,5 +29,5 @@ printf ("And the subvalues of a composite value can be reassigned.\n"); samples [2] := [1, 2, 3]; samples [0][1] := {}; -show () +show ()