grammar refactoring: build_visitor fixed & visitors tested

This commit is contained in:
ProgramSnail 2023-04-11 13:49:22 +03:00
parent 3c2d496a85
commit e4802896bd
35 changed files with 118128 additions and 91770 deletions

View file

@ -1,29 +1,21 @@
decl test_arrays : Unit -> Unit
def test_arrays = {
var arr1 = [1, 2, 3]
const arr2 = [] // empty array ??
var arr3 = [] : Int.5 // TODO: decide ??
const arr4= ['a'..'z']
const n = 100;
var @arr5 = @[] : @Int.n // unique pointer (??)
var arr1 = [1; 2; 3]
const arr2 = []
var arr3 = []
const arr4 = 'a'..'z'
const n = 100
var @arr5 = @$Int_n
var @@arr6 = @@[] : @@Int.n // shared pointer (??)
var @@arr6_pointer = @@arr6
var @arr6 = @$Int_n
var @arr6_pointer = @arr6
const elem1 = arr1.1
var elem2 = arr1.1
const *ref1 = *arr1.1 // reference <-> unmanaged pointer (??)
var *ref2 = *arr1.1
; *arr1.1 = 123
const ~ref1 = ~arr1.1
var ~ref2 = ~arr1.1
; ~arr1.1 = 123
; ref1 = arr1.2 // set value
; *ref1 = *ref2 // set reference
// ?? references, that can't change ??
// ?? array access, array mutable access, array get reference to elem ??
// ?? arrays as basic type ??
// ?? custom allocators ??
; ~ref1 = ~ref2 // set reference
}
// ????????????????????

View file

@ -1,12 +1,3 @@
// ?? value - parametric classes ??
// struct fields/etc. accessible from everywere
// class fields/etc. accessible only from namespace of class or class instance (from "methods")
// points at the beginning of constructor name - amount of needed constructor prefixes ?
// ?? how to make class compositons ??
struct Fruit =
| Apple
| Orange
@ -20,13 +11,13 @@ struct (Result : #Move) 'A 'B =
| & 'A
| Error & 'B
// struct (Complex : #Value) =
// & Float(0.0)
// & Float(0.0)
//
// struct Task =
// & name("Task") : String
// & duration(0.0) : Float
struct (Complex : #Value) =
& Float
& Float
struct Task =
& name : String
& duration : Float
class Employee =
& name : String

View file

@ -12,6 +12,7 @@ namespace Employee {
& duration = 10.3
& sleep_on_work = ($Productivity.SleepOnWork.No))
& salary = 123)
}
}

View file

