mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
Spec changed; Changes introduced; fixed minor bugs
This commit is contained in:
parent
7c7ef67e1d
commit
59f78fe38a
6 changed files with 49 additions and 23 deletions
20
Changes
Normal file
20
Changes
Normal 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.
|
||||
|
|
@ -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 >}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
fun show (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 (" ")
|
||||
od;
|
||||
|
||||
case x of
|
||||
#unboxed -> 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)
|
||||
|
|
|
|||
|
|
@ -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 ()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue