Bugfixes, remove the cast_ptr function

This commit is contained in:
Nathan Braswell
2016-04-19 06:04:22 -04:00
parent cf46fb13af
commit 04d2af4168
7 changed files with 29 additions and 57 deletions

2
.gitignore vendored
View File

@@ -22,3 +22,5 @@ kraken
*.c
kraken_bac
kraken_deprecated
bootstrap_kalypso
kraken_bootstrap

View File

@@ -1,17 +1,14 @@
#!/bin/bash
kraken="kraken"
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3)
if [[ $1 == "clean" ]]
then
rm ${kraken}
rm ${kraken}_bac
rm ${kraken}_deprecated
rm -r deprecated_compiler/stdlib
rm deprecated_compiler/krakenGrammer.kgm.comp
rm deprecated_compiler/krakenGrammer.kgm
rm -r deprecated_compiler/build
rm -r deprecated_compiler/build_kraken
rm -rf bootstrap_kalypso
else
if [[ $1 == "backup" ]]
then
@@ -22,6 +19,7 @@ else
rm ${kraken}
rm ${kraken}_bac
rm ${kraken}_deprecated
rm ${kraken}_bootstrap
fi
if [ -s "$kraken" ]
@@ -34,7 +32,10 @@ else
then
if ! [ -s "${kraken}_deprecated" ]
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 krakenGrammer.kgm deprecated_compiler
cp kraken.krak deprecated_compiler
@@ -50,7 +51,10 @@ else
../build/kraken kraken.krak
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
echo "${kraken}_deprecated exists, calling"
fi

View File

@@ -586,11 +586,9 @@ obj c_generator (Object) {
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
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()) &&
( (!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)) ) )
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() + ", " + 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)))))) {
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 {

View File

@@ -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
}

View File

@@ -4,7 +4,6 @@ import string
import mem
import set
import util
import conversions
import serialize
fun regex(in: *char):regex {
@@ -24,7 +23,7 @@ obj regexState (Object) {
return this
}
fun construct(): *regexState {
return construct(conversions::to_char(0))
return construct((0) cast char)
}
fun copy_construct(old:*regexState): void {
character = old->character
@@ -58,7 +57,7 @@ obj regex (Object, Serializable) {
var beginningAndEnd = compile(regexStringIn)
// init our begin, and the end state as the next state of each end
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); })
return this
}

View File

@@ -1,5 +1,4 @@
import vector
import conversions
import mem
import util
@@ -8,7 +7,7 @@ fun serialize<T(Serializable)>(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>()
for (var i = 0; i < mem::sizeof<T>(); 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
}
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> {
var toRet: T

View File

@@ -1,27 +1,25 @@
import simple_print:*
import conversions:*
fun main():int {
println(to_char(65))
println(to_int('B'))
println((65) cast char)
println(('B') cast int)
var a = 1337
var b = &a;
var c = (b) cast *char
/*var c = cast_ptr<*int, *char>(b)*/
//var d = c + 1
//var e = 1 + c
println(to_int(*(c+0)))
println(to_int(*(c+1)))
println(to_int(*(c+2)))
println(to_int(*(c+3)))
println((*(c+0)) cast int)
println((*(c+1)) cast int)
println((*(c+2)) cast int)
println((*(c+3)) cast int)
println()
println(to_int(c[0]))
println(to_int(c[1]))
println(to_int(c[2]))
println(to_int(c[3]))
println((c[0]) cast int)
println((c[1]) cast int)
println((c[2]) cast int)
println((c[3]) cast int)
return 0
}