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.
|
||||||
|
|
@ -233,7 +233,7 @@ let compile cmd env imports code =
|
||||||
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 >}
|
||||||
|
|
|
||||||
|
|
@ -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 ("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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
| #string -> printf ("string\n")
|
| #str -> 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
|
||||||
|
#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])
|
show (level + 2, x[i])
|
||||||
od
|
od
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
show (0, x)
|
show (0, x)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue