Bugfixes, remove the cast_ptr function
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,3 +22,5 @@ kraken
|
|||||||
*.c
|
*.c
|
||||||
kraken_bac
|
kraken_bac
|
||||||
kraken_deprecated
|
kraken_deprecated
|
||||||
|
bootstrap_kalypso
|
||||||
|
kraken_bootstrap
|
||||||
|
|||||||
18
captain.sh
18
captain.sh
@@ -1,17 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
kraken="kraken"
|
kraken="kraken"
|
||||||
|
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3)
|
||||||
|
|
||||||
if [[ $1 == "clean" ]]
|
if [[ $1 == "clean" ]]
|
||||||
then
|
then
|
||||||
rm ${kraken}
|
rm ${kraken}
|
||||||
rm ${kraken}_bac
|
rm ${kraken}_bac
|
||||||
rm ${kraken}_deprecated
|
rm ${kraken}_deprecated
|
||||||
rm -r deprecated_compiler/stdlib
|
rm -rf bootstrap_kalypso
|
||||||
rm deprecated_compiler/krakenGrammer.kgm.comp
|
|
||||||
rm deprecated_compiler/krakenGrammer.kgm
|
|
||||||
rm -r deprecated_compiler/build
|
|
||||||
rm -r deprecated_compiler/build_kraken
|
|
||||||
else
|
else
|
||||||
if [[ $1 == "backup" ]]
|
if [[ $1 == "backup" ]]
|
||||||
then
|
then
|
||||||
@@ -22,6 +19,7 @@ else
|
|||||||
rm ${kraken}
|
rm ${kraken}
|
||||||
rm ${kraken}_bac
|
rm ${kraken}_bac
|
||||||
rm ${kraken}_deprecated
|
rm ${kraken}_deprecated
|
||||||
|
rm ${kraken}_bootstrap
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -s "$kraken" ]
|
if [ -s "$kraken" ]
|
||||||
@@ -34,7 +32,10 @@ else
|
|||||||
then
|
then
|
||||||
if ! [ -s "${kraken}_deprecated" ]
|
if ! [ -s "${kraken}_deprecated" ]
|
||||||
then
|
then
|
||||||
echo "no ${kraken}_deprecated, using Cephelpod"
|
echo "no ${kraken}_deprecated, bootstrapping using Cephelpod and a chain of old Kalypsos"
|
||||||
|
git clone . bootstrap_kalypso
|
||||||
|
pushd bootstrap_kalypso
|
||||||
|
git checkout $bootstrap_commits[0]
|
||||||
cp -r stdlib deprecated_compiler
|
cp -r stdlib deprecated_compiler
|
||||||
cp krakenGrammer.kgm deprecated_compiler
|
cp krakenGrammer.kgm deprecated_compiler
|
||||||
cp kraken.krak deprecated_compiler
|
cp kraken.krak deprecated_compiler
|
||||||
@@ -50,7 +51,10 @@ else
|
|||||||
../build/kraken kraken.krak
|
../build/kraken kraken.krak
|
||||||
popd
|
popd
|
||||||
popd
|
popd
|
||||||
cp deprecated_compiler/build_kraken/kraken/kraken ./${kraken}_deprecated
|
cp deprecated_compiler/build_kraken/kraken/kraken ../${kraken}_bootstrap
|
||||||
|
popd
|
||||||
|
# Now make
|
||||||
|
./${kraken}_bootstrap kraken.krak ${kraken}_deprecated
|
||||||
else
|
else
|
||||||
echo "${kraken}_deprecated exists, calling"
|
echo "${kraken}_deprecated exists, calling"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -586,11 +586,9 @@ obj c_generator (Object) {
|
|||||||
var declaration = ast_declaration_statement_ptr(temp_ident, null<ast_node>())
|
var declaration = ast_declaration_statement_ptr(temp_ident, null<ast_node>())
|
||||||
// have to pass false to the declaration generator, so can't do it through generate_statement
|
// have to pass false to the declaration generator, so can't do it through generate_statement
|
||||||
to_ret.pre = generate_declaration_statement(declaration, enclosing_object, enclosing_func, defer_stack, false).one_string() + ";\n"
|
to_ret.pre = generate_declaration_statement(declaration, enclosing_object, enclosing_func, defer_stack, false).one_string() + ";\n"
|
||||||
if ((function_return_type->is_object() || temp_ident_type->is_object()) &&
|
if ((function_return_type->is_object() || return_value_type->is_object()) && !function_return_type->equality(return_value_type, false))
|
||||||
( (!function_return_type->is_ref && !function_return_type->equality(temp_ident_type, false)) ||
|
|
||||||
(function_return_type->is_ref && !function_return_type->equality(temp_ident_type->clone_with_decreased_indirection(), false)) ) )
|
|
||||||
// note the clone with decreased indirection because of the clone with increased indirection above
|
// 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() + ", " + temp_ident_type->to_string());
|
error(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)))))) {
|
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()
|
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 {
|
} else {
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
fun to_char<T>(in: T) : char {
|
|
||||||
var out:char
|
|
||||||
__if_comp__ __C__ {
|
|
||||||
simple_passthrough(in = in: out = out:) """
|
|
||||||
char out = (char) in;
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
fun to_int<T>(in: T) : int {
|
|
||||||
var out:int
|
|
||||||
__if_comp__ __C__ {
|
|
||||||
simple_passthrough(in = in: out = out:) """
|
|
||||||
int out = (int) in;
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
fun cast_ptr<T,U>(in: T):U {
|
|
||||||
var out:U
|
|
||||||
simple_passthrough(in:out:) """
|
|
||||||
void* out = in;
|
|
||||||
"""
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -4,7 +4,6 @@ import string
|
|||||||
import mem
|
import mem
|
||||||
import set
|
import set
|
||||||
import util
|
import util
|
||||||
import conversions
|
|
||||||
import serialize
|
import serialize
|
||||||
|
|
||||||
fun regex(in: *char):regex {
|
fun regex(in: *char):regex {
|
||||||
@@ -24,7 +23,7 @@ obj regexState (Object) {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
fun construct(): *regexState {
|
fun construct(): *regexState {
|
||||||
return construct(conversions::to_char(0))
|
return construct((0) cast char)
|
||||||
}
|
}
|
||||||
fun copy_construct(old:*regexState): void {
|
fun copy_construct(old:*regexState): void {
|
||||||
character = old->character
|
character = old->character
|
||||||
@@ -58,7 +57,7 @@ obj regex (Object, Serializable) {
|
|||||||
var beginningAndEnd = compile(regexStringIn)
|
var beginningAndEnd = compile(regexStringIn)
|
||||||
// init our begin, and the end state as the next state of each end
|
// init our begin, and the end state as the next state of each end
|
||||||
begin = beginningAndEnd.first
|
begin = beginningAndEnd.first
|
||||||
var end = mem::new<regexState>()->construct(conversions::to_char(1))
|
var end = mem::new<regexState>()->construct((1) cast char)
|
||||||
beginningAndEnd.second.for_each(fun(it: *regexState): void { it->next_states.add(end); })
|
beginningAndEnd.second.for_each(fun(it: *regexState): void { it->next_states.add(end); })
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import vector
|
import vector
|
||||||
import conversions
|
|
||||||
import mem
|
import mem
|
||||||
import util
|
import util
|
||||||
|
|
||||||
@@ -8,7 +7,7 @@ fun serialize<T(Serializable)>(it: T): vector::vector<char> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun serialize<T>(it: T): vector::vector<char> {
|
fun serialize<T>(it: T): vector::vector<char> {
|
||||||
var char_data = conversions::cast_ptr<*T,*char>(&it)
|
var char_data = (&it) cast *char
|
||||||
var toRet = vector::vector<char>()
|
var toRet = vector::vector<char>()
|
||||||
for (var i = 0; i < mem::sizeof<T>(); i++;)
|
for (var i = 0; i < mem::sizeof<T>(); i++;)
|
||||||
toRet.add(char_data[i])
|
toRet.add(char_data[i])
|
||||||
@@ -20,7 +19,7 @@ fun unserialize<T>(it: ref vector::vector<char>): T {
|
|||||||
return unserialize<T>(it, 0).first
|
return unserialize<T>(it, 0).first
|
||||||
}
|
}
|
||||||
fun unserialize<T>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
fun unserialize<T>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
||||||
return util::make_pair(*conversions::cast_ptr<*char,*T>(it.getBackingMemory()+pos), pos + mem::sizeof<T>())
|
return util::make_pair(*(it.getBackingMemory()+pos) cast *T, pos + mem::sizeof<T>())
|
||||||
}
|
}
|
||||||
fun unserialize<T(Serializable)>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
fun unserialize<T(Serializable)>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
||||||
var toRet: T
|
var toRet: T
|
||||||
|
|||||||
@@ -1,27 +1,25 @@
|
|||||||
import simple_print:*
|
import simple_print:*
|
||||||
import conversions:*
|
|
||||||
|
|
||||||
fun main():int {
|
fun main():int {
|
||||||
println(to_char(65))
|
println((65) cast char)
|
||||||
println(to_int('B'))
|
println(('B') cast int)
|
||||||
|
|
||||||
var a = 1337
|
var a = 1337
|
||||||
var b = &a;
|
var b = &a;
|
||||||
var c = (b) cast *char
|
var c = (b) cast *char
|
||||||
|
|
||||||
/*var c = cast_ptr<*int, *char>(b)*/
|
|
||||||
//var d = c + 1
|
//var d = c + 1
|
||||||
//var e = 1 + c
|
//var e = 1 + c
|
||||||
println(to_int(*(c+0)))
|
println((*(c+0)) cast int)
|
||||||
println(to_int(*(c+1)))
|
println((*(c+1)) cast int)
|
||||||
println(to_int(*(c+2)))
|
println((*(c+2)) cast int)
|
||||||
println(to_int(*(c+3)))
|
println((*(c+3)) cast int)
|
||||||
|
|
||||||
println()
|
println()
|
||||||
|
|
||||||
println(to_int(c[0]))
|
println((c[0]) cast int)
|
||||||
println(to_int(c[1]))
|
println((c[1]) cast int)
|
||||||
println(to_int(c[2]))
|
println((c[2]) cast int)
|
||||||
println(to_int(c[3]))
|
println((c[3]) cast int)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user