example fixes

This commit is contained in:
ProgramSnail 2023-05-13 14:54:48 +03:00
parent 71c7d91e1a
commit 562541087e
13 changed files with 30 additions and 322 deletions

View file

@ -1,21 +1,21 @@
decl test_arrays : Unit -> Unit
decl test_arrays : -> Unit
def test_arrays = {
var arr1 = ,1 ,2 ,3
const arr2 = Int._array: 32
var arr3 = String._array: 11
const arr4 = 'a'--'z'
const n = 100
var @arr5 <- Int.@_new_array: 10
var arr5 <- Int._new_array: 10
var @arr6 <- String.@_new_array: 10
var ~arr6_reference = ~arr6
var arr6 <- String._new_array: 10
var arr6_reference = ^arr6
const elem1 = arr1`0
var elem2 = arr1`2
const ~ref1 = ~arr1`1
var ~ref2 = ~arr1`3
const ref1 = ^arr1`1
var ref2 = ^arr1`3
; arr1`1 = 123
; ref1 = arr1`2 // set value
; ~ref1 = ~ref2 // set reference
; ~ref1 = arr1`2 // set value
; ref1 = ref2 // set pointer / reference
}

View file

@ -1,4 +1,4 @@
decl flow_control_test : Unit -> Unit
decl flow_control_test : -> Unit
def flow_control_test = {
if (a < b ||. a == b) && (b < c) then IO.print: x
elif x < 0 then {
@ -19,7 +19,7 @@ def flow_control_test = {
; IO.print: i
}
for & i & j in & 0--y & 0--k do { // ??
for & i & j in (& 0--y & 0--k) do { // ??
; IO.print: 1
; IO.print: 2
; IO.print: 128

View file

@ -48,10 +48,10 @@ def find_substring : str substr = {
return result
}
decl is_empty : Unit -> Bool
decl is_empty : -> Bool
def is_empty = 0
decl do_something : Unit -> Unit
decl do_something : -> Unit
def do_something =
IO.print: "Hello World!"

View file

@ -1,4 +1,4 @@
decl test_lambdas : Unit -> Unit
decl test_lambdas : -> Unit
def test_lambdas = {
const lambda1 = \x -> x * x
const lambda2 = \x -> x.hash:

View file

@ -1,7 +1,3 @@
================================================================================
Match
================================================================================
decl fruit_cost : Fruit -> Int
def fruit_cost : fruit = {
return (match fruit with
@ -19,248 +15,3 @@ def amount_to_string : x is_zero_separated = {
| _ -> "Lots"
return ans
}
--------------------------------------------------------------------------------
(source_file
(source_statement
(namespace_statement
(function_declaration
(extended_name
(name_identifier))
(function_type
(scoped_any_type
(type_expression
(parametrized_type
(type_identifier))))
(scoped_any_type
(type_expression
(parametrized_type
(type_identifier))))))))
(source_statement
(namespace_statement
(function_definition_statement
(function_definition
(extended_name
(name_identifier))
(extended_name
(name_identifier)))
(superexpression
(expression
(prefixed_expression
(block
(block_statement
(prefixed_expression
(return_expression
(expression
(subexpression
(subexpression_token
(scoped_statement
(superexpression
(flow_control
(match
(expression
(subexpression
(subexpression_token
(name_expression
(extended_name
(name_identifier))))))
(match_case
(pattern
(type_constructor_pattern
(type_expression
(parametrized_type
(type_identifier)))))
(expression
(subexpression
(subexpression_token
(literal
(number_literal))))))
(match_case
(pattern
(type_constructor_pattern
(type_expression
(parametrized_type
(type_identifier))))))
(match_case
(pattern
(type_constructor_pattern
(type_expression
(parametrized_type
(type_identifier)))))
(expression
(subexpression
(subexpression_token
(literal
(number_literal)))))))))))))))))))))))
(source_statement
(namespace_statement
(function_declaration
(extended_name
(name_identifier))
(function_type
(scoped_any_type
(type_expression
(parametrized_type
(type_identifier))))
(scoped_any_type
(type_expression
(parametrized_type
(type_identifier))))
(scoped_any_type
(type_expression
(parametrized_type
(type_identifier))))))))
(source_statement
(namespace_statement
(function_definition_statement
(function_definition
(extended_name
(name_identifier))
(extended_name
(name_identifier))
(extended_name
(name_identifier)))
(superexpression
(expression
(prefixed_expression
(block
(block_statement
(variable_definition_statement
(any_name
(annotated_name
(extended_name
(name_identifier))))
(superexpression
(flow_control
(match
(expression
(subexpression
(subexpression_token
(name_expression
(extended_name
(name_identifier))))))
(match_case
(pattern
(literal
(number_literal)))
(expression
(subexpression
(subexpression_token
(name_expression
(extended_name
(name_identifier))))))
(expression
(subexpression
(subexpression_token
(literal
(string_literal))))))
(match_case
(pattern
(literal
(number_literal))))
(match_case
(pattern
(literal
(number_literal))))
(match_case
(pattern
(literal
(number_literal))))
(match_case
(pattern
(literal
(number_literal))))
(match_case
(pattern
(literal
(number_literal)))
(expression
(subexpression
(subexpression_token
(literal
(string_literal))))))
(match_case
(pattern
(extended_name
(name_identifier)))
(expression
(subexpression
(function_call_expression
(subexpression_token
(scoped_statement
(superexpression
(expression
(subexpression
(binary_operator_expression
(subexpression
(subexpression_token
(literal
(number_literal))))
(operator)
(subexpression
(subexpression_token
(literal
(number_literal))))))))))
(extended_name
(name_identifier))
(subexpression_token
(name_expression
(extended_name
(name_identifier)))))))
(expression
(subexpression
(subexpression_token
(literal
(string_literal))))))
(match_case
(pattern
(extended_name
(name_identifier)))
(expression
(subexpression
(function_call_expression
(subexpression_token
(scoped_statement
(superexpression
(expression
(subexpression
(binary_operator_expression
(subexpression
(subexpression_token
(literal
(number_literal))))
(operator)
(subexpression
(subexpression_token
(literal
(number_literal))))))))))
(extended_name
(name_identifier))
(subexpression_token
(name_expression
(extended_name
(name_identifier)))))))
(expression
(subexpression
(subexpression_token
(literal
(string_literal))))))
(match_case
(pattern
(extended_name
(name_identifier)))
(expression
(subexpression
(subexpression_token
(literal
(string_literal)))))))))))
(block_statement
(prefixed_expression
(return_expression
(expression
(subexpression
(subexpression_token
(name_expression
(extended_name
(name_identifier)))))))))))))))))

View file

@ -1,8 +1,8 @@
struct StructWithRef =
& @Int_0
decl test_memory : Unit -> Unit
decl test_memory : -> Unit
def test_memory = {
const @unique_ref1 <- Int.@_new: 5
var @unique_ref2 <- Array.@of: 1 2 3
const unique_ref1 <- Int._new: 5
var unique_ref2 <- Array.of: 1 2 3
}

View file

@ -1,19 +1,19 @@
namespace Namespace {
decl something : Unit -> Unit
decl something : -> Unit
}
namespace Array {
decl something : Unit -> Unit
decl something : -> Unit
}
namespace Array {
decl something : Unit -> Unit
decl something : -> Unit
}
namespace var Array {
decl something : Unit -> Unit
decl something : -> Unit
}
namespace const Array {
decl something : Unit -> Unit
decl something : -> Unit
}

View file

@ -1,4 +1,4 @@
decl test_tuples : Unit -> Unit
decl test_tuples : -> Unit
def test_tuples = {
var tuple1 = & "a" & 2 & "hello"
const & t1 & t2 & t3 = f: x

View file

@ -1,4 +1,4 @@
decl test_type_casting : Unit -> Unit
decl test_type_casting : -> Unit
def test_type_casting = {
var x = y.as Int:
var k = (f: y x).as Float:

View file

@ -5,14 +5,17 @@ typeclass (Ord : #Eq) =
& is_less_then : Ord -> Bool
typeclass (D : #A #B #C) 'A 'B =
& do_something : Unit -> (& 'A & 'B)
& do_something : -> (& 'A & 'B)
typeclass E 'A =
& do_something : Unit -> 'A
& do_something : -> 'A
decl ( == ) ('A : #Ord) : 'A -> 'A -> Bool
def ( == ) : a b = a.is_equal_to: b
decl ( != ) ('A : #Ord) : 'A -> 'A -> Bool
def ( != ) : a b = not: (a == b)
decl ( < ) ('A : #Ord) : 'A -> 'A -> Bool
def ( < ) : a b = a.is_less_then: b

View file

@ -1,7 +1,3 @@
================================================================================
Types
================================================================================
alias T1 = Int
abstract (T2 : #A #B #C)
@ -10,45 +6,3 @@ abstract (T2 : #A #B #C)
let T2 = Int
let T2 = Float
let T2 = Complex
--------------------------------------------------------------------------------
(source_file
(source_statement
(namespace_statement
(alias_definition_statement
(type_identifier)
(type_expression
(parametrized_type
(type_identifier))))))
(source_statement
(abstract_type_definition_statement
(annotated_type
(type_identifier)
(parametrized_typeclass
(typeclass_identifier))
(parametrized_typeclass
(typeclass_identifier))
(parametrized_typeclass
(typeclass_identifier)))))
(source_statement
(namespace_statement
(alias_definition_statement
(type_identifier)
(type_expression
(parametrized_type
(type_identifier))))))
(source_statement
(namespace_statement
(alias_definition_statement
(type_identifier)
(type_expression
(parametrized_type
(type_identifier))))))
(source_statement
(namespace_statement
(alias_definition_statement
(type_identifier)
(type_expression
(parametrized_type
(type_identifier)))))))

View file

@ -1,4 +1,4 @@
decl test_variants : Unit -> Unit
decl test_variants : -> Unit
def test_variants = {
var variant1 = | 'a' | 2 | "hello"
var | val | err = f: x