Some bugfixes/added errors, convert most to not use simple_passthrough
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
kraken="kraken"
|
||||
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3 2cd43e5a217318c70097334b3598d2924f64b362 2051f54b559ac5edf67277d4f1134aca2cb9215d ecbbcb4eda56e2467efb0a04e7d668b95856aa4b)
|
||||
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3 2cd43e5a217318c70097334b3598d2924f64b362 2051f54b559ac5edf67277d4f1134aca2cb9215d ecbbcb4eda56e2467efb0a04e7d668b95856aa4b d126cbf24ba8b26e3814e2260d555ecaee86508c)
|
||||
|
||||
# Echo version string to a file included by kraken.krak
|
||||
# There is a default version string in the file in case kraken is not built with captain
|
||||
|
||||
@@ -77,7 +77,7 @@ fun main(argc: int, argv: **char):int {
|
||||
println("Generating C")
|
||||
/*println("NOW DOING C_GENERATOR")*/
|
||||
var c_generator.construct(): c_generator
|
||||
var c_output_pair = c_generator.generate_c(importer.name_ast_map)
|
||||
var c_output_pair = c_generator.generate_c(importer.name_ast_map, importer.ast_pass.ast_to_syntax)
|
||||
var kraken_c_output_name = kraken_file_name + ".c"
|
||||
write_file(kraken_c_output_name, c_output_pair.first)
|
||||
/*println(string("linker string: ") + c_output_pair.second)*/
|
||||
|
||||
@@ -615,7 +615,7 @@ obj ast_transformation (Object) {
|
||||
identifier->identifier.type = get_ast_type(expression)->clone_without_ref()
|
||||
}
|
||||
if (!identifier->identifier.type) error(node, "declaration statement with no type or expression from which to inference type")
|
||||
if (identifier->identifier.type->is_none()) error(node, "declaration statement with bad type")
|
||||
if (identifier->identifier.type->is_none() || (identifier->identifier.type->indirection == 0 && identifier->identifier.type->is_void())) error(node, "declaration statement with bad type")
|
||||
var declaration = ast_declaration_statement_ptr(identifier, expression)
|
||||
// ok, deal with the possible init position method call
|
||||
if (identifiers.size == 2) {
|
||||
@@ -716,9 +716,13 @@ obj ast_transformation (Object) {
|
||||
}
|
||||
fun transform_return_statement(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *ast_node {
|
||||
var return_value = get_node("boolean_expression", node)
|
||||
var to_ret: *ast_node
|
||||
if (return_value)
|
||||
return ast_return_statement_ptr(transform(return_value, scope, template_replacements))
|
||||
return ast_return_statement_ptr(null<ast_node>())
|
||||
to_ret = ast_return_statement_ptr(transform(return_value, scope, template_replacements))
|
||||
else
|
||||
to_ret = ast_return_statement_ptr(null<ast_node>())
|
||||
ast_to_syntax.set(to_ret, node)
|
||||
return to_ret
|
||||
}
|
||||
fun transform_branching_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||
if (node->data.name == "break_statement")
|
||||
@@ -778,8 +782,8 @@ obj ast_transformation (Object) {
|
||||
parameters = get_nodes("intrinsic_parameter", node).map(fun(child: *tree<symbol>): string return concat_symbol_tree(child);)
|
||||
if (get_nodes("type", node).size)
|
||||
type_parameters = get_nodes("type", node).map(fun(child: *tree<symbol>): *type return transform_type(child, scope, template_replacements);)
|
||||
/*return ast_compiler_intrinsic_ptr(concat_symbol_tree(get_node("identifier", node)), parameters, type_parameters, type_ptr(base_type::ulong_int()))*/
|
||||
return ast_compiler_intrinsic_ptr(concat_symbol_tree(get_node("identifier", node)), parameters, type_parameters, type_ptr(base_type::integer()))
|
||||
return ast_compiler_intrinsic_ptr(concat_symbol_tree(get_node("identifier", node)), parameters, type_parameters, type_ptr(base_type::ulong_int()))
|
||||
/*return ast_compiler_intrinsic_ptr(concat_symbol_tree(get_node("identifier", node)), parameters, type_parameters, type_ptr(base_type::integer()))*/
|
||||
}
|
||||
fun transform_lambda(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *ast_node {
|
||||
var function_node = second_pass_function(node, scope, template_replacements, false)
|
||||
|
||||
@@ -75,6 +75,7 @@ obj code_triple (Object) {
|
||||
|
||||
obj c_generator (Object) {
|
||||
var id_counter: int
|
||||
var ast_to_syntax: map<*ast_node, *tree<symbol>>
|
||||
var ast_name_map: map<*ast_node, string>
|
||||
var closure_struct_map: map<set<*ast_node>, string>
|
||||
var function_type_map: map<type, string>
|
||||
@@ -86,6 +87,7 @@ obj c_generator (Object) {
|
||||
var linker_string: string
|
||||
fun construct(): *c_generator {
|
||||
id_counter = 0
|
||||
ast_to_syntax.construct()
|
||||
ast_name_map.construct()
|
||||
closure_struct_map.construct()
|
||||
function_type_map.construct()
|
||||
@@ -144,6 +146,7 @@ obj c_generator (Object) {
|
||||
}
|
||||
fun copy_construct(old: *c_generator) {
|
||||
id_counter = old->id_counter
|
||||
ast_to_syntax.copy_construct(&old->ast_to_syntax)
|
||||
ast_name_map.copy_construct(&old->ast_name_map)
|
||||
closure_struct_map.copy_construct(&old->closure_struct_map)
|
||||
function_type_map.copy_construct(&old->function_type_map)
|
||||
@@ -159,6 +162,7 @@ obj c_generator (Object) {
|
||||
copy_construct(&other)
|
||||
}
|
||||
fun destruct() {
|
||||
ast_to_syntax.destruct()
|
||||
ast_name_map.destruct()
|
||||
closure_struct_map.destruct()
|
||||
function_type_map.destruct()
|
||||
@@ -205,8 +209,9 @@ obj c_generator (Object) {
|
||||
return make_pair(type_to_c(backing.type->return_type) + " " + decorated_name + "(" + parameter_types + ");\n",
|
||||
type_to_c(backing.type->return_type) + " " + decorated_name + "(" + parameters + ")")
|
||||
}
|
||||
fun generate_c(name_ast_map: map<string, pair<*tree<symbol>,*ast_node>>): pair<string,string> {
|
||||
var prequal: string = "#include <stdbool.h>\n#include <stdlib.h>\n#include <stdio.h>\n"
|
||||
fun generate_c(name_ast_map: map<string, pair<*tree<symbol>,*ast_node>>, ast_to_syntax_in: map<*ast_node, *tree<symbol>> ): pair<string,string> {
|
||||
ast_to_syntax = ast_to_syntax_in
|
||||
var prequal: string = "#include <stdbool.h>\n"
|
||||
var plain_typedefs: string = "\n/**Plain Typedefs**/\n"
|
||||
var top_level_c_passthrough: string = ""
|
||||
var variable_extern_declarations: string = ""
|
||||
@@ -371,7 +376,6 @@ obj c_generator (Object) {
|
||||
ast_node::declaration_statement(backing) variable_declarations += generate_declaration_statement(child, null<ast_node>(), null<ast_node>(), null<stack<pair<bool,stack<*ast_node>>>>(), false).one_string() + ";\n" // false - don't do defer
|
||||
ast_node::function(backing) {
|
||||
// check for and add to parameters if a closure
|
||||
if (!backing.is_extern)
|
||||
generate_function_definition(child, null<ast_node>(), false)
|
||||
}
|
||||
ast_node::template(backing) {
|
||||
@@ -446,7 +450,8 @@ obj c_generator (Object) {
|
||||
structs += "};\n"
|
||||
})
|
||||
|
||||
return make_pair(prequal+plain_typedefs+top_level_c_passthrough+variable_extern_declarations+structs+function_typedef_string+closure_struct_definitions+function_prototypes+variable_declarations+function_definitions + "\n", linker_string)
|
||||
/*return make_pair(prequal+plain_typedefs+top_level_c_passthrough+variable_extern_declarations+structs+function_typedef_string+closure_struct_definitions+function_prototypes+variable_declarations+function_definitions + "\n", linker_string)*/
|
||||
return make_pair(prequal+plain_typedefs+function_typedef_string+top_level_c_passthrough+variable_extern_declarations+structs+closure_struct_definitions+function_prototypes+variable_declarations+function_definitions + "\n", linker_string)
|
||||
}
|
||||
fun get_closure_struct_type(closed_variables: set<*ast_node>): string {
|
||||
if (!closure_struct_map.contains_key(closed_variables)) {
|
||||
@@ -599,7 +604,7 @@ obj c_generator (Object) {
|
||||
to_ret.pre = generate_declaration_statement(declaration, enclosing_object, enclosing_func, defer_stack, false).one_string() + ";\n"
|
||||
if ((function_return_type->is_object() || return_value_type->is_object()) && !function_return_type->equality(return_value_type, false))
|
||||
// note the clone with decreased indirection because of the clone with increased indirection above
|
||||
error(string("return type does not match: ") + function_return_type->to_string() + ", " + return_value_type->to_string());
|
||||
error(ast_to_syntax[node], string("return type does not match: ") + function_return_type->to_string() + ", " + return_value_type->to_string());
|
||||
if (!function_return_type->is_ref && return_value_type->indirection == 0 && (return_value_type->is_adt() || (return_value_type->is_object() && has_method(return_value_type->type_def, "copy_construct", vector(return_value_type->clone_with_indirection(1)))))) {
|
||||
to_ret.pre += generate_statement(ast_statement_ptr(make_method_call(temp_ident, "copy_construct", vector(make_operator_call("&", vector(return_value))))), enclosing_object, enclosing_func, defer_stack).one_string()
|
||||
} else {
|
||||
@@ -724,7 +729,7 @@ obj c_generator (Object) {
|
||||
if (as_value) {
|
||||
var closed_vars = node->function.closed_variables
|
||||
if (closed_vars.size() == 0)
|
||||
return code_triple(string("((") + type_to_c(node->function.type) + "){(void*)NULL,(void*)" + get_name(node) + "})")
|
||||
return code_triple(string("((") + type_to_c(node->function.type) + "){(void*)0,(void*)" + get_name(node) + "})")
|
||||
var temp_closure_struct = string("closure_struct_temp") + get_id()
|
||||
var to_ret = code_triple()
|
||||
var closure_type_str = get_closure_struct_type(closed_vars)
|
||||
|
||||
@@ -4,9 +4,7 @@ __if_comp__ __C__ simple_passthrough(::"-pthread") """
|
||||
#include <pthread.h>
|
||||
"""
|
||||
|
||||
def pthread_t float
|
||||
|
||||
fun pthread_create(thrd : *pthread_t, strt_routine : fun() : void) : int {
|
||||
fun pthread_create(thrd : *ulong, strt_routine : fun() : void) : int {
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(thrd,strt_routine::) """
|
||||
pthread_attr_t attr;
|
||||
@@ -20,7 +18,7 @@ fun pthread_create(thrd : *pthread_t, strt_routine : fun() : void) : int {
|
||||
return 0
|
||||
}
|
||||
|
||||
fun pthread_join(thrd : *pthread_t) : int {
|
||||
fun pthread_join(thrd : *ulong) : int {
|
||||
__if_comp__ __C__ { simple_passthrough(thrd::) """
|
||||
pthread_t thread = *((pthread_t*)thrd);
|
||||
return pthread_join(thread, NULL);
|
||||
@@ -48,7 +46,7 @@ obj future<T> {
|
||||
var status : int
|
||||
var psy : fun() : T
|
||||
var wrapper : fun() : void
|
||||
var thread : pthread_t
|
||||
var thread : ulong
|
||||
|
||||
fun construct(in : fun() : T) : *future<T> {
|
||||
status = 0
|
||||
|
||||
@@ -65,7 +65,7 @@ obj hash_map<T,U> (Object, Serializable) {
|
||||
/*io::println((this) cast int)*/
|
||||
/*io::print("size of data:")*/
|
||||
/*io::println(data.size)*/
|
||||
var key_hash = util::hash(key)
|
||||
var key_hash = (util::hash(key)) cast int
|
||||
if (!data[key_hash%data.size].contains_key(key)) {
|
||||
size++
|
||||
if (size > data.size) {
|
||||
@@ -75,7 +75,7 @@ obj hash_map<T,U> (Object, Serializable) {
|
||||
for (var i = 0; i < size*2; i++;)
|
||||
new_data.addEnd(map::map<T,U>())
|
||||
for_each(fun(key: T, value: U) {
|
||||
new_data[util::hash(key)%new_data.size].set(key, value)
|
||||
new_data[(util::hash(key)) cast int%new_data.size].set(key, value)
|
||||
})
|
||||
data = new_data
|
||||
}
|
||||
@@ -83,10 +83,10 @@ obj hash_map<T,U> (Object, Serializable) {
|
||||
data[key_hash%data.size].set(key, value)
|
||||
}
|
||||
fun get(key: T): ref U {
|
||||
return data[util::hash(key)%data.size].get(key)
|
||||
return data[(util::hash(key)) cast int%data.size].get(key)
|
||||
}
|
||||
fun contains_key(key: T): bool {
|
||||
return data[util::hash(key)%data.size].contains_key(key)
|
||||
return data[(util::hash(key)) cast int%data.size].contains_key(key)
|
||||
}
|
||||
fun contains_value(value: U): bool {
|
||||
for (var i = 0; i < data.size; i++;) {
|
||||
@@ -103,7 +103,7 @@ obj hash_map<T,U> (Object, Serializable) {
|
||||
io::println("trying to reverse get a value that is not in the hash_map")
|
||||
}
|
||||
fun remove(key: T) {
|
||||
data[util::hash(key)%data.size].remove(key)
|
||||
data[(util::hash(key)) cast int%data.size].remove(key)
|
||||
}
|
||||
fun for_each(func: fun(T, U):void) {
|
||||
for (var i = 0; i < data.size; i++;)
|
||||
|
||||
151
stdlib/io.krak
151
stdlib/io.krak
@@ -2,10 +2,6 @@ import string;
|
||||
import vector;
|
||||
import mem:*
|
||||
|
||||
__if_comp__ __C__ simple_passthrough """
|
||||
#include <stdio.h>
|
||||
"""
|
||||
|
||||
fun println() : void {
|
||||
print("\n");
|
||||
}
|
||||
@@ -15,35 +11,18 @@ fun println<T>(toPrint: T) : void {
|
||||
print("\n")
|
||||
}
|
||||
|
||||
fun print<T>(toPrint: *T) : void{
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(toPrint = toPrint::) """
|
||||
printf("%p", (void*)toPrint);
|
||||
fflush(0);
|
||||
"""
|
||||
}
|
||||
return;
|
||||
}
|
||||
fun print<T>(toPrint: *T)
|
||||
print((toPrint) cast ulong)
|
||||
|
||||
ext fun printf(fmt_str: *char, to_print: *char): int
|
||||
ext fun fflush(file: int): int
|
||||
fun print(toPrint: *char) : void {
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(toPrint = toPrint::) """
|
||||
printf("%s", toPrint);
|
||||
fflush(0);
|
||||
"""
|
||||
}
|
||||
return;
|
||||
printf("%s", toPrint)
|
||||
fflush(0)
|
||||
}
|
||||
|
||||
fun print(toPrint: char) : void {
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(toPrint = toPrint::) """
|
||||
printf("%c", toPrint);
|
||||
fflush(0);
|
||||
"""
|
||||
}
|
||||
return;
|
||||
}
|
||||
fun print(toPrint: char) : void
|
||||
print(string::string(toPrint))
|
||||
|
||||
fun print(toPrint: string::string) : void {
|
||||
var charArr = toPrint.toCharArray()
|
||||
@@ -59,52 +38,39 @@ fun print(toPrint: bool): void {
|
||||
return;
|
||||
}
|
||||
|
||||
fun print(toPrint: int): void {
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(toPrint = toPrint::) """
|
||||
printf("%d", toPrint);
|
||||
fflush(0);
|
||||
"""
|
||||
}
|
||||
return;
|
||||
}
|
||||
fun print(toPrint: int): void
|
||||
print(string::to_string(toPrint))
|
||||
fun print(toPrint: ulong): void
|
||||
print(string::to_string(toPrint))
|
||||
|
||||
fun print(toPrint: float): void {
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(toPrint = toPrint::) """
|
||||
printf("%f", toPrint);
|
||||
fflush(0);
|
||||
"""
|
||||
}
|
||||
return;
|
||||
}
|
||||
ext fun sprintf(to_str: *char, format: *char, d: double)
|
||||
fun print(toPrint: float)
|
||||
print((toPrint) cast double)
|
||||
|
||||
fun print(toPrint: double) : void{
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(toPrint = toPrint::) """
|
||||
printf("%f", toPrint);
|
||||
fflush(0);
|
||||
"""
|
||||
}
|
||||
return;
|
||||
fun print(toPrint: double) {
|
||||
var int_str = new<char>((#sizeof<double>) cast int)
|
||||
sprintf(int_str, "%f", toPrint)
|
||||
print(int_str)
|
||||
delete(int_str)
|
||||
}
|
||||
|
||||
// Ok, just some DEAD simple file io for now
|
||||
ext fun fopen(path: *char, mode: *char): *void
|
||||
ext fun fclose(file: *void): int
|
||||
ext fun fprintf(file: *void, format: *char, data: *char): int
|
||||
ext fun ftell(file: *void): long
|
||||
ext fun fseek(file: *void, offset: long, whence: int): int
|
||||
ext fun fread(ptr: *void, size: ulong, nmemb: ulong, file: *void): ulong
|
||||
ext fun fwrite(ptr: *void, size: ulong, nmemb: ulong, file: *void): ulong
|
||||
fun file_exists(path: string::string): bool {
|
||||
var char_path = path.toCharArray()
|
||||
defer delete(char_path)
|
||||
var result = false
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(char_path:result:) """
|
||||
bool result = false;
|
||||
FILE *fp = fopen(char_path, "r");
|
||||
var fp = fopen(char_path, "r")
|
||||
if (fp) {
|
||||
result = true;
|
||||
fclose(fp);
|
||||
fclose(fp)
|
||||
return true
|
||||
}
|
||||
"""
|
||||
}
|
||||
return result
|
||||
return false
|
||||
}
|
||||
fun read_file(path: string::string): string::string {
|
||||
if (!file_exists(path))
|
||||
@@ -117,40 +83,25 @@ fun write_file(path: string::string, data: string::string) {
|
||||
defer delete(char_path)
|
||||
var char_data = data.toCharArray()
|
||||
defer delete(char_data)
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(char_path,char_data::) """
|
||||
FILE *fp = fopen(char_path, "w");
|
||||
fprintf(fp, "%s", char_data);
|
||||
fclose(fp);
|
||||
"""
|
||||
}
|
||||
var fp = fopen(char_path, "w")
|
||||
fprintf(fp, "%s", char_data)
|
||||
fclose(fp)
|
||||
}
|
||||
fun read_file_binary(path: string::string): vector::vector<char> {
|
||||
var char_path = path.toCharArray()
|
||||
defer delete(char_path)
|
||||
var data: *char
|
||||
var size: int
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(char_path = char_path:data = data, size = size:) """
|
||||
FILE *fp = fopen(char_path, "r");
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
long size = ftell(fp);
|
||||
fseek(fp, 0L, SEEK_SET);
|
||||
char *data = malloc(size+1);
|
||||
size_t readSize = fread(data, 1, size, fp);
|
||||
data[readSize] = 0;
|
||||
fclose(fp);
|
||||
"""
|
||||
}
|
||||
var toRet.construct(size): vector::vector<char>
|
||||
var fp = fopen(char_path, "r")
|
||||
fseek(fp, (0) cast long, 2)// fseek(fp, 0L, SEEK_END)
|
||||
var size = ftell(fp)
|
||||
fseek(fp, (0) cast long, 0)//fseek(fp, 0L, SEEK_SET)
|
||||
var data = new<char>((size+1) cast int)
|
||||
var readSize = fread((data) cast *void, (1) cast ulong, (size) cast ulong, fp)
|
||||
fclose(fp)
|
||||
data[readSize] = 0
|
||||
var toRet.construct((size) cast int): vector::vector<char>
|
||||
for (var i = 0; i < size; i++;)
|
||||
toRet.add(data[i])
|
||||
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(data = data::) """
|
||||
free(data);
|
||||
"""
|
||||
}
|
||||
delete(data)
|
||||
return toRet
|
||||
}
|
||||
fun write_file_binary(path: string::string, vdata: vector::vector<char>) {
|
||||
@@ -158,13 +109,9 @@ fun write_file_binary(path: string::string, vdata: vector::vector<char>) {
|
||||
defer delete(char_path)
|
||||
var data = vdata.getBackingMemory()
|
||||
var size = vdata.size
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(char_path, data, size::) """
|
||||
FILE *fp = fopen(char_path, "w");
|
||||
fwrite(data, 1, size, fp);
|
||||
fclose(fp);
|
||||
"""
|
||||
}
|
||||
var fp = fopen(char_path, "w")
|
||||
fwrite((data) cast *void, (1) cast ulong, (size) cast ulong, fp)
|
||||
fclose(fp)
|
||||
}
|
||||
|
||||
fun BoldRed(): void{
|
||||
@@ -195,7 +142,3 @@ fun Reset(): void{
|
||||
print("\033[0m");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
146
stdlib/math.krak
146
stdlib/math.krak
@@ -1,139 +1,27 @@
|
||||
__if_comp__ __C__ simple_passthrough(::"-lm") """
|
||||
#include <math.h>
|
||||
"""
|
||||
|
||||
fun fibanacci(num: int): int {
|
||||
if (num < 2)
|
||||
return 1;
|
||||
return fibanacci(num-1) + fibanacci(num-2);
|
||||
var l1 = 1
|
||||
var l2 = 1
|
||||
for (var i = 0; i < num; i++;) {
|
||||
var next = l1 + l2
|
||||
l2 = l1
|
||||
l1 = next
|
||||
}
|
||||
return l1
|
||||
}
|
||||
|
||||
/*********************
|
||||
* Trig Functions
|
||||
********************/
|
||||
|
||||
fun atan(arg: double): double
|
||||
{
|
||||
var ans: double = 0;
|
||||
__if_comp__ __C__{
|
||||
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
|
||||
ans = atan(arg);
|
||||
"""
|
||||
}//end C wrapper
|
||||
|
||||
return ans;
|
||||
}//end atan function
|
||||
|
||||
fun atan2(x: double, y: double): double
|
||||
{
|
||||
var ans: double = 0;
|
||||
__if_comp__ __C__{
|
||||
simple_passthrough(x = x, y = y, ans = ans : ans = ans :) """
|
||||
ans = atan2(x,y);
|
||||
"""
|
||||
}//end C wrapper
|
||||
|
||||
return ans;
|
||||
}//end atan2 function
|
||||
|
||||
fun acos(arg: double): double
|
||||
{
|
||||
var ans: double = 0;
|
||||
__if_comp__ __C__{
|
||||
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
|
||||
ans = acos(arg);
|
||||
"""
|
||||
}//end C wrapper
|
||||
|
||||
return ans;
|
||||
}//end acos function
|
||||
|
||||
fun asin(arg: double): double
|
||||
{
|
||||
var ans: double = 0;
|
||||
__if_comp__ __C__{
|
||||
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
|
||||
ans = asin(arg);
|
||||
"""
|
||||
}//end C wrapper
|
||||
|
||||
return ans;
|
||||
}//end asin function
|
||||
|
||||
fun tan(arg: double): double
|
||||
{
|
||||
var ans: double = 0;
|
||||
__if_comp__ __C__{
|
||||
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
|
||||
ans = tan(arg);
|
||||
"""
|
||||
}//end C wrapper
|
||||
|
||||
return ans;
|
||||
}//end tan function
|
||||
|
||||
fun cos(arg: double): double
|
||||
{
|
||||
var ans: double = 0;
|
||||
__if_comp__ __C__{
|
||||
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
|
||||
ans = cos(arg);
|
||||
"""
|
||||
}//end C wrapper
|
||||
|
||||
return ans;
|
||||
}//end cos function
|
||||
|
||||
fun sin(arg: double): double
|
||||
{
|
||||
var ans: double = 0;
|
||||
__if_comp__ __C__{
|
||||
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
|
||||
ans = sin(arg);
|
||||
"""
|
||||
}//end C wrapper
|
||||
|
||||
return ans;
|
||||
}//end sin function
|
||||
|
||||
ext fun atan(arg: double): double
|
||||
ext fun atan2(x: double, y: double): double
|
||||
ext fun acos(arg: double): double
|
||||
ext fun asin(arg: double): double
|
||||
ext fun tan(arg: double): double
|
||||
ext fun cos(arg: double): double
|
||||
ext fun sin(arg: double): double
|
||||
fun mod(x: double, y: double): double
|
||||
{
|
||||
var ans: double;
|
||||
var intAns: int;
|
||||
|
||||
intAns = x / y;
|
||||
ans = x - intAns*y;
|
||||
|
||||
return ans;
|
||||
var intAns = x / y;
|
||||
return x - intAns*y;
|
||||
}
|
||||
|
||||
val M_PI = acos(-1);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
|
||||
fun null<T>(): *T {
|
||||
return (0) cast *T
|
||||
}
|
||||
|
||||
ext fun malloc(size: int): *void
|
||||
ext fun malloc(size: ulong): *void
|
||||
ext fun free(size: *void)
|
||||
|
||||
fun null<T>(): *T
|
||||
return (0) cast *T
|
||||
|
||||
fun new<T>(count: int): *T
|
||||
return (malloc( #sizeof<T> * count )) cast *T
|
||||
return (malloc( (#sizeof<T> * count ) cast ulong )) cast *T
|
||||
|
||||
fun new<T>(): *T
|
||||
return new<T>(1)
|
||||
|
||||
@@ -7,22 +7,7 @@ fun system(call_string: string):int {
|
||||
delete(c_call_string)
|
||||
return result
|
||||
}
|
||||
fun system(call_string: *char): int {
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(call_string::) """
|
||||
return system(call_string);
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
ext fun system(call_string: *char): int
|
||||
ext fun exit(code: int):void
|
||||
fun exit() exit(0);
|
||||
fun exit(code: int) {
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(code::) """
|
||||
exit(code);
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ fun unserialize<T>(it: ref vector::vector<char>): T {
|
||||
return unserialize<T>(it, 0).first
|
||||
}
|
||||
fun unserialize<T>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
||||
return util::make_pair(*(it.getBackingMemory()+pos) cast *T, pos + #sizeof<T>)
|
||||
return util::make_pair(*(it.getBackingMemory()+pos) cast *T, pos + (#sizeof<T>) cast int)
|
||||
}
|
||||
fun unserialize<T(Serializable)>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
||||
var toRet: T
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
|
||||
fun println() {
|
||||
print("\n")
|
||||
}
|
||||
fun println(to_print: *char) {
|
||||
print(to_print)
|
||||
print("\n")
|
||||
}
|
||||
fun println(to_print: char) {
|
||||
print(to_print)
|
||||
print("\n")
|
||||
}
|
||||
fun println(to_print: int) {
|
||||
print(to_print)
|
||||
print("\n")
|
||||
}
|
||||
fun println(to_print: float) {
|
||||
print(to_print)
|
||||
print("\n")
|
||||
}
|
||||
fun println(to_print: double) {
|
||||
print(to_print)
|
||||
print("\n")
|
||||
}
|
||||
fun println(to_print: bool) {
|
||||
print(to_print)
|
||||
print("\n")
|
||||
}
|
||||
fun print(to_print: *char) {
|
||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||
printf("%s", to_print);
|
||||
"""
|
||||
}
|
||||
fun print(to_print: char) {
|
||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||
printf("%c", to_print);
|
||||
"""
|
||||
}
|
||||
fun print(to_print: int) {
|
||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||
printf("%d", to_print);
|
||||
"""
|
||||
}
|
||||
|
||||
fun print(to_print: float) {
|
||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||
printf("%f", to_print);
|
||||
"""
|
||||
}
|
||||
fun print(to_print: double) {
|
||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||
printf("%f", to_print);
|
||||
"""
|
||||
}
|
||||
fun print(to_print: bool) {
|
||||
if (to_print) print("true")
|
||||
else print("false")
|
||||
}
|
||||
|
||||
@@ -2,16 +2,41 @@ import vector
|
||||
import util
|
||||
import mem
|
||||
import serialize
|
||||
import io
|
||||
|
||||
fun to_string(in: int): string {
|
||||
var dest = mem::new<char>(#sizeof<int> * 8)
|
||||
defer mem::delete(dest)
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(dest = dest, in = in::) """
|
||||
sprintf(dest, "%d", in);
|
||||
"""
|
||||
fun to_string(in: uchar): string
|
||||
return to_string_num(in)
|
||||
fun to_string(in: short): string
|
||||
return to_string_num(in)
|
||||
fun to_string(in: ushort): string
|
||||
return to_string_num(in)
|
||||
fun to_string(in: int): string
|
||||
return to_string_num(in)
|
||||
fun to_string(in: uint): string
|
||||
return to_string_num(in)
|
||||
fun to_string(in: long): string
|
||||
return to_string_num(in)
|
||||
fun to_string(in: ulong): string
|
||||
return to_string_num(in)
|
||||
|
||||
fun to_string_num<T>(in: T): string {
|
||||
if (in == 0)
|
||||
return string("0")
|
||||
var ret = string()
|
||||
var pos = 0
|
||||
var is_neg = false
|
||||
if (in > 0) {
|
||||
pos = in
|
||||
} else {
|
||||
pos = -in
|
||||
is_neg = true
|
||||
}
|
||||
var ret = string(dest)
|
||||
while (pos) {
|
||||
ret = string((pos%10 + '0') cast char) + ret
|
||||
pos = pos / 10
|
||||
}
|
||||
if (is_neg)
|
||||
return string("-") + ret
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,18 @@ fun min<T>(a: T, b: T): T {
|
||||
return a;
|
||||
}
|
||||
|
||||
fun hash<T(Hashable)>(item: T): int return item.hash()
|
||||
fun hash<T>(item: *T): int return (item) cast int
|
||||
fun hash(item: int): int return item
|
||||
fun hash(item: char): int return item
|
||||
fun hash<T(Hashable)>(item: T): ulong return item.hash()
|
||||
fun hash<T>(item: *T): ulong return (item) cast ulong
|
||||
fun hash(item: char): ulong return item
|
||||
fun hash(item: uchar): ulong return item
|
||||
fun hash(item: short): ulong return item
|
||||
fun hash(item: ushort): ulong return item
|
||||
fun hash(item: int): ulong return item
|
||||
fun hash(item: uint): ulong return item
|
||||
fun hash(item: long): ulong return item
|
||||
fun hash(item: ulong): ulong return item
|
||||
// default hash
|
||||
fun hash<T>(item: T): int {
|
||||
fun hash<T>(item: T): ulong {
|
||||
io::println("using empty hash - please do not do!")
|
||||
return 0
|
||||
}
|
||||
@@ -95,8 +101,7 @@ obj pair<T,U> (Object, Serializable, Hashable) {
|
||||
return second_pair.second
|
||||
}
|
||||
|
||||
fun hash():int return hash(first) ^ hash(second)
|
||||
/*fun hash():int return 0*/
|
||||
fun hash():ulong return hash(first) ^ hash(second)
|
||||
|
||||
// the old unnecessary template to prevent generation
|
||||
// if not used trick (in this case, changing out U with V)
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
import io:*
|
||||
import grammer:*
|
||||
import parser:*
|
||||
import lexer:*
|
||||
import string:*
|
||||
import util:*
|
||||
import symbol:*
|
||||
import tree:*
|
||||
import serialize:*
|
||||
|
||||
fun main():int {
|
||||
|
||||
/*var a.construct(): grammer*/
|
||||
// delay construction until unserialization or copy_construction now
|
||||
var a: grammer
|
||||
|
||||
var file_name = string("../krakenGrammer.kgm")
|
||||
/*var file_name = string("../simplifiedKrakenGrammer.kgm")*/
|
||||
/*var file_name = string("grammer.kgm")*/
|
||||
|
||||
var compiled_name = file_name + string(".comp_new")
|
||||
var file_contents = read_file(file_name)
|
||||
var loaded_and_valid = false
|
||||
|
||||
if (file_exists(compiled_name)) {
|
||||
println("cached file exists")
|
||||
var pos = 0
|
||||
var binary = read_file_binary(compiled_name)
|
||||
println("read file!")
|
||||
var cached_contents = string()
|
||||
println("made tmp string!")
|
||||
unpack(cached_contents, pos) = unserialize<string>(binary, pos)
|
||||
println("unserialized the string!")
|
||||
if (cached_contents == file_contents) {
|
||||
println("loaded_and_valid, using cached version!")
|
||||
loaded_and_valid = true
|
||||
/*unpack(a, pos) = unserialize<grammer>(binary, pos)*/
|
||||
// avoid extra copies
|
||||
pos = a.unserialize(binary, pos)
|
||||
println("finished unserializeing!!")
|
||||
} else {
|
||||
println("file contents do not match:")
|
||||
println("CACHED:")
|
||||
println(cached_contents)
|
||||
println("REAL:")
|
||||
println(file_contents)
|
||||
println("END")
|
||||
}
|
||||
} else {
|
||||
println("cached file does not exist")
|
||||
}
|
||||
if (!loaded_and_valid) {
|
||||
println("Not loaded_and_valid, re-generating and writing out")
|
||||
/*a = load_grammer(file_contents)*/
|
||||
// copy construct now
|
||||
a.copy_construct(&load_grammer(file_contents))
|
||||
println("grammer loaded, calculate_first_set")
|
||||
a.calculate_first_set()
|
||||
println("grammer loaded, calculate_state_automaton")
|
||||
a.calculate_state_automaton()
|
||||
println("calculated, writing out")
|
||||
write_file_binary(compiled_name, serialize(file_contents) + serialize(a))
|
||||
println("done writing")
|
||||
}
|
||||
/*println(a.to_string())*/
|
||||
var doFirstSet = fun() {
|
||||
println("///////////////////START FIRST SET/////////////")
|
||||
println("//TERMINALS//")
|
||||
a.terminals.for_each( fun(terminal: util::pair<symbol::symbol, regex::regex>) {
|
||||
var set_str = string::string("{ ")
|
||||
a.first_set_map[terminal.first].for_each( fun(sym: symbol::symbol) {
|
||||
set_str += sym.to_string() + ", "
|
||||
})
|
||||
set_str += "}"
|
||||
print(terminal.first.to_string() + " first: " + set_str + "\n")
|
||||
})
|
||||
println("//NON TERMINALS//")
|
||||
a.non_terminals.for_each( fun(non_terminal: symbol::symbol) {
|
||||
var set_str = string::string("{ ")
|
||||
a.first_set_map[non_terminal].for_each( fun(sym: symbol::symbol) {
|
||||
set_str += sym.to_string() + ", "
|
||||
})
|
||||
set_str += "}"
|
||||
print(non_terminal.to_string() + " first: " + set_str + "\n")
|
||||
println()
|
||||
})
|
||||
println("///////////////////END FIRST SET/////////////")
|
||||
}
|
||||
/*doFirstSet()*/
|
||||
|
||||
println(a.to_string())
|
||||
a.parse_table.print_string()
|
||||
var lex = lexer(a.terminals)
|
||||
|
||||
lex.set_input(read_file(string("to_parse.krak")))
|
||||
/*lex.set_input(string("ccdahas spacedhas*/
|
||||
/*returndaaaaaaaaaaaaaa"))*/
|
||||
//lex.set_input(string("hibyed"))
|
||||
println("woo lexing:")
|
||||
range(8).for_each(fun(i: int) { println(lex.next().to_string()); } )
|
||||
/*range(80).for_each(fun(i: int) { println(lex.next().to_string()); } )*/
|
||||
|
||||
|
||||
var parse.construct(a): parser
|
||||
/*var result = parse.parse_input(string("a"), string("fun name"))*/
|
||||
/*var result = parse.parse_input(read_file(string("test_adt.krak")), string("fun name"))*/
|
||||
var result = parse.parse_input(read_file(string("to_parse.krak")), string("fun name"))
|
||||
/*var result = parse.parse_input(string("inport a;"), string("fun name"))*/
|
||||
/*var result = parse.parse_input(string("fun main():int { return 0; }"), string("fun name"))*/
|
||||
/*var result = parse.parse_input(string("ad"), string("fun name"))*/
|
||||
/*var result = parse.parse_input(string("hibyed"), string("fun name"))*/
|
||||
/*var result = parse.parse_input(string("hmmhmmend"), string("fun name"))*/
|
||||
/*var result = parse.parse_input(string("hid"), string("fun name"))*/
|
||||
println("the tree")
|
||||
println(syntax_tree_to_dot(result))
|
||||
write_file(string("syntax_tree.dot"), syntax_tree_to_dot(result))
|
||||
/*var parse.construct(): parser*/
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
3.141593
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
krakenPath="../build/kraken"
|
||||
#testDir=${1:-"../tests"}
|
||||
testDir="."
|
||||
ext=${2:-"krak"}
|
||||
|
||||
fileList=""
|
||||
for dir in `find ${testDir} -type f -name "test_*.${ext}"`; do
|
||||
filename=$(basename ${dir})
|
||||
filename="${filename%.*}"
|
||||
fileList+=\ $testDir\/$filename
|
||||
done
|
||||
|
||||
${krakenPath} "--test" ${fileList}
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
obj Vec2 {
|
||||
var x: int;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
fun fibanacci(num: int): int {
|
||||
if (num < 2)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun retVoid() {
|
||||
println("Woooo")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun main(): int {
|
||||
simple_print::println("Spam");
|
||||
io::println("Spam");
|
||||
var x: int = 4;
|
||||
x += 3;
|
||||
x++;
|
||||
@@ -10,16 +10,16 @@ fun main(): int {
|
||||
var q :int = z+z;
|
||||
var q2:int = z*3;
|
||||
var q3:int = y + y;
|
||||
simple_print::println(q3);
|
||||
simple_print::println(z);
|
||||
simple_print::println(q);
|
||||
io::println(q3);
|
||||
io::println(z);
|
||||
io::println(q);
|
||||
for (var i:int = 0; i < 20; i++;) z++;
|
||||
if (z > 20) simple_print::println("We'll find out.");
|
||||
simple_print::println(z);
|
||||
if (z > 20) io::println("We'll find out.");
|
||||
io::println(z);
|
||||
var boolean = false
|
||||
if ( z > 20 && !boolean)
|
||||
simple_print::println("woo not")
|
||||
simple_print::println('b' == 'a')
|
||||
io::println("woo not")
|
||||
io::println('b' == 'a')
|
||||
println(3|5)
|
||||
println(3^5)
|
||||
println(3&5)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj BracketAssign {
|
||||
fun operator[]=(index:int, rhs:int) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun main():int {
|
||||
for (var i = 1; i < 10; i++;) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*here*/
|
||||
/*here*/import /*here*/simple_print/*here*/:/*here*/*/*here*/
|
||||
/*here*/import /*here*/io/*here*/:/*here*/*/*here*/
|
||||
/*here*/
|
||||
/*here*/fun/*here*/ main/*here*/(/*here*/)/*here*/:/*here*/ int/*here*/ {/*here*/
|
||||
/*here*/ println/*here*/( /*here*/1 /*here*/ )/*here*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
import vector:*
|
||||
|
||||
fun onlyMatch(vec: vector<int>, matchWith: int): vector<int> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import vector:*;
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
fun test<T>(a: vector<T>): T {
|
||||
return a.at(0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun func(it: ref int) {
|
||||
it++
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Comment first! */
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
fun main(): int {
|
||||
println(1337) /*how bout now*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun Comparable<T>(): Comparable<T> {
|
||||
var toRet : Comparable<T>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun main(): int {
|
||||
println(#sizeof<char>)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun main():int {
|
||||
println((65) cast char)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
import mem:*;
|
||||
|
||||
obj ClassWithConstructor {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj wDestructor {
|
||||
var data: *char
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
|
||||
fun main(): int {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import simple_print;
|
||||
import io;
|
||||
|
||||
fun nothing(): void {}
|
||||
|
||||
fun main(): int {
|
||||
nothing();
|
||||
simple_print::println("It was nothing");
|
||||
io::println("It was nothing");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ ext fun printf(format_str: *char, actual_str: *char): int
|
||||
|
||||
fun main():int {
|
||||
printf("%s", "Hello extern!\n")
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
fun addAndPrint<T,J>(a: T, b: J): void {
|
||||
print(a+b);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj FuncObj {
|
||||
fun operator()(a:int, b:*char): void {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
fun ret1(): int {
|
||||
return ret2() / 2;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj Traited(Traits) {}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import simple_print;
|
||||
import io;
|
||||
|
||||
fun addAndPrint<T>(a: T, b: T): T {
|
||||
simple_print::print(a+b);
|
||||
io::print(a+b);
|
||||
return a+b;
|
||||
}
|
||||
|
||||
fun main(): int {
|
||||
addAndPrint<int>(10,12);
|
||||
simple_print::print("\n");
|
||||
io::print("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun test(): void {
|
||||
println(9)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun do_num(it: int) {
|
||||
print("int: ")
|
||||
|
||||
BIN
tests/test_math
Executable file
BIN
tests/test_math
Executable file
Binary file not shown.
7
tests/test_math.expected_results
Normal file
7
tests/test_math.expected_results
Normal file
@@ -0,0 +1,7 @@
|
||||
atan = 3.141593
|
||||
atan2 = 0.000000
|
||||
acos = 0.000000
|
||||
asin = 3.141593
|
||||
tan = 0.990050
|
||||
cos = 1.000000
|
||||
sin = 0.000000
|
||||
@@ -1,13 +1,10 @@
|
||||
import simple_print:*;
|
||||
import math:*;
|
||||
import io:*
|
||||
import math:*
|
||||
|
||||
fun main(): int
|
||||
{
|
||||
var STD_PI = 3.12159265
|
||||
var ans: double;
|
||||
var STD_PI: double = 4.0*atan(1.0);
|
||||
println(STD_PI);
|
||||
|
||||
/*
|
||||
ans = 4.0*atan(1.0);
|
||||
print("atan = ");
|
||||
println(ans);
|
||||
@@ -35,6 +32,5 @@ fun main(): int
|
||||
ans = sin(0.0);
|
||||
print("sin = ");
|
||||
println(ans);
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import mem:*;
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
obj AnObject {
|
||||
var a: int;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
obj firstObject {
|
||||
var objectNum: int;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
import trivial_container:*;
|
||||
|
||||
obj RegularObject {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun main():int {
|
||||
println("multi
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
|
||||
fun main(): int {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
Qualified simple_print!
|
||||
Qualified io!
|
||||
7
|
||||
9
|
||||
11
|
||||
Qualified Container!
|
||||
Even template functions qualified!
|
||||
|
||||
Unqualified simple_print!
|
||||
Unqualified io!
|
||||
8
|
||||
10
|
||||
12
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import simple_print;
|
||||
import io;
|
||||
import scopeQualified;
|
||||
import scopeUnqualified : * ;
|
||||
|
||||
fun main(): int {
|
||||
simple_print::println("Qualified simple_print!");
|
||||
io::println("Qualified io!");
|
||||
|
||||
// Defined in scopeQualified
|
||||
simple_print::println(scopeQualified::qualified_variable);
|
||||
simple_print::println(scopeQualified::qualified_func());
|
||||
io::println(scopeQualified::qualified_variable);
|
||||
io::println(scopeQualified::qualified_func());
|
||||
var qClass.construct(11): scopeQualified::qualified_class;
|
||||
simple_print::println(qClass.get());
|
||||
io::println(qClass.get());
|
||||
|
||||
var sayQualified.construct("Qualified Container!"): scopeQualified::qualified_container<*char>;
|
||||
simple_print::println(sayQualified.get());
|
||||
simple_print::println(scopeQualified::qualified_id<*char>("Even template functions qualified!"));
|
||||
io::println(sayQualified.get());
|
||||
io::println(scopeQualified::qualified_id<*char>("Even template functions qualified!"));
|
||||
|
||||
simple_print::println();
|
||||
io::println();
|
||||
|
||||
simple_print::println("Unqualified simple_print!");
|
||||
io::println("Unqualified io!");
|
||||
// Defined in scopeUnqualified
|
||||
simple_print::println(unqualifed_variable);
|
||||
simple_print::println(unqualified_func());
|
||||
io::println(unqualifed_variable);
|
||||
io::println(unqualified_func());
|
||||
var uqClass.construct(12): unqualified_class;
|
||||
simple_print::println(uqClass.get());
|
||||
io::println(uqClass.get());
|
||||
|
||||
var sayUnqualified.construct("Unqualified Container!"): unqualified_container<*char>;
|
||||
simple_print::println(sayUnqualified.get());
|
||||
simple_print::println(unqualified_id<*char>("Even template functions unqualified!"));
|
||||
io::println(sayUnqualified.get());
|
||||
io::println(unqualified_id<*char>("Even template functions unqualified!"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun main(): int {
|
||||
println("no semicolons!")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj ConTest {
|
||||
var a: int
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
obj objectA {
|
||||
var a: int;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun oneLine1():void println(7)
|
||||
fun oneLine2():int return 8
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun main():int {
|
||||
var message = "thingy: "
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj test_cons(Object) {
|
||||
fun construct(): *test_cons {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
import sameNameOne
|
||||
import sameNameTwo
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun is_true():bool {
|
||||
return true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
fun addAndPrintInt(a: int, b: int): int {
|
||||
print(a+b);
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import simple_print;
|
||||
import io;
|
||||
|
||||
|
||||
obj TemplateTest<T,J> {
|
||||
var a: T;
|
||||
var b: J;
|
||||
fun print(): void {
|
||||
simple_print::print("a: ");
|
||||
simple_print::print(a);
|
||||
simple_print::print("\n");
|
||||
simple_print::print("b: ");
|
||||
simple_print::print(b);
|
||||
simple_print::print("\n");
|
||||
io::print("a: ");
|
||||
io::print(a);
|
||||
io::print("\n");
|
||||
io::print("b: ");
|
||||
io::print(b);
|
||||
io::print("\n");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import simple_print;
|
||||
import io;
|
||||
|
||||
|
||||
obj TemplateTest<T> {
|
||||
var a: int;
|
||||
var b: T;
|
||||
fun print(): void {
|
||||
simple_print::print("a: ");
|
||||
simple_print::print(a);
|
||||
simple_print::print("\n");
|
||||
simple_print::print("b: ");
|
||||
simple_print::print(b);
|
||||
simple_print::print("\n");
|
||||
io::print("a: ");
|
||||
io::print(a);
|
||||
io::print("\n");
|
||||
io::print("b: ");
|
||||
io::print(b);
|
||||
io::print("\n");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import simple_print;
|
||||
import io;
|
||||
|
||||
obj FirstObject {
|
||||
var objectNum: int;
|
||||
fun PrintSelf(a: int): void {
|
||||
simple_print::print(objectNum);
|
||||
simple_print::print(a);
|
||||
io::print(objectNum);
|
||||
io::print(a);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,6 +12,6 @@ fun main(): int {
|
||||
var wooObject: FirstObject;
|
||||
wooObject.objectNum = 5;
|
||||
wooObject.PrintSelf(7);
|
||||
simple_print::print("\n");
|
||||
io::print("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj templd<T> {
|
||||
var data: T
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
import trivial_container:*;
|
||||
|
||||
obj TemplateTest<T> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj it {
|
||||
fun operator+<U>(other: U): it {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj Object<T> {
|
||||
var data: T
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
fun main(): int {
|
||||
var b: int;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import simple_print;
|
||||
import io;
|
||||
|
||||
var a: int = 42;
|
||||
var b = "hi";
|
||||
|
||||
fun main(): int {
|
||||
simple_print::println(a);
|
||||
simple_print::println(b);
|
||||
io::println(a);
|
||||
io::println(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print:*;
|
||||
import io:*;
|
||||
|
||||
obj NoTraits {};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import simple_print;
|
||||
import io;
|
||||
|
||||
obj ClassWithConstructor {
|
||||
var data: int;
|
||||
@@ -7,7 +7,7 @@ obj ClassWithConstructor {
|
||||
return this;
|
||||
}
|
||||
fun printData(): void {
|
||||
simple_print::println(data);
|
||||
io::println(data);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,6 +15,6 @@ fun main(): int {
|
||||
var object.construct(4): ClassWithConstructor;
|
||||
object.printData();
|
||||
var a :int = 8;
|
||||
simple_print::println(a);
|
||||
io::println(a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import util:*
|
||||
import simple_print:*
|
||||
import io:*
|
||||
|
||||
obj test(Object) {
|
||||
var counter:int
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import simple_print;
|
||||
import io;
|
||||
|
||||
obj trivialContainer<T> {
|
||||
var data: T;
|
||||
fun print(): void {
|
||||
simple_print::print(data);
|
||||
io::print(data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user