From: Mike Lowis Date: Thu, 13 Jun 2024 20:24:42 +0000 (-0400) Subject: added stubs for hashes and arrays X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e092e35934275cf16480a1b9f95e42b6d0131629;p=proto%2Fcerise-c.git added stubs for hashes and arrays --- diff --git a/cerise-c.m b/cerise-c.m index aa00b71..e1b7fa7 100644 --- a/cerise-c.m +++ b/cerise-c.m @@ -107,12 +107,12 @@ TestHashOps() Main() { - def foo = [1,2,3] - def bar = foo TestLiterals() TestBoolOps() TestIntOps() TestRealOps() TestStringOps() + TestArrayOps() + TestHashOps() return true } diff --git a/cerise-c.rb b/cerise-c.rb index 633bf84..113f15a 100755 --- a/cerise-c.rb +++ b/cerise-c.rb @@ -1153,28 +1153,18 @@ module Codegen elsif v.value.is_a? String putln state, "Value #{var} = MakeString(#{v.value});" elsif v.value.is_a? Array - putln state, "Value #{var} = MakeArrayOfLength(#{v.value.length});" + putln state, "Value #{var} = MakeArray(#{v.value.length});" v.value.each_with_index do |e, i| val = emit(state, e) - putln state, "Array_SetIndex(#{var}, #{i}, #{val});" + putln state, "Array_Set(#{var}, #{i}, #{val});" end elsif v.value.is_a? Hash -# putln state, "Value #{var} = MakeHash(#{v.value});" - - putln state, "Value #{var} = MakeHashOfLength(#{v.value.length});" + putln state, "Value #{var} = MakeHash(#{v.value.length});" v.value.each do |k, v| val = emit(state, v) - putln state, "Hash_SetIndex(#{var}, MakeString(#{k.value}), #{val});" -# -# -# pp k -# val = emit(state, e) -# putln state, "Array_SetIndex(#{var}, #{i}, #{val});" -# + putln state, "Hash_Set(#{var}, MakeString(#{k.value}), #{val});" end - - else raise "code emitting constants of this type not implemented" end @@ -1208,7 +1198,7 @@ module Codegen lvar = emit(state, v.left) rvar = emit(state, v.right) result = mktemp(state); - putln state, "Value #{result} = ArrayOrHashGet(#{lvar}, #{rvar});" + putln state, "Value #{result} = Object_Get(#{lvar}, #{rvar});" else lvar = emit(state, v.left) rvar = emit(state, v.right) @@ -1274,7 +1264,7 @@ module Codegen object = emit(state, v.name.left) key = emit(state, v.name.right) value = emit(state, v.value) - putln state, "ArrayOrHashSet(#{object}, #{key}, #{value});" + putln state, "Object_Set(#{object}, #{key}, #{value});" else temp = emit(state, v.value) raise "invalid local definition: #{v.name.name}" if not state.locals.index(v.name.name) diff --git a/runtime.h b/runtime.h index 1150cb4..c512780 100644 --- a/runtime.h +++ b/runtime.h @@ -171,19 +171,25 @@ static inline Value MakeString(char* s) { }; } -//static inline Value MakeRecord(int32_t nslots) { -// Value* record = calloc(nslots+1,sizeof(Value)); -// record[0] = MakeInt(nslots); -// return (Value){ .as_uint64 = (NAN_TAG_RECORD | (uintptr_t)record) }; -//} -// -//static inline Value MakeArray(int32_t nslots) { +static inline Value MakeArray(int32_t nslots) { // Value* record = calloc(2,sizeof(Value)); // record[0] = MakeInt(1); // record[1] = MakeInt(nslots); // // record[2] = MakeInt(nslots); // -// return (Value){ .as_uint64 = (NAN_TAG_RECORD | (uintptr_t)record) }; -//} +// return (Value){ .as_uint64 = (NAN_TAG_ARRAY | (uintptr_t)record) }; + return MakeNil(); +} + + +static inline Value MakeHash(int32_t nslots) { +// Value* record = calloc(2,sizeof(Value)); +// record[0] = MakeInt(1); +// record[1] = MakeInt(nslots); // +// record[2] = MakeInt(nslots); // +// return (Value){ .as_uint64 = (NAN_TAG_ARRAY | (uintptr_t)record) }; + return MakeNil(); +} + /* Value Type Conversions *************************************************/ @@ -385,3 +391,33 @@ static inline Value OpNeq(Value left, Value right) { } return result; } + +/* Arrays And Hashes + *************************************************/ +static void Array_Set(Value array, int index, Value value) +{ +} + +static Value Array_Get(Value array, int index) +{ + return MakeNil(); +} + +static void Hash_Set(Value hash, Value key, Value value) +{ +} + +static Value Hash_Get(Value hash, Value key) +{ + return MakeNil(); +} + +static Value Object_Get(Value object, Value key) +{ + return MakeNil(); +} + +static Value Object_Set(Value object, Value key, Value value) +{ + return MakeNil(); +}