This commit is contained in:
Dmitry Boulytchev 2018-04-26 22:31:47 +03:00
parent dd5956d663
commit 25eff5c282
3 changed files with 7 additions and 5 deletions

View file

@ -14,5 +14,6 @@ for i:=0, i<x.length, i:=i+1 do
x[i] := x[i]+2
od;
printString (x)
printString (x);
printString (strcat ("abc", "def"))

View file

@ -85,7 +85,10 @@ module Builtin =
)
| "$length" -> (st, i, o, Some (Value.of_int (match List.hd args with Value.Array a -> List.length a | Value.String s -> String.length s)))
| "$array" -> (st, i, o, Some (Value.of_array args))
| s -> failwith (Printf.sprintf "Wow: %s\n" s)
| "strcat" -> let [x; y] = args in
(st, i, o, Some (Value.of_string @@ Value.to_string x ^ Value.to_string y))
| "isArray" -> let [a] = args in
(st, i, o, Some (Value.of_int @@ match a with Array _ -> 1 | _ -> 0))
end

View file

@ -6,8 +6,6 @@ open Language
(* binary operator *) | BINOP of string
(* put a constant on the stack *) | CONST of int
(* put a string on the stack *) | STRING of string
(* read to stack *) | READ
(* write from stack *) | WRITE
(* load a variable to the stack *) | LD of string
(* store a variable from the stack *) | ST of string
(* store in an array *) | STA of string * int