@ -1,22 +1,14 @@
decl flow_control_test : Unit -> Unit
def flow_control_test = {
// if && || a < b
// || a == b
// && b < c
// && c > 10
if ((a < b) || (a == b)) && (b < c)
then IO.print x
elif x < 0
then {
if ((a < b) || (a == b)) && (b < c) then IO.print x
elif x < 0 then {
; ++x
; IO.print y
} else {
return {}
}
while (a > 0) && (!array.is_empty)
do {
while (a > 0) && (!array.is_empty) do {
; --a
; array.pop
}
@ -28,9 +20,7 @@ def flow_control_test = {
; IO.print i
}
for & i & j
in (& 0..y & 0..k)
do { // TODO: decide ??? does it work (like auto zip) ???
for & i & j in (& 0..y & 0..k) do {
; IO.print 1
; IO.print 2
; IO.print 128

View file

@ -1,7 +1,5 @@
// "decl" is not required, but useful in module interface
decl sum ('A : #Add) : 'A -> 'A -> 'A
def sum : a b = a + b
def sum 'A : a b = a + b
decl fib : Int -> Int
def fib : n =
@ -16,25 +14,22 @@ def fact : n =
| n -> n * fact (n - 1)
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> Array 'H
def find_prefix_hashes ('H : (#AccHash Char)) : str = {
def find_prefix_hashes 'H : str = {
var hashes = (Array 'H).new (str.size + 1)
; hashes.0 = 'H.of str.0
for i in 1..hashes.size do {
; hashes.i = hashes.(i - 1).clone
; hashes.i.append str.i
}
return hashes
; hashes.0 = 'H.of str.0
for i in 1..hashes.size do {
; hashes.i = hashes.(i - 1).clone
; hashes.i.append str.i
}
return hashes
}
// ?? other default constructor symbol (instead of placeholder _), etc. ??
// seporate first and last iteration of loop ?
// previous and next iterations ?
alias Hash = AccHash Char
decl find_substring : String -> String -> Array Index
def find_substring : str substr = {
alias Hash = AccHash Char
var result = (Array Index).empty
@ -64,7 +59,4 @@ decl mul : Int -> Int -> Int
def mul : x y = x * y
decl mul_10 : Int -> Int
def mul_10 = mul 10 // or argument can be used
// ?? is partial application feature needed ??
def mul_10 = mul 10

View file

@ -1,11 +1,11 @@
import "module"
import "module" : func
import "module" :
Type1
func1
func2
func3
func4
func5
use ModuleNamespace = import "module"
@ -14,5 +14,3 @@ use PartOfModuleNamespace =
func1
func2
func3
// ?? use ":" once again ??

View file

@ -1,12 +1,9 @@
decl test_lambdas : Unit -> Unit
def test_lambdas = {
const lambda1 = \x -> x * x
// const lambda2 = \(x : #Hash) -> x.hash // ??
const lambda2 = \x -> x.hash
const lambda3 = \x y -> x + y
// TODO: type LambdaType = Int -> Int // ?? type keyword ??
// const typed_lambda = \x -> x + 1
const lambda4 = \x -> {
; IO.print x
const y = x + x

View file

@ -1,9 +1,8 @@
struct StructWithRef =
& @Int._ // unique pointer to any-sized array (default size is zero ??)
& @Int_
decl test_memory : Unit -> Unit
def test_memory = {
const @unique_ref1 <- @5 // move unique reference
const @unique_ref1 <- @(5)
var @unique_ref2 <- @(Array.of 1 2 3)
// ?? reference to constant value ??
}

View file

@ -1,20 +1,15 @@
namespace Namespace {
decl something : Unit
decl something : Unit -> Unit
}
namespace Array 'A {
decl something : Unit
// "static methods" of Array 'a class
namespace Array {
decl something : Unit -> Unit
}
namespace Array ('A : #Copy) {
decl something : Unit
// "static methods" of Array 'a with "copyable" 'a
namespace Array {
decl something : Unit -> Unit
}
namespace var a : Array ('A : #Copy) {
decl something : Unit
// "methods" of Array 'a (a as array instance) with "copyable" 'a
namespace var a : Array {
decl something : Unit -> Unit
}
// ?? what to do with const/public/... methods ??

View file

@ -1,5 +0,0 @@
class (FixedArray : #Ord) 'A : (a : Int) =
& size(a) : Int // ?? const ??
& @[] : @'A.a
// ?? not shure about array definition ??

View file

@ -1,38 +1,23 @@
// partition DOC { // or .doc.lang filename
// // ...
// }
// ?? separated doc ??
partition TEST { // or .test.lang filename
decl something : Unit
decl something : Unit -> Unit
}
partition INTERFACE { // or .interface.lang filename
decl something : Unit
decl something : Unit -> Unit
}
partition CORE { // or .core.lang filename
decl something : Unit
decl something : Unit -> Unit
}
partition LIB { // or .lib.lang filename
decl something : Unit
decl something : Unit -> Unit
}
partition MODULE { // or .module.lang filename
decl something : Unit
decl something : Unit -> Unit
}
// maybe another name for partition
partition EXE { // or .exe.lang filename
decl something : Unit
decl something : Unit -> Unit
}
// partition CONFIG { // or .config.lang filename
// decl something : Unit
// }
// ?? config is one of the partitions ??
// ?? maybe more ??

View file

@ -7,6 +7,4 @@ def test_tuples = {
}
// ??????????????????????????

View file

@ -3,5 +3,3 @@ def test_type_casting = {
var x = y.as Int
var k = (f y x).as Float
}
// type casting is can be done by generic method "as"

View file

@ -1,36 +1,20 @@
typeclass #Copy =
& copy : #Copy -> #Copy
typeclass Copy =
& copy : Copy -> Copy
typeclass (#Ord : #Eq) =
& ( < ) : #Ord -> #Ord -> Bool
& ( > ) : #Ord -> #Ord -> Bool
& ( <= ) : #Ord -> #Ord -> Bool
& ( >= ) : #Ord -> #Ord -> Bool
typeclass (Ord : #Eq) =
& ( < ) : Ord -> Ord -> Bool
& ( > ) : Ord -> Ord -> Bool
& ( <= ) : Ord -> Ord -> Bool
& ( >= ) : Ord -> Ord -> Bool
typeclass (#D : #A #B #C) 'A 'B =
typeclass (D : #A #B #C) 'A 'B =
& do_something : Unit -> (& 'A & 'B)
typeclass #E 'A =
typeclass E 'A =
& do_something : Unit -> 'A
namespace const ord : #Ord {
namespace const ord : Ord {
def ( <= ) : a b = (a < b) || (a == b)
def ( > ) : a b = !(a <= b)
def ( >= ) : a b = !(a < b)
}
// === ?? dependent types ?? ===
//
// typeclass #F : (a : Int) (b : Int) =
// & do_something Int -> Int
//
// namespace (f : #F a b c) {
// require do_sometihng a = b
// }
//
// ===
// ?? operators over functions (without arguments, like "def <= = < || ==;") ??
// ?? define operators like OCaml ??
// ?? denote moved type ??
// ?? "trait" VS "typeclass" ??

View file

@ -1,14 +1,8 @@
alias T1 = Int;
alias T1 = Int
type (T2 : #A #B #C);
abstract (T2 : #A #B #C)
// Define file level abstract type
T2 =
| Int
| Float
| Complex;
// Compile module (functions, types, ...) for T2 = Int, Float, Complex
// ?? file level <-> module level ??
// Used to pre-compile module for some types
let T2 = Int
let T2 = Float
let T2 = Complex

View file

@ -1,14 +1,12 @@
decl test_variants : Unit -> Unit
def test_variants = {
var variant1 = | 'a' | 2 | "hello"
var | val | err = f x // optional types for each
var | val | err = f x
; val -> "something" // open variant as value in expr
; val -!> "nothing" // open variant as None in expr
; ?err // open variant as value, or return None (if possible), operator
match variant1 with
| 'a' -> "something"
| 2 -> "something"
@ -18,5 +16,3 @@ def test_variants = {
| Int.of i -> "someting"
| 11 -> "nothing"
}
// ???????????????????????