mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-07 15:28:49 +00:00
Regression tests in interpretation only
This commit is contained in:
parent
1cfd3123be
commit
5527013a7f
15 changed files with 38 additions and 28 deletions
|
|
@ -9,7 +9,7 @@ check: $(TESTS)
|
||||||
$(TESTS): %: %.expr
|
$(TESTS): %: %.expr
|
||||||
@echo $@
|
@echo $@
|
||||||
# @$(RC) $< && cat $@.input | ./$@ > $@.log && diff $@.log orig/$@.log
|
# @$(RC) $< && cat $@.input | ./$@ > $@.log && diff $@.log orig/$@.log
|
||||||
cat $@.input | $(RC) -i $< > $@.log && diff $@.log orig/$@.log
|
cat $@.input | $(RC) -i $< > $@.log && diff $@.log orig/$@.log; true
|
||||||
# @cat $@.input | $(RC) -s $< > $@.log && diff $@.log orig/$@.log
|
# @cat $@.input | $(RC) -s $< > $@.log && diff $@.log orig/$@.log
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
local x, y, z;
|
x := read ();
|
||||||
read (x);
|
y := read ();
|
||||||
read (y);
|
|
||||||
z := x*y*3;
|
z := x*y*3;
|
||||||
write (z)
|
write (z)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
fun fib (n) local r {
|
fun fib (n) {
|
||||||
|
local r;
|
||||||
if n <= 1
|
if n <= 1
|
||||||
then result := 1
|
then result := 1
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
fun test (n, m) local i, s {
|
fun test (n, m) {
|
||||||
|
local i, s;
|
||||||
s := 0;
|
s := 0;
|
||||||
for i := 0, i <= n, i := i + 1 do
|
for i := 0, i <= n, i := i + 1 do
|
||||||
s := s + i;
|
s := s + i;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
fun printArray (x) local elem {
|
fun printArray (x) {
|
||||||
|
local elem;
|
||||||
if x.length == 0 then return fi;
|
if x.length == 0 then return fi;
|
||||||
for i:=0, i<x.length, i:=i+1 do
|
for i:=0, i<x.length, i:=i+1 do
|
||||||
write (x[i])
|
write (x[i])
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
fun sort (x) local i, j, y, n {
|
fun sort (x) {
|
||||||
|
local i, j, y, n;
|
||||||
n := x.length;
|
n := x.length;
|
||||||
|
|
||||||
if n == 0 then return x fi;
|
if n == 0 then return x fi;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
fun printString (s) local i {
|
fun printString (s) {
|
||||||
|
local i;
|
||||||
for i := 0, i < s.length, i := i + 1 do
|
for i := 0, i < s.length, i := i + 1 do
|
||||||
write (s[i])
|
write (s[i])
|
||||||
od
|
od
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
fun collect_ints_acc (v, tail) local i {
|
fun collect_ints_acc (v, tail) {
|
||||||
|
local i;
|
||||||
case v of
|
case v of
|
||||||
a@#unboxed -> return Cons (a, tail)
|
a@#unboxed -> return Cons (a, tail)
|
||||||
| #string -> return tail
|
| #string -> return tail
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
fun test (n, m) local i, s {
|
fun test (n, m) {
|
||||||
|
local i, s;
|
||||||
write (n);
|
write (n);
|
||||||
write (m);
|
write (m);
|
||||||
return n
|
return n
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
fun test (n, m) local i, s {
|
fun test (n, m) {
|
||||||
|
local i, s;
|
||||||
s := 0;
|
s := 0;
|
||||||
for i := 0, i <= n, i := i + 1 do
|
for i := 0, i <= n, i := i + 1 do
|
||||||
s := s + i;
|
s := s + i;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ fun print_list (l) {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
fun array_to_list (a) local l, i {
|
fun array_to_list (a) {
|
||||||
|
local l, i;
|
||||||
l := {};
|
l := {};
|
||||||
for i := a.length, i > 0, i := i-1 do
|
for i := a.length, i > 0, i := i-1 do
|
||||||
l := a[i-1] : l
|
l := a[i-1] : l
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
infix "===" at "==" (v1, v2) local s1, s2, i {
|
infix "===" at "==" (v1, v2) {
|
||||||
|
local s1, s2, i;
|
||||||
|
|
||||||
s1 := v1.string;
|
s1 := v1.string;
|
||||||
s2 := v2.string;
|
s2 := v2.string;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ let parse infile =
|
||||||
"while"; "do"; "od";
|
"while"; "do"; "od";
|
||||||
"repeat"; "until";
|
"repeat"; "until";
|
||||||
"for";
|
"for";
|
||||||
"fun"; "local"; "return";
|
"fun"; "local"; "return"; "global";
|
||||||
"length";
|
"length";
|
||||||
"string";
|
"string";
|
||||||
"case"; "of"; "esac"; "when";
|
"case"; "of"; "esac"; "when";
|
||||||
|
|
|
||||||
|
|
@ -259,7 +259,7 @@ module Expr =
|
||||||
(* entering the scope *) | Scope of string list * t
|
(* entering the scope *) | Scope of string list * t
|
||||||
(* leave a scope *) | Leave
|
(* leave a scope *) | Leave
|
||||||
(* intrinsic (for evaluation) *) | Intrinsic of (config -> config)
|
(* intrinsic (for evaluation) *) | Intrinsic of (config -> config)
|
||||||
(* control (for control flow) *) | Control of (config -> t * config)
|
(* control (for control flow) *) | Control of (config -> t * config)
|
||||||
|
|
||||||
(* Reff : parsed expression should return value Reff (look for ":=");
|
(* Reff : parsed expression should return value Reff (look for ":=");
|
||||||
Val : -//- returns simple value;
|
Val : -//- returns simple value;
|
||||||
|
|
@ -553,18 +553,16 @@ module Expr =
|
||||||
| c:CHAR => {notRef atr} => {ignore atr (Const (Char.code c))}
|
| c:CHAR => {notRef atr} => {ignore atr (Const (Char.code c))}
|
||||||
| "[" es:!(Util.list0)[parse def infix Val] "]" => {notRef atr} => {ignore atr (Array es)}
|
| "[" es:!(Util.list0)[parse def infix Val] "]" => {notRef atr} => {ignore atr (Array es)}
|
||||||
| "{" <(d, infix')> : def[infix] expr:parse[def][infix][atr] "}" => {notRef atr} => {
|
| "{" <(d, infix')> : def[infix] expr:parse[def][infix][atr] "}" => {notRef atr} => {
|
||||||
ignore atr (
|
|
||||||
let vars, body =
|
let vars, body =
|
||||||
List.fold_left
|
List.fold_left
|
||||||
(fun (vs, bd) -> function
|
(fun (vs, bd) -> function
|
||||||
| (name, `Local value) -> name :: vs, (match value with None -> bd | Some v -> Seq (Assign (Var name, v), bd))
|
| (name, `Variable value) -> name :: vs, (match value with None -> bd | Some v -> Seq (Assign (Var name, v), bd))
|
||||||
| _ -> invalid_arg "function"
|
| _ -> invalid_arg "function"
|
||||||
)
|
)
|
||||||
([], expr)
|
([], expr)
|
||||||
d
|
d
|
||||||
in
|
in
|
||||||
Scope (vars, body)
|
Scope (vars, body)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
| "{" es:!(Util.list0)[parse def infix Val] "}" => {notRef atr} => {ignore atr (match es with
|
| "{" es:!(Util.list0)[parse def infix Val] "}" => {notRef atr} => {ignore atr (match es with
|
||||||
| [] -> Const 0
|
| [] -> Const 0
|
||||||
|
|
@ -691,7 +689,7 @@ module Definition =
|
||||||
struct
|
struct
|
||||||
|
|
||||||
(* The type for a definition: aither a function/infix, or a local variable *)
|
(* The type for a definition: aither a function/infix, or a local variable *)
|
||||||
type t = string * [`Fun of string list * Expr.t | `Local of Expr.t option]
|
type t = string * [`Fun of string list * Expr.t | `Variable of Expr.t option]
|
||||||
|
|
||||||
ostap (
|
ostap (
|
||||||
arg : LIDENT;
|
arg : LIDENT;
|
||||||
|
|
@ -708,9 +706,9 @@ module Definition =
|
||||||
| `Ok infix' -> name, infix'
|
| `Ok infix' -> name, infix'
|
||||||
| `Fail msg -> raise (Semantic_error msg)
|
| `Fail msg -> raise (Semantic_error msg)
|
||||||
};
|
};
|
||||||
local_var[infix][expr][def]: name:LIDENT value:(-"=" expr[def][infix][Expr.Val])? {name, `Local value};
|
local_var[infix][expr][def]: name:LIDENT value:(-"=" expr[def][infix][Expr.Val])? {name, `Variable value};
|
||||||
parse[infix][expr][def]:
|
parse[kind][infix][expr][def]:
|
||||||
%"local" locs:!(Util.list (local_var infix expr def)) ";" {locs, infix}
|
kind locs:!(Util.list (local_var infix expr def)) ";" {locs, infix}
|
||||||
| <(name, infix')> : head[infix] "(" args:!(Util.list0 arg) ")"
|
| <(name, infix')> : head[infix] "(" args:!(Util.list0 arg) ")"
|
||||||
body:expr[def][infix'][Expr.Void] {
|
body:expr[def][infix'][Expr.Void] {
|
||||||
[(name, `Fun (args, body))], infix'
|
[(name, `Fun (args, body))], infix'
|
||||||
|
|
@ -752,8 +750,10 @@ let eval ((defs, body) : t) i =
|
||||||
|
|
||||||
(* Top-level parser *)
|
(* Top-level parser *)
|
||||||
ostap (
|
ostap (
|
||||||
parse[infix]: <(defs, infix')> : definitions[infix] body:!(Expr.parse definitions infix' Expr.Void) {(defs : Definition.t list), body};
|
parse[infix]: <(defs, infix')> : definitions[global][infix] body:!(Expr.parse (definitions local) infix' Expr.Void) {(defs : Definition.t list), body};
|
||||||
definitions[infix]:
|
local: %"local";
|
||||||
<(def, infix')> : !(Definition.parse infix Expr.parse definitions) <(defs, infix'')> : definitions[infix'] {def @ defs, infix''}
|
global: %"global";
|
||||||
|
definitions[kind][infix]:
|
||||||
|
<(def, infix')> : !(Definition.parse kind infix Expr.parse (definitions local)) <(defs, infix'')> : definitions[kind][infix'] {def @ defs, infix''}
|
||||||
| empty {[], infix}
|
| empty {[], infix}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ OCAMLDEP = ocamlfind dep
|
||||||
SOURCES = Language.ml SM.ml X86.ml Driver.ml
|
SOURCES = Language.ml SM.ml X86.ml Driver.ml
|
||||||
CAMLP5 = -syntax camlp5o -package ostap.syntax,GT.syntax.all
|
CAMLP5 = -syntax camlp5o -package ostap.syntax,GT.syntax.all
|
||||||
PXFLAGS = $(CAMLP5)
|
PXFLAGS = $(CAMLP5)
|
||||||
BFLAGS = -rectypes
|
BFLAGS = -rectypes -g
|
||||||
OFLAGS = $(BFLAGS)
|
OFLAGS = $(BFLAGS)
|
||||||
|
|
||||||
all: .depend $(TOPFILE).opt
|
all: .depend $(TOPFILE).opt
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue