Added short/long and unsigned types for all int based types
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
kraken="kraken"
|
kraken="kraken"
|
||||||
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3 2cd43e5a217318c70097334b3598d2924f64b362 2051f54b559ac5edf67277d4f1134aca2cb9215d)
|
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3 2cd43e5a217318c70097334b3598d2924f64b362 2051f54b559ac5edf67277d4f1134aca2cb9215d ecbbcb4eda56e2467efb0a04e7d668b95856aa4b)
|
||||||
|
|
||||||
# Echo version string to a file included by kraken.krak
|
# 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
|
# There is a default version string in the file in case kraken is not built with captain
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ translation_unit = WS unorderd_list_part WS ;
|
|||||||
unorderd_list_part = import WS unorderd_list_part | function WS unorderd_list_part | type_def line_end WS unorderd_list_part | adt_def line_end WS unorderd_list_part | if_comp WS unorderd_list_part | simple_passthrough WS unorderd_list_part | declaration_statement line_end WS unorderd_list_part | import | function | type_def line_end | adt_def line_end | if_comp | simple_passthrough | declaration_statement line_end ;
|
unorderd_list_part = import WS unorderd_list_part | function WS unorderd_list_part | type_def line_end WS unorderd_list_part | adt_def line_end WS unorderd_list_part | if_comp WS unorderd_list_part | simple_passthrough WS unorderd_list_part | declaration_statement line_end WS unorderd_list_part | import | function | type_def line_end | adt_def line_end | if_comp | simple_passthrough | declaration_statement line_end ;
|
||||||
|
|
||||||
type = "ref" WS pre_reffed | pre_reffed ;
|
type = "ref" WS pre_reffed | pre_reffed ;
|
||||||
pre_reffed = "\*" WS pre_reffed | "void" | "int" | "float" | "double" | "char" | scoped_identifier | scoped_identifier WS template_inst | function_type ;
|
pre_reffed = "\*" WS pre_reffed | "void" | "char" | "uchar" | "short" | "ushort" | "int" | "uint" | "long" | "ulong" | "float" | "double" | scoped_identifier | scoped_identifier WS template_inst | function_type ;
|
||||||
function_type = "fun" WS "\(" WS opt_type_list WS "\)" WS ":" WS type ;
|
function_type = "fun" WS "\(" WS opt_type_list WS "\)" WS ":" WS type ;
|
||||||
dec_type = ":" WS type ;
|
dec_type = ":" WS type ;
|
||||||
|
|
||||||
|
|||||||
@@ -396,14 +396,26 @@ obj ast_transformation (Object) {
|
|||||||
return type_ptr(base_type::void_return(), indirection, is_ref)
|
return type_ptr(base_type::void_return(), indirection, is_ref)
|
||||||
else if (type_syntax_str == "bool")
|
else if (type_syntax_str == "bool")
|
||||||
return type_ptr(base_type::boolean(), indirection, is_ref)
|
return type_ptr(base_type::boolean(), indirection, is_ref)
|
||||||
|
else if (type_syntax_str == "char")
|
||||||
|
return type_ptr(base_type::character(), indirection, is_ref)
|
||||||
|
else if (type_syntax_str == "uchar")
|
||||||
|
return type_ptr(base_type::ucharacter(), indirection, is_ref)
|
||||||
|
else if (type_syntax_str == "short")
|
||||||
|
return type_ptr(base_type::short_int(), indirection, is_ref)
|
||||||
|
else if (type_syntax_str == "ushort")
|
||||||
|
return type_ptr(base_type::ushort_int(), indirection, is_ref)
|
||||||
else if (type_syntax_str == "int")
|
else if (type_syntax_str == "int")
|
||||||
return type_ptr(base_type::integer(), indirection, is_ref)
|
return type_ptr(base_type::integer(), indirection, is_ref)
|
||||||
|
else if (type_syntax_str == "uint")
|
||||||
|
return type_ptr(base_type::uinteger(), indirection, is_ref)
|
||||||
|
else if (type_syntax_str == "long")
|
||||||
|
return type_ptr(base_type::long_int(), indirection, is_ref)
|
||||||
|
else if (type_syntax_str == "ulong")
|
||||||
|
return type_ptr(base_type::ulong_int(), indirection, is_ref)
|
||||||
else if (type_syntax_str == "float")
|
else if (type_syntax_str == "float")
|
||||||
return type_ptr(base_type::floating(), indirection, is_ref)
|
return type_ptr(base_type::floating(), indirection, is_ref)
|
||||||
else if (type_syntax_str == "double")
|
else if (type_syntax_str == "double")
|
||||||
return type_ptr(base_type::double_precision(), indirection, is_ref)
|
return type_ptr(base_type::double_precision(), indirection, is_ref)
|
||||||
else if (type_syntax_str == "char")
|
|
||||||
return type_ptr(base_type::character(), indirection, is_ref)
|
|
||||||
else if (get_node("function_type", real_node)) {
|
else if (get_node("function_type", real_node)) {
|
||||||
var types = get_nodes("type", get_node("function_type", real_node)).map(fun(node: *tree<symbol>): *type transform_type(node, scope, template_replacements);)
|
var types = get_nodes("type", get_node("function_type", real_node)).map(fun(node: *tree<symbol>): *type transform_type(node, scope, template_replacements);)
|
||||||
return type_ptr(types.slice(0,-2), types.last(), indirection, is_ref)
|
return type_ptr(types.slice(0,-2), types.last(), indirection, is_ref)
|
||||||
@@ -766,6 +778,7 @@ obj ast_transformation (Object) {
|
|||||||
parameters = get_nodes("intrinsic_parameter", node).map(fun(child: *tree<symbol>): string return concat_symbol_tree(child);)
|
parameters = get_nodes("intrinsic_parameter", node).map(fun(child: *tree<symbol>): string return concat_symbol_tree(child);)
|
||||||
if (get_nodes("type", node).size)
|
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);)
|
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::integer()))
|
||||||
}
|
}
|
||||||
fun transform_lambda(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *ast_node {
|
fun transform_lambda(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *ast_node {
|
||||||
|
|||||||
@@ -970,7 +970,13 @@ obj c_generator (Object) {
|
|||||||
base_type::void_return() return indirection + string("void")
|
base_type::void_return() return indirection + string("void")
|
||||||
base_type::boolean() return indirection + string("bool")
|
base_type::boolean() return indirection + string("bool")
|
||||||
base_type::character() return indirection + string("char")
|
base_type::character() return indirection + string("char")
|
||||||
|
base_type::ucharacter() return indirection + string("uchar")
|
||||||
|
base_type::short_int() return indirection + string("short")
|
||||||
|
base_type::ushort_int() return indirection + string("ushort")
|
||||||
base_type::integer() return indirection + string("int")
|
base_type::integer() return indirection + string("int")
|
||||||
|
base_type::uinteger() return indirection + string("uint")
|
||||||
|
base_type::long_int() return indirection + string("long")
|
||||||
|
base_type::ulong_int() return indirection + string("ulong")
|
||||||
base_type::floating() return indirection + string("float")
|
base_type::floating() return indirection + string("float")
|
||||||
base_type::double_precision() return indirection + string("double")
|
base_type::double_precision() return indirection + string("double")
|
||||||
base_type::object() return cify_name(type->type_def->type_def.name)
|
base_type::object() return cify_name(type->type_def->type_def.name)
|
||||||
@@ -994,7 +1000,13 @@ obj c_generator (Object) {
|
|||||||
base_type::void_return() return string("void") + indirection
|
base_type::void_return() return string("void") + indirection
|
||||||
base_type::boolean() return string("bool") + indirection
|
base_type::boolean() return string("bool") + indirection
|
||||||
base_type::character() return string("char") + indirection
|
base_type::character() return string("char") + indirection
|
||||||
|
base_type::ucharacter() return string("unsigned char") + indirection
|
||||||
|
base_type::short_int() return string("short") + indirection
|
||||||
|
base_type::ushort_int() return string("unsigned short") + indirection
|
||||||
base_type::integer() return string("int") + indirection
|
base_type::integer() return string("int") + indirection
|
||||||
|
base_type::uinteger() return string("unsigned int") + indirection
|
||||||
|
base_type::long_int() return string("long") + indirection
|
||||||
|
base_type::ulong_int() return string("unsigned long") + indirection
|
||||||
base_type::floating() return string("float") + indirection
|
base_type::floating() return string("float") + indirection
|
||||||
base_type::double_precision() return string("double") + indirection
|
base_type::double_precision() return string("double") + indirection
|
||||||
base_type::object() return get_name(type->type_def) + indirection
|
base_type::object() return get_name(type->type_def) + indirection
|
||||||
@@ -1058,7 +1070,7 @@ obj c_generator (Object) {
|
|||||||
// TODO keyword avoid seems not to work
|
// TODO keyword avoid seems not to work
|
||||||
if (ast_name_map.contains_value(result) || c_keyword_avoid.contains(result))
|
if (ast_name_map.contains_value(result) || c_keyword_avoid.contains(result))
|
||||||
result += get_id()
|
result += get_id()
|
||||||
println("HERE: " + result)
|
/*println("HERE: " + result)*/
|
||||||
ast_name_map.set(node, result)
|
ast_name_map.set(node, result)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,20 @@
|
|||||||
__if_comp__ __C__ simple_passthrough """
|
|
||||||
#include <stdlib.h>
|
|
||||||
"""
|
|
||||||
|
|
||||||
/* we have a template versions so we don't have to cast (because we don't have that yet) */
|
|
||||||
|
|
||||||
fun null<T>(): *T {
|
fun null<T>(): *T {
|
||||||
__if_comp__ __C__ {
|
return (0) cast *T
|
||||||
simple_passthrough(::) """
|
|
||||||
return (void*)0;
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun malloc<T>(size: int): *T {
|
ext fun malloc(size: int): *void
|
||||||
var memPtr: *T;
|
ext fun free(size: *void)
|
||||||
__if_comp__ __C__ {
|
|
||||||
simple_passthrough( size = size, memPtr = memPtr : memPtr = memPtr :) """
|
|
||||||
memPtr = malloc(size);
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
return memPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
fun free<T>(memPtr: *T): void {
|
fun new<T>(count: int): *T
|
||||||
__if_comp__ __C__ {
|
return (malloc( #sizeof<T> * count )) cast *T
|
||||||
simple_passthrough(memPtr = memPtr ::) """
|
|
||||||
free(memPtr);
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun new<T>(count: int): *T {
|
fun new<T>(): *T
|
||||||
return malloc<T>( #sizeof<T> * count );
|
return new<T>(1)
|
||||||
}
|
|
||||||
|
|
||||||
fun new<T>(): *T {
|
|
||||||
return new<T>(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We specilize on the trait Object to decide on whether or not the destructor should be called */
|
/* We specilize on the trait Object to decide on whether or not the destructor should be called */
|
||||||
fun delete<T>(toDelete: *T, itemCount: int): void {
|
fun delete<T>(toDelete: *T, itemCount: int)
|
||||||
delete<T>(toDelete);
|
delete<T>(toDelete)
|
||||||
}
|
|
||||||
|
|
||||||
/* Calling this with itemCount = 0 allows you to delete destructable objects without calling their destructors. */
|
/* Calling this with itemCount = 0 allows you to delete destructable objects without calling their destructors. */
|
||||||
fun delete<T(Object)>(toDelete: *T, itemCount: int): void {
|
fun delete<T(Object)>(toDelete: *T, itemCount: int): void {
|
||||||
@@ -49,45 +22,38 @@ fun delete<T(Object)>(toDelete: *T, itemCount: int): void {
|
|||||||
// finishes the pointer
|
// finishes the pointer
|
||||||
for (var i: int = 0; i < itemCount; i++;)
|
for (var i: int = 0; i < itemCount; i++;)
|
||||||
toDelete[i].destruct();
|
toDelete[i].destruct();
|
||||||
free<T>(toDelete);
|
free((toDelete) cast *void);
|
||||||
//delete<T>(toDelete);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We specilize on the trait Object to decide on whether or not the destructor should be called */
|
/* We specilize on the trait Object to decide on whether or not the destructor should be called */
|
||||||
fun delete<T>(toDelete: *T): void {
|
fun delete<T>(toDelete: *T)
|
||||||
free<T>(toDelete);
|
free((toDelete) cast *void)
|
||||||
}
|
|
||||||
|
|
||||||
fun delete<T(Object)>(toDelete: *T): void {
|
fun delete<T(Object)>(toDelete: *T): void {
|
||||||
toDelete->destruct();
|
toDelete->destruct();
|
||||||
free<T>(toDelete);
|
free((toDelete) cast *void);
|
||||||
}
|
}
|
||||||
|
|
||||||
// a wrapper for construct if it has the Object trait
|
// a wrapper for construct if it has the Object trait
|
||||||
fun maybe_construct<T>(it:*T):*T {
|
fun maybe_construct<T>(it:*T):*T
|
||||||
return it
|
return it
|
||||||
}
|
|
||||||
|
|
||||||
fun maybe_construct<T(Object)>(it:*T):*T {
|
fun maybe_construct<T(Object)>(it:*T):*T
|
||||||
return it->construct()
|
return it->construct()
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// a wrapper for copy constructing if it has the Object trait
|
// a wrapper for copy constructing if it has the Object trait
|
||||||
fun maybe_copy_construct<T>(to:*T, from:*T):void {
|
fun maybe_copy_construct<T>(to:*T, from:*T)
|
||||||
*to = *from
|
*to = *from
|
||||||
}
|
|
||||||
|
|
||||||
fun maybe_copy_construct<T(Object)>(to:*T, from:*T):void {
|
|
||||||
|
fun maybe_copy_construct<T(Object)>(to:*T, from:*T)
|
||||||
to->copy_construct(from)
|
to->copy_construct(from)
|
||||||
}
|
|
||||||
|
|
||||||
// a wrapper for destruct if it has the Object trait
|
// a wrapper for destruct if it has the Object trait
|
||||||
fun maybe_destruct<T>(it:*T):void {}
|
fun maybe_destruct<T>(it:*T) {}
|
||||||
|
|
||||||
fun maybe_destruct<T(Object)>(it:*T):void {
|
fun maybe_destruct<T(Object)>(it:*T)
|
||||||
it->destruct()
|
it->destruct()
|
||||||
}
|
|
||||||
|
|
||||||
obj shared_ptr<T> (Object){
|
obj shared_ptr<T> (Object){
|
||||||
var data: *T;
|
var data: *T;
|
||||||
@@ -151,4 +117,3 @@ obj shared_ptr<T> (Object){
|
|||||||
|
|
||||||
}; //end shared_ptr class
|
}; //end shared_ptr class
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,6 @@ fun operator+(first: *char, second: ref string): string {
|
|||||||
return string(first) + second
|
return string(first) + second
|
||||||
}
|
}
|
||||||
|
|
||||||
/*fun operator+<T>(first: *char, second: T): string {*/
|
|
||||||
/*return string(first) + second*/
|
|
||||||
/*}*/
|
|
||||||
|
|
||||||
fun string(in:*char):string {
|
fun string(in:*char):string {
|
||||||
var out.construct(in):string
|
var out.construct(in):string
|
||||||
return out
|
return out
|
||||||
|
|||||||
@@ -12,15 +12,21 @@ adt base_type {
|
|||||||
object,
|
object,
|
||||||
adt,
|
adt,
|
||||||
no_type_adt_option,
|
no_type_adt_option,
|
||||||
|
function,
|
||||||
template,
|
template,
|
||||||
template_type,
|
template_type,
|
||||||
void_return,
|
void_return,
|
||||||
boolean,
|
boolean,
|
||||||
character,
|
character,
|
||||||
|
ucharacter,
|
||||||
|
short_int,
|
||||||
|
ushort_int,
|
||||||
integer,
|
integer,
|
||||||
|
uinteger,
|
||||||
|
long_int,
|
||||||
|
ulong_int,
|
||||||
floating,
|
floating,
|
||||||
double_precision,
|
double_precision
|
||||||
function
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun type_ptr(): *type {
|
fun type_ptr(): *type {
|
||||||
@@ -161,7 +167,13 @@ obj type (Object) {
|
|||||||
base_type::void_return() return indr_string + string("void_return") + trait_string
|
base_type::void_return() return indr_string + string("void_return") + trait_string
|
||||||
base_type::boolean() return indr_string + string("boolean") + trait_string
|
base_type::boolean() return indr_string + string("boolean") + trait_string
|
||||||
base_type::character() return indr_string + string("character") + trait_string
|
base_type::character() return indr_string + string("character") + trait_string
|
||||||
|
base_type::short_int() return indr_string + string("short") + trait_string
|
||||||
base_type::integer() return indr_string + string("integer") + trait_string
|
base_type::integer() return indr_string + string("integer") + trait_string
|
||||||
|
base_type::long_int() return indr_string + string("long") + trait_string
|
||||||
|
base_type::ucharacter() return indr_string + string("ucharacter") + trait_string
|
||||||
|
base_type::ushort_int() return indr_string + string("ushort") + trait_string
|
||||||
|
base_type::uinteger() return indr_string + string("uinteger") + trait_string
|
||||||
|
base_type::ulong_int() return indr_string + string("ulong") + trait_string
|
||||||
base_type::floating() return indr_string + string("floating") + trait_string
|
base_type::floating() return indr_string + string("floating") + trait_string
|
||||||
base_type::double_precision() return indr_string + string("double_precision") + trait_string
|
base_type::double_precision() return indr_string + string("double_precision") + trait_string
|
||||||
base_type::function() {
|
base_type::function() {
|
||||||
@@ -177,9 +189,15 @@ obj type (Object) {
|
|||||||
return 5
|
return 5
|
||||||
match (base) {
|
match (base) {
|
||||||
base_type::character() return 1
|
base_type::character() return 1
|
||||||
base_type::integer() return 2
|
base_type::ucharacter() return 1
|
||||||
base_type::floating() return 3
|
base_type::short_int() return 2
|
||||||
base_type::double_precision() return 4
|
base_type::ushort_int() return 2
|
||||||
|
base_type::integer() return 3
|
||||||
|
base_type::uinteger() return 3
|
||||||
|
base_type::long_int() return 4
|
||||||
|
base_type::ulong_int() return 4
|
||||||
|
base_type::floating() return 5
|
||||||
|
base_type::double_precision() return 6
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user