mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
example fixes
This commit is contained in:
parent
71c7d91e1a
commit
562541087e
13 changed files with 30 additions and 322 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit 3ffcfa276c80724af4910c8c310b1945c995dc4b
|
Subproject commit 62c8b6193437e0a10d5b605dc002c7db5e3fc256
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
decl test_arrays : Unit -> Unit
|
decl test_arrays : -> Unit
|
||||||
def test_arrays = {
|
def test_arrays = {
|
||||||
var arr1 = ,1 ,2 ,3
|
var arr1 = ,1 ,2 ,3
|
||||||
const arr2 = Int._array: 32
|
const arr2 = Int._array: 32
|
||||||
var arr3 = String._array: 11
|
var arr3 = String._array: 11
|
||||||
const arr4 = 'a'--'z'
|
const arr4 = 'a'--'z'
|
||||||
const n = 100
|
const n = 100
|
||||||
var @arr5 <- Int.@_new_array: 10
|
var arr5 <- Int._new_array: 10
|
||||||
|
|
||||||
var @arr6 <- String.@_new_array: 10
|
var arr6 <- String._new_array: 10
|
||||||
var ~arr6_reference = ~arr6
|
var arr6_reference = ^arr6
|
||||||
|
|
||||||
const elem1 = arr1`0
|
const elem1 = arr1`0
|
||||||
var elem2 = arr1`2
|
var elem2 = arr1`2
|
||||||
const ~ref1 = ~arr1`1
|
const ref1 = ^arr1`1
|
||||||
var ~ref2 = ~arr1`3
|
var ref2 = ^arr1`3
|
||||||
; arr1`1 = 123
|
; arr1`1 = 123
|
||||||
|
|
||||||
; ref1 = arr1`2 // set value
|
; ~ref1 = arr1`2 // set value
|
||||||
; ~ref1 = ~ref2 // set reference
|
; ref1 = ref2 // set pointer / reference
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
decl flow_control_test : Unit -> Unit
|
decl flow_control_test : -> Unit
|
||||||
def flow_control_test = {
|
def flow_control_test = {
|
||||||
if (a < b ||. a == b) && (b < c) then IO.print: x
|
if (a < b ||. a == b) && (b < c) then IO.print: x
|
||||||
elif x < 0 then {
|
elif x < 0 then {
|
||||||
|
|
@ -19,7 +19,7 @@ def flow_control_test = {
|
||||||
; IO.print: i
|
; 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: 1
|
||||||
; IO.print: 2
|
; IO.print: 2
|
||||||
; IO.print: 128
|
; IO.print: 128
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,10 @@ def find_substring : str substr = {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
decl is_empty : Unit -> Bool
|
decl is_empty : -> Bool
|
||||||
def is_empty = 0
|
def is_empty = 0
|
||||||
|
|
||||||
decl do_something : Unit -> Unit
|
decl do_something : -> Unit
|
||||||
def do_something =
|
def do_something =
|
||||||
IO.print: "Hello World!"
|
IO.print: "Hello World!"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
decl test_lambdas : Unit -> Unit
|
decl test_lambdas : -> Unit
|
||||||
def test_lambdas = {
|
def test_lambdas = {
|
||||||
const lambda1 = \x -> x * x
|
const lambda1 = \x -> x * x
|
||||||
const lambda2 = \x -> x.hash:
|
const lambda2 = \x -> x.hash:
|
||||||
|
|
|
||||||
249
tests/match.lang
249
tests/match.lang
|
|
@ -1,7 +1,3 @@
|
||||||
================================================================================
|
|
||||||
Match
|
|
||||||
================================================================================
|
|
||||||
|
|
||||||
decl fruit_cost : Fruit -> Int
|
decl fruit_cost : Fruit -> Int
|
||||||
def fruit_cost : fruit = {
|
def fruit_cost : fruit = {
|
||||||
return (match fruit with
|
return (match fruit with
|
||||||
|
|
@ -19,248 +15,3 @@ def amount_to_string : x is_zero_separated = {
|
||||||
| _ -> "Lots"
|
| _ -> "Lots"
|
||||||
return ans
|
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)))))))))))))))))
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
struct StructWithRef =
|
struct StructWithRef =
|
||||||
& @Int_0
|
& @Int_0
|
||||||
|
|
||||||
decl test_memory : Unit -> Unit
|
decl test_memory : -> Unit
|
||||||
def test_memory = {
|
def test_memory = {
|
||||||
const @unique_ref1 <- Int.@_new: 5
|
const unique_ref1 <- Int._new: 5
|
||||||
var @unique_ref2 <- Array.@of: 1 2 3
|
var unique_ref2 <- Array.of: 1 2 3
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
namespace Namespace {
|
namespace Namespace {
|
||||||
decl something : Unit -> Unit
|
decl something : -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Array {
|
namespace Array {
|
||||||
decl something : Unit -> Unit
|
decl something : -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Array {
|
namespace Array {
|
||||||
decl something : Unit -> Unit
|
decl something : -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace var Array {
|
namespace var Array {
|
||||||
decl something : Unit -> Unit
|
decl something : -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace const Array {
|
namespace const Array {
|
||||||
decl something : Unit -> Unit
|
decl something : -> Unit
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
decl test_tuples : Unit -> Unit
|
decl test_tuples : -> Unit
|
||||||
def test_tuples = {
|
def test_tuples = {
|
||||||
var tuple1 = & "a" & 2 & "hello"
|
var tuple1 = & "a" & 2 & "hello"
|
||||||
const & t1 & t2 & t3 = f: x
|
const & t1 & t2 & t3 = f: x
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
decl test_type_casting : Unit -> Unit
|
decl test_type_casting : -> Unit
|
||||||
def test_type_casting = {
|
def test_type_casting = {
|
||||||
var x = y.as Int:
|
var x = y.as Int:
|
||||||
var k = (f: y x).as Float:
|
var k = (f: y x).as Float:
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,17 @@ typeclass (Ord : #Eq) =
|
||||||
& is_less_then : Ord -> Bool
|
& is_less_then : Ord -> Bool
|
||||||
|
|
||||||
typeclass (D : #A #B #C) 'A 'B =
|
typeclass (D : #A #B #C) 'A 'B =
|
||||||
& do_something : Unit -> (& 'A & 'B)
|
& do_something : -> (& 'A & 'B)
|
||||||
|
|
||||||
typeclass E 'A =
|
typeclass E 'A =
|
||||||
& do_something : Unit -> 'A
|
& do_something : -> 'A
|
||||||
|
|
||||||
decl ( == ) ('A : #Ord) : 'A -> 'A -> Bool
|
decl ( == ) ('A : #Ord) : 'A -> 'A -> Bool
|
||||||
def ( == ) : a b = a.is_equal_to: b
|
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
|
decl ( < ) ('A : #Ord) : 'A -> 'A -> Bool
|
||||||
def ( < ) : a b = a.is_less_then: b
|
def ( < ) : a b = a.is_less_then: b
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
================================================================================
|
|
||||||
Types
|
|
||||||
================================================================================
|
|
||||||
|
|
||||||
alias T1 = Int
|
alias T1 = Int
|
||||||
|
|
||||||
abstract (T2 : #A #B #C)
|
abstract (T2 : #A #B #C)
|
||||||
|
|
@ -10,45 +6,3 @@ abstract (T2 : #A #B #C)
|
||||||
let T2 = Int
|
let T2 = Int
|
||||||
let T2 = Float
|
let T2 = Float
|
||||||
let T2 = Complex
|
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)))))))
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
decl test_variants : Unit -> Unit
|
decl test_variants : -> Unit
|
||||||
def test_variants = {
|
def test_variants = {
|
||||||
var variant1 = | 'a' | 2 | "hello"
|
var variant1 = | 'a' | 2 | "hello"
|
||||||
var | val | err = f: x
|
var | val | err = f: x
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue